Skip to content
Open

Dev #56

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/workflows/sonarqube.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: SonarQube

on:
push:
branches:
- dev


jobs:
build:
name: Build and analyze
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: SonarSource/sonarqube-scan-action@v6
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
8 changes: 7 additions & 1 deletion constitutional.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,14 @@ func EvaluatePolls() {
logging.Logger.WithFields(logrus.Fields{"method": "EvaluatePolls close"}).Error(err)
continue
}
announceStr := "The vote \"" + poll.ShortDescription + "\" has closed."
if !poll.Hidden {
announceStr += " Check out the results at " + pollLink
} else {
announceStr += " Results will be posted shortly."
}
_, _, _, err = slackData.Client.SendMessage(slackData.AnnouncementsChannel,
slack.MsgOptionText("The vote \""+poll.ShortDescription+"\" has closed. Check out the results at "+pollLink, false))
slack.MsgOptionText(announceStr, false))
if err != nil {
logging.Logger.WithFields(logrus.Fields{"method": "EvaluatePolls announce"}).Error(err)
}
Expand Down
1 change: 0 additions & 1 deletion database/poll.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,6 @@ func (poll *Poll) GetResult(ctx context.Context) ([]map[string]int, error) {
// In that case, it's a tie?
if val != minVote {
end = false
break
}
}
if end {
Expand Down
41 changes: 27 additions & 14 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func main() {
r.GET("/auth/callback", csh.AuthCallback)
r.GET("/auth/logout", csh.AuthLogout)

// TODO: change ALL the response codes to use http.(actual description)
r.GET("/", csh.AuthWrapper(func(c *gin.Context) {
cl, _ := c.Get("cshauth")
claims := cl.(cshAuth.CSHClaims)
Expand Down Expand Up @@ -298,8 +299,23 @@ func main() {
UserId: claims.UserInfo.Username,
}

maxNum := len(poll.Options)
voted := make([]bool, maxNum)
fmt.Println(poll.Options)

for _, option := range poll.Options {
optionRankStr := c.PostForm(option)
optionRank, err := strconv.Atoi(optionRankStr)

if len(optionRankStr) < 1 {
continue
}
if err != nil {
c.JSON(400, gin.H{"error": "non-number ranking"})
return
}

vote.Options[option] = optionRank
}

// process write-in
if c.PostForm("writeinOption") != "" && c.PostForm("writein") != "" {
for candidate := range vote.Options {
Expand All @@ -318,27 +334,24 @@ func main() {
return
}
vote.Options[c.PostForm("writeinOption")] = rank
maxNum += 1 //you can rank all options in the poll PLUS one
}

for _, opt := range poll.Options {
option := c.PostForm(opt)
rank, err := strconv.Atoi(option)
if len(option) < 1 {
continue
}
if err != nil {
c.JSON(400, gin.H{"error": "non-number ranking"})
return
}
maxNum := len(vote.Options)
voted := make([]bool, maxNum)

for _, rank := range vote.Options {
if rank > 0 && rank <= maxNum {
vote.Options[opt] = rank
if voted[rank-1] {
c.JSON(400, gin.H{"error": "You ranked two or more candidates at the same level"})
return
}
voted[rank-1] = true
} else {
c.JSON(400, gin.H{"error": fmt.Sprintf("votes must be from 1 - %d", maxNum)})
return
}
}

rankedCandidates := len(vote.Options)
for _, voteOpt := range vote.Options {
if voteOpt > rankedCandidates {
Expand Down
1 change: 1 addition & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sonar.projectKey=ComputerScienceHouse_vote_c5ba863d-30d7-4fa9-97dd-4f2c58f8f5fa