mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-05-01 11:19:32 -05:00

Directly check permissions and no subscription (uisettings is always initialized on frontend startup) update permission directive to accept single string add explicit management permission name
40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
import {
|
|
Input,
|
|
OnInit,
|
|
Directive,
|
|
ViewContainerRef,
|
|
TemplateRef,
|
|
} from '@angular/core'
|
|
import { SettingsService } from '../services/settings.service'
|
|
|
|
@Directive({
|
|
selector: '[ifPermissions]',
|
|
})
|
|
export class IfPermissionsDirective implements OnInit {
|
|
// The role the user must have
|
|
@Input() public ifPermissions: Array<string> | string
|
|
|
|
/**
|
|
* @param {ViewContainerRef} viewContainerRef -- The location where we need to render the templateRef
|
|
* @param {TemplateRef<any>} templateRef -- The templateRef to be potentially rendered
|
|
* @param {SettignsService} settignsService -- Will give us access to the permissions a user has
|
|
*/
|
|
constructor(
|
|
private viewContainerRef: ViewContainerRef,
|
|
private templateRef: TemplateRef<any>,
|
|
private settingsService: SettingsService
|
|
) {}
|
|
|
|
public ngOnInit(): void {
|
|
if (
|
|
[]
|
|
.concat(this.ifPermissions)
|
|
.every((perm) => this.settingsService.currentUserCan(perm))
|
|
) {
|
|
this.viewContainerRef.createEmbeddedView(this.templateRef)
|
|
} else {
|
|
this.viewContainerRef.clear()
|
|
}
|
|
}
|
|
}
|