@@ -38,15 +38,31 @@ func GetHomepage(c *gin.Context) {
3838 // A user may be unable to vote but should still be able to see a list of polls
3939 user := GetUserData (c )
4040
41- polls , err := database .GetOpenPolls (c )
41+ pollResults , err := database .GetOpenPolls (c )
4242 if err != nil {
4343 c .JSON (http .StatusInternalServerError , gin.H {"error" : err .Error ()})
4444 return
4545 }
46- sort .Slice (polls , func (i , j int ) bool {
47- return polls [i ].Id > polls [j ].Id
46+ sort .Slice (pollResults , func (i , j int ) bool {
47+ return pollResults [i ].Id > pollResults [j ].Id
4848 })
4949
50+ polls := []* database.Poll {}
51+
52+ for i := range pollResults {
53+ poll := pollResults [i ]
54+
55+ if poll .HideForIneligible {
56+ canVoteResult := canVote (user , * poll , poll .AllowedUsers )
57+
58+ if canVoteResult != 0 && canVoteResult != 9 {
59+ continue
60+ }
61+ }
62+
63+ polls = append (polls , pollResults [i ])
64+ }
65+
5066 c .HTML (http .StatusOK , "index.tmpl" , gin.H {
5167 "Polls" : polls ,
5268 "Username" : user .Username ,
@@ -151,17 +167,18 @@ func CreatePoll(c *gin.Context) {
151167 quorum = quorum / 100
152168
153169 poll := & database.Poll {
154- Id : "" ,
155- CreatedBy : user .Username ,
156- Title : c .PostForm ("title" ),
157- Description : c .PostForm ("description" ),
158- VoteType : database .POLL_TYPE_SIMPLE ,
159- OpenedTime : time .Now (),
160- Open : true ,
161- QuorumType : quorum ,
162- Gatekeep : c .PostForm ("gatekeep" ) == "true" ,
163- AllowWriteIns : c .PostForm ("allowWriteIn" ) == "true" ,
164- Hidden : c .PostForm ("hidden" ) == "true" ,
170+ Id : "" ,
171+ CreatedBy : user .Username ,
172+ Title : c .PostForm ("title" ),
173+ Description : c .PostForm ("description" ),
174+ VoteType : database .POLL_TYPE_SIMPLE ,
175+ OpenedTime : time .Now (),
176+ Open : true ,
177+ QuorumType : quorum ,
178+ Gatekeep : c .PostForm ("gatekeep" ) == "true" ,
179+ AllowWriteIns : c .PostForm ("allowWriteIn" ) == "true" ,
180+ Hidden : c .PostForm ("hidden" ) == "true" ,
181+ HideForIneligible : c .PostForm ("hideIneligible" ) == "true" ,
165182 }
166183 if c .PostForm ("rankedChoice" ) == "true" {
167184 poll .VoteType = database .POLL_TYPE_RANKED
@@ -253,6 +270,19 @@ func GetPollResults(c *gin.Context) {
253270
254271 canModify := IsActiveRTP (user ) || IsEboard (user ) || ownsPoll (poll , user )
255272
273+ if poll .HideForIneligible {
274+ canVoteResult := canVote (user , * poll , poll .AllowedUsers )
275+
276+ if canVoteResult != 0 && canVoteResult != 9 {
277+ c .HTML (http .StatusForbidden , "unauthorized.tmpl" , gin.H {
278+ "Username" : user .Username ,
279+ "FullName" : user .FullName ,
280+ "EBoard" : IsEboard (user ),
281+ })
282+ return
283+ }
284+ }
285+
256286 if poll .Hidden && poll .Open {
257287 c .HTML (http .StatusUnauthorized , "hidden.tmpl" , gin.H {
258288 "Id" : poll .Id ,
0 commit comments