import * as jsonpath from 'jsonpath';
import { RestService } from 'RestService';
import { Permission, PermissionGroup, RoleConfig, RoleData } from 'RolesModel';
-import { SharedService } from 'SharedService';
-import { isNullOrUndefined } from 'util';
+import { SharedService, isNullOrUndefined } from 'SharedService';
/**
* Creating component
/** Contains view selection value either text or preview @public */
public viewMode: string = 'text';
+ /** Contains current permissions data @private */
+ private currentPermissions: string;
+
+ /** Contains current role name @private */
+ private currentRoleName: string;
+
+ /** Contains modified role name @private */
+ private modifiedRoleName: string;
+
/** Contains role id value @private */
private roleRef: string;
};
this.restService.postResource(apiURLHeader, postData).subscribe(() => {
this.notifierService.notify('success', this.translateService.instant('PAGE.ROLES.CREATEDSUCCESSFULLY'));
- this.router.navigate(['/roles/details']).catch();
+ this.router.navigate(['/roles/details']).catch((): void => {
+ // Catch Navigation Error
+ });
}, (error: ERRORDATA) => {
this.isLoadingResults = false;
this.restService.handleError(error, 'post');
url: environment.ROLES_URL + '/' + this.roleRef,
httpOptions: { headers: this.headers }
};
+ this.modifiedRoleName = this.roleForm.value.roleName;
let permissionData: Object = {};
this.sharedService.cleanForm(this.roleForm);
if (!this.roleForm.invalid) {
if (this.viewMode === 'preview') {
- this.isLoadingResults = true;
permissionData = this.generatePermissions();
this.roleEditAPI(apiURLHeader, permissionData);
} else {
if (this.checkPermission()) {
- this.isLoadingResults = true;
permissionData = this.roleForm.value.permissions !== '' ? JSON.parse(this.roleForm.value.permissions) : {};
this.roleEditAPI(apiURLHeader, permissionData);
}
/** Method to handle role edit API call */
public roleEditAPI(apiURLHeader: APIURLHEADER, permissionData: {}): void {
+ if ((JSON.stringify(permissionData, null, '\t') === this.currentPermissions) && (this.modifiedRoleName === this.currentRoleName)) {
+ this.notifierService.notify('warning', this.translateService.instant('PAGE.TOPOLOGY.DATAEMPTY'));
+ return;
+ }
+ this.isLoadingResults = true;
const postData: {} = {
name: this.roleForm.value.roleName,
permissions: !isNullOrUndefined(permissionData) ? permissionData : {}
};
this.restService.patchResource(apiURLHeader, postData).subscribe(() => {
this.notifierService.notify('success', this.translateService.instant('PAGE.ROLES.UPDATEDSUCCESSFULLY'));
- this.router.navigate(['/roles/details']).catch();
+ this.router.navigate(['/roles/details']).catch((): void => {
+ // Catch Navigation Error
+ });
}, (error: ERRORDATA) => {
this.isLoadingResults = false;
this.restService.handleError(error, 'patch');
}
this.viewMode = 'text';
}
-
}
/** Generate role permission post data @private */
this.roleForm.value.permissions = this.roleForm.value.permissions.replace(/'/g, '"');
const rolePermission: {} = JSON.parse(this.roleForm.value.permissions);
for (const key of Object.keys(rolePermission)) {
+ // eslint-disable-next-line security/detect-object-injection
if (typeof rolePermission[key] !== 'boolean') {
this.notifierService.notify('error', this.translateService.instant('PAGE.ROLES.ROLEKEYERROR', { roleKey: key }));
return false;
/** Get role data from NBI based on ID and apply filter @private */
private getRoleData(): void {
- // tslint:disable-next-line: no-backbone-get-set-outside-model
this.roleRef = this.activatedRoute.snapshot.paramMap.get('id');
if (!isNullOrUndefined(this.roleRef)) {
this.restService.getResource(environment.ROLES_URL + '/' + this.roleRef).subscribe((data: RoleData) => {
this.roleForm.setValue({ roleName: data.name, permissions: JSON.stringify(data.permissions, null, '\t') });
this.filterRoleData(data.permissions);
this.isLoadingResults = false;
+ this.currentRoleName = data.name;
+ this.currentPermissions = JSON.stringify(data.permissions, null, '\t');
}, (error: ERRORDATA) => {
- this.router.navigate(['/roles/details']).catch();
+ this.router.navigate(['/roles/details']).catch((): void => {
+ // Catch Navigation Error
+ });
this.restService.handleError(error, 'get');
});
}
Object.keys(permissions).forEach((permission: string) => {
jsonpath.apply(this.rolePermissions, '$..permissions[?(@.operation == "' + permission + '")]', (response: Permission) => {
if (response.operation === permission) {
+ // eslint-disable-next-line security/detect-object-injection
response.value = permissions[permission];
}
return response;
});
});
}
-
}