Skip to content

Commit

Permalink
Enhance motion fields (#844)
Browse files Browse the repository at this point in the history
Co-authored-by: Bastian Rihm <[email protected]>
  • Loading branch information
jsangmeister and bastianjoel authored Feb 15, 2024
1 parent ed55562 commit 82c7d35
Show file tree
Hide file tree
Showing 10 changed files with 934 additions and 668 deletions.
2 changes: 2 additions & 0 deletions internal/restrict/collection/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,14 @@ var collectionMap = map[string]Restricter{
MotionBlock{}.Name(): MotionBlock{},
MotionCategory{}.Name(): MotionCategory{},
MotionChangeRecommendation{}.Name(): MotionChangeRecommendation{},
MotionEditor{}.Name(): MotionEditor{},
MotionState{}.Name(): MotionState{},
MotionStatuteParagraph{}.Name(): MotionStatuteParagraph{},
MotionComment{}.Name(): MotionComment{},
MotionCommentSection{}.Name(): MotionCommentSection{},
MotionSubmitter{}.Name(): MotionSubmitter{},
MotionWorkflow{}.Name(): MotionWorkflow{},
MotionWorkingGroupSpeaker{}.Name(): MotionWorkingGroupSpeaker{},
Option{}.Name(): Option{},
Organization{}.Name(): Organization{},
OrganizationTag{}.Name(): OrganizationTag{},
Expand Down
4 changes: 2 additions & 2 deletions internal/restrict/collection/motion.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ 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 B: The user has the permission motion.can_manage_metadata in the motion's meeting.
//
// Mode C: The user can see the motion.
//
Expand Down Expand Up @@ -124,7 +124,7 @@ 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)
return meetingPerm(ctx, ds, m, motionIDs, perm.MotionCanManageMetadata)
}

// leadMotionIndex creates an index from a motionID to its lead motion id. It
Expand Down
44 changes: 44 additions & 0 deletions internal/restrict/collection/motion_editor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package collection

import (
"context"
"fmt"

"github.com/OpenSlides/openslides-autoupdate-service/internal/restrict/perm"
"github.com/OpenSlides/openslides-autoupdate-service/pkg/datastore/dsfetch"
)

// MotionEditor handels restrictions of the collection motion_editor.
//
// The user can see a motion_editor if he has `motion.can_manage_metadata`
//
// Mode A: The user can see the motion editor.
type MotionEditor struct{}

// Name returns the collection name.
func (m MotionEditor) Name() string {
return "motion_editor"
}

// MeetingID returns the meetingID for the object.
func (m MotionEditor) MeetingID(ctx context.Context, ds *dsfetch.Fetch, id int) (int, bool, error) {
meetingID, err := ds.MotionEditor_MeetingID(id).Value(ctx)
if err != nil {
return 0, false, fmt.Errorf("get meeting id: %w", err)
}

return meetingID, true, nil
}

// Modes returns the restrictions modes for the meeting collection.
func (m MotionEditor) Modes(mode string) FieldRestricter {
switch mode {
case "A":
return m.see
}
return nil
}

func (m MotionEditor) see(ctx context.Context, ds *dsfetch.Fetch, motionEditorIDs ...int) ([]int, error) {
return meetingPerm(ctx, ds, m, motionEditorIDs, perm.MotionCanManageMetadata)
}
6 changes: 3 additions & 3 deletions internal/restrict/collection/motion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,16 +495,16 @@ func TestMotionModeB(t *testing.T) {
)

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

Expand Down
44 changes: 44 additions & 0 deletions internal/restrict/collection/motion_working_group_speaker.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package collection

import (
"context"
"fmt"

"github.com/OpenSlides/openslides-autoupdate-service/internal/restrict/perm"
"github.com/OpenSlides/openslides-autoupdate-service/pkg/datastore/dsfetch"
)

// MotionWorkingGroupSpeaker handels restrictions of the collection motion_working_group_speaker.
//
// The user can see a motion_working_group_speaker if he has `motion.can_manage_metadata`
//
// Mode A: The user can see the motion working group speaker.
type MotionWorkingGroupSpeaker struct{}

// Name returns the collection name.
func (m MotionWorkingGroupSpeaker) Name() string {
return "motion_working_group_speaker"
}

// MeetingID returns the meetingID for the object.
func (m MotionWorkingGroupSpeaker) MeetingID(ctx context.Context, ds *dsfetch.Fetch, id int) (int, bool, error) {
meetingID, err := ds.MotionWorkingGroupSpeaker_MeetingID(id).Value(ctx)
if err != nil {
return 0, false, fmt.Errorf("get meeting id: %w", err)
}

return meetingID, true, nil
}

// Modes returns the restrictions modes for the meeting collection.
func (m MotionWorkingGroupSpeaker) Modes(mode string) FieldRestricter {
switch mode {
case "A":
return m.see
}
return nil
}

func (m MotionWorkingGroupSpeaker) see(ctx context.Context, ds *dsfetch.Fetch, motionWorkingGroupSpeakerIDs ...int) ([]int, error) {
return meetingPerm(ctx, ds, m, motionWorkingGroupSpeakerIDs, perm.MotionCanManageMetadata)
}
74 changes: 49 additions & 25 deletions internal/restrict/field_def.go

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

2 changes: 2 additions & 0 deletions internal/restrict/restrict.go
Original file line number Diff line number Diff line change
Expand Up @@ -580,4 +580,6 @@ var collectionOrder = map[string]int{
"import_preview": 41,
"structure_level": 42,
"structure_level_list_of_speakers": 43,
"motion_working_group_speaker": 44,
"motion_editor": 45,
}
2 changes: 1 addition & 1 deletion meta
Submodule meta updated 2 files
+1 −1 dev/requirements.txt
+74 −10 models.yml
Loading

0 comments on commit 82c7d35

Please sign in to comment.