[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:
+43
-4
@@ -15,6 +15,7 @@
|
||||
import Certificates from "./views/Certificates.svelte";
|
||||
import History from "./views/History.svelte";
|
||||
import Hosts from "./views/Hosts.svelte";
|
||||
import Previews from "./views/Previews.svelte";
|
||||
import RenewByHand from "./views/RenewByHand.svelte";
|
||||
import Settings from "./views/Settings.svelte";
|
||||
import SignedIn from "./views/SignedIn.svelte";
|
||||
@@ -24,6 +25,7 @@
|
||||
const p = u.pathname.replace(/\/+$/, "") || "/";
|
||||
const seg = p.split("/").filter(Boolean).map(decodeURIComponent);
|
||||
if (p === "/signed-in") return { view: "signed-in" as const };
|
||||
if (seg[0] === "previews") return { view: "previews" as const };
|
||||
if (seg[0] === "history") return { view: "history" as const, host: u.searchParams.get("host") ?? undefined, pick: seg[1] };
|
||||
if (seg[0] === "certificates") return { view: seg[1] === "renew-by-hand" ? ("renew" as const) : ("certs" as const), newDevice: seg[1] === "new" };
|
||||
if (seg[0] === "settings") return { view: "settings" as const, tab: seg[1] ?? "general" };
|
||||
@@ -32,18 +34,51 @@
|
||||
|
||||
const NAV: { href: string; label: string; icon: IconName; views: string[] }[] = [
|
||||
{ href: "/", label: "Hosts", icon: "building", views: ["hosts"] },
|
||||
{ href: "/previews", label: "Previews", icon: "link", views: ["previews"] },
|
||||
{ href: "/history", label: "History", icon: "history", views: ["history"] },
|
||||
{ href: "/certificates", label: "Certificates", icon: "shield", views: ["certs", "renew"] },
|
||||
{ href: "/settings/general", label: "Settings", icon: "gear", views: ["settings"] },
|
||||
];
|
||||
const TITLES: Record<string, string> = { hosts: "Hosts", history: "History", certs: "Certificates", renew: "Certificates", settings: "Settings", "signed-in": "Signed in" };
|
||||
const TITLES: Record<string, string> = { hosts: "Hosts", history: "History", previews: "Previews", certs: "Certificates", renew: "Certificates", settings: "Settings", "signed-in": "Signed in" };
|
||||
|
||||
$effect(() => {
|
||||
document.title = `${TITLES[route.view] ?? "Hosts"} — Ianitor Domi`;
|
||||
});
|
||||
|
||||
// A setup or invite link (`#signin=<code>`, crate::team): one click on the link signs in.
|
||||
async function signInFromLink(): Promise<void> {
|
||||
const m = /^#signin=([A-Za-z0-9_-]{8,100})$/.exec(location.hash);
|
||||
if (!m) return;
|
||||
history.replaceState(null, "", location.pathname + location.search);
|
||||
try {
|
||||
const r = await fetch("/api/v1/session", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json", "X-Ianitor-UI": "1" },
|
||||
body: JSON.stringify({ code: m[1], device: navigator.platform || "Browser" }),
|
||||
credentials: "same-origin",
|
||||
});
|
||||
if (!r.ok) {
|
||||
const j = await r.json().catch(() => null);
|
||||
app.linkProblem = j?.error?.message ?? "This sign-in link does not work.";
|
||||
}
|
||||
} catch {
|
||||
app.linkProblem = "Ianitor did not answer the sign-in.";
|
||||
}
|
||||
}
|
||||
|
||||
async function signOutSession() {
|
||||
try {
|
||||
await fetch("/api/v1/session/end", { method: "POST", headers: { "X-Ianitor-UI": "1" }, credentials: "same-origin" });
|
||||
} finally {
|
||||
location.href = "/";
|
||||
}
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
if (route.view === "signed-in") return;
|
||||
if (location.hash.startsWith("#signin=")) {
|
||||
void signInFromLink().then(() => refresh());
|
||||
}
|
||||
const stop = startPolling();
|
||||
// Resume an apply this tab was watching before a reload or a sign-in (§3).
|
||||
const id = remembered();
|
||||
@@ -101,7 +136,8 @@
|
||||
<a href={n.href} class="nav" aria-current={n.views.includes(route.view) ? "page" : undefined} onclick={(e) => go(e, n.href)}><Icon name={n.icon} />{n.label}</a>
|
||||
{/each}
|
||||
<div class="foot ia-muted">
|
||||
<p>{viewer?.via === "authelia" ? `Signed in as ${viewer.name} through Authelia` : viewer ? `Using the API token "${viewer.name}"` : "Signed in through Authelia"}</p>
|
||||
<p>{viewer?.via === "authelia" ? `Signed in as ${viewer.name} through Authelia` : viewer?.via === "session" ? `Signed in as ${viewer.name}` : viewer ? `Using the API token "${viewer.name}"` : "Not signed in"}</p>
|
||||
{#if viewer?.via === "session"}<button type="button" class="domi-btn link" onclick={signOutSession}>Sign out</button>{/if}
|
||||
<p>Control on 127.0.0.1 only</p>
|
||||
{#if app.overview?.site?.auth_logout_url}<a class="domi-btn link" href={app.overview.site.auth_logout_url}>Sign out</a>{/if}
|
||||
</div>
|
||||
@@ -109,8 +145,11 @@
|
||||
<header class="topbar"><span class="ia-wordmark">IANITOR DOMI</span>{#if app.phone}<EngineChip />{/if}</header>
|
||||
<main id="main" tabindex="-1">
|
||||
<TopBanners />
|
||||
{#if app.linkProblem}<p class="domi-error" role="alert">{app.linkProblem}</p>{/if}
|
||||
{#if route.view === "hosts"}
|
||||
<Hosts route={{ newHost: route.newHost, edit: route.edit }} />
|
||||
{:else if route.view === "previews"}
|
||||
<Previews />
|
||||
{:else if route.view === "history"}
|
||||
{#key route.host}<History host={route.host} pick={route.pick} />{/key}
|
||||
{:else if route.view === "certs"}
|
||||
@@ -141,7 +180,7 @@
|
||||
|
||||
{#if app.signedOut}
|
||||
<Dialog title="Your sign-in has ended" role="alertdialog" escape={false} closable={false} onclose={() => {}}>
|
||||
<p>Sign in again; this page keeps what you typed.</p>
|
||||
<p>Sign in again; this page keeps what you typed. Without Authelia, open your sign-in link again or ask an admin of your team for a new one.</p>
|
||||
{#snippet footer()}
|
||||
<Button onclick={signedInAgain}>I have signed in</Button>
|
||||
<Button variant="primary" onclick={signIn} data-autofocus>Sign in</Button>
|
||||
@@ -167,7 +206,7 @@
|
||||
.topbar { display: flex; align-items: center; justify-content: space-between; background: var(--colonnade); border-bottom: 1px solid var(--hairline); padding: 10px 16px; }
|
||||
.topbar .ia-wordmark { font-size: 12px; letter-spacing: 0.26em; }
|
||||
main { padding: 18px 16px calc(90px + env(safe-area-inset-bottom)); gap: 14px; }
|
||||
.bottombar { display: grid; grid-template-columns: repeat(4, 1fr); position: fixed; left: 0; right: 0; bottom: 0; background: var(--colonnade); border-top: 1px solid var(--hairline); padding: 6px 8px calc(10px + env(safe-area-inset-bottom)); z-index: 40; }
|
||||
.bottombar { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; background: var(--colonnade); border-top: 1px solid var(--hairline); padding: 6px 8px calc(10px + env(safe-area-inset-bottom)); z-index: 40; }
|
||||
.bottombar a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: var(--phone-bar-h); border-radius: var(--radius-sm); color: var(--text-2); font-weight: 600; font-size: var(--fs-tab-phone); text-decoration: none; }
|
||||
.bottombar a[aria-current="page"] { background: var(--surface-2); color: var(--text); }
|
||||
.bottombar a[aria-current="page"] :global(svg) { color: var(--accent); }
|
||||
|
||||
@@ -0,0 +1,137 @@
|
||||
<!-- This Source Code Form is subject to the terms of the Mozilla Public
|
||||
- License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
- file, You can obtain one at https://mozilla.org/MPL/2.0/. -->
|
||||
<script lang="ts">
|
||||
// T4: the team without Authelia. Invite: Settings → Team → Invite (3 clicks), then Copy link.
|
||||
import { onMount } from "svelte";
|
||||
import { Banner, Button, Segmented } from "@ianitor/ui";
|
||||
import { del, get, post, put, sentence } from "../lib/api";
|
||||
import { toast } from "../lib/app.svelte";
|
||||
import { shortDate } from "../lib/format";
|
||||
import type { TeamView } from "../lib/types";
|
||||
|
||||
let team = $state<TeamView | null>(null);
|
||||
let problem = $state<string | null>(null);
|
||||
let name = $state("");
|
||||
let role = $state<"member" | "admin">("member");
|
||||
let link = $state<string | null>(null);
|
||||
let confirmRemove = $state<string | null>(null);
|
||||
let root = $state("");
|
||||
|
||||
async function load() {
|
||||
try {
|
||||
team = await get<TeamView>("/team");
|
||||
root = team.me?.tessera_root ?? "";
|
||||
problem = null;
|
||||
} catch (e) {
|
||||
problem = sentence(e);
|
||||
}
|
||||
}
|
||||
onMount(() => void load());
|
||||
|
||||
async function invite() {
|
||||
try {
|
||||
const r = await post<{ link_fragment: string }>("/team/invites", { name: name.trim(), role });
|
||||
link = `${location.origin}/${r.link_fragment}`;
|
||||
name = "";
|
||||
await load();
|
||||
} catch (e) {
|
||||
problem = sentence(e);
|
||||
}
|
||||
}
|
||||
|
||||
async function copy() {
|
||||
if (!link) return;
|
||||
try {
|
||||
await navigator.clipboard.writeText(link);
|
||||
toast("Copied. Send it to them; it works once, for 7 days.");
|
||||
} catch {
|
||||
problem = "Your browser did not allow copying. Select the link and press Ctrl+C.";
|
||||
}
|
||||
}
|
||||
|
||||
async function remove(id: string) {
|
||||
try {
|
||||
await del(`/team/members/${encodeURIComponent(id)}`);
|
||||
confirmRemove = null;
|
||||
toast("Removed and signed out everywhere.");
|
||||
await load();
|
||||
} catch (e) {
|
||||
problem = sentence(e);
|
||||
}
|
||||
}
|
||||
|
||||
async function saveRoot() {
|
||||
try {
|
||||
await put("/team/me/root", { tessera_root: root.trim() || null });
|
||||
toast("Saved.");
|
||||
await load();
|
||||
} catch (e) {
|
||||
problem = sentence(e);
|
||||
}
|
||||
}
|
||||
|
||||
const admin = $derived(team?.me ? team.me.role === "admin" : true);
|
||||
</script>
|
||||
|
||||
{#if problem}<Banner tone="notice" live="status" ondismiss={() => (problem = null)}>{#snippet title()}{problem}{/snippet}</Banner>{/if}
|
||||
{#if team?.authelia}
|
||||
<p class="ia-hint">Authelia signs people in on this server. Team links work too.</p>
|
||||
{/if}
|
||||
<h2 class="ia-h3">People</h2>
|
||||
<ul class="rows">
|
||||
{#each team?.members ?? [] as m (m.id)}
|
||||
<li>
|
||||
<div class="grow"><strong>{m.name}</strong>{team?.me?.id === m.id ? " (you)" : ""}
|
||||
<span class="ia-sub" style="display:block">{m.role} · since {shortDate(m.added_at)}{m.match_code ? ` · Domi identity ${m.match_code}` : ""}</span></div>
|
||||
{#if admin && team?.me?.id !== m.id}
|
||||
{#if confirmRemove === m.id}
|
||||
<span>Remove {m.name}? They are signed out everywhere.</span>
|
||||
<Button small onclick={() => (confirmRemove = null)}>Keep</Button>
|
||||
<Button small variant="danger" onclick={() => remove(m.id)}>Remove</Button>
|
||||
{:else}
|
||||
<Button small variant="danger" onclick={() => (confirmRemove = m.id)}>Remove</Button>
|
||||
{/if}
|
||||
{/if}
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
|
||||
{#if admin}
|
||||
<div class="row">
|
||||
<div class="domi-field">
|
||||
<label class="domi-field-label" for="invite-name">Name</label>
|
||||
<input id="invite-name" class="domi-input" bind:value={name} placeholder="Petra" />
|
||||
</div>
|
||||
<Segmented legend="Role" name="invite-role" bind:value={role} options={[{ value: "member", label: "Member" }, { value: "admin", label: "Admin" }]} />
|
||||
<Button variant="outline" icon="plus" onclick={invite} disabled={!name.trim()}>Invite</Button>
|
||||
</div>
|
||||
<p class="ia-hint">Members change hosts and previews. Admins also manage people, API tokens, the engine and certificates.</p>
|
||||
{#if link}
|
||||
<div class="grid">
|
||||
<input class="ia-secret" readonly value={link} aria-label="Invite link" onfocus={(e) => (e.currentTarget as HTMLInputElement).select()} />
|
||||
<Button variant="primary" icon="copy" onclick={copy} data-autofocus>Copy link</Button>
|
||||
</div>
|
||||
{/if}
|
||||
{/if}
|
||||
|
||||
{#if team?.me}
|
||||
<h2 class="ia-h3">Your Domi identity</h2>
|
||||
<div class="row">
|
||||
<div class="domi-field grow">
|
||||
<label class="domi-field-label" for="tessera-root">Tessera root (Custos → Domi identity)</label>
|
||||
<input id="tessera-root" class="domi-input" bind:value={root} spellcheck="false" />
|
||||
</div>
|
||||
<Button onclick={saveRoot}>Save</Button>
|
||||
</div>
|
||||
<p class="ia-hint">Your teammates see its match code next to your name, the same digits Custos shows.</p>
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
.rows { list-style: none; margin: 0; padding: 0; }
|
||||
.rows li { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; min-height: 44px; padding: 8px 0; border-top: 1px solid var(--hairline); }
|
||||
.grow { flex: 1 1 200px; min-width: 0; }
|
||||
.row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
|
||||
.grid { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: end; }
|
||||
@media (max-width: 719.98px) { .grid { grid-template-columns: 1fr; } }
|
||||
</style>
|
||||
@@ -139,7 +139,7 @@ export async function call<T>(
|
||||
await sleep(Math.min(60, env.error.retry_after_s ?? 1) * 1000);
|
||||
continue;
|
||||
}
|
||||
if (res.status === 401 && env.error.code.startsWith("token.")) {
|
||||
if (res.status === 401 && (env.error.code.startsWith("token.") || env.error.code.startsWith("session."))) {
|
||||
// The UI holds no token: a token refusal means the sign-in did not reach control.
|
||||
events.onSignedOut?.();
|
||||
throw new SignedOut(env.error.message);
|
||||
|
||||
@@ -14,6 +14,8 @@ export interface Toast {
|
||||
}
|
||||
|
||||
export const app = $state({
|
||||
/** Why a `#signin=` link did not sign this browser in. */
|
||||
linkProblem: null as string | null,
|
||||
overview: null as Overview | null,
|
||||
etag: null as string | null,
|
||||
loadError: false,
|
||||
|
||||
@@ -212,6 +212,7 @@ export interface TokenRow {
|
||||
last_used_at: string | null;
|
||||
expires_at: string | null;
|
||||
revoked_at?: string | null;
|
||||
scope?: "full" | "previews";
|
||||
}
|
||||
|
||||
export interface CreatedToken {
|
||||
@@ -249,3 +250,36 @@ export interface Bundle {
|
||||
filename: string;
|
||||
qr_svg: string | null;
|
||||
}
|
||||
|
||||
// T4: branch previews and the team (docs/previews.md, crate::team).
|
||||
export interface PreviewView {
|
||||
hostname: string;
|
||||
url: string;
|
||||
project: string;
|
||||
branch: string;
|
||||
upstream: string;
|
||||
expires_at: string;
|
||||
state: "applying" | "live" | "failed";
|
||||
problem?: string | null;
|
||||
}
|
||||
|
||||
export interface PreviewList {
|
||||
items: PreviewView[];
|
||||
domain: string | null;
|
||||
}
|
||||
|
||||
export interface MemberView {
|
||||
id: string;
|
||||
name: string;
|
||||
role: "admin" | "member";
|
||||
added_at: string;
|
||||
tessera_root: string | null;
|
||||
match_code: string | null;
|
||||
}
|
||||
|
||||
export interface TeamView {
|
||||
me: MemberView | null;
|
||||
members: MemberView[];
|
||||
invites: { id: string; name: string | null; role: string; expires_at: string }[];
|
||||
authelia: boolean;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
<!-- This Source Code Form is subject to the terms of the Mozilla Public
|
||||
- License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
- file, You can obtain one at https://mozilla.org/MPL/2.0/. -->
|
||||
<script lang="ts">
|
||||
// T4: branch previews Fabrica opens. See them: 1 click (the nav). Close one: 2 clicks
|
||||
// (Close → Close preview).
|
||||
import { onMount } from "svelte";
|
||||
import { Banner, Button, Status } from "@ianitor/ui";
|
||||
import type { StatusKind } from "@ianitor/ui";
|
||||
import { del, get, sentence } from "../lib/api";
|
||||
import { app, toast } from "../lib/app.svelte";
|
||||
import { whenInline } from "../lib/format";
|
||||
import type { PreviewList, PreviewView } from "../lib/types";
|
||||
|
||||
let list = $state<PreviewList | null>(null);
|
||||
let problem = $state<string | null>(null);
|
||||
let confirm = $state<string | null>(null);
|
||||
let closing = $state<string | null>(null);
|
||||
|
||||
async function load() {
|
||||
try {
|
||||
list = await get<PreviewList>("/previews");
|
||||
problem = null;
|
||||
} catch (e) {
|
||||
problem = sentence(e);
|
||||
}
|
||||
}
|
||||
|
||||
async function close(p: PreviewView) {
|
||||
closing = p.hostname;
|
||||
try {
|
||||
await del(`/previews/${encodeURIComponent(p.hostname)}`);
|
||||
toast(`Closing the preview of ${p.branch}.`);
|
||||
confirm = null;
|
||||
await load();
|
||||
} catch (e) {
|
||||
problem = sentence(e);
|
||||
} finally {
|
||||
closing = null;
|
||||
}
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
void load();
|
||||
const t = setInterval(() => void load(), 5000);
|
||||
const f = () => void load();
|
||||
window.addEventListener("focus", f);
|
||||
return () => {
|
||||
clearInterval(t);
|
||||
window.removeEventListener("focus", f);
|
||||
};
|
||||
});
|
||||
|
||||
function badge(p: PreviewView): [StatusKind, string] {
|
||||
if (p.state === "live") return ["healthy", "live"];
|
||||
if (p.state === "failed") return ["down", "failed"];
|
||||
return ["running", "opening"];
|
||||
}
|
||||
</script>
|
||||
|
||||
<h1 class="ia-display">Previews</h1>
|
||||
{#if problem}<Banner tone="notice" live="status" ondismiss={() => (problem = null)}>{#snippet title()}{problem}{/snippet}</Banner>{/if}
|
||||
|
||||
{#if list && !list.domain}
|
||||
<div class="ia-frame">
|
||||
<h2 class="ia-h3">Previews are off</h2>
|
||||
<p class="ia-text2">Set a preview domain in control.toml (<code>[previews] domain</code>) and point a wildcard DNS record at this server. Then every branch Fabrica builds gets its own address here.</p>
|
||||
</div>
|
||||
{:else if list && list.items.length === 0}
|
||||
<div class="ia-frame">
|
||||
<h2 class="ia-h3">No previews open</h2>
|
||||
<p class="ia-text2">When Fabrica builds a branch, its preview appears here as <code><branch>--<project>.{list.domain}</code>. It closes on merge or when its time runs out.</p>
|
||||
</div>
|
||||
{:else if list}
|
||||
<p class="ia-hint">Under {list.domain}. Fabrica opens them with a token that can only manage previews.</p>
|
||||
<ul class="rows">
|
||||
{#each list.items as p (p.hostname)}
|
||||
{@const [kind, label] = badge(p)}
|
||||
<li>
|
||||
<Status {kind} word={label} />
|
||||
<div class="grow">
|
||||
<a class="host" href={p.url} target="_blank" rel="noreferrer">{p.hostname}</a>
|
||||
<span class="ia-sub" style="display:block">{p.branch} · {p.project} · to {p.upstream} · closes {whenInline(p.expires_at, app.now)}</span>
|
||||
{#if p.problem}<span class="domi-error">{p.problem}</span>{/if}
|
||||
</div>
|
||||
{#if confirm === p.hostname}
|
||||
<span>Close the preview of {p.branch}? Its address stops working.</span>
|
||||
<Button small onclick={() => (confirm = null)}>Keep it</Button>
|
||||
<Button small variant="danger" pending={closing === p.hostname} onclick={() => close(p)} data-autofocus>Close preview</Button>
|
||||
{:else}
|
||||
<Button small variant="danger" onclick={() => (confirm = p.hostname)}>Close</Button>
|
||||
{/if}
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
.rows { list-style: none; margin: 0; padding: 0; }
|
||||
.rows li { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; min-height: 52px; padding: 10px 0; border-top: 1px solid var(--hairline); }
|
||||
.grow { flex: 1 1 260px; min-width: 0; }
|
||||
.host { font-weight: 600; color: var(--text); overflow-wrap: anywhere; }
|
||||
</style>
|
||||
@@ -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>
|
||||
|
||||
@@ -170,6 +170,37 @@ describe("ROADMAP §4 flows, clicks counted", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("T4 flows, clicks counted", () => {
|
||||
it("See active previews = 1 click", async () => {
|
||||
start();
|
||||
const nav = (await screen.findAllByRole("navigation", { name: "Main" }, T))[0];
|
||||
await click(within(nav).getByRole("link", { name: "Previews" }));
|
||||
await screen.findByRole("link", { name: "fix-42--shop.preview.home.test" }, T);
|
||||
expect(clicks).toBe(1);
|
||||
});
|
||||
|
||||
it("Kill a preview = 2 clicks (Close → Close preview)", async () => {
|
||||
start("/previews");
|
||||
await click(await screen.findByRole("button", { name: "Close" }, T));
|
||||
await click(await screen.findByRole("button", { name: "Close preview" }));
|
||||
await waitFor(() => expect(called("DELETE", "/previews/fix-42--shop.preview.home.test")).toBe(true), T);
|
||||
await screen.findByRole("heading", { name: "No previews open" }, T);
|
||||
expect(clicks).toBe(2);
|
||||
});
|
||||
|
||||
it("Invite a teammate: Settings → Team → Invite = 3 clicks, the link shown", async () => {
|
||||
start();
|
||||
const nav = (await screen.findAllByRole("navigation", { name: "Main" }, T))[0];
|
||||
await click(within(nav).getByRole("link", { name: "Settings" }));
|
||||
await click(await screen.findByRole("tab", { name: "Team" }));
|
||||
await user.type(await screen.findByLabelText("Name"), "Petra");
|
||||
await click(screen.getByRole("button", { name: "Invite" }));
|
||||
const link = (await screen.findByLabelText("Invite link", {}, T)) as HTMLInputElement;
|
||||
expect(link.value).toMatch(/\/#signin=iin_testcode$/);
|
||||
expect(clicks).toBe(3);
|
||||
});
|
||||
});
|
||||
|
||||
describe("focus", () => {
|
||||
it("+ Host puts the cursor in Hostname, so typing right after the click lands there", async () => {
|
||||
start();
|
||||
|
||||
@@ -12,6 +12,7 @@ export interface Mock {
|
||||
calls: { method: string; path: string; body: unknown }[];
|
||||
state: {
|
||||
engine: "pingora" | "caddy";
|
||||
previewClosed: boolean;
|
||||
switching: number;
|
||||
intermediate: "ok" | "due";
|
||||
renewal: boolean;
|
||||
@@ -65,7 +66,7 @@ export type Route = [string, RegExp, (mm: RegExpMatchArray, body: Json) => [numb
|
||||
export function newMock(): Mock {
|
||||
return {
|
||||
calls: [],
|
||||
state: { engine: "pingora", switching: 0, intermediate: "due", renewal: false, requestPolls: 0, hostsAdded: [] },
|
||||
state: { engine: "pingora", switching: 0, intermediate: "due", renewal: false, requestPolls: 0, hostsAdded: [], previewClosed: false },
|
||||
};
|
||||
}
|
||||
|
||||
@@ -170,6 +171,17 @@ export function mockRoutes(m: Mock): Route[] {
|
||||
["GET", /^\/tokens$/, () => [200, { items: [] }]],
|
||||
["POST", /^\/tokens$/, (_, b) => [201, { id: "tk_1", name: b.name, token: "ian_tk1_secretvalue", expires_at: later(365 * 86400) }]],
|
||||
["GET", /^\/share-links$/, () => [200, { items: [], epoch: 0 }]],
|
||||
// T4: previews and the team (invented .test names only).
|
||||
["GET", /^\/previews$/, () => [200, {
|
||||
domain: "preview.home.test",
|
||||
items: m.state.previewClosed ? [] : [{ hostname: "fix-42--shop.preview.home.test", url: "https://fix-42--shop.preview.home.test/", project: "team/shop", branch: "fix-42", upstream: "http://10.0.0.7:8080", expires_at: later(86400), state: "live" }],
|
||||
}]],
|
||||
["DELETE", /^\/previews\/fix-42--shop\.preview\.home\.test$/, () => {
|
||||
m.state.previewClosed = true;
|
||||
return [202, { apply: apply("ch_pv", "queued", "Closed the preview of fix-42 (team/shop)", ["fix-42--shop.preview.home.test"]) }];
|
||||
}],
|
||||
["GET", /^\/team$/, () => [200, { me: { id: "m1", name: "Mark", role: "admin", added_at: now(), tessera_root: null, match_code: null }, members: [{ id: "m1", name: "Mark", role: "admin", added_at: now(), tessera_root: null, match_code: null }], invites: [], authelia: false }]],
|
||||
["POST", /^\/team\/invites$/, (_, b) => [201, { invite: { id: "iv1", name: b.name, role: b.role, expires_at: later(7 * 86400) }, link_fragment: "#signin=iin_testcode" }]],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user