web/admin: fix error when user doesn't have permissions to read source

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-04-16 17:06:06 +02:00
parent 7880c7fb98
commit ada49c077a
2 changed files with 16 additions and 17 deletions

View File

@ -56,7 +56,7 @@ export class UserSettingsPage extends LitElement {
renderSourceSettings(source: UserSetting): TemplateResult { renderSourceSettings(source: UserSetting): TemplateResult {
switch (source.component) { switch (source.component) {
case "ak-user-settings-source-oauth": case "ak-user-settings-source-oauth":
return html`<ak-user-settings-source-oauth objectId=${source.objectUid}> return html`<ak-user-settings-source-oauth objectId=${source.objectUid} title=${source.title}>
</ak-user-settings-source-oauth>`; </ak-user-settings-source-oauth>`;
default: default:
return html`<p>${t`Error: unsupported source settings: ${source.component}`}</p>`; return html`<p>${t`Error: unsupported source settings: ${source.component}`}</p>`;

View File

@ -1,6 +1,6 @@
import { customElement, html, TemplateResult } from "lit-element"; import { customElement, html, property, TemplateResult } from "lit-element";
import { BaseUserSettings } from "./BaseUserSettings"; import { BaseUserSettings } from "./BaseUserSettings";
import { OAuthSource, SourcesApi } from "authentik-api"; import { SourcesApi } from "authentik-api";
import { until } from "lit-html/directives/until"; import { until } from "lit-html/directives/until";
import { DEFAULT_CONFIG } from "../../../api/Config"; import { DEFAULT_CONFIG } from "../../../api/Config";
import { t } from "@lingui/macro"; import { t } from "@lingui/macro";
@ -9,22 +9,21 @@ import { AppURLManager } from "../../../api/legacy";
@customElement("ak-user-settings-source-oauth") @customElement("ak-user-settings-source-oauth")
export class SourceSettingsOAuth extends BaseUserSettings { export class SourceSettingsOAuth extends BaseUserSettings {
@property()
title!: string;
render(): TemplateResult { render(): TemplateResult {
return html`${until(new SourcesApi(DEFAULT_CONFIG).sourcesOauthRead({ return html`<div class="pf-c-card">
slug: this.objectId <div class="pf-c-card__title">
}).then((source) => { ${t`Source ${this.title}`}
return html`<div class="pf-c-card"> </div>
<div class="pf-c-card__title"> <div class="pf-c-card__body">
${t`Source ${source.name}`} ${this.renderInner()}
</div> </div>
<div class="pf-c-card__body"> </div>`;
${this.renderInner(source)}
</div>
</div>`;
}))}`;
} }
renderInner(source: OAuthSource): TemplateResult { renderInner(): TemplateResult {
return html`${until(new SourcesApi(DEFAULT_CONFIG).sourcesOauthUserConnectionsList({ return html`${until(new SourcesApi(DEFAULT_CONFIG).sourcesOauthUserConnectionsList({
sourceSlug: this.objectId sourceSlug: this.objectId
}).then((connection) => { }).then((connection) => {
@ -41,7 +40,7 @@ export class SourceSettingsOAuth extends BaseUserSettings {
} }
return html`<p>${t`Not connected.`}</p> return html`<p>${t`Not connected.`}</p>
<a class="pf-c-button pf-m-primary" <a class="pf-c-button pf-m-primary"
href=${AppURLManager.sourceOAuth(source.slug, "login")}> href=${AppURLManager.sourceOAuth(this.objectId, "login")}>
${t`Connect`} ${t`Connect`}
</a>`; </a>`;
}))}`; }))}`;