From 56235e65f163f1e907800c4396f5c7f064dd3fbe Mon Sep 17 00:00:00 2001 From: Dan Percic Date: Sun, 13 Nov 2022 13:37:24 +0200 Subject: [PATCH] RED-5482: wip permissions --- .../default-colors-screen.component.html | 4 +-- .../default-colors-screen.component.ts | 17 ++++++++++--- .../digital-signature-screen.component.html | 3 ++- ...r-attributes-listing-screen.component.html | 12 ++++----- ...ier-attributes-listing-screen.component.ts | 11 +++++--- .../dictionary-screen.component.html | 2 +- .../dictionary/dictionary-screen.component.ts | 16 ++++++------ ...e-attributes-listing-screen.component.html | 18 ++++++------- ...ile-attributes-listing-screen.component.ts | 10 +++++--- .../justifications-screen.component.html | 6 ++--- .../justifications-screen.component.ts | 9 +++---- .../table-item/table-item.component.html | 2 +- .../table-item/table-item.component.ts | 7 +++--- .../license-screen.component.ts | 1 + .../license-select.component.html | 8 +++++- .../license-select.component.ts | 5 +++- .../reports-screen.component.html | 16 ++++++++---- .../reports-screen.component.ts | 10 +++++--- .../admin/screens/reports/reports.module.ts | 3 ++- .../watermark-screen.component.html | 2 +- .../watermark-screen.component.ts | 25 +++++++++++++------ .../screens/watermark/watermark.module.ts | 2 ++ .../watermarks-listing-screen.component.html | 8 +++--- .../watermarks-listing-screen.component.ts | 16 ++++++------ .../src/app/services/permissions.service.ts | 20 +++++++++++++-- apps/red-ui/src/app/users/roles.ts | 1 + 26 files changed, 148 insertions(+), 86 deletions(-) diff --git a/apps/red-ui/src/app/modules/admin/screens/default-colors/default-colors-screen.component.html b/apps/red-ui/src/app/modules/admin/screens/default-colors/default-colors-screen.component.html index 99a4580af..12a96582e 100644 --- a/apps/red-ui/src/app/modules/admin/screens/default-colors/default-colors-screen.component.html +++ b/apps/red-ui/src/app/modules/admin/screens/default-colors/default-colors-screen.component.html @@ -39,10 +39,10 @@
diff --git a/apps/red-ui/src/app/modules/admin/screens/default-colors/default-colors-screen.component.ts b/apps/red-ui/src/app/modules/admin/screens/default-colors/default-colors-screen.component.ts index a7a3fce5d..e5d3f56b8 100644 --- a/apps/red-ui/src/app/modules/admin/screens/default-colors/default-colors-screen.component.ts +++ b/apps/red-ui/src/app/modules/admin/screens/default-colors/default-colors-screen.component.ts @@ -1,13 +1,21 @@ import { ChangeDetectionStrategy, Component } from '@angular/core'; -import { DefaultColorTypes, DOSSIER_TEMPLATE_ID } from '@red/domain'; +import { DefaultColorTypes, DOSSIER_TEMPLATE_ID, User } from '@red/domain'; import { AdminDialogService } from '../../services/admin-dialog.service'; -import { CircleButtonTypes, getParam, IListable, ListingComponent, listingProvidersFactory, TableColumnConfig } from '@iqser/common-ui'; +import { + CircleButtonTypes, + getCurrentUser, + getParam, + IListable, + ListingComponent, + listingProvidersFactory, + TableColumnConfig, +} from '@iqser/common-ui'; import { defaultColorsTranslations } from '@translations/default-colors-translations'; import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker'; -import { getCurrentUser } from '@users/user.service'; import { combineLatest } from 'rxjs'; import { map, tap } from 'rxjs/operators'; import { DefaultColorsService } from '@services/entity-services/default-colors.service'; +import { ROLES } from '@users/roles'; interface ListItem extends IListable { readonly key: string; @@ -22,7 +30,8 @@ interface ListItem extends IListable { }) export class DefaultColorsScreenComponent extends ListingComponent { readonly circleButtonTypes = CircleButtonTypes; - readonly currentUser = getCurrentUser(); + readonly currentUser = getCurrentUser(); + readonly roles = ROLES; readonly translations = defaultColorsTranslations; readonly tableHeaderLabel = _('default-colors-screen.table-header.title'); readonly tableColumnConfigs: TableColumnConfig[] = [ diff --git a/apps/red-ui/src/app/modules/admin/screens/digital-signature/digital-signature-screen.component.html b/apps/red-ui/src/app/modules/admin/screens/digital-signature/digital-signature-screen.component.html index 34d0e82a6..913feb8d7 100644 --- a/apps/red-ui/src/app/modules/admin/screens/digital-signature/digital-signature-screen.component.html +++ b/apps/red-ui/src/app/modules/admin/screens/digital-signature/digital-signature-screen.component.html @@ -1,7 +1,7 @@
@@ -12,6 +12,7 @@ [buttonIcon]="null" [buttonLabel]="'digital-signature-screen.no-data.action' | translate" [helpModeKey]="'digital_signature'" + [showButton]="permissionsService.has$(roles.digitalSignature.write) | async" [text]="'digital-signature-screen.no-data.title' | translate" icon="iqser:document" > diff --git a/apps/red-ui/src/app/modules/admin/screens/dossier-attributes-listing/dossier-attributes-listing-screen.component.html b/apps/red-ui/src/app/modules/admin/screens/dossier-attributes-listing/dossier-attributes-listing-screen.component.html index fb4cd1b3b..dd3da97cf 100644 --- a/apps/red-ui/src/app/modules/admin/screens/dossier-attributes-listing/dossier-attributes-listing-screen.component.html +++ b/apps/red-ui/src/app/modules/admin/screens/dossier-attributes-listing/dossier-attributes-listing-screen.component.html @@ -28,8 +28,8 @@ [noDataButtonLabel]="'dossier-attributes-listing.no-data.action' | translate" [noDataText]="'dossier-attributes-listing.no-data.title' | translate" [noMatchText]="'dossier-attributes-listing.no-match.title' | translate" - [selectionEnabled]="true" - [showNoDataButton]="currentUser.isAdmin" + [selectionEnabled]="canEditDossierAttributes" + [showNoDataButton]="canEditDossierAttributes" [tableColumnConfigs]="tableColumnConfigs" emptyColumnWidth="1fr" noDataIcon="red:attribute" @@ -41,7 +41,7 @@
@@ -87,7 +87,7 @@
-
+
implements OnInit { readonly iconButtonTypes = IconButtonTypes; readonly circleButtonTypes = CircleButtonTypes; - readonly currentUser = getCurrentUser(); + readonly currentUser = getCurrentUser(); readonly translations = dossierAttributeTypesTranslations; readonly tableHeaderLabel = _('dossier-attributes-listing.table-header.title'); readonly tableColumnConfigs: TableColumnConfig[] = [ @@ -36,9 +37,11 @@ export class DossierAttributesListingScreenComponent extends ListingComponent; - readonly #dossierTemplateId: string = getParam(DOSSIER_TEMPLATE_ID); + readonly canEditDossierAttributes = this.permissionsService.canEditGlobalDossierAttributes(); + readonly #dossierTemplateId = getParam(DOSSIER_TEMPLATE_ID); constructor( + readonly permissionsService: PermissionsService, private readonly _loadingService: LoadingService, private readonly _dialogService: AdminDialogService, private readonly _dossierAttributesService: DossierAttributesService, diff --git a/apps/red-ui/src/app/modules/admin/screens/entities/screens/dictionary/dictionary-screen.component.html b/apps/red-ui/src/app/modules/admin/screens/entities/screens/dictionary/dictionary-screen.component.html index ff89234fd..4200737b1 100644 --- a/apps/red-ui/src/app/modules/admin/screens/entities/screens/dictionary/dictionary-screen.component.html +++ b/apps/red-ui/src/app/modules/admin/screens/entities/screens/dictionary/dictionary-screen.component.html @@ -2,7 +2,7 @@ #dictionaryManager (saveDictionary)="save()" [canDownload]="permissionsService.canDownloadEntityDictionary()" - [canEdit]="currentUser.isAdmin" + [canEdit]="currentUser.isAdmin && (iqserPermissionsService.has$(roles.dictionaryEntries.write) | async)" [entityType]="entityType" [filterByDossierTemplate]="true" [initialEntries]="initialEntries$ | async" diff --git a/apps/red-ui/src/app/modules/admin/screens/entities/screens/dictionary/dictionary-screen.component.ts b/apps/red-ui/src/app/modules/admin/screens/entities/screens/dictionary/dictionary-screen.component.ts index 3a7ac6d6e..b5df24952 100644 --- a/apps/red-ui/src/app/modules/admin/screens/entities/screens/dictionary/dictionary-screen.component.ts +++ b/apps/red-ui/src/app/modules/admin/screens/entities/screens/dictionary/dictionary-screen.component.ts @@ -2,11 +2,11 @@ import { ChangeDetectionStrategy, Component, OnInit, ViewChild } from '@angular/ import { ActivatedRoute } from '@angular/router'; import { DictionaryManagerComponent } from '@shared/components/dictionary-manager/dictionary-manager.component'; import { DictionaryService } from '@services/entity-services/dictionary.service'; -import { List, LoadingService } from '@iqser/common-ui'; -import { UserService } from '@users/user.service'; +import { getCurrentUser, getParam, IqserPermissionsService, List, LoadingService } from '@iqser/common-ui'; import { BehaviorSubject, firstValueFrom } from 'rxjs'; import { DICTIONARY_TO_ENTRY_TYPE_MAP, DICTIONARY_TYPE_KEY_MAP, DictionaryType, DOSSIER_TEMPLATE_ID, ENTITY_TYPE, User } from '@red/domain'; import { PermissionsService } from '@services/permissions.service'; +import { ROLES } from '@users/roles'; @Component({ templateUrl: './dictionary-screen.component.html', @@ -14,25 +14,23 @@ import { PermissionsService } from '@services/permissions.service'; changeDetection: ChangeDetectionStrategy.OnPush, }) export class DictionaryScreenComponent implements OnInit { - readonly currentUser: User; + readonly currentUser = getCurrentUser(); + readonly roles = ROLES; readonly initialEntries$ = new BehaviorSubject([]); isLeavingPage = false; readonly type: DictionaryType; - readonly entityType: string; - readonly #dossierTemplateId: string; + readonly entityType = getParam(ENTITY_TYPE); + readonly #dossierTemplateId = getParam(DOSSIER_TEMPLATE_ID); @ViewChild('dictionaryManager', { static: false }) private readonly _dictionaryManager: DictionaryManagerComponent; constructor( readonly route: ActivatedRoute, - readonly userService: UserService, readonly permissionsService: PermissionsService, + readonly iqserPermissionsService: IqserPermissionsService, private readonly _loadingService: LoadingService, private readonly _dictionaryService: DictionaryService, ) { - this.currentUser = userService.currentUser; - this.#dossierTemplateId = route.parent.snapshot.paramMap.get(DOSSIER_TEMPLATE_ID); - this.entityType = route.parent.snapshot.paramMap.get(ENTITY_TYPE); this.type = route.snapshot.routeConfig.path as DictionaryType; } diff --git a/apps/red-ui/src/app/modules/admin/screens/file-attributes-listing/file-attributes-listing-screen.component.html b/apps/red-ui/src/app/modules/admin/screens/file-attributes-listing/file-attributes-listing-screen.component.html index d7713fdd4..adc800b6d 100644 --- a/apps/red-ui/src/app/modules/admin/screens/file-attributes-listing/file-attributes-listing-screen.component.html +++ b/apps/red-ui/src/app/modules/admin/screens/file-attributes-listing/file-attributes-listing-screen.component.html @@ -26,7 +26,7 @@ [itemSize]="80" [noDataText]="'file-attributes-listing.no-data.title' | translate" [noMatchText]="'file-attributes-listing.no-match.title' | translate" - [selectionEnabled]="true" + [selectionEnabled]="permissionsService.canEditGlobalFileAttributes()" [tableColumnConfigs]="tableColumnConfigs" emptyColumnWidth="1fr" noDataIcon="red:attribute" @@ -46,7 +46,7 @@
@@ -129,7 +129,7 @@
-
+
implements OnInit, OnDestroy { readonly iconButtonTypes = IconButtonTypes; readonly circleButtonTypes = CircleButtonTypes; - readonly currentUser = getCurrentUser(); + readonly currentUser = getCurrentUser(); readonly translations = fileAttributeTypesTranslations; readonly tableHeaderLabel = _('file-attributes-listing.table-header.title'); readonly tableColumnConfigs: TableColumnConfig[] = [ @@ -45,12 +47,14 @@ export class FileAttributesListingScreenComponent extends ListingComponent; #existingConfiguration: IFileAttributesConfig; @ViewChild('fileInput') private _fileInput: ElementRef; readonly #dossierTemplateId = getParam(DOSSIER_TEMPLATE_ID); constructor( + readonly permissionsService: PermissionsService, private readonly _toaster: Toaster, private readonly _loadingService: LoadingService, private readonly _dialogService: AdminDialogService, diff --git a/apps/red-ui/src/app/modules/admin/screens/justifications/justifications-screen/justifications-screen.component.html b/apps/red-ui/src/app/modules/admin/screens/justifications/justifications-screen/justifications-screen.component.html index 8ad7ac075..016817b83 100644 --- a/apps/red-ui/src/app/modules/admin/screens/justifications/justifications-screen/justifications-screen.component.html +++ b/apps/red-ui/src/app/modules/admin/screens/justifications/justifications-screen/justifications-screen.component.html @@ -3,7 +3,7 @@ [headerTemplate]="headerTemplate" [itemSize]="80" [noDataText]="'justifications-listing.no-data.title' | translate" - [selectionEnabled]="canUpdateJustifications" + [selectionEnabled]="canAddEditJustifications" [tableColumnConfigs]="tableColumnConfigs" noDataIcon="iqser:document" > @@ -11,7 +11,7 @@ { this._loadingService.start(); await firstValueFrom(this._justificationService.loadAll(this.#dossierTemplateId)); diff --git a/apps/red-ui/src/app/modules/admin/screens/justifications/table-item/table-item.component.html b/apps/red-ui/src/app/modules/admin/screens/justifications/table-item/table-item.component.html index fcc79db5a..e386a03e8 100644 --- a/apps/red-ui/src/app/modules/admin/screens/justifications/table-item/table-item.component.html +++ b/apps/red-ui/src/app/modules/admin/screens/justifications/table-item/table-item.component.html @@ -14,7 +14,7 @@
- + this.sendMail(), type: IconButtonTypes.primary, helpModeKey: 'license_information', + hide: !this.permissionsService.has(ROLES.license.readReport), }, ]; diff --git a/apps/red-ui/src/app/modules/admin/screens/license/license-select/license-select.component.html b/apps/red-ui/src/app/modules/admin/screens/license/license-select/license-select.component.html index 254941a67..6694f8c1f 100644 --- a/apps/red-ui/src/app/modules/admin/screens/license/license-select/license-select.component.html +++ b/apps/red-ui/src/app/modules/admin/screens/license/license-select/license-select.component.html @@ -1,5 +1,11 @@
- + diff --git a/apps/red-ui/src/app/modules/admin/screens/license/license-select/license-select.component.ts b/apps/red-ui/src/app/modules/admin/screens/license/license-select/license-select.component.ts index ecb78ad6b..bec041580 100644 --- a/apps/red-ui/src/app/modules/admin/screens/license/license-select/license-select.component.ts +++ b/apps/red-ui/src/app/modules/admin/screens/license/license-select/license-select.component.ts @@ -3,6 +3,8 @@ import { LicenseService } from '@services/license.service'; import { ILicense } from '@red/domain'; import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker'; import { map, tap } from 'rxjs/operators'; +import { IqserPermissionsService } from '@iqser/common-ui'; +import { ROLES } from '@users/roles'; const translations = { active: _('license-info-screen.status.active'), @@ -24,8 +26,9 @@ export class LicenseSelectComponent { } }), ); + readonly isReadonly$ = this._permissionsService.has$(ROLES.license.edit).pipe(map(has => !has)); - constructor(readonly licenseService: LicenseService) {} + constructor(readonly licenseService: LicenseService, private readonly _permissionsService: IqserPermissionsService) {} getStatus(id) { return id === this.licenseService.activeLicenseId ? translations.active : translations.inactive; diff --git a/apps/red-ui/src/app/modules/admin/screens/reports/reports-screen/reports-screen.component.html b/apps/red-ui/src/app/modules/admin/screens/reports/reports-screen/reports-screen.component.html index b91496dea..3ca03ab33 100644 --- a/apps/red-ui/src/app/modules/admin/screens/reports/reports-screen/reports-screen.component.html +++ b/apps/red-ui/src/app/modules/admin/screens/reports/reports-screen/reports-screen.component.html @@ -23,16 +23,16 @@
@@ -43,11 +43,17 @@
- + ([]); availableTemplates$ = new BehaviorSubject([]); - readonly #dossierTemplateId: string = getParam(DOSSIER_TEMPLATE_ID); - + readonly currentUser = getCurrentUser(); + readonly roles = ROLES; + readonly #dossierTemplateId = getParam(DOSSIER_TEMPLATE_ID); @ViewChild('fileInput') private _fileInput: ElementRef; constructor( diff --git a/apps/red-ui/src/app/modules/admin/screens/reports/reports.module.ts b/apps/red-ui/src/app/modules/admin/screens/reports/reports.module.ts index 3d3b8a97a..6be448070 100644 --- a/apps/red-ui/src/app/modules/admin/screens/reports/reports.module.ts +++ b/apps/red-ui/src/app/modules/admin/screens/reports/reports.module.ts @@ -4,7 +4,7 @@ import { RouterModule } from '@angular/router'; import { SharedModule } from '@shared/shared.module'; import { ReportsScreenComponent } from './reports-screen/reports-screen.component'; import { TranslateModule } from '@ngx-translate/core'; -import { IqserButtonsModule, IqserHelpModeModule, IqserScrollbarModule } from '@iqser/common-ui'; +import { IqserButtonsModule, IqserHelpModeModule, IqserPermissionsModule, IqserScrollbarModule } from '@iqser/common-ui'; const routes = [{ path: '', component: ReportsScreenComponent }]; @@ -18,6 +18,7 @@ const routes = [{ path: '', component: ReportsScreenComponent }]; IqserButtonsModule, IqserScrollbarModule, IqserHelpModeModule, + IqserPermissionsModule, ], }) export class ReportsModule {} diff --git a/apps/red-ui/src/app/modules/admin/screens/watermark/watermark-screen/watermark-screen.component.html b/apps/red-ui/src/app/modules/admin/screens/watermark/watermark-screen/watermark-screen.component.html index 703c33672..8bc3c616d 100644 --- a/apps/red-ui/src/app/modules/admin/screens/watermark/watermark-screen/watermark-screen.component.html +++ b/apps/red-ui/src/app/modules/admin/screens/watermark/watermark-screen/watermark-screen.component.html @@ -1,6 +1,6 @@
-
+
= { text: 'Watermark', @@ -32,9 +42,10 @@ export const DEFAULT_WATERMARK: Partial = { }) export class WatermarkScreenComponent { readonly iconButtonTypes = IconButtonTypes; - readonly form: UntypedFormGroup = this._getForm(); + readonly currentUser = getCurrentUser(); + readonly form = this._getForm(); readonly watermark$: Observable>; - readonly #dossierTemplateId: string = getParam(DOSSIER_TEMPLATE_ID); + readonly #dossierTemplateId = getParam(DOSSIER_TEMPLATE_ID); readonly #watermarkId = Number(getParam(WATERMARK_ID)); private _instance: WebViewerInstance; private _watermark: Partial = {}; @@ -45,7 +56,7 @@ export class WatermarkScreenComponent { private readonly _http: HttpClient, private readonly _toaster: Toaster, private readonly _formBuilder: UntypedFormBuilder, - readonly permissionsService: PermissionsService, + readonly permissionsService: IqserPermissionsService, private readonly _loadingService: LoadingService, private readonly _licenseService: LicenseService, @Inject(BASE_HREF_FN) private readonly _convertPath: BaseHrefFn, @@ -210,7 +221,7 @@ export class WatermarkScreenComponent { orientation: [null], }); - if (!this.permissionsService.isAdmin()) { + if (!this.currentUser.isAdmin || !this.permissionsService.has(ROLES.watermarks.write)) { form.disable(); } diff --git a/apps/red-ui/src/app/modules/admin/screens/watermark/watermark.module.ts b/apps/red-ui/src/app/modules/admin/screens/watermark/watermark.module.ts index 2f6dd99b0..b33918c7f 100644 --- a/apps/red-ui/src/app/modules/admin/screens/watermark/watermark.module.ts +++ b/apps/red-ui/src/app/modules/admin/screens/watermark/watermark.module.ts @@ -10,6 +10,7 @@ import { IqserButtonsModule, IqserHelpModeModule, IqserListingModule, + IqserPermissionsModule, IqserScrollbarModule, IqserUsersModule, } from '@iqser/common-ui'; @@ -57,6 +58,7 @@ const routes = [ IqserListingModule, IqserScrollbarModule, IqserHelpModeModule, + IqserPermissionsModule, ], }) export class WatermarkModule {} diff --git a/apps/red-ui/src/app/modules/admin/screens/watermark/watermarks-listing/watermarks-listing-screen.component.html b/apps/red-ui/src/app/modules/admin/screens/watermark/watermarks-listing/watermarks-listing-screen.component.html index f8f384229..cdaadddd8 100644 --- a/apps/red-ui/src/app/modules/admin/screens/watermark/watermarks-listing/watermarks-listing-screen.component.html +++ b/apps/red-ui/src/app/modules/admin/screens/watermark/watermarks-listing/watermarks-listing-screen.component.html @@ -12,11 +12,11 @@
@@ -32,7 +32,7 @@ @@ -66,7 +66,7 @@ { readonly iconButtonTypes = IconButtonTypes; readonly circleButtonTypes = CircleButtonTypes; - readonly currentUser = getCurrentUser(); + readonly currentUser = getCurrentUser(); + readonly roles = ROLES; readonly tableColumnConfigs: TableColumnConfig[] = [ { label: _('watermarks-listing.table-col-names.name'), sortByKey: 'searchKey', width: '2fr' }, { label: _('watermarks-listing.table-col-names.status'), sortByKey: 'enabled', class: 'flex-center' }, @@ -36,8 +38,8 @@ export class WatermarksListingScreenComponent extends ListingComponent