Skip to content

Commit

Permalink
#368 - Unable to remove access lines from the Access overview
Browse files Browse the repository at this point in the history
  • Loading branch information
Yi-Jacob committed Nov 20, 2024
1 parent 7e939f7 commit a1aa85a
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 12 deletions.
9 changes: 6 additions & 3 deletions environments/environment.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
export const environment = {
dfAdminApiKey: '6498a8ad1beb9d84d63035c5d1120c007fad6de706734db9689f8996707e0f7d',
dfApiDocsApiKey: '36fda24fe5588fa4285ac6c6c2fdfbdb6b6bc9834699774c9bf777f706d05a88',
dfFileManagerApiKey: 'b5cb82af7b5d4130f36149f90aa2746782e59a872ac70454ac188743cb55b0ba',
dfAdminApiKey:
'6498a8ad1beb9d84d63035c5d1120c007fad6de706734db9689f8996707e0f7d',
dfApiDocsApiKey:
'36fda24fe5588fa4285ac6c6c2fdfbdb6b6bc9834699774c9bf777f706d05a88',
dfFileManagerApiKey:
'b5cb82af7b5d4130f36149f90aa2746782e59a872ac70454ac188743cb55b0ba',
};
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

<div formArrayName="serviceAccess" class="full-width">
<df-roles-access
[visible]="visibilityArray"
[formArray]="serviceAccess"
[roleForm]="roleForm"
class="full-width"></df-roles-access>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export class DfRoleDetailsComponent implements OnInit {
alertMsg = '';
showAlert = false;
alertType: AlertType = 'error';
visibilityArray: boolean[] = [];

constructor(
@Inject(ROLE_SERVICE_TOKEN)
Expand Down Expand Up @@ -100,6 +101,7 @@ export class DfRoleDetailsComponent implements OnInit {
this.filterOp = data.roleServiceAccessByRoleId[0].filterOp;
data.roleServiceAccessByRoleId.forEach(
(item: RoleServiceAccessType) => {
this.visibilityArray.push(true);
const advancedFilters = new FormArray(
(item.filters || []).map(
(each: any) =>
Expand Down Expand Up @@ -266,7 +268,7 @@ export class DfRoleDetailsComponent implements OnInit {
description: formValue.description,
isActive: formValue.active,
roleServiceAccessByRoleId: formValue.serviceAccess.map(
(val: AccessForm) => {
(val: AccessForm, index: number) => {
const filtersArray = val.advancedFilters.map((filter: any) => ({
name: filter.expandField,
operator: filter.expandOperator,
Expand All @@ -275,8 +277,10 @@ export class DfRoleDetailsComponent implements OnInit {
const filterOp = val.advancedFilters.map(
(filter: any) => filter.filterOp
);
const roleId = this.visibilityArray[index] ? formValue.id : null;
return {
id: val.id,
roleId: roleId,
serviceId: val.service === 0 ? null : val.service,
component: val.component,
verbMask: val.access.reduce((acc, cur) => acc + cur, 0), // add up all the values in the array
Expand Down
13 changes: 9 additions & 4 deletions src/app/adf-roles/df-roles-access/df-roles-access.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import { CommonModule } from '@angular/common';
export class DfRolesAccessComponent implements OnInit {
@Input() formArray: FormArray;
@Input() roleForm: FormGroup;
@Input() visible: boolean[];
rootForm: FormGroup;
serviceAccess: FormArray;
dataSource: MatTableDataSource<any>;
Expand Down Expand Up @@ -268,8 +269,10 @@ export class DfRolesAccessComponent implements OnInit {
}

updateDataSource() {
if (!this.formArray) return;
this.dataSource = new MatTableDataSource(this.formArray.controls);
const visibleControls = this.formArray.controls.filter(
(control, index) => this.visible[index]
);
this.dataSource = new MatTableDataSource(visibleControls);
}

get hasServiceAccess() {
Expand All @@ -290,7 +293,7 @@ export class DfRolesAccessComponent implements OnInit {
serviceAccess: new FormControl(''),
})
);

this.visible.push(true);
this.updateDataSource();
}

Expand Down Expand Up @@ -320,7 +323,9 @@ export class DfRolesAccessComponent implements OnInit {
}

remove(index: number) {
this.formArray.removeAt(index);
if (index >= 0 && index < this.formArray.length) {
this.visible[index] = false;
}
this.updateDataSource();
}

Expand Down
11 changes: 7 additions & 4 deletions src/app/shared/interceptors/session-token.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@ export const sessionTokenInterceptor: HttpInterceptorFn = (
next: HttpHandlerFn
) => {
if (req.url.startsWith('/api')) {
const isApiDocs = req.urlWithParams.includes('swagger') ||
req.url.includes('service_type') ||
req.url.includes('api_docs');
const isApiDocs =
req.urlWithParams.includes('swagger') ||
req.url.includes('service_type') ||
req.url.includes('api_docs');
req = req.clone({
setHeaders: {
[API_KEY_HEADER]: isApiDocs ? environment.dfApiDocsApiKey : environment.dfAdminApiKey,
[API_KEY_HEADER]: isApiDocs
? environment.dfApiDocsApiKey
: environment.dfAdminApiKey,
},
});
const userDataService = inject(DfUserDataService);
Expand Down

0 comments on commit a1aa85a

Please sign in to comment.