From eade47fb9ec163a80695c9269a094a7631cd7731 Mon Sep 17 00:00:00 2001 From: Johannes Heucher Date: Tue, 24 Jan 2023 14:00:15 +0100 Subject: [PATCH] fixed problem opening role with a missing right #5 --- acm-api.service.ts | 68 +++++++++++++++++++ acm-consts.ts | 10 --- acm-route-component.class.ts | 14 +--- acm.module.ts | 2 +- .../rights-management.component.ts | 18 ++--- .../locale/roles-translations.de-DE.ts | 42 +++++++----- .../locale/roles-translations.en-US.ts | 42 +++++++----- .../roles-management.component.ts | 29 ++++++-- user-management/user-management.component.ts | 3 +- xo/xo-right.model.ts | 40 ++++++----- 10 files changed, 178 insertions(+), 90 deletions(-) create mode 100644 acm-api.service.ts diff --git a/acm-api.service.ts b/acm-api.service.ts new file mode 100644 index 0000000..a31de5a --- /dev/null +++ b/acm-api.service.ts @@ -0,0 +1,68 @@ +/* + * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + * Copyright 2022 GIP SmartMercial GmbH, Germany + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + */ +import { HttpClient } from '@angular/common/http'; +import { Injectable } from '@angular/core'; +import { ApiService, StartOrderOptionsBuilder, StartOrderResult } from '@zeta/api'; +import { I18nService } from '@zeta/i18n'; +import { XcDialogService } from '@zeta/xc'; +import { catchError, EMPTY, filter, Observable } from 'rxjs'; +import { extractError, RTC, XACM_WF } from './acm-consts'; +import { XoACMLocale } from './xo/xo-locale.model'; +import { XoRight } from './xo/xo-right.model'; + + +@Injectable() +export class ACMApiService extends ApiService { + + defaultStartOrderOptions1 = new StartOrderOptionsBuilder() + .withErrorMessage(true) + .options; + + private readonly currentXoLocale: XoACMLocale; + + + constructor(http: HttpClient, readonly i18n: I18nService, private readonly dialogService: XcDialogService) { + super(http); + this.currentXoLocale = new XoACMLocale(); + this.currentXoLocale.language = i18n.language; + } + + + createRight(right: XoRight): Observable { + return this.startOrder(RTC, XACM_WF.xmcp.xacm.rightsmanagement.CreateRight, [right, this.xoLocale], null, StartOrderOptionsBuilder.defaultOptionsWithErrorMessage).pipe( + catchError(error => { + this.dialogService.error(extractError(error)); + return EMPTY; + }), + filter(response => { + if (response?.errorMessage) { + this.dialogService.error(response.errorMessage); + } + return response && !response.errorMessage; + }) + ); + } + + + /** @todo Add functions for all other ACM API calls (move them from their management-components into this service) */ + + + get xoLocale(): XoACMLocale { + return this.currentXoLocale; + } +} diff --git a/acm-consts.ts b/acm-consts.ts index fdf3536..4a6aebe 100644 --- a/acm-consts.ts +++ b/acm-consts.ts @@ -15,8 +15,6 @@ * limitations under the License. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ -import { Injectable } from '@angular/core'; - import { ApiService, RuntimeContext, StartOrderOptionsBuilder, StartOrderResult } from '@zeta/api'; import { Observable, Subject } from 'rxjs'; @@ -83,11 +81,3 @@ export function getAllRights(apiService: ApiService, xoLocale: XoACMLocale): Obs return subject.asObservable(); } - - -@Injectable() -export class ACMApiService extends ApiService { - defaultStartOrderOptions = new StartOrderOptionsBuilder() - .withErrorMessage(true) - .options; -} diff --git a/acm-route-component.class.ts b/acm-route-component.class.ts index 420f4d6..2340b65 100644 --- a/acm-route-component.class.ts +++ b/acm-route-component.class.ts @@ -18,12 +18,13 @@ import { Component, Injector, OnInit, ViewChild } from '@angular/core'; import { ActivatedRoute, NavigationExtras, Router } from '@angular/router'; -import { ApiService, StartOrderOptionsBuilder } from '@zeta/api'; +import { StartOrderOptionsBuilder } from '@zeta/api'; import { I18nService } from '@zeta/i18n'; import { RouteComponent } from '@zeta/nav'; import { XcDialogService, XcFormDirective, XDSIconName } from '@zeta/xc'; import { Observable, of, Subject } from 'rxjs'; +import { ACMApiService } from './acm-api.service'; import { RTC, XACM_WF } from './acm-consts'; import { ACMNavigationService } from './acm-navigation.service'; @@ -33,7 +34,6 @@ import { acm_route_translations_de_DE } from './locale/acm-translations.de-DE'; import { acm_route_translations_en_US } from './locale/acm-translations.en-US'; import { ACMTableObject } from './xo/acm-table-object.model'; import { XoDomainArray } from './xo/xo-domain.model'; -import { XoACMLocale } from './xo/xo-locale.model'; @Component({ @@ -72,8 +72,6 @@ export abstract class ACMRouteComponent extends RouteC private readonly currentObjectChangeSubject = new Subject(); - private readonly currentXoLocale: XoACMLocale; - get currentObjectChange() { return this.currentObjectChangeSubject.asObservable(); } @@ -86,13 +84,9 @@ export abstract class ACMRouteComponent extends RouteC return (this.i18nService.language === I18nService.EN_US); } - get xoLocale(): XoACMLocale { - return this.currentXoLocale; - } - constructor( readonly injector: Injector, - protected readonly apiService: ApiService, + protected readonly apiService: ACMApiService, protected readonly i18nService: I18nService, protected readonly dialogService: XcDialogService, protected readonly settings: ACMSettingsService @@ -103,8 +97,6 @@ export abstract class ACMRouteComponent extends RouteC this.router = injector.get(Router); - this.currentXoLocale = new XoACMLocale(); - this.currentXoLocale.language = this.i18nService.language; this.route = injector.get(ActivatedRoute); this.acmNavigationService = injector.get(ACMNavigationService); diff --git a/acm.module.ts b/acm.module.ts index 269a9f5..633e7d7 100644 --- a/acm.module.ts +++ b/acm.module.ts @@ -20,8 +20,8 @@ import { NgModule } from '@angular/core'; import { RouterModule } from '@angular/router'; import { ZetaModule } from '@zeta/zeta.module'; +import { ACMApiService } from './acm-api.service'; -import { ACMApiService } from './acm-consts'; import { ACMNavigationService } from './acm-navigation.service'; import { ACMSettingsService } from './acm-settings.service'; import { AcmComponent } from './acm.component'; diff --git a/rights-management/rights-management.component.ts b/rights-management/rights-management.component.ts index ee75dc3..a152148 100644 --- a/rights-management/rights-management.component.ts +++ b/rights-management/rights-management.component.ts @@ -20,8 +20,9 @@ import { Component, Injector } from '@angular/core'; import { StartOrderOptionsBuilder, StartOrderResult } from '@zeta/api'; import { I18nService } from '@zeta/i18n'; import { XcDialogService, XcRichListItem } from '@zeta/xc'; +import { ACMApiService } from '../acm-api.service'; -import { ACMApiService, extractError, RTC, XACM_WF } from '../acm-consts'; +import { extractError, RTC, XACM_WF } from '../acm-consts'; import { ACMRouteComponent } from '../acm-route-component.class'; import { ACMSettingsService } from '../acm-settings.service'; import { XoModifyRightRequest } from '../xo/xo-modify-right-request.model'; @@ -65,7 +66,7 @@ export class RightsManagementComponent extends ACMRouteComponent { beforeInitTableRefresh() { this.tableDataSource.output = XoRightArray; - this.tableDataSource.input = this.xoLocale; + this.tableDataSource.input = this.apiService.xoLocale; } create(refRight?: XoRight) { @@ -76,15 +77,8 @@ export class RightsManagementComponent extends ACMRouteComponent { this.dialogService.custom(AddNewRightComponent, data).afterDismissResult().subscribe(right => { if (right) { - this.apiService.startOrder(RTC, XACM_WF.xmcp.xacm.rightsmanagement.CreateRight, [right, this.xoLocale], null, StartOrderOptionsBuilder.defaultOptionsWithErrorMessage).subscribe( - result => { - if (result && !result.errorMessage) { - this.refresh(true); - } else { - this.dialogService.error(result.errorMessage); - } - }, - error => this.dialogService.error(extractError(error)) + this.apiService.createRight(right).subscribe(result => + this.refresh(true) ); } }); @@ -98,7 +92,7 @@ export class RightsManagementComponent extends ACMRouteComponent { const request = new XoModifyRightRequest(); request.rightName = this.currentObject.rightName; request.documentation = this.currentObject.documentation; - request.locale = this.xoLocale; + request.locale = this.apiService.xoLocale; this.apiService.startOrder(RTC, XACM_WF.xmcp.xacm.rightsmanagement.ModifyRight, request, null, StartOrderOptionsBuilder.defaultOptionsWithErrorMessage).subscribe( (result: StartOrderResult) => { diff --git a/roles-management/locale/roles-translations.de-DE.ts b/roles-management/locale/roles-translations.de-DE.ts index 8da04c3..ec6e545 100644 --- a/roles-management/locale/roles-translations.de-DE.ts +++ b/roles-management/locale/roles-translations.de-DE.ts @@ -1,20 +1,20 @@ -/* - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * Copyright 2022 GIP SmartMercial GmbH, Germany - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ +/* + * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + * Copyright 2022 GIP SmartMercial GmbH, Germany + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + */ import { I18nTranslation } from '@zeta/i18n'; @@ -91,6 +91,14 @@ export const roles_translations_de_DE: I18nTranslation[] = [ key: 'xmcp.xacm.roles.revoke', value: 'Entziehen' }, + { + key: 'xmcp.xacm.roles.unknown-right-title', + value: 'Unbekanntes Recht' + }, + { + key: 'xmcp.xacm.roles.unknown-right', + value: 'Das verwendete Recht "%right%" existiert nicht. Soll es angelegt werden, um diese Rolle bearbeiten zu können?' + }, // TABLE COLUMNS { diff --git a/roles-management/locale/roles-translations.en-US.ts b/roles-management/locale/roles-translations.en-US.ts index b8aea72..f369c4f 100644 --- a/roles-management/locale/roles-translations.en-US.ts +++ b/roles-management/locale/roles-translations.en-US.ts @@ -1,20 +1,20 @@ -/* - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * Copyright 2022 GIP SmartMercial GmbH, Germany - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ +/* + * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + * Copyright 2022 GIP SmartMercial GmbH, Germany + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + */ import { I18nTranslation } from '@zeta/i18n'; @@ -90,5 +90,13 @@ export const roles_translations_en_US: I18nTranslation[] = [ { key: 'xmcp.xacm.roles.revoke', value: 'Revoke' + }, + { + key: 'xmcp.xacm.roles.unknown-right-title', + value: 'Unknown Right' + }, + { + key: 'xmcp.xacm.roles.unknown-right-body', + value: 'Linked right "%right%" is not known to the factory. Create right in order to manage this role?' } ]; diff --git a/roles-management/roles-management.component.ts b/roles-management/roles-management.component.ts index 59765cf..e3df3c9 100644 --- a/roles-management/roles-management.component.ts +++ b/roles-management/roles-management.component.ts @@ -24,8 +24,9 @@ import { XcDialogService, XcLocalTableDataSource, XDSIconName } from '@zeta/xc'; import { of, throwError } from 'rxjs'; import { Observable } from 'rxjs/internal/Observable'; import { catchError, filter, map } from 'rxjs/operators'; +import { ACMApiService } from '../acm-api.service'; -import { ACMApiService, extractError, getAllRights, RTC, XACM_WF } from '../acm-consts'; +import { extractError, getAllRights, RTC, XACM_WF } from '../acm-consts'; import { ACMRouteComponent } from '../acm-route-component.class'; import { ACMSettingsService } from '../acm-settings.service'; import { XoRight, XoRightArray } from '../xo/xo-right.model'; @@ -187,7 +188,7 @@ export class RolesManagementComponent extends ACMRouteComponent { if (rights) { this.allRights = rights; @@ -203,8 +204,28 @@ export class RolesManagementComponent extends ACMRouteComponent result.errorMessage ? (this.dialogService.error(result.errorMessage, null, result.stackTrace.join('\r\n')), false) : true), + .startOrder(RTC, XACM_WF.xmcp.xacm.rolesmanagement.GetRoleDetails, [roleName, this.apiService.xoLocale], XoRole, StartOrderOptionsBuilder.defaultOptionsWithErrorMessage).pipe( + filter(result => { + if (result.errorMessage) { + // if the error is due to a missing right ... + const missingRight = /Right\s(.*)\sis\snot\sknown\sto\sthe\sfactory/.exec(result.errorMessage)[1]; + if (missingRight) { + this.dialogService.confirm( + this.i18nService.translate('xmcp.xacm.roles.unknown-right-title'), + this.i18nService.translate('xmcp.xacm.roles.unknown-right-body', { key: '%right%', value: missingRight }) + ).afterDismissResult().pipe(filter(answer => answer)).subscribe(answer => { + // ... create missing right + const right = XoRight.withName(missingRight); + this.apiService.createRight(right).subscribe(); + }); + } else { + // ... else show general error + this.dialogService.error(result.errorMessage, null, result.stackTrace.join('\r\n')); + } + return false; + } + return true; + }), filter(result => result && !result.errorMessage), map(result => result.output[0] as XoRole), catchError(error => { diff --git a/user-management/user-management.component.ts b/user-management/user-management.component.ts index a56ca40..e2b0d23 100644 --- a/user-management/user-management.component.ts +++ b/user-management/user-management.component.ts @@ -23,8 +23,9 @@ import { I18nService } from '@zeta/i18n'; import { XcAutocompleteDataWrapper, XcDialogService, XcOptionItem, XcOptionItemString, XcRichListItem } from '@zeta/xc'; import { Observable, of, Subject, Subscription } from 'rxjs'; +import { ACMApiService } from '../acm-api.service'; -import { ACMApiService, extractError, RTC, XACM_WF } from '../acm-consts'; +import { extractError, RTC, XACM_WF } from '../acm-consts'; import { ACMRouteComponent } from '../acm-route-component.class'; import { ACMSettingsService } from '../acm-settings.service'; import { XoCreateUserRequest } from '../xo/xo-create-user-request.model'; diff --git a/xo/xo-right.model.ts b/xo/xo-right.model.ts index 5b3373a..fec5071 100644 --- a/xo/xo-right.model.ts +++ b/xo/xo-right.model.ts @@ -1,20 +1,20 @@ -/* - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * Copyright 2022 GIP SmartMercial GmbH, Germany - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ +/* + * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + * Copyright 2022 GIP SmartMercial GmbH, Germany + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + */ import { XoArray, XoArrayClass, XoObjectClass, XoProperty, XoTransient, XoUnique } from '@zeta/api'; import { ACMTableObject } from './acm-table-object.model'; @@ -93,6 +93,12 @@ export class XoRight extends ACMTableObject { return ''; } + static withName(name: string): XoRight { + const right = new XoRight(); + right.rightName = name; + return right; + } + static getXoRightParameterFromString(para: string, type: RightParameterType): XoRightParameter { // - 3 Possibilities // 1. options! if it starts with an '[' every option is seperated by ',' and it ends with ']'