Refactor permissions to use enums, permissions service

This commit is contained in:
Michael Shamoon
2022-11-12 04:03:35 -08:00
parent 5c5486d2ea
commit dfdfd8a7d7
39 changed files with 335 additions and 134 deletions

View File

@@ -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 {