mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-07-28 18:24:38 -05:00
Refactor permissions check code
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
This commit is contained in:
@@ -11,7 +11,7 @@ import {
|
||||
} from '@angular/core'
|
||||
import { Meta } from '@angular/platform-browser'
|
||||
import { CookieService } from 'ngx-cookie-service'
|
||||
import { first, Observable, of, tap } from 'rxjs'
|
||||
import { first, Observable, tap } from 'rxjs'
|
||||
import {
|
||||
BRIGHTNESS,
|
||||
estimateBrightnessForColor,
|
||||
@@ -45,7 +45,7 @@ export class SettingsService {
|
||||
protected baseUrl: string = environment.apiBaseUrl + 'ui_settings/'
|
||||
|
||||
private settings: Object = {}
|
||||
private _permissions: string[]
|
||||
private permissions: string[]
|
||||
|
||||
public displayName: string
|
||||
|
||||
@@ -75,7 +75,7 @@ export class SettingsService {
|
||||
if (this.settings['language']?.length)
|
||||
this.setLanguage(this.settings['language'])
|
||||
this.displayName = uisettings.display_name.trim()
|
||||
this._permissions = uisettings.permissions
|
||||
this.permissions = uisettings.permissions
|
||||
})
|
||||
)
|
||||
}
|
||||
@@ -458,7 +458,7 @@ export class SettingsService {
|
||||
)
|
||||
}
|
||||
|
||||
public permissions(): Observable<string[]> {
|
||||
return of(this._permissions)
|
||||
currentUserCan(permission: string): boolean {
|
||||
return this.permissions.includes(permission)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user