[web] Previews and the team: a Previews screen (see: 1 click, close: 2), sign-in from a setup or invite link, Settings → Team (invite: 3 clicks), previews-only API tokens; click-counted tests
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
// accepted 4th), Share links and About.
|
||||
import { onMount } from "svelte";
|
||||
import { Banner, Button, Dialog, Segmented } from "@ianitor/ui";
|
||||
import TeamTab from "../components/TeamTab.svelte";
|
||||
import { ApiError, call, del, get, newKey, patch, post, sentence } from "../lib/api";
|
||||
import { app, navigate, toast } from "../lib/app.svelte";
|
||||
import { longDate, shortDate, whenInline } from "../lib/format";
|
||||
@@ -14,6 +15,7 @@
|
||||
let { tab }: { tab: string } = $props();
|
||||
const TABS = [
|
||||
{ id: "general", label: "General" },
|
||||
{ id: "team", label: "Team" },
|
||||
{ id: "api", label: "API" },
|
||||
{ id: "share-links", label: "Share links" },
|
||||
{ id: "about", label: "About" },
|
||||
@@ -25,6 +27,7 @@
|
||||
let links = $state<ShareLink[]>([]);
|
||||
let problem = $state<string | null>(null);
|
||||
let expiry = $state<"year" | "never">("year");
|
||||
let scope = $state<"full" | "previews">("full");
|
||||
let made = $state<CreatedToken | null>(null);
|
||||
let tokenName = $state("");
|
||||
let tokenCopied = $state(false);
|
||||
@@ -69,8 +72,8 @@
|
||||
async function newToken() {
|
||||
creating = true;
|
||||
try {
|
||||
const name = `Token made ${shortDate(new Date().toISOString())}`;
|
||||
const body = expiry === "never" ? { name, never_expires: true } : { name, expires_in_days: 365 };
|
||||
const name = scope === "previews" ? `Fabrica previews ${shortDate(new Date().toISOString())}` : `Token made ${shortDate(new Date().toISOString())}`;
|
||||
const body = expiry === "never" ? { name, never_expires: true, scope } : { name, expires_in_days: 365, scope };
|
||||
made = await post<CreatedToken>("/tokens", body);
|
||||
tokenName = made.name;
|
||||
tokenCopied = false;
|
||||
@@ -164,18 +167,22 @@
|
||||
<div role="tabpanel" id="panel-{tab}" aria-labelledby="tab-{tab}" class="panel">
|
||||
{#if tab === "general"}
|
||||
<p class="ia-label">Routes repository</p>
|
||||
<p>{settings?.repo ? `${settings.repo.name} on Gitea · ${settings.repo.last_push_at ? "pushed " + whenInline(settings.repo.last_push_at, app.now) : "not pushed yet"}` : "No place to push to is set up."}</p>
|
||||
<p>{settings?.repo ? `${settings.repo.name} · ${settings.repo.last_push_at ? "pushed " + whenInline(settings.repo.last_push_at, app.now) : "not pushed yet"}` : "No place to push to is set up."}</p>
|
||||
<p class="ia-label">Health watch after apply</p>
|
||||
<p>{settings?.watch_seconds ?? app.overview?.site?.watch_seconds ?? 60} seconds</p>
|
||||
<p class="ia-label">Signed in</p>
|
||||
<p>{viewer ? (viewer.via === "authelia" ? `${viewer.name} through Authelia` : `API token "${viewer.name}"`) : "Through Authelia"}</p>
|
||||
<p>{viewer ? (viewer.via === "authelia" ? `${viewer.name} through Authelia` : viewer.via === "session" ? viewer.name : `API token "${viewer.name}"`) : "Not signed in"}</p>
|
||||
{#if app.overview?.site?.auth_logout_url}<p><a class="domi-btn link" href={app.overview.site.auth_logout_url}>Sign out</a></p>{/if}
|
||||
{:else if tab === "team"}
|
||||
<TeamTab />
|
||||
{:else if tab === "api"}
|
||||
<div class="row">
|
||||
<h2 class="ia-h3">API tokens</h2>
|
||||
<Button variant="outline" icon="plus" onclick={newToken} pending={creating}>New token</Button>
|
||||
<Segmented legend="New tokens expire after" name="token-expiry" bind:value={expiry} options={[{ value: "year", label: "1 year" }, { value: "never", label: "Never" }]} />
|
||||
<Segmented legend="New tokens may" name="token-scope" bind:value={scope} options={[{ value: "full", label: "Do everything" }, { value: "previews", label: "Previews only" }]} />
|
||||
</div>
|
||||
<p class="ia-hint">Fabrica needs a previews-only token: it can open and close branch previews and touch nothing else. Keep it in the Custos team vault.</p>
|
||||
<p class="ia-hint">The API listens on 127.0.0.1 only. Ianitor keeps a hash of each token, never the token.</p>
|
||||
{#if tokens.length === 0}
|
||||
<div class="ia-frame"><h2 class="ia-h3">No API tokens</h2><p class="ia-text2">Scripts and other Domi apps use a token to talk to Ianitor.</p></div>
|
||||
@@ -184,7 +191,7 @@
|
||||
{#each tokens as t (t.id)}
|
||||
<li>
|
||||
<div class="grow">
|
||||
<span class="tname" class:struck={!!revoked[t.id] || !!t.revoked_at}>{t.name}</span>
|
||||
<span class="tname" class:struck={!!revoked[t.id] || !!t.revoked_at}>{t.name}</span>{#if t.scope === "previews"} <span class="ia-sub">previews only</span>{/if}
|
||||
<span class="ia-sub" style="display:block">
|
||||
{#if revoked[t.id]}Revoked {whenInline(revoked[t.id], app.now)}{:else}Made {shortDate(t.created_at)} · {t.last_used_at ? `last used ${whenInline(t.last_used_at, app.now)}` : "never used"} · {t.expires_at ? `expires ${shortDate(t.expires_at)}` : "never expires"}{/if}
|
||||
</span>
|
||||
@@ -233,7 +240,7 @@
|
||||
{/if}
|
||||
{/if}
|
||||
{:else}
|
||||
<p>Ianitor Domi 0.1.0</p>
|
||||
<p>Ianitor Domi 0.2.0</p>
|
||||
<p>MPL-2.0</p>
|
||||
<p>Built, tested and signed by Fabrica Domi</p>
|
||||
<p><a class="domi-btn link" href="https://gitea.marek-novak.cz/mnovak/Ianitor" rel="noreferrer">Source on Gitea</a></p>
|
||||
|
||||
Reference in New Issue
Block a user