Skip to content

Commit

Permalink
Avoid repeated default role assignments
Browse files Browse the repository at this point in the history
When using the metadata storage (the current default) the default role
assignments were recreated at every start of the settings service. Leading to
duplicated role assignments

Fixes: owncloud#3432
  • Loading branch information
rhafer committed Mar 14, 2023
1 parent b041995 commit dbe40bd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions changelog/unreleased/fix-duplicated-demouser-roles.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Bugfix: Fix default role assignment for demo users

The roles-assignments for demo users where duplicated with every
restart of the settings service.

https://github.com/owncloud/ocis/issues/3432
10 changes: 10 additions & 0 deletions services/settings/pkg/store/metadata/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,21 @@ func (s *Store) initMetadataClient(mdc MetadataClient) error {
return err
}

assIDs, err := mdc.ReadDir(ctx, accountPath(accountUUID))
if err != nil {
return err
}
if len(assIDs) > 0 {
// There is already a role assignment for this ID, skip to the next
continue
}

ass := &settingsmsg.UserRoleAssignment{
Id: uuid.Must(uuid.NewV4()).String(),
AccountUuid: accountUUID,
RoleId: roleID,
}

b, err := json.Marshal(ass)
if err != nil {
return err
Expand Down

0 comments on commit dbe40bd

Please sign in to comment.