Skip to content

Commit

Permalink
Fixes requests from anonymous user
Browse files Browse the repository at this point in the history
When the restrictor depends on db-values of the request user, then it has to pay attanchen, that the request is not send
for the anonsmous user (userID==0) since the anonyomus user is not in the database.

There were two cases, where a check was missing. This PR adds these checks.

Fixes OpenSlides#789
  • Loading branch information
ostcar committed Mar 3, 2024
1 parent 68f78c4 commit adf403c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal/restrict/collection/personal_note.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ func (p PersonalNote) see(ctx context.Context, ds *dsfetch.Fetch, personalNoteID
return nil, fmt.Errorf("getting request user: %w", err)
}

if requestUser == 0 {
return nil, nil
}

meetingUserIDs, err := ds.User_MeetingUserIDs(requestUser).Value(ctx)
if err != nil {
return nil, fmt.Errorf("getting meeting users: %w", err)
Expand Down
13 changes: 13 additions & 0 deletions internal/restrict/collection/personal_note_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@ import (
func TestPersonalNoteModeA(t *testing.T) {
var p collection.PersonalNote

testCase(
"as anonymous",
t,
p.Modes("A"),
false,
`---
personal_note/1/meeting_user_id: 5
meeting_user/5/user_id: 1
user/1/meeting_user_ids: [5]
`,
withRequestUser(0),
)

testCase(
"own note",
t,
Expand Down
4 changes: 4 additions & 0 deletions internal/restrict/collection/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,10 @@ func (u User) modeH(ctx context.Context, ds *dsfetch.Fetch, userIDs ...int) ([]i
return nil, fmt.Errorf("getting request user: %w", err)
}

if requestUser == 0 {
return nil, nil
}

ownOrgaManagementLevel, err := ds.User_OrganizationManagementLevel(requestUser).Value(ctx)
if err != nil {
return nil, fmt.Errorf("getting own managament: %w", err)
Expand Down
10 changes: 10 additions & 0 deletions internal/restrict/collection/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1057,4 +1057,14 @@ func TestUserModeH(t *testing.T) {
withElementID(2),
withPerms(5, perm.UserCanManage),
)

testCase(
"As anonymous",
t,
u.Modes("H"),
false,
`user/2/id: 2`,
withRequestUser(0),
withElementID(2),
)
}

0 comments on commit adf403c

Please sign in to comment.