Skip to content

Commit e120fb7

Browse files
committed
Make hidden act as progressIsSecret
1 parent 6db11af commit e120fb7

File tree

4 files changed

+4
-59
lines changed

4 files changed

+4
-59
lines changed

database/poll.go

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,11 @@ type Poll struct {
2121
Gatekeep bool `bson:"gatekeep"`
2222
QuorumType float64 `bson:"quorumType"`
2323
AllowedUsers []string `bson:"allowedUsers"`
24-
Hidden bool `bson:"hidden"`
2524
AllowWriteIns bool `bson:"writeins"`
2625

2726
// Prevent this poll from having progress displayed
2827
// This is important for events like elections where the results shouldn't be visible mid vote
29-
SecretProgress bool `bson:"secretProgress"`
28+
Hidden bool `bson:"hidden"`
3029
}
3130

3231
const POLL_TYPE_SIMPLE = "simple"
@@ -73,50 +72,6 @@ func (poll *Poll) Hide(ctx context.Context) error {
7372
return nil
7473
}
7574

76-
func (poll *Poll) Reveal(ctx context.Context) error {
77-
ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
78-
defer cancel()
79-
80-
objId, _ := primitive.ObjectIDFromHex(poll.Id)
81-
82-
_, err := Client.Database(db).Collection("polls").UpdateOne(ctx, map[string]interface{}{"_id": objId}, map[string]interface{}{"$set": map[string]interface{}{"hidden": false}})
83-
if err != nil {
84-
return err
85-
}
86-
87-
return nil
88-
}
89-
90-
// This is currently unused, if you make a poll you're committing to if it's secret or not
91-
func (poll *Poll) MakeProgressSecret(ctx context.Context) error {
92-
ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
93-
defer cancel()
94-
95-
objId, _ := primitive.ObjectIDFromHex(poll.Id)
96-
97-
_, err := Client.Database(db).Collection("polls").UpdateOne(ctx, map[string]interface{}{"_id": objId}, map[string]interface{}{"$set": map[string]interface{}{"secretProgress": true}})
98-
if err != nil {
99-
return err
100-
}
101-
102-
return nil
103-
}
104-
105-
// This is currently unused, if you make a poll you're committing to if it's secret or not
106-
func (poll *Poll) RevealProgress(ctx context.Context) error {
107-
ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
108-
defer cancel()
109-
110-
objId, _ := primitive.ObjectIDFromHex(poll.Id)
111-
112-
_, err := Client.Database(db).Collection("polls").UpdateOne(ctx, map[string]interface{}{"_id": objId}, map[string]interface{}{"$set": map[string]interface{}{"secretProgress": false}})
113-
if err != nil {
114-
return err
115-
}
116-
117-
return nil
118-
}
119-
12075
func CreatePoll(ctx context.Context, poll *Poll) (string, error) {
12176
ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
12277
defer cancel()

main.go

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,9 @@ func main() {
158158
OpenedTime: time.Now(),
159159
Open: true,
160160
QuorumType: quorum,
161-
Hidden: false,
162161
Gatekeep: c.PostForm("gatekeep") == "true",
163162
AllowWriteIns: c.PostForm("allowWriteIn") == "true",
164-
SecretProgress: c.PostForm("secretProgress") == "true",
163+
Hidden: c.PostForm("hidden") == "true",
165164
}
166165
if c.PostForm("rankedChoice") == "true" {
167166
poll.VoteType = database.POLL_TYPE_RANKED
@@ -394,14 +393,6 @@ func main() {
394393
return
395394
}
396395

397-
if poll.Hidden && poll.CreatedBy != claims.UserInfo.Username {
398-
c.HTML(403, "hidden.tmpl", gin.H{
399-
"Username": claims.UserInfo.Username,
400-
"FullName": claims.UserInfo.FullName,
401-
})
402-
return
403-
}
404-
405396
results, err := poll.GetResult(c)
406397
if err != nil {
407398
c.JSON(500, gin.H{"error": err.Error()})
@@ -421,7 +412,6 @@ func main() {
421412
"Results": results,
422413
"IsOpen": poll.Open,
423414
"IsHidden": poll.Hidden,
424-
"ProgressIsSecret": poll.SecretProgress,
425415
"CanModify": canModify,
426416
"Username": claims.UserInfo.Username,
427417
"FullName": claims.UserInfo.FullName,

templates/create.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
<div class="form-group">
7676
<input
7777
type="checkbox"
78-
name="secretProgress"
78+
name="hidden"
7979
value="true"
8080
>
8181
<span>Hide Results Till Vote is Complete</span>

templates/result.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
<br />
3434
<br />
3535

36-
{{ if $.ProgressIsSecret }}
36+
{{ if and $.IsHidden $.IsOpen }}
3737
<div id="results">
3838
<h4>Results will be available once the poll closes</h4>
3939
</div>

0 commit comments

Comments
 (0)