@@ -30,20 +30,19 @@ 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 = 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"
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"
3635
3736func inc (x int ) string {
3837 return strconv .Itoa (x + 1 )
3938}
4039
41- // GetVoterCount Gets the number of people eligible to vote in a poll
40+ // Gets the number of people eligible to vote in a poll
4241func GetVoterCount (poll database.Poll ) int {
4342 return len (poll .AllowedUsers )
4443}
4544
46- // CalculateQuorum Calculates the number of votes required for quorum in a poll
45+ // Calculates the number of votes required for quorum in a poll
4746func CalculateQuorum (poll database.Poll ) int {
4847 voterCount := GetVoterCount (poll )
4948 return int (math .Ceil (float64 (voterCount ) * poll .QuorumType ))
@@ -96,12 +95,15 @@ func main() {
9695 r .GET ("/auth/callback" , csh .AuthCallback )
9796 r .GET ("/auth/logout" , csh .AuthLogout )
9897
98+ r .GET ("/eboard" , csh .AuthWrapper (HandleGetEboardVote ))
99+ r .POST ("/eboard" , csh .AuthWrapper (HandlePostEboardVote ))
100+ r .POST ("/eboard/manage" , csh .AuthWrapper (HandleManageEboardVote ))
101+
99102 // TODO: change ALL the response codes to use http.(actual description)
100103 r .GET ("/" , csh .AuthWrapper (func (c * gin.Context ) {
101- cl , _ := c .Get ("cshauth" )
102- claims := cl .(cshAuth.CSHClaims )
103104 // This is intentionally left unprotected
104105 // A user may be unable to vote but should still be able to see a list of polls
106+ user := getUserData (c )
105107
106108 polls , err := database .GetOpenPolls (c )
107109 if err != nil {
@@ -114,8 +116,9 @@ func main() {
114116
115117 c .HTML (http .StatusOK , "index.tmpl" , gin.H {
116118 "Polls" : polls ,
117- "Username" : claims .UserInfo .Username ,
118- "FullName" : claims .UserInfo .FullName ,
119+ "Username" : user .Username ,
120+ "FullName" : user .FullName ,
121+ "EBoard" : slices .Contains (user .Groups , "eboard" ),
119122 })
120123 }))
121124
@@ -200,19 +203,8 @@ func main() {
200203 AllowWriteIns : c .PostForm ("allowWriteIn" ) == "true" ,
201204 Hidden : c .PostForm ("hidden" ) == "true" ,
202205 }
203- switch c .PostForm ("pollType" ) {
204- case "rankedChoice" :
206+ if c .PostForm ("rankedChoice" ) == "true" {
205207 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
216208 }
217209
218210 switch c .PostForm ("options" ) {
@@ -361,6 +353,7 @@ func main() {
361353
362354 vote .Options [option ] = optionRank
363355 }
356+
364357 // process write-in
365358 if c .PostForm ("writeinOption" ) != "" && c .PostForm ("writein" ) != "" {
366359 for candidate := range vote .Options {
@@ -380,8 +373,8 @@ func main() {
380373 }
381374 vote .Options [c .PostForm ("writeinOption" )] = rank
382375 }
383- // Perform checks, vote does not change beyond this
384376
377+ // Perform checks, vote does not change beyond this
385378 optionCount := len (vote .Options )
386379 voted := make ([]bool , optionCount )
387380
@@ -394,6 +387,10 @@ func main() {
394387 // Duplicate ranks and range check
395388 for _ , rank := range vote .Options {
396389 if rank > 0 && rank <= optionCount {
390+ if rank > optionCount {
391+ c .JSON (http .StatusBadRequest , gin.H {"error" : "Rank choice is more than the amount of candidates ranked" })
392+ return
393+ }
397394 if voted [rank - 1 ] {
398395 c .JSON (http .StatusBadRequest , gin.H {"error" : "You ranked two or more candidates at the same level" })
399396 return
@@ -562,10 +559,6 @@ func isEvals(user cshAuth.CSHUserInfo) bool {
562559 return DEV_FORCE_IS_EVALS || slices .Contains (user .Groups , "eboard-evaluations" )
563560}
564561
565- func isChair (user cshAuth.CSHUserInfo ) bool {
566- return DEV_FORCE_IS_CHAIR || slices .Contains (user .Groups , "eboard-chairman" )
567- }
568-
569562// canVote determines whether a user can cast a vote.
570563//
571564// returns an integer value: 0 is success, 1 is database error, 3 is not active, 4 is gatekept, 9 is already voted
@@ -591,6 +584,12 @@ func canVote(user cshAuth.CSHUserInfo, poll database.Poll, allowedUsers []string
591584 return 0
592585}
593586
587+ func getUserData (c * gin.Context ) cshAuth.CSHUserInfo {
588+ cl , _ := c .Get ("cshauth" )
589+ user := cl .(cshAuth.CSHClaims ).UserInfo
590+ return user
591+ }
592+
594593func uniquePolls (polls []* database.Poll ) []* database.Poll {
595594 var unique []* database.Poll
596595 for _ , poll := range polls {
0 commit comments