Skip to content

Commit ca24206

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

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
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: 12 additions & 2 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"
@@ -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 {
@@ -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)