Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes requests from anonymous user #873

Merged
merged 1 commit into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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),
)
}
Loading