UI: Fixed edit and disabled oauth client settings scope
This commit is contained in:
parent
7aa77faf78
commit
a004472c05
@ -162,28 +162,12 @@
|
|||||||
</mat-slide-toggle>
|
</mat-slide-toggle>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
<div class="tb-form-row tb-standard-fields no-border no-padding column-xs">
|
<tb-string-items-list
|
||||||
<mat-form-field class="flex">
|
formControlName="scope"
|
||||||
<mat-label translate>admin.oauth2.scope</mat-label>
|
label="{{ 'admin.oauth2.scope' | translate }}"
|
||||||
<mat-chip-grid #scopeList required [disabled]="!this.createNewDialog && !(this.isEdit || this.isAdd)">
|
requiredText="{{ 'admin.oauth2.scope-required' | translate }}"
|
||||||
<mat-chip-row *ngFor="let scope of entityForm.get('scope').value; let k = index; trackBy: trackByParams"
|
required>
|
||||||
removable (removed)="removeScope(k, entityForm)">
|
</tb-string-items-list>
|
||||||
{{scope}}
|
|
||||||
<mat-icon matChipRemove>cancel</mat-icon>
|
|
||||||
</mat-chip-row>
|
|
||||||
<input [matChipInputFor]="scopeList"
|
|
||||||
[matChipInputSeparatorKeyCodes]="separatorKeysCodes"
|
|
||||||
matChipInputAddOnBlur
|
|
||||||
(matChipInputTokenEnd)="addScope($event, entityForm)">
|
|
||||||
</mat-chip-grid>
|
|
||||||
<mat-error *ngIf="entityForm.get('scope').hasError('required')">
|
|
||||||
{{ 'admin.oauth2.scope-required' | translate }}
|
|
||||||
</mat-error>
|
|
||||||
</mat-form-field>
|
|
||||||
</div>
|
|
||||||
<tb-error style="display: block; margin-top: -24px;"
|
|
||||||
[error]="entityForm.get('scope').hasError('required') ? ('admin.oauth2.scope-required' | translate) : ''">
|
|
||||||
</tb-error>
|
|
||||||
</section>
|
</section>
|
||||||
<section class="tb-form-panel no-border no-padding no-gap" *ngIf="!generalSettingsMode">
|
<section class="tb-form-panel no-border no-padding no-gap" *ngIf="!generalSettingsMode">
|
||||||
<div class="tb-form-row tb-standard-fields no-border no-padding">
|
<div class="tb-form-row tb-standard-fields no-border no-padding">
|
||||||
|
|||||||
@ -33,18 +33,10 @@ import { AppState } from '@core/core.state';
|
|||||||
import { EntityTableConfig } from '@home/models/entity/entities-table-config.models';
|
import { EntityTableConfig } from '@home/models/entity/entities-table-config.models';
|
||||||
import { TranslateService } from '@ngx-translate/core';
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
import { Store } from '@ngrx/store';
|
import { Store } from '@ngrx/store';
|
||||||
import {
|
import { AbstractControl, UntypedFormBuilder, UntypedFormGroup, Validators } from '@angular/forms';
|
||||||
AbstractControl,
|
|
||||||
UntypedFormArray,
|
|
||||||
UntypedFormBuilder,
|
|
||||||
UntypedFormGroup,
|
|
||||||
ValidationErrors,
|
|
||||||
Validators
|
|
||||||
} from '@angular/forms';
|
|
||||||
import { isDefinedAndNotNull } from '@core/utils';
|
import { isDefinedAndNotNull } from '@core/utils';
|
||||||
import { OAuth2Service } from '@core/http/oauth2.service';
|
import { OAuth2Service } from '@core/http/oauth2.service';
|
||||||
import { Subscription } from 'rxjs';
|
import { Subscription } from 'rxjs';
|
||||||
import { MatChipInputEvent } from '@angular/material/chips';
|
|
||||||
import { COMMA, ENTER } from '@angular/cdk/keycodes';
|
import { COMMA, ENTER } from '@angular/cdk/keycodes';
|
||||||
import { PageLink } from '@shared/models/page/page-link';
|
import { PageLink } from '@shared/models/page/page-link';
|
||||||
import { coerceBoolean } from '@app/shared/decorators/coercion';
|
import { coerceBoolean } from '@app/shared/decorators/coercion';
|
||||||
@ -84,16 +76,6 @@ export class ClientComponent extends EntityComponent<OAuth2Client, PageLink, OAu
|
|||||||
|
|
||||||
private subscriptions: Array<Subscription> = [];
|
private subscriptions: Array<Subscription> = [];
|
||||||
|
|
||||||
public static validateScope(control: AbstractControl): ValidationErrors | null {
|
|
||||||
const scope: string[] = control.value;
|
|
||||||
if (!scope || !scope.length) {
|
|
||||||
return {
|
|
||||||
required: true
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
readonly separatorKeysCodes: number[] = [ENTER, COMMA];
|
readonly separatorKeysCodes: number[] = [ENTER, COMMA];
|
||||||
|
|
||||||
clientAuthenticationMethods = Object.keys(ClientAuthenticationMethod);
|
clientAuthenticationMethods = Object.keys(ClientAuthenticationMethod);
|
||||||
@ -146,7 +128,7 @@ export class ClientComponent extends EntityComponent<OAuth2Client, PageLink, OAu
|
|||||||
loginButtonLabel: [entity?.loginButtonLabel ? entity.loginButtonLabel : null, Validators.required],
|
loginButtonLabel: [entity?.loginButtonLabel ? entity.loginButtonLabel : null, Validators.required],
|
||||||
loginButtonIcon: [entity?.loginButtonIcon ? entity.loginButtonIcon : null],
|
loginButtonIcon: [entity?.loginButtonIcon ? entity.loginButtonIcon : null],
|
||||||
userNameAttributeName: [entity?.userNameAttributeName ? entity.userNameAttributeName : 'email', Validators.required],
|
userNameAttributeName: [entity?.userNameAttributeName ? entity.userNameAttributeName : 'email', Validators.required],
|
||||||
scope: this.fb.array(entity?.scope ? entity.scope : [], ClientComponent.validateScope),
|
scope: [entity?.scope ? entity.scope : [], Validators.required],
|
||||||
mapperConfig: this.fb.group({
|
mapperConfig: this.fb.group({
|
||||||
allowUserCreation: [isDefinedAndNotNull(entity?.mapperConfig?.allowUserCreation) ?
|
allowUserCreation: [isDefinedAndNotNull(entity?.mapperConfig?.allowUserCreation) ?
|
||||||
entity.mapperConfig.allowUserCreation : true],
|
entity.mapperConfig.allowUserCreation : true],
|
||||||
@ -166,6 +148,7 @@ export class ClientComponent extends EntityComponent<OAuth2Client, PageLink, OAu
|
|||||||
clientId: entity.clientId,
|
clientId: entity.clientId,
|
||||||
clientSecret: entity.clientSecret,
|
clientSecret: entity.clientSecret,
|
||||||
accessTokenUri: entity.accessTokenUri,
|
accessTokenUri: entity.accessTokenUri,
|
||||||
|
scope: entity.scope,
|
||||||
authorizationUri: entity.authorizationUri,
|
authorizationUri: entity.authorizationUri,
|
||||||
jwkSetUri: entity.jwkSetUri,
|
jwkSetUri: entity.jwkSetUri,
|
||||||
userInfoUri: entity.userInfoUri,
|
userInfoUri: entity.userInfoUri,
|
||||||
@ -181,19 +164,6 @@ export class ClientComponent extends EntityComponent<OAuth2Client, PageLink, OAu
|
|||||||
}, {emitEvent: false});
|
}, {emitEvent: false});
|
||||||
|
|
||||||
this.changeMapperConfigType(this.entityForm, this.entityValue.mapperConfig.type, this.entityValue.mapperConfig);
|
this.changeMapperConfigType(this.entityForm, this.entityValue.mapperConfig.type, this.entityValue.mapperConfig);
|
||||||
|
|
||||||
const scopeControls = this.entityForm.get('scope') as UntypedFormArray;
|
|
||||||
if (entity.scope.length === scopeControls.length) {
|
|
||||||
scopeControls.patchValue(entity.scope, {emitEvent: false});
|
|
||||||
} else {
|
|
||||||
const newScopeControls: Array<AbstractControl> = [];
|
|
||||||
if (entity.scope) {
|
|
||||||
for (const scope of entity.scope) {
|
|
||||||
newScopeControls.push(this.fb.control(scope, [Validators.required]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.entityForm.setControl('scope', this.fb.array(newScopeControls));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getProviderName(): string {
|
getProviderName(): string {
|
||||||
@ -204,35 +174,6 @@ export class ClientComponent extends EntityComponent<OAuth2Client, PageLink, OAu
|
|||||||
return this.getProviderName() === 'Custom';
|
return this.getProviderName() === 'Custom';
|
||||||
}
|
}
|
||||||
|
|
||||||
trackByParams(index: number): number {
|
|
||||||
return index;
|
|
||||||
}
|
|
||||||
|
|
||||||
trackByItem(i, item) {
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
|
|
||||||
addScope(event: MatChipInputEvent, control: AbstractControl): void {
|
|
||||||
const input = event.chipInput.inputElement;
|
|
||||||
const value = event.value;
|
|
||||||
const controller = control.get('scope') as UntypedFormArray;
|
|
||||||
if ((value.trim() !== '')) {
|
|
||||||
controller.push(this.fb.control(value.trim()));
|
|
||||||
controller.markAsDirty();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (input) {
|
|
||||||
input.value = '';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
removeScope(i: number, control: AbstractControl): void {
|
|
||||||
const controller = control.get('scope') as UntypedFormArray;
|
|
||||||
controller.removeAt(i);
|
|
||||||
controller.markAsTouched();
|
|
||||||
controller.markAsDirty();
|
|
||||||
}
|
|
||||||
|
|
||||||
private initTemplates(templates: OAuth2ClientRegistrationTemplate[]): void {
|
private initTemplates(templates: OAuth2ClientRegistrationTemplate[]): void {
|
||||||
templates.map(provider => {
|
templates.map(provider => {
|
||||||
delete provider.additionalInfo;
|
delete provider.additionalInfo;
|
||||||
@ -264,7 +205,7 @@ export class ClientComponent extends EntityComponent<OAuth2Client, PageLink, OAu
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
this.subscriptions.push(this.entityForm.get('additionalInfo.providerName').valueChanges.subscribe((provider) => {
|
this.subscriptions.push(this.entityForm.get('additionalInfo.providerName').valueChanges.subscribe((provider) => {
|
||||||
(this.entityForm.get('scope') as UntypedFormArray).clear();
|
this.entityForm.get('scope').setValue([]);
|
||||||
this.setProviderDefaultValue(provider, this.entityForm);
|
this.setProviderDefaultValue(provider, this.entityForm);
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
@ -355,9 +296,6 @@ export class ClientComponent extends EntityComponent<OAuth2Client, PageLink, OAu
|
|||||||
const template = this.templates.get(provider);
|
const template = this.templates.get(provider);
|
||||||
template.clientId = '';
|
template.clientId = '';
|
||||||
template.clientSecret = '';
|
template.clientSecret = '';
|
||||||
template.scope.forEach(() => {
|
|
||||||
(clientRegistration.get('scope') as UntypedFormArray).push(this.fb.control(''));
|
|
||||||
});
|
|
||||||
clientRegistration.patchValue(template);
|
clientRegistration.patchValue(template);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user