|
5 | 5 | "encoding/json" |
6 | 6 | "fmt" |
7 | 7 | "html/template" |
| 8 | + "math" |
8 | 9 | "net/http" |
9 | 10 | "os" |
10 | 11 | "slices" |
@@ -35,6 +36,17 @@ func inc(x int) string { |
35 | 36 | return strconv.Itoa(x + 1) |
36 | 37 | } |
37 | 38 |
|
| 39 | +// Gets the number of people eligible to vote in a poll |
| 40 | +func GetVoterCount(poll database.Poll) int { |
| 41 | + return len(poll.AllowedUsers) |
| 42 | +} |
| 43 | + |
| 44 | +// Calculates the number of votes required for quorum in a poll |
| 45 | +func CalculateQuorum(poll database.Poll) int { |
| 46 | + voterCount := GetVoterCount(poll) |
| 47 | + return int(math.Ceil(float64(voterCount) * poll.QuorumType)) |
| 48 | +} |
| 49 | + |
38 | 50 | func MakeLinks(s string) template.HTML { |
39 | 51 | rx := xurls.Strict() |
40 | 52 | s = template.HTMLEscapeString(s) |
@@ -68,11 +80,11 @@ func main() { |
68 | 80 | oidcClient.setupOidcClient(os.Getenv("VOTE_OIDC_ID"), os.Getenv("VOTE_OIDC_SECRET")) |
69 | 81 | InitConstitution() |
70 | 82 |
|
71 | | - if (DEV_DISABLE_ACTIVE_FILTERS) { |
| 83 | + if DEV_DISABLE_ACTIVE_FILTERS { |
72 | 84 | logging.Logger.WithFields(logrus.Fields{"method": "main init"}).Warning("Dev disable active filters is set!") |
73 | 85 | } |
74 | 86 |
|
75 | | - if (DEV_FORCE_IS_EVALS) { |
| 87 | + if DEV_FORCE_IS_EVALS { |
76 | 88 | logging.Logger.WithFields(logrus.Fields{"method": "main init"}).Warning("Dev force evals is set!") |
77 | 89 | } |
78 | 90 |
|
@@ -169,7 +181,7 @@ func main() { |
169 | 181 | VoteType: database.POLL_TYPE_SIMPLE, |
170 | 182 | OpenedTime: time.Now(), |
171 | 183 | Open: true, |
172 | | - QuorumType: quorum, |
| 184 | + QuorumType: float64(quorum), |
173 | 185 | Gatekeep: c.PostForm("gatekeep") == "true", |
174 | 186 | AllowWriteIns: c.PostForm("allowWriteIn") == "true", |
175 | 187 | Hidden: c.PostForm("hidden") == "true", |
@@ -408,18 +420,22 @@ func main() { |
408 | 420 |
|
409 | 421 | canModify := containsString(claims.UserInfo.Groups, "active_rtp") || containsString(claims.UserInfo.Groups, "eboard") || poll.CreatedBy == claims.UserInfo.Username |
410 | 422 |
|
| 423 | + votesNeededForQuorum := int(poll.QuorumType * float64(len(poll.AllowedUsers))) |
411 | 424 | c.HTML(200, "result.tmpl", gin.H{ |
412 | | - "Id": poll.Id, |
413 | | - "ShortDescription": poll.ShortDescription, |
414 | | - "LongDescription": poll.LongDescription, |
415 | | - "VoteType": poll.VoteType, |
416 | | - "Results": results, |
417 | | - "IsOpen": poll.Open, |
418 | | - "IsHidden": poll.Hidden, |
419 | | - "CanModify": canModify, |
420 | | - "Username": claims.UserInfo.Username, |
421 | | - "FullName": claims.UserInfo.FullName, |
422 | | - "Gatekeep": poll.Gatekeep, |
| 425 | + "Id": poll.Id, |
| 426 | + "ShortDescription": poll.ShortDescription, |
| 427 | + "LongDescription": poll.LongDescription, |
| 428 | + "VoteType": poll.VoteType, |
| 429 | + "Results": results, |
| 430 | + "IsOpen": poll.Open, |
| 431 | + "IsHidden": poll.Hidden, |
| 432 | + "CanModify": canModify, |
| 433 | + "Username": claims.UserInfo.Username, |
| 434 | + "FullName": claims.UserInfo.FullName, |
| 435 | + "Gatekeep": poll.Gatekeep, |
| 436 | + "Quorum": strconv.FormatFloat(poll.QuorumType*100.0, 'f', 0, 64), |
| 437 | + "EligibleVoters": poll.AllowedUsers, |
| 438 | + "VotesNeededForQuorum": votesNeededForQuorum, |
423 | 439 | }) |
424 | 440 | })) |
425 | 441 |
|
|
0 commit comments