Skip to content
Merged
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
8 changes: 3 additions & 5 deletions constitutional.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"context"
"fmt"
"math"
"os"
"strings"
"time"
Expand Down Expand Up @@ -99,10 +98,9 @@ func EvaluatePolls() {
if poll.OpenedTime.AddDate(0, 0, 2).After(now) {
continue
}
//Two-Thirds Quorum
voterCount := len(poll.AllowedUsers)
//fuckass rounding
quorum := int(math.Ceil(float64(voterCount) * poll.QuorumType))

quorum := CalculateQuorum(*poll)

notVoted := make([]*OIDCUser, 0)
votedCount := 0
// check all voters to see if they have voted
Expand Down
1 change: 0 additions & 1 deletion database/poll.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ func CreatePoll(ctx context.Context, poll *Poll) (string, error) {
if err != nil {
return "", err
}

return result.InsertedID.(primitive.ObjectID).Hex(), nil
}

Expand Down
44 changes: 30 additions & 14 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"html/template"
"math"
"net/http"
"os"
"slices"
Expand Down Expand Up @@ -35,6 +36,17 @@ func inc(x int) string {
return strconv.Itoa(x + 1)
}

// Gets the number of people eligible to vote in a poll
func GetVoterCount(poll database.Poll) int {
return len(poll.AllowedUsers)
}

// Calculates the number of votes required for quorum in a poll
func CalculateQuorum(poll database.Poll) int {
voterCount := GetVoterCount(poll)
return int(math.Ceil(float64(voterCount) * poll.QuorumType))
}

func MakeLinks(s string) template.HTML {
rx := xurls.Strict()
s = template.HTMLEscapeString(s)
Expand Down Expand Up @@ -68,11 +80,11 @@ func main() {
oidcClient.setupOidcClient(os.Getenv("VOTE_OIDC_ID"), os.Getenv("VOTE_OIDC_SECRET"))
InitConstitution()

if (DEV_DISABLE_ACTIVE_FILTERS) {
if DEV_DISABLE_ACTIVE_FILTERS {
logging.Logger.WithFields(logrus.Fields{"method": "main init"}).Warning("Dev disable active filters is set!")
}

if (DEV_FORCE_IS_EVALS) {
if DEV_FORCE_IS_EVALS {
logging.Logger.WithFields(logrus.Fields{"method": "main init"}).Warning("Dev force evals is set!")
}

Expand Down Expand Up @@ -169,7 +181,7 @@ func main() {
VoteType: database.POLL_TYPE_SIMPLE,
OpenedTime: time.Now(),
Open: true,
QuorumType: quorum,
QuorumType: float64(quorum),
Gatekeep: c.PostForm("gatekeep") == "true",
AllowWriteIns: c.PostForm("allowWriteIn") == "true",
Hidden: c.PostForm("hidden") == "true",
Expand Down Expand Up @@ -408,18 +420,22 @@ func main() {

canModify := containsString(claims.UserInfo.Groups, "active_rtp") || containsString(claims.UserInfo.Groups, "eboard") || poll.CreatedBy == claims.UserInfo.Username

votesNeededForQuorum := int(poll.QuorumType * float64(len(poll.AllowedUsers)))
c.HTML(200, "result.tmpl", gin.H{
"Id": poll.Id,
"ShortDescription": poll.ShortDescription,
"LongDescription": poll.LongDescription,
"VoteType": poll.VoteType,
"Results": results,
"IsOpen": poll.Open,
"IsHidden": poll.Hidden,
"CanModify": canModify,
"Username": claims.UserInfo.Username,
"FullName": claims.UserInfo.FullName,
"Gatekeep": poll.Gatekeep,
"Id": poll.Id,
"ShortDescription": poll.ShortDescription,
"LongDescription": poll.LongDescription,
"VoteType": poll.VoteType,
"Results": results,
"IsOpen": poll.Open,
"IsHidden": poll.Hidden,
"CanModify": canModify,
"Username": claims.UserInfo.Username,
"FullName": claims.UserInfo.FullName,
"Gatekeep": poll.Gatekeep,
"Quorum": strconv.FormatFloat(poll.QuorumType*100.0, 'f', 0, 64),
"EligibleVoters": poll.AllowedUsers,
"VotesNeededForQuorum": votesNeededForQuorum,
})
}))

Expand Down
15 changes: 15 additions & 0 deletions templates/result.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,21 @@
<h4>Results will be available once the poll closes</h4>
</div>
{{ else }}
{{/* Displays information about required quorum and number of voters */}}
<div id="quorum-info">
<h5>Number of Eligible Voters: {{ len .EligibleVoters }}</h5>
<div id="votes-needed-for-quorum">
{{/* This works currently because quorum type can only be set if gatekeep is required */}}
{{ if not .Gatekeep }}
<h5>No quorum required for this poll.</h5>
{{ else }}
<h5>Quorum Type: {{ .Quorum }}%</h5>
<h5>Votes Needed For Quorum: {{ .VotesNeededForQuorum }}</h5>
{{ end }}
<br/>
<br/>
</div>
</div>
<div id="results">
{{ range $i, $val := .Results }}
{{ if eq $.VoteType "ranked" }}
Expand Down