@@ -30,19 +30,20 @@ var CONDITIONAL_GATEKEEP_URL = os.Getenv("VOTE_CONDITIONAL_URL")
3030var VOTE_HOST = os .Getenv ("VOTE_HOST" )
3131
3232// Dev mode flags
33- var DEV_DISABLE_ACTIVE_FILTERS bool = os .Getenv ("DEV_DISABLE_ACTIVE_FILTERS" ) == "true"
34- var DEV_FORCE_IS_EVALS bool = os .Getenv ("DEV_FORCE_IS_EVALS" ) == "true"
33+ var DEV_DISABLE_ACTIVE_FILTERS = os .Getenv ("DEV_DISABLE_ACTIVE_FILTERS" ) == "true"
34+ var DEV_FORCE_IS_EVALS = os .Getenv ("DEV_FORCE_IS_EVALS" ) == "true"
35+ var DEV_FORCE_IS_CHAIR = os .Getenv ("DEV_FORCE_IS_CHAIR" ) == "true"
3536
3637func inc (x int ) string {
3738 return strconv .Itoa (x + 1 )
3839}
3940
40- // Gets the number of people eligible to vote in a poll
41+ // GetVoterCount Gets the number of people eligible to vote in a poll
4142func GetVoterCount (poll database.Poll ) int {
4243 return len (poll .AllowedUsers )
4344}
4445
45- // Calculates the number of votes required for quorum in a poll
46+ // CalculateQuorum Calculates the number of votes required for quorum in a poll
4647func CalculateQuorum (poll database.Poll ) int {
4748 voterCount := GetVoterCount (poll )
4849 return int (math .Ceil (float64 (voterCount ) * poll .QuorumType ))
@@ -111,23 +112,6 @@ func main() {
111112 return polls [i ].Id > polls [j ].Id
112113 })
113114
114- closedPolls , err := database .GetClosedVotedPolls (c , claims .UserInfo .Username )
115- if err != nil {
116- c .JSON (http .StatusInternalServerError , gin.H {"error" : err .Error ()})
117- return
118- }
119- ownedPolls , err := database .GetClosedOwnedPolls (c , claims .UserInfo .Username )
120- if err != nil {
121- c .JSON (http .StatusInternalServerError , gin.H {"error" : err .Error ()})
122- return
123- }
124- closedPolls = append (closedPolls , ownedPolls ... )
125-
126- sort .Slice (closedPolls , func (i , j int ) bool {
127- return closedPolls [i ].Id > closedPolls [j ].Id
128- })
129- closedPolls = uniquePolls (closedPolls )
130-
131115 c .HTML (http .StatusOK , "index.tmpl" , gin.H {
132116 "Polls" : polls ,
133117 "Username" : claims .UserInfo .Username ,
@@ -216,8 +200,19 @@ func main() {
216200 AllowWriteIns : c .PostForm ("allowWriteIn" ) == "true" ,
217201 Hidden : c .PostForm ("hidden" ) == "true" ,
218202 }
219- if c .PostForm ("rankedChoice" ) == "true" {
203+ switch c .PostForm ("pollType" ) {
204+ case "rankedChoice" :
220205 poll .VoteType = database .POLL_TYPE_RANKED
206+ case "eboard" :
207+ eboard := oidcClient .GetEBoard ()
208+ var usernames []string
209+ for _ , member := range eboard {
210+ usernames = append (usernames , member .Username )
211+ }
212+ poll .AllowedUsers = usernames
213+ poll .AllowWriteIns = false
214+ poll .Hidden = true
215+ poll .Gatekeep = false
221216 }
222217
223218 switch c .PostForm ("options" ) {
@@ -229,7 +224,7 @@ func main() {
229224 poll .Options = []string {}
230225 for opt := range strings .SplitSeq (c .PostForm ("customOptions" ), "," ) {
231226 poll .Options = append (poll .Options , strings .TrimSpace (opt ))
232- if ! containsString (poll .Options , "Abstain" ) && (poll .VoteType == database .POLL_TYPE_SIMPLE ) {
227+ if ! slices . Contains (poll .Options , "Abstain" ) && (poll .VoteType == database .POLL_TYPE_SIMPLE ) {
233228 poll .Options = append (poll .Options , "Abstain" )
234229 }
235230 }
@@ -283,7 +278,7 @@ func main() {
283278 writeInAdj = 1
284279 }
285280
286- canModify := containsString (claims .UserInfo .Groups , "active_rtp" ) || containsString (claims .UserInfo .Groups , "eboard" ) || poll .CreatedBy == claims .UserInfo .Username
281+ canModify := slices . Contains (claims .UserInfo .Groups , "active_rtp" ) || slices . Contains (claims .UserInfo .Groups , "eboard" ) || poll .CreatedBy == claims .UserInfo .Username
287282
288283 c .HTML (200 , "poll.tmpl" , gin.H {
289284 "Id" : poll .Id ,
@@ -448,7 +443,7 @@ func main() {
448443 return
449444 }
450445
451- canModify := containsString (claims .UserInfo .Groups , "active_rtp" ) || containsString (claims .UserInfo .Groups , "eboard" ) || poll .CreatedBy == claims .UserInfo .Username
446+ canModify := slices . Contains (claims .UserInfo .Groups , "active_rtp" ) || slices . Contains (claims .UserInfo .Groups , "eboard" ) || poll .CreatedBy == claims .UserInfo .Username
452447
453448 votesNeededForQuorum := int (poll .QuorumType * float64 (len (poll .AllowedUsers )))
454449 c .HTML (http .StatusOK , "result.tmpl" , gin.H {
@@ -525,8 +520,7 @@ func main() {
525520 }
526521
527522 if poll .CreatedBy != claims .UserInfo .Username {
528- if containsString (claims .UserInfo .Groups , "active_rtp" ) || containsString (claims .UserInfo .Groups , "eboard" ) {
529- } else {
523+ if ! (slices .Contains (claims .UserInfo .Groups , "active_rtp" ) || slices .Contains (claims .UserInfo .Groups , "eboard" )) {
530524 c .JSON (http .StatusForbidden , gin.H {"error" : "You cannot end this poll." })
531525 return
532526 }
@@ -563,7 +557,11 @@ func main() {
563557
564558// isEvals determines if the current user is evals, allowing for a dev mode override
565559func isEvals (user cshAuth.CSHUserInfo ) bool {
566- return DEV_FORCE_IS_EVALS || containsString (user .Groups , "eboard-evaluations" )
560+ return DEV_FORCE_IS_EVALS || slices .Contains (user .Groups , "eboard-evaluations" )
561+ }
562+
563+ func isChair (user cshAuth.CSHUserInfo ) bool {
564+ return DEV_FORCE_IS_CHAIR || slices .Contains (user .Groups , "eboard-chairman" )
567565}
568566
569567// canVote determines whether a user can cast a vote.
@@ -618,12 +616,3 @@ func hasOption(poll *database.Poll, option string) bool {
618616 }
619617 return false
620618}
621-
622- func containsString (arr []string , val string ) bool {
623- for _ , a := range arr {
624- if a == val {
625- return true
626- }
627- }
628- return false
629- }
0 commit comments