web/admin: fix non-matching provider type being selected when creating an OAuth Source

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-04-17 19:16:23 +02:00
parent 67240fb9ad
commit 0021a93952
3 changed files with 14 additions and 1 deletions

View File

@ -86,6 +86,7 @@ class ProviderViewSet(
"name": _("SAML Provider from Metadata"),
"description": _("Create a SAML Provider by importing its Metadata."),
"component": "ak-provider-saml-import-form",
"model_name": "",
}
)
return Response(TypeCreateSerializer(data, many=True).data)

View File

@ -128,6 +128,9 @@ export class SourceListPage extends TablePage<Source> {
</span>
<ak-proxy-form
slot="form"
.args=${{
"modelName": type.modelName
}}
type=${type.component}>
</ak-proxy-form>
<button slot="trigger" class="pf-c-dropdown__menu-item">

View File

@ -22,6 +22,9 @@ export class OAuthSourceForm extends Form<OAuthSource> {
});
}
@property()
modelName?: string;
@property({attribute: false})
source?: OAuthSource;
@ -148,7 +151,13 @@ export class OAuthSourceForm extends Form<OAuthSource> {
}}>
${until(new SourcesApi(DEFAULT_CONFIG).sourcesOauthSourceTypes().then(types => {
return types.map(type => {
return html`<option ?data-urls-custom=${type.urlsCustomizable} value=${type.slug} ?selected=${this.source?.providerType === type.slug}>${type.name}</option>`;
let selected = this.source?.providerType === type.slug;
if (!this.source?.pk) {
if (this.modelName?.replace("oauthsource", "") === type.slug) {
selected = true;
}
}
return html`<option ?data-urls-custom=${type.urlsCustomizable} value=${type.slug} ?selected=${selected}>${type.name}</option>`;
});
}), html`<option>${t`Loading...`}</option>`)}
</select>