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 1770e42cbf
commit d01fd7cdb7
2 changed files with 16 additions and 17 deletions

View File

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