|
|
|
|
@ -36,7 +36,7 @@ export class MenuComponent {
|
|
|
|
|
) {
|
|
|
|
|
this.permission = this.fb.group({ userCode: [null] });
|
|
|
|
|
this.defaultPermissions().subscribe((data: PermissionNode[]) => {
|
|
|
|
|
this.permissions = data; // needed for savePermissions
|
|
|
|
|
this.permissions = data;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -71,19 +71,7 @@ export class MenuComponent {
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
// mapEndpointsToPermissions(endpoints: string[]): PermissionNode[] {
|
|
|
|
|
// return [{
|
|
|
|
|
// name: 'menu',
|
|
|
|
|
// checked: false,
|
|
|
|
|
// expanded: false,
|
|
|
|
|
// children: [
|
|
|
|
|
// { name: 'accountToAccount', checked: endpoints.includes(this.uriService.getURIForRequest(URIKey.ACCOUNT_TO_ACCOUNT)), expanded: false },
|
|
|
|
|
// { name: 'glToGl', checked: endpoints.includes(this.uriService.getURIForRequest(URIKey.GL_TO_GL)), expanded: false },
|
|
|
|
|
// { name: 'accountToGl', checked: endpoints.includes(this.uriService.getURIForRequest(URIKey.ACCOUNT_TO_GL)), expanded: false },
|
|
|
|
|
// { name: 'glToAccount', checked: endpoints.includes(this.uriService.getURIForRequest(URIKey.GL_TO_ACCOUNT)), expanded: false }
|
|
|
|
|
// ]
|
|
|
|
|
// }];
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
onUserChange() {
|
|
|
|
|
this.showPermissions = true;
|
|
|
|
|
const userId = this.permission.get('userCode')?.value;
|
|
|
|
|
@ -110,41 +98,12 @@ onUserChange() {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Add this helper method to the class
|
|
|
|
|
private normalizeUrl(url: string): string {
|
|
|
|
|
return url?.trim().toLowerCase().replace(/\/+$/, ''); // trim, lowercase, remove trailing slash
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// savePermissions() {
|
|
|
|
|
// const selectedUser = this.permission.get('userCode')?.value;
|
|
|
|
|
// const menuNode = this.permissions.find(x => x.name === 'menu');
|
|
|
|
|
// if (!menuNode) return;
|
|
|
|
|
|
|
|
|
|
// const nameToURIKey: { [key: string]: URIKey } = {
|
|
|
|
|
// accountToAccount: URIKey.ACCOUNT_TO_ACCOUNT,
|
|
|
|
|
// glToGl: URIKey.GL_TO_GL,
|
|
|
|
|
// accountToGl: URIKey.ACCOUNT_TO_GL,
|
|
|
|
|
// glToAccount: URIKey.GL_TO_ACCOUNT
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
// const transactionEndpoints: string[] = (menuNode.children || [])
|
|
|
|
|
// .filter(c => c.checked)
|
|
|
|
|
// .map(c => this.uriService.getURIForRequest(nameToURIKey[c.name]));
|
|
|
|
|
|
|
|
|
|
// const payload = { userId: selectedUser, transactionEndpoints, permissions: JSON.stringify(this.permissions) };
|
|
|
|
|
|
|
|
|
|
// this.httpService.requestPOST(URIKey.TRANSACTION_PERMISSIONS_ASSIGN, payload).subscribe((response: any) => {
|
|
|
|
|
// if (!(response instanceof HttpErrorResponse)) {
|
|
|
|
|
// this.i18nService.success(SuccessMessages.SAVED_SUCCESSFULLY, []);
|
|
|
|
|
// this.permission.get('userCode')?.setValue(selectedUser);
|
|
|
|
|
// this.onUserChange();
|
|
|
|
|
// }
|
|
|
|
|
// });
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
savePermissions() {
|
|
|
|
|
if (this.saving) return; // ← guard against double clicks
|
|
|
|
|
if (this.saving) return;
|
|
|
|
|
this.saving = true;
|
|
|
|
|
|
|
|
|
|
const selectedUser = this.permission.get('userCode')?.value;
|
|
|
|
|
@ -157,7 +116,11 @@ savePermissions() {
|
|
|
|
|
.filter(item => item.checked)
|
|
|
|
|
.map(item => item.endpoint);
|
|
|
|
|
|
|
|
|
|
const payload = { userId: selectedUser, transactionEndpoints };
|
|
|
|
|
const payload = {
|
|
|
|
|
porOrgacode: this.credentialService.getPorOrgacode(),
|
|
|
|
|
userId: selectedUser,
|
|
|
|
|
transactionEndpoints
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
this.httpService.requestPOST(URIKey.TRANSACTION_PERMISSIONS_ASSIGN, payload)
|
|
|
|
|
.subscribe({
|
|
|
|
|
@ -183,9 +146,7 @@ savePermissions() {
|
|
|
|
|
if (savedNode) {
|
|
|
|
|
// Update state from saved node
|
|
|
|
|
existingNode.checked = savedNode.checked;
|
|
|
|
|
//existingNode.expanded = savedNode.expanded;
|
|
|
|
|
|
|
|
|
|
// Recursively update children if they exist
|
|
|
|
|
if (existingNode.children) {
|
|
|
|
|
this.updatePermissions(savedNode.children || [], existingNode.children);
|
|
|
|
|
}
|
|
|
|
|
|