UI: Added validation scope

This commit is contained in:
Vladyslav Prykhodko 2020-10-13 00:59:56 +03:00
parent 220c5f6275
commit e113daa085
2 changed files with 16 additions and 2 deletions

View File

@ -316,6 +316,10 @@
{{ 'admin.oauth2.scope-required' | translate }}
</mat-error>
</mat-form-field>
<tb-error style="display: block; margin-top: -24px;"
[error]="registration.get('scope').hasError('required')
? ('admin.oauth2.scope-required' | translate) : ''">
</tb-error>
</mat-tab>
<mat-tab label="{{ 'admin.oauth2.mapper' | translate }}">

View File

@ -15,7 +15,7 @@
///
import { Component, Inject, OnDestroy, OnInit } from '@angular/core';
import { AbstractControl, FormArray, FormBuilder, FormGroup, Validators } from '@angular/forms';
import { AbstractControl, FormArray, FormBuilder, FormGroup, ValidationErrors, Validators } from '@angular/forms';
import {
ClientAuthenticationMethod,
ClientRegistration,
@ -266,7 +266,7 @@ export class OAuth2SettingsComponent extends PageComponent implements OnInit, Ha
authorizationUri: [clientRegistration?.authorizationUri ? clientRegistration.authorizationUri : '',
[Validators.required,
Validators.pattern(this.URL_REGEXP)]],
scope: this.fb.array(clientRegistration?.scope ? clientRegistration.scope : [], Validators.required),
scope: this.fb.array(clientRegistration?.scope ? clientRegistration.scope : [], this.validateScope),
jwkSetUri: [clientRegistration?.jwkSetUri ? clientRegistration.jwkSetUri : '', Validators.pattern(this.URL_REGEXP)],
userInfoUri: [clientRegistration?.userInfoUri ? clientRegistration.userInfoUri : '',
[Validators.required,
@ -307,6 +307,16 @@ export class OAuth2SettingsComponent extends PageComponent implements OnInit, Ha
return clientRegistrationFormGroup;
}
private validateScope (control: AbstractControl): ValidationErrors | null {
const scope: string[] = control.value;
if (!scope || !scope.length) {
return {
required: true
};
}
return null;
}
private setProviderDefaultValue(provider: string, clientRegistration: FormGroup) {
if (provider === 'Custom') {
clientRegistration.reset(this.defaultProvider, {emitEvent: false});