Skip to content

Commit 82c7d35

Browse files
Enhance motion fields (#844)
Co-authored-by: Bastian Rihm <[email protected]>
1 parent ed55562 commit 82c7d35

10 files changed

+934
-668
lines changed

internal/restrict/collection/collection.go

+2
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,14 @@ var collectionMap = map[string]Restricter{
178178
MotionBlock{}.Name(): MotionBlock{},
179179
MotionCategory{}.Name(): MotionCategory{},
180180
MotionChangeRecommendation{}.Name(): MotionChangeRecommendation{},
181+
MotionEditor{}.Name(): MotionEditor{},
181182
MotionState{}.Name(): MotionState{},
182183
MotionStatuteParagraph{}.Name(): MotionStatuteParagraph{},
183184
MotionComment{}.Name(): MotionComment{},
184185
MotionCommentSection{}.Name(): MotionCommentSection{},
185186
MotionSubmitter{}.Name(): MotionSubmitter{},
186187
MotionWorkflow{}.Name(): MotionWorkflow{},
188+
MotionWorkingGroupSpeaker{}.Name(): MotionWorkingGroupSpeaker{},
187189
Option{}.Name(): Option{},
188190
Organization{}.Name(): Organization{},
189191
OrganizationTag{}.Name(): OrganizationTag{},

internal/restrict/collection/motion.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
//
2323
// 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.
2424
//
25-
// Mode B: The user has the permission motion.can_manage in the motion's meeting.
25+
// Mode B: The user has the permission motion.can_manage_metadata in the motion's meeting.
2626
//
2727
// Mode C: The user can see the motion.
2828
//
@@ -124,7 +124,7 @@ func (m Motion) see(ctx context.Context, ds *dsfetch.Fetch, motionIDs ...int) ([
124124
}
125125

126126
func (m Motion) modeB(ctx context.Context, ds *dsfetch.Fetch, motionIDs ...int) ([]int, error) {
127-
return meetingPerm(ctx, ds, m, motionIDs, perm.MotionCanManage)
127+
return meetingPerm(ctx, ds, m, motionIDs, perm.MotionCanManageMetadata)
128128
}
129129

130130
// leadMotionIndex creates an index from a motionID to its lead motion id. It
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package collection
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/OpenSlides/openslides-autoupdate-service/internal/restrict/perm"
8+
"github.com/OpenSlides/openslides-autoupdate-service/pkg/datastore/dsfetch"
9+
)
10+
11+
// MotionEditor handels restrictions of the collection motion_editor.
12+
//
13+
// The user can see a motion_editor if he has `motion.can_manage_metadata`
14+
//
15+
// Mode A: The user can see the motion editor.
16+
type MotionEditor struct{}
17+
18+
// Name returns the collection name.
19+
func (m MotionEditor) Name() string {
20+
return "motion_editor"
21+
}
22+
23+
// MeetingID returns the meetingID for the object.
24+
func (m MotionEditor) MeetingID(ctx context.Context, ds *dsfetch.Fetch, id int) (int, bool, error) {
25+
meetingID, err := ds.MotionEditor_MeetingID(id).Value(ctx)
26+
if err != nil {
27+
return 0, false, fmt.Errorf("get meeting id: %w", err)
28+
}
29+
30+
return meetingID, true, nil
31+
}
32+
33+
// Modes returns the restrictions modes for the meeting collection.
34+
func (m MotionEditor) Modes(mode string) FieldRestricter {
35+
switch mode {
36+
case "A":
37+
return m.see
38+
}
39+
return nil
40+
}
41+
42+
func (m MotionEditor) see(ctx context.Context, ds *dsfetch.Fetch, motionEditorIDs ...int) ([]int, error) {
43+
return meetingPerm(ctx, ds, m, motionEditorIDs, perm.MotionCanManageMetadata)
44+
}

internal/restrict/collection/motion_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -495,16 +495,16 @@ func TestMotionModeB(t *testing.T) {
495495
)
496496

497497
testCase(
498-
"motion.can_manage",
498+
"motion.can_manage_metadata",
499499
t,
500500
f,
501501
true,
502502
`---
503503
motion/1:
504504
meeting_id: 30
505-
editor_id: 3
505+
editor_ids: [3]
506506
`,
507-
withPerms(30, perm.MotionCanManage),
507+
withPerms(30, perm.MotionCanManageMetadata),
508508
)
509509
}
510510

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package collection
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/OpenSlides/openslides-autoupdate-service/internal/restrict/perm"
8+
"github.com/OpenSlides/openslides-autoupdate-service/pkg/datastore/dsfetch"
9+
)
10+
11+
// MotionWorkingGroupSpeaker handels restrictions of the collection motion_working_group_speaker.
12+
//
13+
// The user can see a motion_working_group_speaker if he has `motion.can_manage_metadata`
14+
//
15+
// Mode A: The user can see the motion working group speaker.
16+
type MotionWorkingGroupSpeaker struct{}
17+
18+
// Name returns the collection name.
19+
func (m MotionWorkingGroupSpeaker) Name() string {
20+
return "motion_working_group_speaker"
21+
}
22+
23+
// MeetingID returns the meetingID for the object.
24+
func (m MotionWorkingGroupSpeaker) MeetingID(ctx context.Context, ds *dsfetch.Fetch, id int) (int, bool, error) {
25+
meetingID, err := ds.MotionWorkingGroupSpeaker_MeetingID(id).Value(ctx)
26+
if err != nil {
27+
return 0, false, fmt.Errorf("get meeting id: %w", err)
28+
}
29+
30+
return meetingID, true, nil
31+
}
32+
33+
// Modes returns the restrictions modes for the meeting collection.
34+
func (m MotionWorkingGroupSpeaker) Modes(mode string) FieldRestricter {
35+
switch mode {
36+
case "A":
37+
return m.see
38+
}
39+
return nil
40+
}
41+
42+
func (m MotionWorkingGroupSpeaker) see(ctx context.Context, ds *dsfetch.Fetch, motionWorkingGroupSpeakerIDs ...int) ([]int, error) {
43+
return meetingPerm(ctx, ds, m, motionWorkingGroupSpeakerIDs, perm.MotionCanManageMetadata)
44+
}

internal/restrict/field_def.go

+49-25
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/restrict/restrict.go

+2
Original file line numberDiff line numberDiff line change
@@ -580,4 +580,6 @@ var collectionOrder = map[string]int{
580580
"import_preview": 41,
581581
"structure_level": 42,
582582
"structure_level_list_of_speakers": 43,
583+
"motion_working_group_speaker": 44,
584+
"motion_editor": 45,
583585
}

meta

0 commit comments

Comments
 (0)