Skip to content

Commit

Permalink
Add new motion fields and motion restriction mode B
Browse files Browse the repository at this point in the history
  • Loading branch information
jsangmeister committed Jan 23, 2024
1 parent a03f851 commit 886cc9a
Show file tree
Hide file tree
Showing 8 changed files with 694 additions and 572 deletions.
2 changes: 1 addition & 1 deletion internal/models/models-version
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
// Can be the name of a branch like "master" or the name of a tag like
// "v1.0.1" or a commit id.
//
// After chaning this value call `go generate ./...` to update the generated
// After changing this value call `go generate ./...` to update the generated
// files.
main
2 changes: 1 addition & 1 deletion internal/restrict/collection/list_of_speakers.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (los ListOfSpeakers) see(ctx context.Context, ds *dsfetch.Fetch, losIDs ...
return eachMeeting(ctx, ds, los, losIDs, func(meetingID int, ids []int) ([]int, error) {
perms, err := perm.FromContext(ctx, meetingID)
if err != nil {
return nil, fmt.Errorf("getting perms for meetind %d: %w", meetingID, err)
return nil, fmt.Errorf("getting perms for meeting %d: %w", meetingID, err)
}

canSee := perms.Has(perm.ListOfSpeakersCanSee) || perms.Has(perm.ListOfSpeakersCanBeSpeaker)
Expand Down
8 changes: 8 additions & 0 deletions internal/restrict/collection/motion.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
//
// Mode A: The user can see the motion or can see a referenced motion in motion/all_origin_ids and motion/all_derived_motion_ids.
//
// Mode B: The user has the permission motion.can_manage in the motion's meeting.
//
// Mode C: The user can see the motion.
//
// Mode D: Never published to any user.
Expand All @@ -47,6 +49,8 @@ func (m Motion) Modes(mode string) FieldRestricter {
switch mode {
case "A":
return m.modeA
case "B":
return m.modeB
case "C":
return m.see
case "D":
Expand Down Expand Up @@ -115,6 +119,10 @@ func (m Motion) see(ctx context.Context, ds *dsfetch.Fetch, motionIDs ...int) ([
})
}

func (m Motion) modeB(ctx context.Context, ds *dsfetch.Fetch, motionIDs ...int) ([]int, error) {
return meetingPerm(ctx, ds, m, motionIDs, perm.MotionCanManage)
}

// leadMotionIndex creates an index from a motionID to its lead motion id. It
// also contains pairs for each found lead motion id.
//
Expand Down
29 changes: 29 additions & 0 deletions internal/restrict/collection/motion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,35 @@ func TestMotionModeA(t *testing.T) {
)
}

func TestMotionModeB(t *testing.T) {
f := collection.Motion{}.Modes("B")

testCase(
"no permissions",
t,
f,
false,
`---
motion/1:
id: 1
meeting_id: 30
`,
)

testCase(
"motion.can_manage",
t,
f,
true,
`---
motion/1:
meeting_id: 30
editor_id: 3
`,
withPerms(30, perm.MotionCanManage),
)
}

func TestMotionModeD(t *testing.T) {
f := collection.Motion{}.Modes("D")

Expand Down
2 changes: 1 addition & 1 deletion internal/restrict/collection/speaker.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (s Speaker) see(ctx context.Context, ds *dsfetch.Fetch, speakerIDs ...int)
return eachMeeting(ctx, ds, s, speakerIDs, func(meetingID int, ids []int) ([]int, error) {
perms, err := perm.FromContext(ctx, meetingID)
if err != nil {
return nil, fmt.Errorf("getting perms for meetind %d: %w", meetingID, err)
return nil, fmt.Errorf("getting perms for meeting %d: %w", meetingID, err)
}

if canSee := perms.Has(perm.ListOfSpeakersCanSee); canSee {
Expand Down
44 changes: 27 additions & 17 deletions internal/restrict/field_def.go

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

54 changes: 54 additions & 0 deletions pkg/datastore/dsfetch/fields_generated.go

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

Loading

0 comments on commit 886cc9a

Please sign in to comment.