-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
1,625 additions
and
1,033 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package collection | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/OpenSlides/openslides-autoupdate-service/internal/restrict/perm" | ||
"github.com/OpenSlides/openslides-autoupdate-service/pkg/datastore/dsfetch" | ||
) | ||
|
||
// StructureLevel handels restrictions of the collection structure_level. | ||
// | ||
// The user can see a structure level if he has `list_of_speakers.can_see` OR `user.can_see` | ||
// | ||
// Mode A: The user can see the speaker. | ||
type StructureLevel struct{} | ||
|
||
// Name returns the collection name. | ||
func (s StructureLevel) Name() string { | ||
return "structure_level" | ||
} | ||
|
||
// MeetingID returns the meetingID for the object. | ||
func (s StructureLevel) MeetingID(ctx context.Context, ds *dsfetch.Fetch, id int) (int, bool, error) { | ||
meetingID, err := ds.StructureLevel_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 (s StructureLevel) Modes(mode string) FieldRestricter { | ||
switch mode { | ||
case "A": | ||
return s.see | ||
case "B": | ||
return never // TODO: Remove me after the fix in the backend | ||
} | ||
return nil | ||
} | ||
|
||
func (s StructureLevel) see(ctx context.Context, ds *dsfetch.Fetch, structureLevelIDs ...int) ([]int, error) { | ||
return meetingPerm(ctx, ds, s, structureLevelIDs, perm.ListOfSpeakersCanSee, perm.UserCanSee) | ||
} |
44 changes: 44 additions & 0 deletions
44
internal/restrict/collection/structure_level_list_of_speakers.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
) | ||
|
||
// StructureLevelListOfSpeakers handels restrictions of the collection structure_level_list_of_speakers. | ||
// | ||
// The user can see a structure level if he has `list_of_speakers.can_see` | ||
// | ||
// Mode A: The user can see the speaker. | ||
type StructureLevelListOfSpeakers struct{} | ||
|
||
// Name returns the collection name. | ||
func (s StructureLevelListOfSpeakers) Name() string { | ||
return "structure_level_list_of_speakers" | ||
} | ||
|
||
// MeetingID returns the meetingID for the object. | ||
func (s StructureLevelListOfSpeakers) MeetingID(ctx context.Context, ds *dsfetch.Fetch, id int) (int, bool, error) { | ||
meetingID, err := ds.StructureLevelListOfSpeakers_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 (s StructureLevelListOfSpeakers) Modes(mode string) FieldRestricter { | ||
switch mode { | ||
case "A": | ||
return s.see | ||
} | ||
return nil | ||
} | ||
|
||
func (s StructureLevelListOfSpeakers) see(ctx context.Context, ds *dsfetch.Fetch, structureLevelIDs ...int) ([]int, error) { | ||
return meetingPerm(ctx, ds, s, structureLevelIDs, perm.ListOfSpeakersCanSee) | ||
} |
44 changes: 44 additions & 0 deletions
44
internal/restrict/collection/structure_level_list_of_speakers_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package collection_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/OpenSlides/openslides-autoupdate-service/internal/restrict/collection" | ||
"github.com/OpenSlides/openslides-autoupdate-service/internal/restrict/perm" | ||
) | ||
|
||
func TestStructureLevelListOfSpeakersModeA(t *testing.T) { | ||
f := collection.StructureLevelListOfSpeakers{}.Modes("A") | ||
|
||
testCase( | ||
"no perms", | ||
t, | ||
f, | ||
false, | ||
`--- | ||
structure_level_list_of_speakers/1/meeting_id: 30 | ||
`, | ||
) | ||
|
||
testCase( | ||
"list_of_speakers.can_see", | ||
t, | ||
f, | ||
true, | ||
`--- | ||
structure_level_list_of_speakers/1/meeting_id: 30 | ||
`, | ||
withPerms(30, perm.ListOfSpeakersCanSee), | ||
) | ||
|
||
testCase( | ||
"user.can_see", | ||
t, | ||
f, | ||
false, | ||
`--- | ||
structure_level_list_of_speakers/1/meeting_id: 30 | ||
`, | ||
withPerms(30, perm.UserCanSee), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package collection_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/OpenSlides/openslides-autoupdate-service/internal/restrict/collection" | ||
"github.com/OpenSlides/openslides-autoupdate-service/internal/restrict/perm" | ||
) | ||
|
||
func TestStructureLevelModeA(t *testing.T) { | ||
f := collection.StructureLevel{}.Modes("A") | ||
|
||
testCase( | ||
"no perms", | ||
t, | ||
f, | ||
false, | ||
`--- | ||
structure_level/1/meeting_id: 30 | ||
`, | ||
) | ||
|
||
testCase( | ||
"list_of_speakers.can_see", | ||
t, | ||
f, | ||
true, | ||
`--- | ||
structure_level/1/meeting_id: 30 | ||
`, | ||
withPerms(30, perm.ListOfSpeakersCanSee), | ||
) | ||
|
||
testCase( | ||
"user.can_see", | ||
t, | ||
f, | ||
true, | ||
`--- | ||
structure_level/1/meeting_id: 30 | ||
`, | ||
withPerms(30, perm.UserCanSee), | ||
) | ||
} |
Oops, something went wrong.