mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-07-30 18:27:45 -05:00
disable document form components when no object permissions
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import { Injectable } from '@angular/core'
|
||||
import { ObjectWithPermissions } from '../data/object-with-permissions'
|
||||
import { PaperlessUser } from '../data/paperless-user'
|
||||
|
||||
export enum PermissionAction {
|
||||
Add = 'add',
|
||||
@@ -33,15 +35,30 @@ export interface PaperlessPermission {
|
||||
})
|
||||
export class PermissionsService {
|
||||
private permissions: string[]
|
||||
private currentUser: PaperlessUser
|
||||
|
||||
public initialize(permissions: string[]) {
|
||||
public initialize(permissions: string[], currentUser: PaperlessUser) {
|
||||
this.permissions = permissions
|
||||
this.currentUser = currentUser
|
||||
}
|
||||
|
||||
public currentUserCan(permission: PaperlessPermission): boolean {
|
||||
return this.permissions.includes(this.getPermissionCode(permission))
|
||||
}
|
||||
|
||||
public currentUserIsOwner(owner: PaperlessUser): boolean {
|
||||
return owner?.id === this.currentUser.id
|
||||
}
|
||||
|
||||
public currentUserHasObjectPermissions(
|
||||
action: string,
|
||||
object: ObjectWithPermissions
|
||||
): boolean {
|
||||
return (object.permissions[action] as Array<number>)?.includes(
|
||||
this.currentUser.id
|
||||
)
|
||||
}
|
||||
|
||||
public getPermissionCode(permission: PaperlessPermission): string {
|
||||
return permission.type.replace('%s', permission.action)
|
||||
}
|
||||
|
@@ -79,7 +79,10 @@ export class SettingsService {
|
||||
id: uisettings['user_id'],
|
||||
username: uisettings['username'],
|
||||
}
|
||||
this.permissionsService.initialize(uisettings.permissions)
|
||||
this.permissionsService.initialize(
|
||||
uisettings.permissions,
|
||||
this.currentUser
|
||||
)
|
||||
})
|
||||
)
|
||||
}
|
||||
|
Reference in New Issue
Block a user