web/admin: migrate api calls to async (#4335)
migrate api calls to async Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org> Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
		| @ -10,7 +10,7 @@ import { AdminApi, LoginMetrics } from "@goauthentik/api"; | ||||
|  | ||||
| @customElement("ak-charts-admin-login-authorization") | ||||
| export class AdminLoginAuthorizeChart extends AKChart<LoginMetrics> { | ||||
|     apiRequest(): Promise<LoginMetrics> { | ||||
|     async apiRequest(): Promise<LoginMetrics> { | ||||
|         return new AdminApi(DEFAULT_CONFIG).adminMetricsRetrieve(); | ||||
|     } | ||||
|  | ||||
|  | ||||
| @ -34,14 +34,13 @@ export class ApplicationCheckAccessForm extends Form<{ forUser: number }> { | ||||
|         return t`Successfully sent test-request.`; | ||||
|     } | ||||
|  | ||||
|     send = (data: { forUser: number }): Promise<PolicyTestResult> => { | ||||
|     send = async (data: { forUser: number }): Promise<PolicyTestResult> => { | ||||
|         this.request = data.forUser; | ||||
|         return new CoreApi(DEFAULT_CONFIG) | ||||
|             .coreApplicationsCheckAccessRetrieve({ | ||||
|                 slug: this.application?.slug, | ||||
|                 forUser: data.forUser, | ||||
|             }) | ||||
|             .then((result) => (this.result = result)); | ||||
|         const result = await new CoreApi(DEFAULT_CONFIG).coreApplicationsCheckAccessRetrieve({ | ||||
|             slug: this.application?.slug, | ||||
|             forUser: data.forUser, | ||||
|         }); | ||||
|         return (this.result = result); | ||||
|     }; | ||||
|  | ||||
|     resetForm(): void { | ||||
|  | ||||
| @ -26,23 +26,19 @@ export class FlowImportForm extends Form<Flow> { | ||||
|         return super.styles.concat(PFDescriptionList); | ||||
|     } | ||||
|  | ||||
|     // eslint-disable-next-line | ||||
|     send = (data: Flow): Promise<FlowImportResult> => { | ||||
|     send = async (): Promise<FlowImportResult> => { | ||||
|         const file = this.getFormFiles()["flow"]; | ||||
|         if (!file) { | ||||
|             throw new SentryIgnoredError("No form data"); | ||||
|         } | ||||
|         return new FlowsApi(DEFAULT_CONFIG) | ||||
|             .flowsInstancesImportCreate({ | ||||
|                 file: file, | ||||
|             }) | ||||
|             .then((result) => { | ||||
|                 if (!result.success) { | ||||
|                     this.result = result; | ||||
|                     throw new SentryIgnoredError("Failed to import flow"); | ||||
|                 } | ||||
|                 return result; | ||||
|             }); | ||||
|         const result = await new FlowsApi(DEFAULT_CONFIG).flowsInstancesImportCreate({ | ||||
|             file: file, | ||||
|         }); | ||||
|         if (!result.success) { | ||||
|             this.result = result; | ||||
|             throw new SentryIgnoredError("Failed to import flow"); | ||||
|         } | ||||
|         return result; | ||||
|     }; | ||||
|  | ||||
|     renderResult(): TemplateResult { | ||||
|  | ||||
| @ -32,8 +32,8 @@ export class RelatedGroupAdd extends Form<{ groups: string[] }> { | ||||
|         return t`Successfully added user to group(s).`; | ||||
|     } | ||||
|  | ||||
|     send = (data: { groups: string[] }): Promise<{ groups: string[] }> => { | ||||
|         return Promise.all( | ||||
|     send = async (data: { groups: string[] }): Promise<{ groups: string[] }> => { | ||||
|         await Promise.all( | ||||
|             data.groups.map((group) => { | ||||
|                 return new CoreApi(DEFAULT_CONFIG).coreGroupsAddUserCreate({ | ||||
|                     groupUuid: group, | ||||
| @ -42,9 +42,8 @@ export class RelatedGroupAdd extends Form<{ groups: string[] }> { | ||||
|                     }, | ||||
|                 }); | ||||
|             }), | ||||
|         ).then(() => { | ||||
|             return data; | ||||
|         }); | ||||
|         ); | ||||
|         return data; | ||||
|     }; | ||||
|  | ||||
|     renderForm(): TemplateResult { | ||||
|  | ||||
| @ -39,14 +39,13 @@ export class PolicyTestForm extends Form<PolicyTestRequest> { | ||||
|         return t`Successfully sent test-request.`; | ||||
|     } | ||||
|  | ||||
|     send = (data: PolicyTestRequest): Promise<PolicyTestResult> => { | ||||
|     send = async (data: PolicyTestRequest): Promise<PolicyTestResult> => { | ||||
|         this.request = data; | ||||
|         return new PoliciesApi(DEFAULT_CONFIG) | ||||
|             .policiesAllTestCreate({ | ||||
|                 policyUuid: this.policy?.pk || "", | ||||
|                 policyTestRequest: data, | ||||
|             }) | ||||
|             .then((result) => (this.result = result)); | ||||
|         const result = await new PoliciesApi(DEFAULT_CONFIG).policiesAllTestCreate({ | ||||
|             policyUuid: this.policy?.pk || "", | ||||
|             policyTestRequest: data, | ||||
|         }); | ||||
|         return (this.result = result); | ||||
|     }; | ||||
|  | ||||
|     static get styles(): CSSResult[] { | ||||
|  | ||||
| @ -37,15 +37,14 @@ export class PolicyTestForm extends Form<PolicyTestRequest> { | ||||
|         return t`Successfully sent test-request.`; | ||||
|     } | ||||
|  | ||||
|     send = (data: PolicyTestRequest): Promise<PropertyMappingTestResult> => { | ||||
|     send = async (data: PolicyTestRequest): Promise<PropertyMappingTestResult> => { | ||||
|         this.request = data; | ||||
|         return new PropertymappingsApi(DEFAULT_CONFIG) | ||||
|             .propertymappingsAllTestCreate({ | ||||
|                 pmUuid: this.mapping?.pk || "", | ||||
|                 policyTestRequest: data, | ||||
|                 formatResult: true, | ||||
|             }) | ||||
|             .then((result) => (this.result = result)); | ||||
|         const result = await new PropertymappingsApi(DEFAULT_CONFIG).propertymappingsAllTestCreate({ | ||||
|             pmUuid: this.mapping?.pk || "", | ||||
|             policyTestRequest: data, | ||||
|             formatResult: true, | ||||
|         }); | ||||
|         return (this.result = result); | ||||
|     }; | ||||
|  | ||||
|     renderResult(): TemplateResult { | ||||
|  | ||||
| @ -24,7 +24,6 @@ export class SAMLProviderImportForm extends Form<SAMLProvider> { | ||||
|         return t`Successfully imported provider.`; | ||||
|     } | ||||
|  | ||||
|     // eslint-disable-next-line | ||||
|     send = (data: SAMLProvider): Promise<void> => { | ||||
|         const file = this.getFormFiles()["metadata"]; | ||||
|         if (!file) { | ||||
|  | ||||
| @ -44,8 +44,8 @@ export class RelatedUserAdd extends Form<{ users: number[] }> { | ||||
|         return t`Successfully added user(s).`; | ||||
|     } | ||||
|  | ||||
|     send = (data: { users: number[] }): Promise<{ users: number[] }> => { | ||||
|         return Promise.all( | ||||
|     send = async (data: { users: number[] }): Promise<{ users: number[] }> => { | ||||
|         await Promise.all( | ||||
|             data.users.map((user) => { | ||||
|                 return new CoreApi(DEFAULT_CONFIG).coreGroupsAddUserCreate({ | ||||
|                     groupUuid: this.group?.pk || "", | ||||
| @ -54,9 +54,8 @@ export class RelatedUserAdd extends Form<{ users: number[] }> { | ||||
|                     }, | ||||
|                 }); | ||||
|             }), | ||||
|         ).then(() => { | ||||
|             return data; | ||||
|         }); | ||||
|         ); | ||||
|         return data; | ||||
|     }; | ||||
|  | ||||
|     renderForm(): TemplateResult { | ||||
|  | ||||
| @ -20,16 +20,13 @@ export class ServiceAccountForm extends Form<UserServiceAccountRequest> { | ||||
|         return t`Successfully created user.`; | ||||
|     } | ||||
|  | ||||
|     send = (data: UserServiceAccountRequest): Promise<UserServiceAccountResponse> => { | ||||
|         return new CoreApi(DEFAULT_CONFIG) | ||||
|             .coreUsersServiceAccountCreate({ | ||||
|                 userServiceAccountRequest: data, | ||||
|             }) | ||||
|             .then((result) => { | ||||
|                 this.result = result; | ||||
|                 (this.parentElement as ModalForm).showSubmitButton = false; | ||||
|                 return result; | ||||
|             }); | ||||
|     send = async (data: UserServiceAccountRequest): Promise<UserServiceAccountResponse> => { | ||||
|         const result = await new CoreApi(DEFAULT_CONFIG).coreUsersServiceAccountCreate({ | ||||
|             userServiceAccountRequest: data, | ||||
|         }); | ||||
|         this.result = result; | ||||
|         (this.parentElement as ModalForm).showSubmitButton = false; | ||||
|         return result; | ||||
|     }; | ||||
|  | ||||
|     resetForm(): void { | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Jens L
					Jens L