-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(admin-ui): Add support for permissions on custom fields
Relates to #2671
- Loading branch information
1 parent
1c9f8f9
commit 94e0c42
Showing
15 changed files
with
126 additions
and
106 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 |
---|---|---|
|
@@ -560,6 +560,7 @@ export const CUSTOM_FIELD_CONFIG_FRAGMENT = gql` | |
} | ||
readonly | ||
nullable | ||
requiresPermission | ||
ui | ||
} | ||
`; | ||
|
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
41 changes: 41 additions & 0 deletions
41
packages/admin-ui/src/lib/core/src/providers/permissions/permissions.service.ts
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,41 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { BehaviorSubject } from 'rxjs'; | ||
import { Permission } from '../../common/generated-types'; | ||
|
||
/** | ||
* @description | ||
* This service is used internally to power components & logic that are dependent on knowing the | ||
* current user's permissions in the currently-active channel. | ||
*/ | ||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class PermissionsService { | ||
private currentUserPermissions: string[] = []; | ||
private _currentUserPermissions$ = new BehaviorSubject<string[]>([]); | ||
currentUserPermissions$ = this._currentUserPermissions$.asObservable(); | ||
|
||
/** | ||
* @description | ||
* This is called whenever: | ||
* - the user logs in | ||
* - the active channel changes | ||
* | ||
* Since active user validation occurs as part of the main auth guard, we can be assured | ||
* that if the user is logged in, then this method will be called with the user's permissions | ||
* before any other components are rendered lower down in the component tree. | ||
*/ | ||
setCurrentUserPermissions(permissions: string[]) { | ||
this.currentUserPermissions = permissions; | ||
this._currentUserPermissions$.next(permissions); | ||
} | ||
|
||
userHasPermissions(requiredPermissions: Array<string | Permission>): boolean { | ||
for (const perm of requiredPermissions) { | ||
if (this.currentUserPermissions.includes(perm)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
} |
Oops, something went wrong.