-
Notifications
You must be signed in to change notification settings - Fork 319
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NAS-125354 / 24.04 / Added ixRequiresRoles directive (#9340)
- Loading branch information
Showing
104 changed files
with
233 additions
and
10 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
20 changes: 20 additions & 0 deletions
20
src/app/directives/common/requires-roles/requires-roles-wrapper.component.scss
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,20 @@ | ||
|
||
:host ::ng-deep .role-missing { | ||
button { | ||
cursor: none; | ||
pointer-events: none; | ||
} | ||
|
||
.mat-mdc-button, | ||
.mdc-button { | ||
margin-right: 8px; | ||
} | ||
|
||
.mdc-button__label, | ||
.mat-icon, | ||
.mat-mdc-menu-item-text { | ||
opacity: 0.5; | ||
text-decoration: line-through; | ||
} | ||
} | ||
|
15 changes: 15 additions & 0 deletions
15
src/app/directives/common/requires-roles/requires-roles-wrapper.component.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,15 @@ | ||
import { Component, Input, TemplateRef } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'ix-requires-roles-wrapper', | ||
template: ` | ||
<span [class]="['role-missing', class]" [matTooltip]="'Missing permissions for this action' | translate" matTooltipPosition="above"> | ||
<ng-container *ngTemplateOutlet="template"></ng-container> | ||
</span> | ||
`, | ||
styleUrls: ['./requires-roles-wrapper.component.scss'], | ||
}) | ||
export class RequiresRolesWrapperComponent { | ||
@Input() template: TemplateRef<unknown>; | ||
@Input() class: string; | ||
} |
47 changes: 47 additions & 0 deletions
47
src/app/directives/common/requires-roles/requires-roles.directive.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,47 @@ | ||
import { | ||
ComponentRef, Directive, HostBinding, Input, TemplateRef, ViewContainerRef, | ||
} from '@angular/core'; | ||
import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy'; | ||
import { RequiresRolesWrapperComponent } from 'app/directives/common/requires-roles/requires-roles-wrapper.component'; | ||
import { Role } from 'app/enums/role.enum'; | ||
import { AuthService } from 'app/services/auth/auth.service'; | ||
|
||
@UntilDestroy() | ||
@Directive({ | ||
selector: '[ixRequiresRoles]', | ||
}) | ||
export class RequiresRolesDirective { | ||
private wrapperContainer: ComponentRef<RequiresRolesWrapperComponent>; | ||
|
||
@Input() | ||
set ixRequiresRoles(roles: Role[]) { | ||
this.authService.hasRole(roles).pipe(untilDestroyed(this)).subscribe({ | ||
next: (hasRole) => { | ||
if (!hasRole) { | ||
this.wrapperContainer = this.viewContainerRef.createComponent(RequiresRolesWrapperComponent); | ||
this.wrapperContainer.instance.template = this.templateRef; | ||
this.wrapperContainer.instance.class = this.elementClass; | ||
} else { | ||
this.viewContainerRef.createEmbeddedView(this.templateRef); | ||
} | ||
}, | ||
}); | ||
} | ||
|
||
protected cssClassList: string[] = []; | ||
|
||
@Input('class') | ||
@HostBinding('class') | ||
get elementClass(): string { | ||
return this.cssClassList.join(' '); | ||
} | ||
set(val: string): void { | ||
this.cssClassList = val.split(' '); | ||
} | ||
|
||
constructor( | ||
private templateRef: TemplateRef<unknown>, | ||
private viewContainerRef: ViewContainerRef, | ||
private authService: AuthService, | ||
) { } | ||
} |
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
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
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
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
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
Oops, something went wrong.