Skip to content

Commit

Permalink
chore(mock): fix permissions on the mock server
Browse files Browse the repository at this point in the history
  • Loading branch information
iOvergaard committed Jan 21, 2025
1 parent 7831615 commit b530e31
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/mocks/data/user-group/user-group.db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ export class UmbUserGroupMockDB extends UmbEntityMockDbBase<UmbMockUserGroupMode
return uniqueArray;
}

getFallbackPermissions(userGroupIds: Array<{ id: string }>): Array<string> {
const permissions = this.data
.filter((userGroup) => userGroupIds.map((reference) => reference.id).includes(userGroup.id))
.map((userGroup) => (userGroup.fallbackPermissions?.length ? userGroup.fallbackPermissions : []))
.flat();

// Remove duplicates
return Array.from(new Set(permissions));
}

getAllowedSections(userGroupIds: Array<{ id: string }>): string[] {
const sections = this.data
.filter((userGroup) => userGroupIds.map((reference) => reference.id).includes(userGroup.id))
Expand Down
5 changes: 4 additions & 1 deletion src/mocks/data/user/user.db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ class UmbUserMockDB extends UmbEntityMockDbBase<UmbMockUserModel> {
getCurrentUser(): CurrentUserResponseModel {
const firstUser = this.data[0];
const permissions = firstUser.userGroupIds?.length ? umbUserGroupMockDb.getPermissions(firstUser.userGroupIds) : [];
const fallbackPermissions = firstUser.userGroupIds?.length
? umbUserGroupMockDb.getFallbackPermissions(firstUser.userGroupIds)
: [];
const allowedSections = firstUser.userGroupIds?.length
? umbUserGroupMockDb.getAllowedSections(firstUser.userGroupIds)
: [];
Expand All @@ -82,7 +85,7 @@ class UmbUserMockDB extends UmbEntityMockDbBase<UmbMockUserModel> {
mediaStartNodeIds: firstUser.mediaStartNodeIds,
hasDocumentRootAccess: firstUser.hasDocumentRootAccess,
hasMediaRootAccess: firstUser.hasMediaRootAccess,
fallbackPermissions: [],
fallbackPermissions,
permissions,
allowedSections,
isAdmin: firstUser.isAdmin,
Expand Down

0 comments on commit b530e31

Please sign in to comment.