Skip to content

Commit

Permalink
Hide votedIDs (#125)
Browse files Browse the repository at this point in the history
Hide voted_id from ongoing polls
  • Loading branch information
ostcar committed Mar 4, 2021
1 parent fcbcfb8 commit b778a16
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 26 deletions.
11 changes: 9 additions & 2 deletions internal/apps/poll/restrict.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ import (
"github.com/OpenSlides/openslides3-autoupdate-service/internal/restricter"
)

// StatePublished is the state of a poll, when it is published.
const StatePublished = 4
// StateFinished and StatePublished are state ids of polls.
const (
StateFinished = 3
StatePublished = 4
)

// RestrictPoll restricts an element for an assignment or motion poll.
func RestrictPoll(r restricter.HasPermer, canSee, canManage string, restrictedFiels []string) restricter.ElementFunc {
Expand Down Expand Up @@ -69,6 +72,10 @@ func RestrictPoll(r restricter.HasPermer, canSee, canManage string, restrictedFi
return nil, fmt.Errorf("unmarshal poll state: %w", err)
}

if state != StatePublished && state != StateFinished {
delete(poll, "voted_id")
}

// Delete some fields for no managers and unpublished polls.
if !(r.HasPerm(uid, canManage) || state == StatePublished) {
delete(poll, "votesvalid")
Expand Down
12 changes: 0 additions & 12 deletions internal/test/export.json
Original file line number Diff line number Diff line change
Expand Up @@ -16594,9 +16594,6 @@
"id": 1,
"onehundred_percent_base": "valid",
"majority_method": "simple",
"voted_id": [
4
],
"user_has_voted": false,
"user_has_voted_for_delegations": []
},
Expand Down Expand Up @@ -16628,9 +16625,6 @@
"id": 3,
"onehundred_percent_base": "valid",
"majority_method": "simple",
"voted_id": [
11
],
"user_has_voted": false,
"user_has_voted_for_delegations": []
},
Expand Down Expand Up @@ -46831,9 +46825,6 @@
"id": 1,
"onehundred_percent_base": "valid",
"majority_method": "simple",
"voted_id": [
4
],
"user_has_voted": false,
"user_has_voted_for_delegations": []
},
Expand Down Expand Up @@ -46865,9 +46856,6 @@
"id": 3,
"onehundred_percent_base": "valid",
"majority_method": "simple",
"voted_id": [
11
],
"user_has_voted": false,
"user_has_voted_for_delegations": []
},
Expand Down
12 changes: 0 additions & 12 deletions internal/test/export.json.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b778a16

Please sign in to comment.