Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed problem opening role with a missing right #5 #7

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions acm-api.service.ts
Original file line number Diff line number Diff line change
@@ -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<StartOrderResult> {
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;
}
}
10 changes: 0 additions & 10 deletions acm-consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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;
}
14 changes: 3 additions & 11 deletions acm-route-component.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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({
Expand Down Expand Up @@ -72,8 +72,6 @@ export abstract class ACMRouteComponent<T extends ACMTableObject> extends RouteC

private readonly currentObjectChangeSubject = new Subject<T>();

private readonly currentXoLocale: XoACMLocale;

get currentObjectChange() {
return this.currentObjectChangeSubject.asObservable();
}
Expand All @@ -86,13 +84,9 @@ export abstract class ACMRouteComponent<T extends ACMTableObject> 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
Expand All @@ -103,8 +97,6 @@ export abstract class ACMRouteComponent<T extends ACMTableObject> 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);
Expand Down
2 changes: 1 addition & 1 deletion acm.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
18 changes: 6 additions & 12 deletions rights-management/rights-management.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -65,7 +66,7 @@ export class RightsManagementComponent extends ACMRouteComponent<XoRight> {

beforeInitTableRefresh() {
this.tableDataSource.output = XoRightArray;
this.tableDataSource.input = this.xoLocale;
this.tableDataSource.input = this.apiService.xoLocale;
}

create(refRight?: XoRight) {
Expand All @@ -76,15 +77,8 @@ export class RightsManagementComponent extends ACMRouteComponent<XoRight> {

this.dialogService.custom<XoRight, AddNewRightComponentData>(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)
);
}
});
Expand All @@ -98,7 +92,7 @@ export class RightsManagementComponent extends ACMRouteComponent<XoRight> {
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) => {
Expand Down
42 changes: 25 additions & 17 deletions roles-management/locale/roles-translations.de-DE.ts
Original file line number Diff line number Diff line change
@@ -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';


Expand Down Expand Up @@ -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
{
Expand Down
42 changes: 25 additions & 17 deletions roles-management/locale/roles-translations.en-US.ts
Original file line number Diff line number Diff line change
@@ -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';


Expand Down Expand Up @@ -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?'
}
];
29 changes: 25 additions & 4 deletions roles-management/roles-management.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -187,7 +188,7 @@ export class RolesManagementComponent extends ACMRouteComponent<XoRoleTableEntry
}

updateRights() {
getAllRights(this.apiService, this.xoLocale).subscribe(
getAllRights(this.apiService, this.apiService.xoLocale).subscribe(
(rights: XoRightArray) => {
if (rights) {
this.allRights = rights;
Expand All @@ -203,8 +204,28 @@ export class RolesManagementComponent extends ACMRouteComponent<XoRoleTableEntry

if (roleName.roleName) {
return this.apiService
.startOrder(RTC, XACM_WF.xmcp.xacm.rolesmanagement.GetRoleDetails, [roleName, this.xoLocale], XoRole, StartOrderOptionsBuilder.defaultOptionsWithErrorMessage).pipe(
filter(result => 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 => {
Expand Down
3 changes: 2 additions & 1 deletion user-management/user-management.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Loading