mirror of
https://github.com/bitwarden/browser.git
synced 2024-10-02 04:48:57 +02:00
[Key Connector] Fix Key Connector Url test (#1308)
This commit is contained in:
parent
0490314cff
commit
2973d06c9f
@ -57,20 +57,26 @@
|
|||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<input class="form-control" formControlName="keyConnectorUrl" id="keyConnectorUrl" required>
|
<input class="form-control" formControlName="keyConnectorUrl" id="keyConnectorUrl" required>
|
||||||
<div class="input-group-append">
|
<div class="input-group-append">
|
||||||
<button type="button" class="btn btn-outline-secondary" (click)="testKeyConnector()"
|
<button type="button" class="btn btn-outline-secondary" (click)="validateKeyConnectorUrl()"
|
||||||
[disabled]="!enableTestKeyConnector">
|
[disabled]="!enableTestKeyConnector">
|
||||||
|
<i class="fa fa-spinner fa-spin" title="{{'loading' | i18n}}" aria-hidden="true"
|
||||||
|
*ngIf="keyConnectorUrl.pending"></i>
|
||||||
|
<span *ngIf="!keyConnectorUrl.pending">
|
||||||
{{'keyConnectorTest' | i18n}}
|
{{'keyConnectorTest' | i18n}}
|
||||||
|
</span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="text-danger" *ngIf="keyConnectorIsValid === false && keyConnectorUrl.pristine" role="alert">
|
<ng-container *ngIf="keyConnectorUrl.pristine && !keyConnectorUrl.pending">
|
||||||
|
<div class="text-danger" *ngIf="keyConnectorUrl.hasError('invalidUrl')" role="alert">
|
||||||
<i class="fa fa-exclamation-circle" aria-hidden="true"></i>
|
<i class="fa fa-exclamation-circle" aria-hidden="true"></i>
|
||||||
{{'keyConnectorTestFail' | i18n}}
|
{{'keyConnectorTestFail' | i18n}}
|
||||||
</div>
|
</div>
|
||||||
<div class="text-success" *ngIf="keyConnectorIsValid && keyConnectorUrl.pristine" role="alert">
|
<div class="text-success" *ngIf="!keyConnectorUrl.hasError('invalidUrl')" role="alert">
|
||||||
<i class="fa fa-check-circle-o" aria-hidden="true"></i>
|
<i class="fa fa-check-circle-o" aria-hidden="true"></i>
|
||||||
{{'keyConnectorTestSuccess' | i18n}}
|
{{'keyConnectorTestSuccess' | i18n}}
|
||||||
</div>
|
</div>
|
||||||
|
</ng-container>
|
||||||
</div>
|
</div>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
|
|
||||||
|
@ -38,8 +38,6 @@ export class SsoComponent implements OnInit {
|
|||||||
spMetadataUrl: string;
|
spMetadataUrl: string;
|
||||||
spAcsUrl: string;
|
spAcsUrl: string;
|
||||||
|
|
||||||
keyConnectorIsValid: boolean;
|
|
||||||
|
|
||||||
enabled = this.fb.control(false);
|
enabled = this.fb.control(false);
|
||||||
data = this.fb.group({
|
data = this.fb.group({
|
||||||
configType: [],
|
configType: [],
|
||||||
@ -105,6 +103,8 @@ export class SsoComponent implements OnInit {
|
|||||||
this.spMetadataUrl = ssoSettings.urls.spMetadataUrl;
|
this.spMetadataUrl = ssoSettings.urls.spMetadataUrl;
|
||||||
this.spAcsUrl = ssoSettings.urls.spAcsUrl;
|
this.spAcsUrl = ssoSettings.urls.spAcsUrl;
|
||||||
|
|
||||||
|
this.keyConnectorUrl.markAsDirty();
|
||||||
|
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,12 +117,28 @@ export class SsoComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async submit() {
|
async submit() {
|
||||||
if (!this.keyConnectorIsValid || this.keyConnectorUrl.dirty)
|
this.formPromise = this.postData();
|
||||||
{
|
|
||||||
await this.testKeyConnector();
|
try {
|
||||||
if (!this.keyConnectorIsValid) {
|
const response = await this.formPromise;
|
||||||
this.platformUtilsService.showToast('error', null, this.i18nService.t('keyConnectorTestFail'));
|
|
||||||
return;
|
this.data.patchValue(response.data);
|
||||||
|
this.enabled.setValue(response.enabled);
|
||||||
|
|
||||||
|
this.platformUtilsService.showToast('success', null, this.i18nService.t('ssoSettingsSaved'));
|
||||||
|
} catch {
|
||||||
|
// Logged by appApiAction, do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
this.formPromise = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
async postData() {
|
||||||
|
if (this.data.get('keyConnectorEnabled').value) {
|
||||||
|
await this.validateKeyConnectorUrl();
|
||||||
|
|
||||||
|
if (this.keyConnectorUrl.hasError('invalidUrl')) {
|
||||||
|
throw new Error(this.i18nService.t('keyConnectorTestFail'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,30 +146,26 @@ export class SsoComponent implements OnInit {
|
|||||||
request.enabled = this.enabled.value;
|
request.enabled = this.enabled.value;
|
||||||
request.data = this.data.value;
|
request.data = this.data.value;
|
||||||
|
|
||||||
this.formPromise = this.apiService.postOrganizationSso(this.organizationId, request);
|
return this.apiService.postOrganizationSso(this.organizationId, request);
|
||||||
|
|
||||||
const response = await this.formPromise;
|
|
||||||
this.data.patchValue(response.data);
|
|
||||||
this.enabled.setValue(response.enabled);
|
|
||||||
|
|
||||||
this.formPromise = null;
|
|
||||||
this.platformUtilsService.showToast('success', null, this.i18nService.t('ssoSettingsSaved'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async testKeyConnector() {
|
async validateKeyConnectorUrl() {
|
||||||
if (this.keyConnectorIsValid && this.keyConnectorUrl.pristine) {
|
if (this.keyConnectorUrl.pristine) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.keyConnectorUrl.markAsPending();
|
||||||
|
|
||||||
|
try {
|
||||||
|
await this.apiService.getKeyConnectorAlive(this.keyConnectorUrl.value);
|
||||||
|
this.keyConnectorUrl.updateValueAndValidity();
|
||||||
|
} catch {
|
||||||
|
this.keyConnectorUrl.setErrors({
|
||||||
|
invalidUrl: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
this.keyConnectorUrl.markAsPristine();
|
this.keyConnectorUrl.markAsPristine();
|
||||||
try {
|
|
||||||
await this.apiService.getKeyConnectorAlive(this.keyConnectorUrl.value);
|
|
||||||
} catch {
|
|
||||||
this.keyConnectorIsValid = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.keyConnectorIsValid = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get enableTestKeyConnector() {
|
get enableTestKeyConnector() {
|
||||||
|
Loading…
Reference in New Issue
Block a user