fix(ui): use signals for OIDC settings (#1737)
This commit is contained in:
+63
-57
@@ -537,7 +537,8 @@
|
|||||||
<label for="groupSyncMode">{{ t('groupMapping.syncModeLabel') }}</label>
|
<label for="groupSyncMode">{{ t('groupMapping.syncModeLabel') }}</label>
|
||||||
<p-select
|
<p-select
|
||||||
inputId="groupSyncMode"
|
inputId="groupSyncMode"
|
||||||
[(ngModel)]="groupSyncMode"
|
[ngModel]="groupSyncMode()"
|
||||||
|
(ngModelChange)="groupSyncMode.set($event)"
|
||||||
[options]="groupSyncModeOptions"
|
[options]="groupSyncModeOptions"
|
||||||
optionLabel="label"
|
optionLabel="label"
|
||||||
optionValue="value"
|
optionValue="value"
|
||||||
@@ -557,8 +558,8 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@if (groupMappings.length > 0) {
|
@if (groupMappings().length > 0) {
|
||||||
<p-table [value]="groupMappings" [tableStyle]="{'min-width': '100%'}" styleClass="p-datatable-sm">
|
<p-table [value]="groupMappings()" [tableStyle]="{'min-width': '100%'}" styleClass="p-datatable-sm">
|
||||||
<ng-template #header>
|
<ng-template #header>
|
||||||
<tr>
|
<tr>
|
||||||
<th>{{ t('groupMapping.colGroupClaim') }}</th>
|
<th>{{ t('groupMapping.colGroupClaim') }}</th>
|
||||||
@@ -602,72 +603,77 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<p-dialog
|
<p-dialog
|
||||||
[header]="editingGroupMapping.id ? t('groupMapping.editTitle') : t('groupMapping.addTitle')"
|
[header]="groupMappingDraft()?.id ? t('groupMapping.editTitle') : t('groupMapping.addTitle')"
|
||||||
[(visible)]="showGroupMappingDialog"
|
[visible]="!!groupMappingDraft()"
|
||||||
|
(onHide)="groupMappingDraft.set(null)"
|
||||||
[modal]="true"
|
[modal]="true"
|
||||||
[style]="{width: '550px', maxWidth: '95vw'}"
|
[style]="{width: '550px', maxWidth: '95vw'}"
|
||||||
[dismissableMask]="true">
|
[dismissableMask]="true">
|
||||||
<div class="config-grid" style="gap: 0.875rem;">
|
@if (groupMappingDraft(); as draft) {
|
||||||
<div class="config-item full-width">
|
<div class="config-grid" style="gap: 0.875rem;">
|
||||||
<label for="gmGroupClaim">{{ t('groupMapping.groupClaimLabel') }}</label>
|
<div class="config-item full-width">
|
||||||
<input pInputText id="gmGroupClaim" [(ngModel)]="editingGroupMapping.oidcGroupClaim" [placeholder]="t('groupMapping.groupClaimPlaceholder')"/>
|
<label for="gmGroupClaim">{{ t('groupMapping.groupClaimLabel') }}</label>
|
||||||
</div>
|
<input pInputText id="gmGroupClaim" [ngModel]="draft.oidcGroupClaim" (ngModelChange)="updateGroupMappingDraft({oidcGroupClaim: $event})" [placeholder]="t('groupMapping.groupClaimPlaceholder')"/>
|
||||||
<div class="config-item full-width">
|
|
||||||
<label for="gmDescription">{{ t('groupMapping.descriptionLabel') }}</label>
|
|
||||||
<input pInputText id="gmDescription" [(ngModel)]="editingGroupMapping.description" [placeholder]="t('groupMapping.descriptionPlaceholder')"/>
|
|
||||||
</div>
|
|
||||||
<div class="config-item full-width">
|
|
||||||
<div class="provisioning-toggle" style="padding: 0;">
|
|
||||||
<div class="toggle-content">
|
|
||||||
<span class="toggle-label">{{ t('groupMapping.adminLabel') }}</span>
|
|
||||||
</div>
|
|
||||||
<p-toggleswitch
|
|
||||||
[(ngModel)]="editingGroupMapping.isAdmin"
|
|
||||||
(onChange)="onAdminCheckboxChange()"
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<div class="config-item full-width">
|
||||||
<div class="config-item full-width">
|
<label for="gmDescription">{{ t('groupMapping.descriptionLabel') }}</label>
|
||||||
<h4 class="group-title">{{ t('groupMapping.permissionsLabel') }}</h4>
|
<input pInputText id="gmDescription" [ngModel]="draft.description" (ngModelChange)="updateGroupMappingDraft({description: $event})" [placeholder]="t('groupMapping.descriptionPlaceholder')"/>
|
||||||
<div class="permissions-grid">
|
</div>
|
||||||
<div class="permission-item">
|
<div class="config-item full-width">
|
||||||
<p-checkbox [binary]="true" [disabled]="true" [ngModel]="true" inputId="gmPermRead"></p-checkbox>
|
<div class="provisioning-toggle" style="padding: 0;">
|
||||||
<label for="gmPermRead">{{ t('provisioning.readBooks') }}</label>
|
<div class="toggle-content">
|
||||||
</div>
|
<span class="toggle-label">{{ t('groupMapping.adminLabel') }}</span>
|
||||||
<ng-container *transloco="let a; prefix: 'settingsUsers'">
|
|
||||||
@for (perm of editingGroupMappingPerms; track perm) {
|
|
||||||
<div class="permission-item">
|
|
||||||
<p-checkbox
|
|
||||||
[(ngModel)]="perm.selected"
|
|
||||||
[binary]="true"
|
|
||||||
[inputId]="'gm_' + perm.value"
|
|
||||||
[disabled]="editingGroupMapping.isAdmin"
|
|
||||||
/>
|
|
||||||
<label [for]="'gm_' + perm.value">{{ a(perm.translationKey) }}</label>
|
|
||||||
</div>
|
</div>
|
||||||
}
|
<p-toggleswitch
|
||||||
</ng-container>
|
[ngModel]="draft.isAdmin"
|
||||||
|
(ngModelChange)="setGroupMappingAdmin($event)"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="config-item full-width">
|
||||||
|
<h4 class="group-title">{{ t('groupMapping.permissionsLabel') }}</h4>
|
||||||
|
<div class="permissions-grid">
|
||||||
|
<div class="permission-item">
|
||||||
|
<p-checkbox [binary]="true" [disabled]="true" [ngModel]="true" inputId="gmPermRead"></p-checkbox>
|
||||||
|
<label for="gmPermRead">{{ t('provisioning.readBooks') }}</label>
|
||||||
|
</div>
|
||||||
|
<ng-container *transloco="let a; prefix: 'settingsUsers'">
|
||||||
|
@for (perm of availablePermissions; track perm.value) {
|
||||||
|
<div class="permission-item">
|
||||||
|
<p-checkbox
|
||||||
|
[ngModel]="draft.permissions.includes(perm.value)"
|
||||||
|
(ngModelChange)="setGroupMappingPermission(perm.value, $event)"
|
||||||
|
[binary]="true"
|
||||||
|
[inputId]="'gm_' + perm.value"
|
||||||
|
[disabled]="draft.isAdmin"
|
||||||
|
/>
|
||||||
|
<label [for]="'gm_' + perm.value">{{ a(perm.translationKey) }}</label>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</ng-container>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="config-item full-width">
|
||||||
|
<h4 class="group-title">{{ t('groupMapping.librariesLabel') }}</h4>
|
||||||
|
<p-multiSelect
|
||||||
|
[options]="allLibraries"
|
||||||
|
optionLabel="name"
|
||||||
|
optionValue="id"
|
||||||
|
[ngModel]="draft.libraryIds"
|
||||||
|
(ngModelChange)="updateGroupMappingDraft({libraryIds: $event})"
|
||||||
|
[placeholder]="t('provisioning.selectLibraries')"
|
||||||
|
appendTo="body"
|
||||||
|
class="libraries-select">
|
||||||
|
</p-multiSelect>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="config-item full-width">
|
}
|
||||||
<h4 class="group-title">{{ t('groupMapping.librariesLabel') }}</h4>
|
|
||||||
<p-multiSelect
|
|
||||||
[options]="allLibraries"
|
|
||||||
optionLabel="name"
|
|
||||||
optionValue="id"
|
|
||||||
[(ngModel)]="editingGroupMappingLibraryIds"
|
|
||||||
[placeholder]="t('provisioning.selectLibraries')"
|
|
||||||
appendTo="body"
|
|
||||||
class="libraries-select">
|
|
||||||
</p-multiSelect>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<ng-template #footer>
|
<ng-template #footer>
|
||||||
<p-button
|
<p-button
|
||||||
[label]="'common.save' | transloco"
|
[label]="'common.save' | transloco"
|
||||||
icon="pi pi-check"
|
icon="pi pi-check"
|
||||||
(click)="saveGroupMapping()"
|
(click)="saveGroupMapping()"
|
||||||
[disabled]="!editingGroupMapping.oidcGroupClaim">
|
[disabled]="!groupMappingDraft()?.oidcGroupClaim">
|
||||||
</p-button>
|
</p-button>
|
||||||
</ng-template>
|
</ng-template>
|
||||||
</p-dialog>
|
</p-dialog>
|
||||||
|
|||||||
+19
-32
@@ -167,7 +167,7 @@ describe('AuthenticationSettingsComponent', () => {
|
|||||||
expect(component.availablePermissions.find(p => p.value === 'permissionDeleteBook')?.selected).toBe(false);
|
expect(component.availablePermissions.find(p => p.value === 'permissionDeleteBook')?.selected).toBe(false);
|
||||||
expect(component.editingLibraryIds).toEqual([1, 2]);
|
expect(component.editingLibraryIds).toEqual([1, 2]);
|
||||||
expect(component.sessionDurationHours).toBe(12);
|
expect(component.sessionDurationHours).toBe(12);
|
||||||
expect(component.groupSyncMode).toBe('ON_LOGIN');
|
expect(component.groupSyncMode()).toBe('ON_LOGIN');
|
||||||
expect(component.oidcForceOnlyMode).toBe(true);
|
expect(component.oidcForceOnlyMode).toBe(true);
|
||||||
expect(component.oidcProvider.providerName).toBe('Example IdP');
|
expect(component.oidcProvider.providerName).toBe('Example IdP');
|
||||||
expect(component.oidcProvider.claimMapping).toEqual({
|
expect(component.oidcProvider.claimMapping).toEqual({
|
||||||
@@ -177,7 +177,7 @@ describe('AuthenticationSettingsComponent', () => {
|
|||||||
groups: 'memberOf',
|
groups: 'memberOf',
|
||||||
});
|
});
|
||||||
expect(component.mobileRedirectUris).toEqual(['grimmory://oauth2-callback']);
|
expect(component.mobileRedirectUris).toEqual(['grimmory://oauth2-callback']);
|
||||||
expect(component.groupMappings).toEqual(mappings);
|
expect(component.groupMappings()).toEqual(mappings);
|
||||||
expect(groupMappingService.getAll).toHaveBeenCalledOnce();
|
expect(groupMappingService.getAll).toHaveBeenCalledOnce();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -191,31 +191,23 @@ describe('AuthenticationSettingsComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('opens a new group mapping dialog with blank state', () => {
|
it('opens a new group mapping dialog with blank state', () => {
|
||||||
component.editingGroupMapping = {
|
component.groupMappingDraft.set({
|
||||||
oidcGroupClaim: 'existing',
|
oidcGroupClaim: 'existing',
|
||||||
isAdmin: true,
|
isAdmin: true,
|
||||||
permissions: ['permissionUpload'],
|
permissions: ['permissionUpload'],
|
||||||
libraryIds: [1],
|
libraryIds: [1],
|
||||||
description: 'Existing',
|
description: 'Existing',
|
||||||
};
|
});
|
||||||
component.editingGroupMappingPerms = component.availablePermissions.map(permission => ({
|
|
||||||
...permission,
|
|
||||||
selected: true,
|
|
||||||
}));
|
|
||||||
component.editingGroupMappingLibraryIds = [1];
|
|
||||||
|
|
||||||
component.openNewGroupMapping();
|
component.openNewGroupMapping();
|
||||||
|
|
||||||
expect(component.showGroupMappingDialog).toBe(true);
|
expect(component.groupMappingDraft()).toEqual({
|
||||||
expect(component.editingGroupMapping).toEqual({
|
|
||||||
oidcGroupClaim: '',
|
oidcGroupClaim: '',
|
||||||
isAdmin: false,
|
isAdmin: false,
|
||||||
permissions: [],
|
permissions: [],
|
||||||
libraryIds: [],
|
libraryIds: [],
|
||||||
description: '',
|
description: '',
|
||||||
});
|
});
|
||||||
expect(component.editingGroupMappingPerms.every(permission => !permission.selected)).toBe(true);
|
|
||||||
expect(component.editingGroupMappingLibraryIds).toEqual([]);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('opens an existing group mapping dialog with cloned state and selected permissions', () => {
|
it('opens an existing group mapping dialog with cloned state and selected permissions', () => {
|
||||||
@@ -230,12 +222,11 @@ describe('AuthenticationSettingsComponent', () => {
|
|||||||
|
|
||||||
component.openEditGroupMapping(mapping);
|
component.openEditGroupMapping(mapping);
|
||||||
|
|
||||||
expect(component.showGroupMappingDialog).toBe(true);
|
const draft = component.groupMappingDraft();
|
||||||
expect(component.editingGroupMapping).toEqual(mapping);
|
expect(draft).toEqual({...mapping, permissions: ['permissionUpload']});
|
||||||
expect(component.editingGroupMapping).not.toBe(mapping);
|
expect(draft).not.toBe(mapping);
|
||||||
expect(component.editingGroupMappingPerms.find(permission => permission.value === 'permissionUpload')?.selected).toBe(true);
|
expect(draft?.permissions).not.toBe(mapping.permissions);
|
||||||
expect(component.editingGroupMappingPerms.find(permission => permission.value === 'permissionDeleteBook')?.selected).toBe(false);
|
expect(draft?.libraryIds).not.toBe(mapping.libraryIds);
|
||||||
expect(component.editingGroupMappingLibraryIds).toEqual([1, 2]);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('toggles OIDC enablement and reports persistence failures', () => {
|
it('toggles OIDC enablement and reports persistence failures', () => {
|
||||||
@@ -371,7 +362,7 @@ describe('AuthenticationSettingsComponent', () => {
|
|||||||
|
|
||||||
it('saves the group sync mode and reports failures', () => {
|
it('saves the group sync mode and reports failures', () => {
|
||||||
appSettingsService.saveSettings.mockReturnValueOnce(of(void 0));
|
appSettingsService.saveSettings.mockReturnValueOnce(of(void 0));
|
||||||
component.groupSyncMode = 'ON_LOGIN_ADDITIVE';
|
component.groupSyncMode.set('ON_LOGIN_ADDITIVE');
|
||||||
|
|
||||||
component.saveGroupSyncMode();
|
component.saveGroupSyncMode();
|
||||||
|
|
||||||
@@ -428,12 +419,13 @@ describe('AuthenticationSettingsComponent', () => {
|
|||||||
groupMappingService.update.mockReturnValue(of(createdMapping));
|
groupMappingService.update.mockReturnValue(of(createdMapping));
|
||||||
groupMappingService.delete.mockReturnValue(of(void 0));
|
groupMappingService.delete.mockReturnValue(of(void 0));
|
||||||
groupMappingService.getAll.mockReturnValue(of([createdMapping]));
|
groupMappingService.getAll.mockReturnValue(of([createdMapping]));
|
||||||
component.editingGroupMapping = {oidcGroupClaim: 'readers', isAdmin: false, permissions: [], libraryIds: [], description: ''};
|
component.groupMappingDraft.set({
|
||||||
component.editingGroupMappingPerms = component.availablePermissions.map(permission => ({
|
oidcGroupClaim: 'readers',
|
||||||
...permission,
|
isAdmin: false,
|
||||||
selected: permission.value === 'permissionUpload',
|
permissions: ['permissionUpload'],
|
||||||
}));
|
libraryIds: [1],
|
||||||
component.editingGroupMappingLibraryIds = [1];
|
description: '',
|
||||||
|
});
|
||||||
|
|
||||||
component.saveGroupMapping();
|
component.saveGroupMapping();
|
||||||
|
|
||||||
@@ -445,12 +437,7 @@ describe('AuthenticationSettingsComponent', () => {
|
|||||||
description: '',
|
description: '',
|
||||||
});
|
});
|
||||||
|
|
||||||
component.editingGroupMapping = createdMapping;
|
component.groupMappingDraft.set({...createdMapping, permissions: [], libraryIds: [2]});
|
||||||
component.editingGroupMappingPerms = component.availablePermissions.map(permission => ({
|
|
||||||
...permission,
|
|
||||||
selected: false,
|
|
||||||
}));
|
|
||||||
component.editingGroupMappingLibraryIds = [2];
|
|
||||||
component.saveGroupMapping();
|
component.saveGroupMapping();
|
||||||
|
|
||||||
expect(groupMappingService.update).toHaveBeenCalledWith(9, {
|
expect(groupMappingService.update).toHaveBeenCalledWith(9, {
|
||||||
|
|||||||
+40
-39
@@ -1,6 +1,6 @@
|
|||||||
import {HttpErrorResponse} from '@angular/common/http';
|
import {HttpErrorResponse} from '@angular/common/http';
|
||||||
import {Component, effect, inject} from '@angular/core';
|
import {Component, effect, inject, signal} from '@angular/core';
|
||||||
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
|
import {FormsModule} from '@angular/forms';
|
||||||
import {InputText} from 'primeng/inputtext';
|
import {InputText} from 'primeng/inputtext';
|
||||||
import {Button} from 'primeng/button';
|
import {Button} from 'primeng/button';
|
||||||
import {Checkbox} from 'primeng/checkbox';
|
import {Checkbox} from 'primeng/checkbox';
|
||||||
@@ -33,7 +33,6 @@ import {Chip} from 'primeng/chip';
|
|||||||
Button,
|
Button,
|
||||||
MultiSelect,
|
MultiSelect,
|
||||||
InputNumber,
|
InputNumber,
|
||||||
ReactiveFormsModule,
|
|
||||||
ExternalDocLinkComponent,
|
ExternalDocLinkComponent,
|
||||||
TranslocoDirective,
|
TranslocoDirective,
|
||||||
TranslocoPipe,
|
TranslocoPipe,
|
||||||
@@ -105,17 +104,14 @@ export class AuthenticationSettingsComponent {
|
|||||||
showTestDetails = false;
|
showTestDetails = false;
|
||||||
|
|
||||||
// Group mapping
|
// Group mapping
|
||||||
groupSyncMode: string = 'DISABLED';
|
readonly groupSyncMode = signal('DISABLED');
|
||||||
groupSyncModeOptions = [
|
groupSyncModeOptions = [
|
||||||
{label: 'Disabled', value: 'DISABLED'},
|
{label: 'Disabled', value: 'DISABLED'},
|
||||||
{label: 'On Login (Replace)', value: 'ON_LOGIN'},
|
{label: 'On Login (Replace)', value: 'ON_LOGIN'},
|
||||||
{label: 'On Login (Additive)', value: 'ON_LOGIN_ADDITIVE'}
|
{label: 'On Login (Additive)', value: 'ON_LOGIN_ADDITIVE'}
|
||||||
];
|
];
|
||||||
groupMappings: OidcGroupMapping[] = [];
|
readonly groupMappings = signal<OidcGroupMapping[]>([]);
|
||||||
showGroupMappingDialog = false;
|
readonly groupMappingDraft = signal<OidcGroupMapping | null>(null);
|
||||||
editingGroupMapping: OidcGroupMapping = this.emptyGroupMapping();
|
|
||||||
editingGroupMappingPerms: {label: string; value: string; selected: boolean; translationKey: string}[] = [];
|
|
||||||
editingGroupMappingLibraryIds: number[] = [];
|
|
||||||
|
|
||||||
oidcProvider: OidcProviderDetails = {
|
oidcProvider: OidcProviderDetails = {
|
||||||
providerName: '',
|
providerName: '',
|
||||||
@@ -163,7 +159,7 @@ export class AuthenticationSettingsComponent {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.sessionDurationHours = settings.oidcSessionDurationHours ?? null;
|
this.sessionDurationHours = settings.oidcSessionDurationHours ?? null;
|
||||||
this.groupSyncMode = settings.oidcGroupSyncMode ?? 'DISABLED';
|
this.groupSyncMode.set(settings.oidcGroupSyncMode ?? 'DISABLED');
|
||||||
this.oidcForceOnlyMode = settings.oidcForceOnlyMode ?? false;
|
this.oidcForceOnlyMode = settings.oidcForceOnlyMode ?? false;
|
||||||
this.mobileRedirectUris = settings.oidcRedirectUris?.length
|
this.mobileRedirectUris = settings.oidcRedirectUris?.length
|
||||||
? [...settings.oidcRedirectUris]
|
? [...settings.oidcRedirectUris]
|
||||||
@@ -340,14 +336,14 @@ export class AuthenticationSettingsComponent {
|
|||||||
|
|
||||||
// Group mapping methods
|
// Group mapping methods
|
||||||
loadGroupMappings(): void {
|
loadGroupMappings(): void {
|
||||||
this.groupMappingService.getAll().subscribe(mappings => this.groupMappings = mappings);
|
this.groupMappingService.getAll().subscribe(mappings => this.groupMappings.set(mappings));
|
||||||
}
|
}
|
||||||
|
|
||||||
saveGroupSyncMode(): void {
|
saveGroupSyncMode(): void {
|
||||||
const payload = [
|
const payload = [
|
||||||
{
|
{
|
||||||
key: AppSettingKey.OIDC_GROUP_SYNC_MODE,
|
key: AppSettingKey.OIDC_GROUP_SYNC_MODE,
|
||||||
newValue: this.groupSyncMode
|
newValue: this.groupSyncMode()
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
this.appSettingsService.saveSettings(payload).subscribe({
|
this.appSettingsService.saveSettings(payload).subscribe({
|
||||||
@@ -365,34 +361,48 @@ export class AuthenticationSettingsComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
openNewGroupMapping(): void {
|
openNewGroupMapping(): void {
|
||||||
this.editingGroupMapping = this.emptyGroupMapping();
|
this.groupMappingDraft.set(this.emptyGroupMapping());
|
||||||
this.initGroupMappingPerms([]);
|
|
||||||
this.editingGroupMappingLibraryIds = [];
|
|
||||||
this.showGroupMappingDialog = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
openEditGroupMapping(mapping: OidcGroupMapping): void {
|
openEditGroupMapping(mapping: OidcGroupMapping): void {
|
||||||
this.editingGroupMapping = {...mapping};
|
this.groupMappingDraft.set({
|
||||||
this.initGroupMappingPerms(mapping.permissions);
|
...mapping,
|
||||||
this.editingGroupMappingLibraryIds = [...mapping.libraryIds];
|
permissions: mapping.permissions.filter(permission => permission !== 'permissionRead'),
|
||||||
this.showGroupMappingDialog = true;
|
libraryIds: [...mapping.libraryIds],
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private initGroupMappingPerms(selectedPerms: string[]): void {
|
updateGroupMappingDraft(patch: Partial<OidcGroupMapping>): void {
|
||||||
this.editingGroupMappingPerms = this.availablePermissions.map(p => ({
|
this.groupMappingDraft.update(draft => draft ? {...draft, ...patch} : draft);
|
||||||
...p,
|
}
|
||||||
selected: selectedPerms.includes(p.value)
|
|
||||||
}));
|
setGroupMappingAdmin(isAdmin: boolean): void {
|
||||||
|
this.updateGroupMappingDraft(isAdmin
|
||||||
|
? {isAdmin, permissions: this.availablePermissions.map(p => p.value)}
|
||||||
|
: {isAdmin});
|
||||||
|
}
|
||||||
|
|
||||||
|
setGroupMappingPermission(permission: string, selected: boolean): void {
|
||||||
|
this.groupMappingDraft.update(draft => {
|
||||||
|
if (!draft) return draft;
|
||||||
|
|
||||||
|
const permissions = selected
|
||||||
|
? [...draft.permissions, permission]
|
||||||
|
: draft.permissions.filter(value => value !== permission);
|
||||||
|
return {...draft, permissions: [...new Set(permissions)]};
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
saveGroupMapping(): void {
|
saveGroupMapping(): void {
|
||||||
|
const draft = this.groupMappingDraft();
|
||||||
|
if (!draft) return;
|
||||||
|
|
||||||
const mapping: OidcGroupMapping = {
|
const mapping: OidcGroupMapping = {
|
||||||
...this.editingGroupMapping,
|
...draft,
|
||||||
permissions: [
|
permissions: [
|
||||||
'permissionRead',
|
'permissionRead',
|
||||||
...this.editingGroupMappingPerms.filter(p => p.selected).map(p => p.value)
|
...draft.permissions
|
||||||
],
|
]
|
||||||
libraryIds: this.editingGroupMappingLibraryIds
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const obs = mapping.id
|
const obs = mapping.id
|
||||||
@@ -401,7 +411,7 @@ export class AuthenticationSettingsComponent {
|
|||||||
|
|
||||||
obs.subscribe({
|
obs.subscribe({
|
||||||
next: () => {
|
next: () => {
|
||||||
this.showGroupMappingDialog = false;
|
this.groupMappingDraft.set(null);
|
||||||
this.loadGroupMappings();
|
this.loadGroupMappings();
|
||||||
this.messageService.add({
|
this.messageService.add({
|
||||||
severity: 'success',
|
severity: 'success',
|
||||||
@@ -484,15 +494,6 @@ export class AuthenticationSettingsComponent {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
onAdminCheckboxChange(): void {
|
|
||||||
if (this.editingGroupMapping.isAdmin) {
|
|
||||||
this.editingGroupMappingPerms = this.availablePermissions.map(p => ({
|
|
||||||
...p,
|
|
||||||
selected: true,
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private emptyGroupMapping(): OidcGroupMapping {
|
private emptyGroupMapping(): OidcGroupMapping {
|
||||||
return {oidcGroupClaim: '', isAdmin: false, permissions: [], libraryIds: [], description: ''};
|
return {oidcGroupClaim: '', isAdmin: false, permissions: [], libraryIds: [], description: ''};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user