Skip to content

Commit 37e9a22

Browse files
committed
frontend works, backend impl
1 parent fbbea77 commit 37e9a22

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

database/poll.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type Poll struct {
1818
Options []string `bson:"options"`
1919
Open bool `bson:"open"`
2020
Gatekeep bool `bson:"gatekeep"`
21+
WaivedUsers []string `bson:"waivedUsers"`
2122
Hidden bool `bson:"hidden"`
2223
AllowWriteIns bool `bson:"writeins"`
2324
}

main.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
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" {

templates/create.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,12 @@
8383
/>
8484
<option value="gatekeep" selected>Gatekeep Required</option>
8585
</select>
86-
<div style="display:none;" id="waivedUsers" class="form-group">
86+
<div id="waivedUsers" class="form-group">
8787
<input
8888
type="text"
8989
name="waivedUsers"
9090
class="form-control"
91-
placeholder="Waive Usernames (Comma-separated)"
91+
placeholder="Waive Usernames (Comma-separated, NO Whitespace)"
9292
/>
9393
</div>
9494
<input type="submit" class="btn btn-primary" value="Create" />

0 commit comments

Comments
 (0)