mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-07-28 18:24:38 -05:00
Refactor permissions to use enums, permissions service
This commit is contained in:
@@ -5,31 +5,37 @@ import {
|
||||
ViewContainerRef,
|
||||
TemplateRef,
|
||||
} from '@angular/core'
|
||||
import { SettingsService } from '../services/settings.service'
|
||||
import {
|
||||
PaperlessPermission,
|
||||
PermissionsService,
|
||||
} from '../services/permissions.service'
|
||||
|
||||
@Directive({
|
||||
selector: '[ifPermissions]',
|
||||
})
|
||||
export class IfPermissionsDirective implements OnInit {
|
||||
// The role the user must have
|
||||
@Input() public ifPermissions: Array<string> | string
|
||||
@Input()
|
||||
ifPermissions: Array<PaperlessPermission> | PaperlessPermission
|
||||
|
||||
/**
|
||||
* @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
|
||||
* @param {PermissionsService} permissionsService -- Will give us access to the permissions a user has
|
||||
*/
|
||||
constructor(
|
||||
private viewContainerRef: ViewContainerRef,
|
||||
private templateRef: TemplateRef<any>,
|
||||
private settingsService: SettingsService
|
||||
private permissionsService: PermissionsService
|
||||
) {}
|
||||
|
||||
public ngOnInit(): void {
|
||||
if (
|
||||
[]
|
||||
.concat(this.ifPermissions)
|
||||
.every((perm) => this.settingsService.currentUserCan(perm))
|
||||
.every((perm: PaperlessPermission) =>
|
||||
this.permissionsService.currentUserCan(perm)
|
||||
)
|
||||
) {
|
||||
this.viewContainerRef.createEmbeddedView(this.templateRef)
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user