66 "html/template"
77 "net/http"
88 "os"
9+ "slices"
910 "sort"
1011 "strconv"
1112 "strings"
@@ -105,7 +106,7 @@ func main() {
105106 r .GET ("/create" , csh .AuthWrapper (func (c * gin.Context ) {
106107 cl , _ := c .Get ("cshauth" )
107108 claims := cl .(cshAuth.CSHClaims )
108- if ! canVote (claims .UserInfo .Groups , claims .UserInfo .Username , false ) {
109+ if ! canVote (claims .UserInfo .Groups , claims .UserInfo .Username , false , [] string {} ) {
109110 c .HTML (403 , "unauthorized.tmpl" , gin.H {
110111 "Username" : claims .UserInfo .Username ,
111112 "FullName" : claims .UserInfo .FullName ,
@@ -122,7 +123,7 @@ func main() {
122123 r .POST ("/create" , csh .AuthWrapper (func (c * gin.Context ) {
123124 cl , _ := c .Get ("cshauth" )
124125 claims := cl .(cshAuth.CSHClaims )
125- if ! canVote (claims .UserInfo .Groups , claims .UserInfo .Username , false ) {
126+ if ! canVote (claims .UserInfo .Groups , claims .UserInfo .Username , false , [] string {} ) {
126127 c .HTML (403 , "unauthorized.tmpl" , gin.H {
127128 "Username" : claims .UserInfo .Username ,
128129 "FullName" : claims .UserInfo .FullName ,
@@ -152,7 +153,7 @@ func main() {
152153 poll .Options = []string {"Fail" , "Conditional" , "Abstain" }
153154 case "custom" :
154155 poll .Options = []string {}
155- for _ , opt := range strings .Split (c .PostForm ("customOptions" ), "," ) {
156+ for opt := range strings .SplitSeq (c .PostForm ("customOptions" ), "," ) {
156157 poll .Options = append (poll .Options , strings .TrimSpace (opt ))
157158 if ! containsString (poll .Options , "Abstain" ) && (poll .VoteType == database .POLL_TYPE_SIMPLE ) {
158159 poll .Options = append (poll .Options , "Abstain" )
@@ -162,6 +163,12 @@ func main() {
162163 default :
163164 poll .Options = []string {"Pass" , "Fail" , "Abstain" }
164165 }
166+ if poll .Gatekeep {
167+ poll .WaivedUsers = []string {}
168+ for user := range strings .SplitSeq (c .PostForm ("waivedUsers" ), "," ) {
169+ poll .WaivedUsers = append (poll .WaivedUsers , strings .TrimSpace (user ))
170+ }
171+ }
165172
166173 pollId , err := database .CreatePoll (c , poll )
167174 if err != nil {
@@ -185,7 +192,7 @@ func main() {
185192 }
186193
187194 // If the user can't vote, just show them results
188- if ! canVote (claims .UserInfo .Groups , claims .UserInfo .Username , poll .Gatekeep ) {
195+ if ! canVote (claims .UserInfo .Groups , claims .UserInfo .Username , poll .Gatekeep , poll . WaivedUsers ) {
189196 c .Redirect (302 , "/results/" + poll .Id )
190197 return
191198 }
@@ -235,7 +242,7 @@ func main() {
235242 return
236243 }
237244
238- if ! canVote (claims .UserInfo .Groups , claims .UserInfo .Username , poll .Gatekeep ) {
245+ if ! canVote (claims .UserInfo .Groups , claims .UserInfo .Username , poll .Gatekeep , poll . WaivedUsers ) {
239246 c .HTML (403 , "unauthorized.tmpl" , gin.H {
240247 "Username" : claims .UserInfo .Username ,
241248 "FullName" : claims .UserInfo .FullName ,
@@ -528,7 +535,10 @@ type Result struct {
528535 T_Seminars int `json:"t_seminars"`
529536}
530537
531- func canVote (groups []string , username string , gatekeepEnforcedPoll bool ) bool {
538+ func canVote (groups []string , username string , gatekeepEnforcedPoll bool , waivedUsers []string ) bool {
539+ if slices .Contains (waivedUsers , username ) {
540+ return true
541+ }
532542 var active , fallCoop , springCoop bool
533543 for _ , group := range groups {
534544 if group == "active" {
0 commit comments