Skip to content

Commit

Permalink
Use new permission Poll.can_see_progress
Browse files Browse the repository at this point in the history
Fixes #1115
  • Loading branch information
ostcar committed Jan 18, 2025
1 parent 48ce0d7 commit 475c469
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 25 deletions.
5 changes: 3 additions & 2 deletions internal/restrict/collection/poll.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ import (
// Mode C: The poll is in the started state and
//
// the user can manage the poll or
// the user has the permissions `user.can_see` and `list_of_speakers.can_manage`.
// the user has the permissions `user.can_see` and `list_of_speakers.can_manage` or
// the user has the permission `poll.can_see_progress`.
//
// Mode D: Same as Mode B, but for `finished`: Accessible if the user can manage the poll or the user has list_of_speakers.can_manage.
type Poll struct{}
Expand Down Expand Up @@ -196,7 +197,7 @@ func (p Poll) modeC(ctx context.Context, ds *dsfetch.Fetch, pollIDs ...int) ([]i
return nil, fmt.Errorf("getting permissions for meeting %d: %w", meetingID, err)
}

if perms.Has(perm.UserCanSee) && perms.Has(perm.ListOfSpeakersCanManage) {
if perms.Has(perm.UserCanSee) && perms.Has(perm.ListOfSpeakersCanManage) || perms.Has(perm.PollCanSeeProgress) {
return ids, nil
}

Expand Down
76 changes: 53 additions & 23 deletions internal/restrict/collection/poll_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ func TestPollModeA(t *testing.T) {
`---
poll/1:
content_object_id: motion/2
motion/2:
meeting_id: 30
state_id: 3
motion_state/3/id: 3
`,
withPerms(30, perm.MotionCanSee),
Expand All @@ -57,11 +57,11 @@ func TestPollModeA(t *testing.T) {
`---
poll/1:
content_object_id: motion/2
motion/2:
meeting_id: 30
state_id: 3
motion_state/3/id: 3
`,
)
Expand All @@ -74,7 +74,7 @@ func TestPollModeA(t *testing.T) {
`---
poll/1:
content_object_id: assignment/1
assignment/1:
meeting_id: 30
`,
Expand All @@ -89,11 +89,11 @@ func TestPollModeA(t *testing.T) {
`---
poll/1:
content_object_id: assignment/1
assignment/1:
meeting_id: 30
list_of_speakers_id: 300
list_of_speakers/300/meeting_id: 30
`,
)
Expand All @@ -107,7 +107,7 @@ func TestPollModeA(t *testing.T) {
poll/1:
meeting_id: 30
content_object_id: topic/5
topic/5:
meeting_id: 30
agenda_item_id: 3
Expand All @@ -126,7 +126,7 @@ func TestPollModeA(t *testing.T) {
poll/1:
meeting_id: 30
content_object_id: topic/5
topic/5:
meeting_id: 30
agenda_item_id: 3
Expand All @@ -148,11 +148,11 @@ func TestPollModeB(t *testing.T) {
poll/1:
content_object_id: motion/2
state: published
motion/2:
meeting_id: 30
state_id: 3
motion_state/3/id: 3
`,
withPerms(30, perm.MotionCanSee),
Expand All @@ -167,11 +167,11 @@ func TestPollModeB(t *testing.T) {
poll/1:
content_object_id: motion/2
state: published
motion/2:
meeting_id: 30
state_id: 3
motion_state/3/id: 3
`,
)
Expand All @@ -185,7 +185,7 @@ func TestPollModeB(t *testing.T) {
poll/1:
content_object_id: motion/1
state: finished
motion/1:
meeting_id: 30
`,
Expand All @@ -201,7 +201,7 @@ func TestPollModeB(t *testing.T) {
poll/1:
content_object_id: motion/1
state: finished
motion/1:
meeting_id: 30
`,
Expand All @@ -216,7 +216,7 @@ func TestPollModeB(t *testing.T) {
poll/1:
content_object_id: assignment/1
state: finished
assignment/1:
meeting_id: 30
`,
Expand All @@ -232,7 +232,7 @@ func TestPollModeB(t *testing.T) {
poll/1:
content_object_id: assignment/1
state: finished
assignment/1:
meeting_id: 30
`,
Expand Down Expand Up @@ -389,6 +389,36 @@ func TestPollModeC(t *testing.T) {
`,
withPerms(30, perm.UserCanSee, perm.ListOfSpeakersCanManage),
)

testCase(
"Poll.can_see_progress but wrong state",
t,
f,
false,
`---
poll/1:
content_object_id: topic/5
state: finished
meeting_id: 30
topic/5/meeting_id: 30
`,
withPerms(30, perm.PollCanSeeProgress),
)

testCase(
"Poll.can_see_progress with correct state",
t,
f,
true,
`---
poll/1:
content_object_id: topic/5
state: started
meeting_id: 30
topic/5/meeting_id: 30
`,
withPerms(30, perm.PollCanSeeProgress),
)
}

func TestPollModeD(t *testing.T) {
Expand All @@ -404,11 +434,11 @@ func TestPollModeD(t *testing.T) {
content_object_id: motion/2
state: published
meeting_id: 30
motion/2:
meeting_id: 30
state_id: 3
motion_state/3/id: 3
`,
withPerms(30, perm.MotionCanSee),
Expand All @@ -424,7 +454,7 @@ func TestPollModeD(t *testing.T) {
content_object_id: motion/1
state: published
meeting_id: 30
motion/1:
meeting_id: 30
`,
Expand All @@ -440,7 +470,7 @@ func TestPollModeD(t *testing.T) {
content_object_id: motion/1
state: finished
meeting_id: 30
motion/1:
meeting_id: 30
`,
Expand All @@ -457,7 +487,7 @@ func TestPollModeD(t *testing.T) {
content_object_id: motion/1
state: finished
meeting_id: 30
motion/1:
meeting_id: 30
`,
Expand All @@ -473,7 +503,7 @@ func TestPollModeD(t *testing.T) {
content_object_id: motion/1
state: finished
meeting_id: 30
motion/1:
meeting_id: 30
`,
Expand Down

0 comments on commit 475c469

Please sign in to comment.