Compare commits
6
Commits
16ab4a13f5
...
ebbe4a678a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ebbe4a678a | ||
|
|
fe1b61fa4d | ||
|
|
8899bd205f | ||
|
|
b481e6857c | ||
|
|
38b94bd57e | ||
|
|
627c5e43bc |
@@ -53,7 +53,12 @@ private val TRAILING_PUNCTUATION = charArrayOf('.', ',', ';', ':', '!', '?')
|
||||
* both run the `urls` cases in `core/testdata/grammar.json` (here, by hand).
|
||||
*/
|
||||
fun loneUrl(body: String): String? =
|
||||
LONE_URL.matchEntire(body)?.groupValues?.get(1)?.trimEnd(*TRAILING_PUNCTUATION)?.ifEmpty { null }
|
||||
LONE_URL
|
||||
.matchEntire(body)
|
||||
?.groupValues
|
||||
?.get(1)
|
||||
?.trimEnd(*TRAILING_PUNCTUATION)
|
||||
?.ifEmpty { null }
|
||||
|
||||
/**
|
||||
* The preview for a note that is nothing but a URL, or null.
|
||||
|
||||
@@ -3,9 +3,9 @@ import { onMounted, ref } from "vue";
|
||||
import { api } from "../api/client";
|
||||
import { errorMessage } from "../api/errors";
|
||||
import { useSessionStore } from "../stores/session";
|
||||
import { useUiStore } from "../stores/ui";
|
||||
import { appLink } from "../router/links";
|
||||
import OneTimeLink from "./OneTimeLink.vue";
|
||||
import { useRowAction } from "../composables/useAction";
|
||||
|
||||
// Admin: the accounts on this instance, and a password reset link for any of them
|
||||
// (#5173). There is no mail path, so the admin hands the link over.
|
||||
@@ -18,12 +18,11 @@ interface Account {
|
||||
}
|
||||
|
||||
const session = useSessionStore();
|
||||
const ui = useUiStore();
|
||||
|
||||
const accounts = ref<Account[]>([]);
|
||||
const loading = ref(true);
|
||||
const error = ref("");
|
||||
const busy = ref("");
|
||||
const { busy, act } = useRowAction();
|
||||
// The reset link just made, and whose it is. Never retrievable again once dismissed.
|
||||
const fresh = ref<{ link: string; email: string } | null>(null);
|
||||
|
||||
@@ -44,15 +43,14 @@ async function resetLink(account: Account) {
|
||||
? "Make a password reset link for your own account? Using it signs you out everywhere, this browser included."
|
||||
: `Make a password reset link for ${account.email}? Using it signs them out everywhere and unlinks their apps.`;
|
||||
if (!window.confirm(warning)) return;
|
||||
busy.value = account.id;
|
||||
try {
|
||||
const res = await api.post<{ token: string }>(`/api/accounts/${account.id}/reset-link`, {});
|
||||
fresh.value = { link: appLink({ name: "reset-password", query: { token: res.token } }), email: account.email };
|
||||
} catch (e) {
|
||||
ui.showToast(errorMessage(e, "Couldn't make a reset link."));
|
||||
} finally {
|
||||
busy.value = "";
|
||||
}
|
||||
await act(
|
||||
account.id,
|
||||
async () => {
|
||||
const res = await api.post<{ token: string }>(`/api/accounts/${account.id}/reset-link`, {});
|
||||
fresh.value = { link: appLink({ name: "reset-password", query: { token: res.token } }), email: account.email };
|
||||
},
|
||||
"Couldn't make a reset link.",
|
||||
);
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
@@ -62,7 +60,7 @@ onMounted(() => {
|
||||
|
||||
<template>
|
||||
<section class="flex flex-col gap-5">
|
||||
<h2 class="text-xs font-semibold uppercase tracking-wide text-neutral-400">People</h2>
|
||||
<h2 class="section-label">People</h2>
|
||||
|
||||
<OneTimeLink
|
||||
v-if="fresh"
|
||||
@@ -71,14 +69,14 @@ onMounted(() => {
|
||||
@done="fresh = null"
|
||||
/>
|
||||
|
||||
<p v-if="error" class="text-sm text-red-600 dark:text-red-400">{{ error }}</p>
|
||||
<p v-if="error" class="form-error">{{ error }}</p>
|
||||
|
||||
<div v-if="loading" class="py-6 text-center text-sm text-neutral-400">Loading…</div>
|
||||
<div v-if="loading" class="list-empty">Loading…</div>
|
||||
<ul v-else class="flex flex-col gap-2">
|
||||
<li
|
||||
v-for="a in accounts"
|
||||
:key="a.id"
|
||||
class="flex items-center justify-between gap-4 rounded-xl border border-neutral-200 px-4 py-3 dark:border-neutral-800"
|
||||
class="row-card"
|
||||
>
|
||||
<div class="min-w-0">
|
||||
<p class="truncate text-sm font-medium text-neutral-800 dark:text-neutral-100">{{ a.display_name }}</p>
|
||||
@@ -86,7 +84,7 @@ onMounted(() => {
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
class="shrink-0 rounded-md border border-neutral-300 px-2.5 py-1 text-xs text-neutral-700 hover:bg-neutral-100 focus:outline-none focus-visible:ring-2 focus-visible:ring-brand disabled:opacity-50 dark:border-neutral-700 dark:text-neutral-200 dark:hover:bg-neutral-800"
|
||||
class="shrink-0 btn-sm"
|
||||
:disabled="busy === a.id"
|
||||
@click="resetLink(a)"
|
||||
>
|
||||
|
||||
@@ -93,11 +93,11 @@ onMounted(() => {
|
||||
|
||||
<template>
|
||||
<section class="flex flex-col gap-5">
|
||||
<h2 class="text-xs font-semibold uppercase tracking-wide text-neutral-400">Activity</h2>
|
||||
<h2 class="section-label">Activity</h2>
|
||||
|
||||
<p v-if="error" class="text-sm text-red-600 dark:text-red-400">{{ error }}</p>
|
||||
<p v-if="error" class="form-error">{{ error }}</p>
|
||||
|
||||
<div v-if="loading" class="py-6 text-center text-sm text-neutral-400">Loading…</div>
|
||||
<div v-if="loading" class="list-empty">Loading…</div>
|
||||
<p v-else-if="!events.length" class="text-sm text-neutral-400">Nothing yet.</p>
|
||||
<ul v-else class="flex flex-col gap-2">
|
||||
<li
|
||||
@@ -118,7 +118,7 @@ onMounted(() => {
|
||||
<button
|
||||
v-if="more"
|
||||
type="button"
|
||||
class="self-start rounded-md border border-neutral-300 px-2.5 py-1 text-xs text-neutral-700 hover:bg-neutral-100 focus:outline-none focus-visible:ring-2 focus-visible:ring-brand disabled:opacity-50 dark:border-neutral-700 dark:text-neutral-200 dark:hover:bg-neutral-800"
|
||||
class="self-start btn-sm"
|
||||
:disabled="loadingMore"
|
||||
@click="loadMore"
|
||||
>
|
||||
|
||||
@@ -396,7 +396,7 @@ async function signOut() {
|
||||
</RouterLink>
|
||||
|
||||
<div class="mt-3 flex items-center justify-between px-3 pb-1">
|
||||
<span class="text-xs font-semibold uppercase tracking-wide text-neutral-400">Tags</span>
|
||||
<span class="section-label">Tags</span>
|
||||
<button
|
||||
type="button"
|
||||
class="text-neutral-400 hover:text-neutral-600 dark:hover:text-neutral-200"
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
<script setup lang="ts">
|
||||
// The page around every signed-out form: sign in, register, forgot and reset.
|
||||
// One column under the app's icon, a title and a line saying what the page is
|
||||
// for; the form is the default slot, and `footer` is the line under it that
|
||||
// points to the page a person more likely wanted.
|
||||
import { useConfigStore } from "../stores/config";
|
||||
|
||||
defineProps<{ title: string }>();
|
||||
|
||||
const config = useConfigStore();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<main class="flex min-h-full items-center justify-center px-4 py-12">
|
||||
<div class="w-full max-w-sm">
|
||||
<div class="mb-8 text-center">
|
||||
<img
|
||||
src="/icon.svg"
|
||||
:alt="config.siteName"
|
||||
class="mx-auto mb-3 h-12 w-12 rounded-xl"
|
||||
width="48"
|
||||
height="48"
|
||||
/>
|
||||
<h1 class="text-2xl font-bold tracking-tight">{{ title }}</h1>
|
||||
<p class="mt-1 hint"><slot name="subtitle" /></p>
|
||||
</div>
|
||||
|
||||
<slot />
|
||||
|
||||
<p v-if="$slots.footer" class="mt-6 text-center hint">
|
||||
<slot name="footer" />
|
||||
</p>
|
||||
|
||||
<slot name="end" />
|
||||
</div>
|
||||
</main>
|
||||
</template>
|
||||
@@ -132,6 +132,6 @@ onMounted(async () => {
|
||||
</button>
|
||||
</li>
|
||||
</ul>
|
||||
<p v-else class="px-4 py-6 text-center text-sm text-neutral-400">No matches</p>
|
||||
<p v-else class="px-4 list-empty">No matches</p>
|
||||
</BaseModal>
|
||||
</template>
|
||||
|
||||
@@ -4,7 +4,7 @@ import BaseModal from "./BaseModal.vue";
|
||||
import BaseButton from "./BaseButton.vue";
|
||||
import { isDesktop, desktop } from "../desktop/bridge";
|
||||
import { useUiStore } from "../stores/ui";
|
||||
import { errorMessage } from "../api/errors";
|
||||
import { useAction } from "../composables/useAction";
|
||||
|
||||
// First-run prompt (Linux AppImage only) offering to add Inkwell to the
|
||||
// applications menu so it behaves like an installed app instead of a loose file.
|
||||
@@ -15,7 +15,7 @@ const DISMISS_KEY = "desktop.integration.prompted";
|
||||
|
||||
const ui = useUiStore();
|
||||
const show = ref(false);
|
||||
const working = ref(false);
|
||||
const { busy: working, act } = useAction();
|
||||
|
||||
onMounted(async () => {
|
||||
if (!isDesktop() || localStorage.getItem(DISMISS_KEY)) return;
|
||||
@@ -33,17 +33,12 @@ function dismiss() {
|
||||
}
|
||||
|
||||
async function integrate() {
|
||||
working.value = true;
|
||||
try {
|
||||
await act(async () => {
|
||||
await desktop.integrate();
|
||||
localStorage.setItem(DISMISS_KEY, "1");
|
||||
show.value = false;
|
||||
ui.showToast("Inkwell added to your applications menu.");
|
||||
} catch (e) {
|
||||
ui.showToast(errorMessage(e, "Couldn't add to applications."));
|
||||
} finally {
|
||||
working.value = false;
|
||||
}
|
||||
}, "Couldn't add to applications.");
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
import { onMounted, ref } from "vue";
|
||||
import BaseButton from "./BaseButton.vue";
|
||||
import { desktop, isDesktop, type IntegrationStatus } from "../desktop/bridge";
|
||||
import { errorMessage } from "../api/errors";
|
||||
import { useUiStore } from "../stores/ui";
|
||||
import { useAction } from "../composables/useAction";
|
||||
|
||||
// The applications-menu entry for a Linux AppImage: add it, or take it away again.
|
||||
// Renders nothing anywhere else — the web, Windows, or an AppImage-less Linux build.
|
||||
@@ -12,7 +12,7 @@ import { useUiStore } from "../stores/ui";
|
||||
// first-run prompt promised ("undo any time") with no way to reach it.
|
||||
const ui = useUiStore();
|
||||
const status = ref<IntegrationStatus | null>(null);
|
||||
const busy = ref(false);
|
||||
const { busy, act } = useAction();
|
||||
|
||||
onMounted(async () => {
|
||||
if (!isDesktop()) return;
|
||||
@@ -24,17 +24,12 @@ onMounted(async () => {
|
||||
});
|
||||
|
||||
async function toggle() {
|
||||
busy.value = true;
|
||||
try {
|
||||
await act(async () => {
|
||||
status.value = status.value?.is_integrated ? await desktop.unintegrate() : await desktop.integrate();
|
||||
ui.showToast(
|
||||
status.value?.is_integrated ? "Added to your applications menu." : "Removed from your applications menu.",
|
||||
);
|
||||
} catch (e) {
|
||||
ui.showToast(errorMessage(e, "Couldn't update the menu entry."));
|
||||
} finally {
|
||||
busy.value = false;
|
||||
}
|
||||
}, "Couldn't update the menu entry.");
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -42,7 +37,7 @@ async function toggle() {
|
||||
<section v-if="status?.is_appimage" class="mt-10 border-t border-neutral-200 pt-8 dark:border-neutral-800">
|
||||
<h2 class="text-sm font-semibold">Applications menu</h2>
|
||||
<div class="mt-3 flex items-center justify-between gap-4">
|
||||
<p class="text-sm text-neutral-500 dark:text-neutral-400">
|
||||
<p class="hint">
|
||||
{{ status.is_integrated ? "Inkwell is in your applications menu." : "Not in your applications menu." }}
|
||||
</p>
|
||||
<BaseButton
|
||||
|
||||
@@ -1,27 +1,21 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from "vue";
|
||||
import Icon from "./Icon.vue";
|
||||
import { repo } from "../adapters";
|
||||
import { errorMessage } from "../api/errors";
|
||||
import { useUiStore } from "../stores/ui";
|
||||
import { useAction } from "../composables/useAction";
|
||||
|
||||
// Sidebar Export. In a browser the server streams the zip and the browser saves it;
|
||||
// on the desktop the core builds it from the local store with no server, saves it in
|
||||
// Downloads, and says exactly where.
|
||||
const ui = useUiStore();
|
||||
const busy = ref(false);
|
||||
const { busy, act } = useAction();
|
||||
|
||||
async function run() {
|
||||
if (busy.value) return;
|
||||
busy.value = true;
|
||||
try {
|
||||
await act(async () => {
|
||||
const savedTo = await repo.notes.exportAll();
|
||||
if (savedTo) ui.showToast(`Exported to ${savedTo}`);
|
||||
} catch (err) {
|
||||
ui.showToast(errorMessage(err, "Export failed."));
|
||||
} finally {
|
||||
busy.value = false;
|
||||
}
|
||||
}, "Export failed.");
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
import { computed, onMounted, ref } from "vue";
|
||||
import { api } from "../api/client";
|
||||
import { errorMessage } from "../api/errors";
|
||||
import { useUiStore } from "../stores/ui";
|
||||
import BaseButton from "./BaseButton.vue";
|
||||
import BaseInput from "./BaseInput.vue";
|
||||
import Icon from "./Icon.vue";
|
||||
import { useRowAction } from "../composables/useAction";
|
||||
|
||||
// Admin: groups of people a note can be shared with in one go (#5177). A group is
|
||||
// the instance's; anyone can share with it, and a note shared with it reaches whoever
|
||||
@@ -23,7 +23,6 @@ interface Group {
|
||||
members: Person[];
|
||||
}
|
||||
|
||||
const ui = useUiStore();
|
||||
|
||||
const groups = ref<Group[]>([]);
|
||||
const accounts = ref<Person[]>([]);
|
||||
@@ -31,7 +30,7 @@ const loading = ref(true);
|
||||
const error = ref("");
|
||||
const name = ref("");
|
||||
const creating = ref(false);
|
||||
const busy = ref("");
|
||||
const { busy, act } = useRowAction();
|
||||
// Which group's "Add someone" picker holds which account id.
|
||||
const picks = ref<Record<string, string>>({});
|
||||
|
||||
@@ -64,17 +63,6 @@ function replace(updated: Group) {
|
||||
groups.value = groups.value.map((g) => (g.id === updated.id ? updated : g)).sort(byName);
|
||||
}
|
||||
|
||||
async function act(id: string, fn: () => Promise<void>, fallback: string) {
|
||||
busy.value = id;
|
||||
try {
|
||||
await fn();
|
||||
} catch (e) {
|
||||
ui.showToast(errorMessage(e, fallback));
|
||||
} finally {
|
||||
busy.value = "";
|
||||
}
|
||||
}
|
||||
|
||||
async function create() {
|
||||
if (!name.value.trim()) return;
|
||||
creating.value = true;
|
||||
@@ -140,16 +128,16 @@ onMounted(() => {
|
||||
|
||||
<template>
|
||||
<section class="flex flex-col gap-5">
|
||||
<h2 class="text-xs font-semibold uppercase tracking-wide text-neutral-400">Groups</h2>
|
||||
<h2 class="section-label">Groups</h2>
|
||||
|
||||
<form class="flex flex-wrap items-end gap-3" @submit.prevent="create">
|
||||
<BaseInput id="group-name" v-model="name" label="New group" placeholder="Family" class="min-w-48 flex-1" />
|
||||
<BaseButton type="submit" :loading="creating" :disabled="!name.trim()">Create group</BaseButton>
|
||||
</form>
|
||||
|
||||
<p v-if="error" class="text-sm text-red-600 dark:text-red-400">{{ error }}</p>
|
||||
<p v-if="error" class="form-error">{{ error }}</p>
|
||||
|
||||
<div v-if="loading" class="py-6 text-center text-sm text-neutral-400">Loading…</div>
|
||||
<div v-if="loading" class="list-empty">Loading…</div>
|
||||
<p v-else-if="empty" class="text-sm text-neutral-400">No groups yet.</p>
|
||||
<ul v-else class="flex flex-col gap-2">
|
||||
<li
|
||||
@@ -167,7 +155,7 @@ onMounted(() => {
|
||||
<div class="flex shrink-0 items-center gap-2">
|
||||
<button
|
||||
type="button"
|
||||
class="rounded-md border border-neutral-300 px-2.5 py-1 text-xs text-neutral-700 hover:bg-neutral-100 focus:outline-none focus-visible:ring-2 focus-visible:ring-brand disabled:opacity-50 dark:border-neutral-700 dark:text-neutral-200 dark:hover:bg-neutral-800"
|
||||
class="btn-sm"
|
||||
:disabled="busy === g.id"
|
||||
@click="rename(g)"
|
||||
>
|
||||
@@ -175,7 +163,7 @@ onMounted(() => {
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="rounded-md border border-neutral-300 px-2.5 py-1 text-xs text-red-600 hover:bg-red-50 focus:outline-none focus-visible:ring-2 focus-visible:ring-brand disabled:opacity-50 dark:border-neutral-700 dark:text-red-400 dark:hover:bg-red-950/40"
|
||||
class="btn-sm-danger"
|
||||
:disabled="busy === g.id"
|
||||
@click="remove(g)"
|
||||
>
|
||||
@@ -216,7 +204,7 @@ onMounted(() => {
|
||||
</select>
|
||||
<button
|
||||
type="submit"
|
||||
class="rounded-md border border-neutral-300 px-2.5 py-1.5 text-xs text-neutral-700 hover:bg-neutral-100 focus:outline-none focus-visible:ring-2 focus-visible:ring-brand disabled:opacity-50 dark:border-neutral-700 dark:text-neutral-200 dark:hover:bg-neutral-800"
|
||||
class="btn-sm py-1.5"
|
||||
:disabled="busy === g.id || !picks[g.id]"
|
||||
>
|
||||
Add
|
||||
|
||||
@@ -4,7 +4,7 @@ import Icon from "./Icon.vue";
|
||||
import { useNotesStore } from "../stores/notes";
|
||||
import { useLabelsStore } from "../stores/labels";
|
||||
import { useUiStore } from "../stores/ui";
|
||||
import { errorMessage } from "../api/errors";
|
||||
import { useAction } from "../composables/useAction";
|
||||
|
||||
// Sidebar counterpart to Export: pick a .zip (an Inkwell export for round-trip,
|
||||
// or a Google Keep Takeout archive) and import its notes. Additive — never
|
||||
@@ -13,7 +13,7 @@ const notes = useNotesStore();
|
||||
const labels = useLabelsStore();
|
||||
const ui = useUiStore();
|
||||
const inputRef = ref<HTMLInputElement | null>(null);
|
||||
const busy = ref(false);
|
||||
const { busy, act } = useAction();
|
||||
|
||||
function pick() {
|
||||
if (!busy.value) inputRef.value?.click();
|
||||
@@ -24,18 +24,13 @@ async function onFile(e: Event) {
|
||||
const file = input.files?.[0];
|
||||
input.value = ""; // reset so picking the same file again re-fires change
|
||||
if (!file) return;
|
||||
busy.value = true;
|
||||
try {
|
||||
await act(async () => {
|
||||
const res = await notes.importNotes(file);
|
||||
await labels.load(); // surface any labels the import created
|
||||
const noun = res.imported === 1 ? "note" : "notes";
|
||||
const tail = res.skipped ? ` (${res.skipped} skipped)` : "";
|
||||
ui.showToast(`Imported ${res.imported} ${noun}${tail}.`);
|
||||
} catch (err) {
|
||||
ui.showToast(errorMessage(err, "Import failed."));
|
||||
} finally {
|
||||
busy.value = false;
|
||||
}
|
||||
}, "Import failed.");
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
import { onMounted, ref } from "vue";
|
||||
import { api } from "../api/client";
|
||||
import { errorMessage } from "../api/errors";
|
||||
import { useUiStore } from "../stores/ui";
|
||||
import { appLink } from "../router/links";
|
||||
import BaseButton from "./BaseButton.vue";
|
||||
import BaseInput from "./BaseInput.vue";
|
||||
import OneTimeLink from "./OneTimeLink.vue";
|
||||
import { toastOnFailure } from "../composables/useAction";
|
||||
|
||||
// Admin: invite one person to register while registration stays closed (#5172).
|
||||
// The server keeps only a hash of each invite's token, so the link is shown once,
|
||||
@@ -29,7 +29,6 @@ const LIFETIMES = [
|
||||
{ days: 30, label: "30 days" },
|
||||
];
|
||||
|
||||
const ui = useUiStore();
|
||||
|
||||
const invites = ref<Invite[]>([]);
|
||||
const loading = ref(true);
|
||||
@@ -42,7 +41,7 @@ const freshLink = ref("");
|
||||
|
||||
async function load() {
|
||||
error.value = "";
|
||||
try {
|
||||
await toastOnFailure(async () => {
|
||||
invites.value = (await api.get<{ invites: Invite[] }>("/api/invites")).invites;
|
||||
} catch (e) {
|
||||
error.value = errorMessage(e, "Couldn't load invites.");
|
||||
@@ -75,9 +74,7 @@ async function revoke(invite: Invite) {
|
||||
try {
|
||||
const updated = await api.del<Invite>(`/api/invites/${invite.id}`);
|
||||
invites.value = invites.value.map((i) => (i.id === updated.id ? updated : i));
|
||||
} catch (e) {
|
||||
ui.showToast(errorMessage(e, "Couldn't revoke that invite."));
|
||||
}
|
||||
}, "Couldn't revoke that invite.");
|
||||
}
|
||||
|
||||
function who(invite: Invite): string {
|
||||
@@ -109,7 +106,7 @@ onMounted(() => {
|
||||
|
||||
<template>
|
||||
<section class="flex flex-col gap-5">
|
||||
<h2 class="text-xs font-semibold uppercase tracking-wide text-neutral-400">Invites</h2>
|
||||
<h2 class="section-label">Invites</h2>
|
||||
|
||||
<OneTimeLink
|
||||
v-if="freshLink"
|
||||
@@ -132,7 +129,7 @@ onMounted(() => {
|
||||
<select
|
||||
id="invite-days"
|
||||
v-model.number="days"
|
||||
class="rounded-lg border border-neutral-300 bg-white px-3 py-2 text-sm text-neutral-900 shadow-sm focus:outline-none focus-visible:ring-2 focus-visible:ring-brand dark:border-neutral-700 dark:bg-neutral-800 dark:text-neutral-100"
|
||||
class="field"
|
||||
>
|
||||
<option v-for="l in LIFETIMES" :key="l.days" :value="l.days">{{ l.label }}</option>
|
||||
</select>
|
||||
@@ -140,15 +137,15 @@ onMounted(() => {
|
||||
<BaseButton type="submit" :loading="creating">Create invite</BaseButton>
|
||||
</form>
|
||||
|
||||
<p v-if="error" class="text-sm text-red-600 dark:text-red-400">{{ error }}</p>
|
||||
<p v-if="error" class="form-error">{{ error }}</p>
|
||||
|
||||
<div v-if="loading" class="py-6 text-center text-sm text-neutral-400">Loading…</div>
|
||||
<div v-if="loading" class="list-empty">Loading…</div>
|
||||
<p v-else-if="!invites.length" class="text-sm text-neutral-400">No invites yet.</p>
|
||||
<ul v-else class="flex flex-col gap-2">
|
||||
<li
|
||||
v-for="i in invites"
|
||||
:key="i.id"
|
||||
class="flex items-center justify-between gap-4 rounded-xl border border-neutral-200 px-4 py-3 dark:border-neutral-800"
|
||||
class="row-card"
|
||||
>
|
||||
<div class="min-w-0">
|
||||
<p class="truncate text-sm font-medium text-neutral-800 dark:text-neutral-100">
|
||||
@@ -159,7 +156,7 @@ onMounted(() => {
|
||||
<button
|
||||
v-if="i.status === 'pending'"
|
||||
type="button"
|
||||
class="shrink-0 rounded-md border border-neutral-300 px-2.5 py-1 text-xs text-red-600 hover:bg-red-50 focus:outline-none focus-visible:ring-2 focus-visible:ring-brand dark:border-neutral-700 dark:text-red-400 dark:hover:bg-red-950/40"
|
||||
class="shrink-0 btn-sm-danger"
|
||||
@click="revoke(i)"
|
||||
>
|
||||
Revoke
|
||||
|
||||
@@ -761,7 +761,7 @@ function revPreview(rev: NoteRevision): string {
|
||||
v-if="!isCreate && showHistory"
|
||||
class="flex flex-col gap-1 border-t border-neutral-100 pt-2 dark:border-neutral-800"
|
||||
>
|
||||
<p class="text-xs font-semibold uppercase tracking-wide text-neutral-400">History</p>
|
||||
<p class="section-label">History</p>
|
||||
<p v-if="!revisions.length" class="text-xs text-neutral-400">
|
||||
No earlier versions yet — your edits will show up here.
|
||||
</p>
|
||||
|
||||
@@ -115,7 +115,7 @@ onMounted(load);
|
||||
<p v-if="loading" class="py-4 text-center text-sm text-neutral-400">Loading…</p>
|
||||
|
||||
<div v-else-if="loadError" class="py-4 text-center">
|
||||
<p class="text-sm text-red-600 dark:text-red-400">{{ loadError }}</p>
|
||||
<p class="form-error">{{ loadError }}</p>
|
||||
<button
|
||||
type="button"
|
||||
class="mt-2 rounded-md border border-neutral-300 px-3 py-1 text-sm hover:bg-neutral-100 dark:border-neutral-700 dark:hover:bg-neutral-800"
|
||||
@@ -126,7 +126,7 @@ onMounted(load);
|
||||
</div>
|
||||
|
||||
<template v-else>
|
||||
<p v-if="!anyone" class="text-sm text-neutral-500 dark:text-neutral-400">
|
||||
<p v-if="!anyone" class="hint">
|
||||
No one else has an account here yet. An admin can invite people from Settings.
|
||||
</p>
|
||||
|
||||
@@ -156,10 +156,10 @@ onMounted(load);
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<p v-if="error" role="alert" class="text-sm text-red-600 dark:text-red-400">{{ error }}</p>
|
||||
<p v-if="error" role="alert" class="form-error">{{ error }}</p>
|
||||
|
||||
<div class="flex flex-col gap-1">
|
||||
<p class="text-xs font-semibold uppercase tracking-wide text-neutral-400">Shared with</p>
|
||||
<p class="section-label">Shared with</p>
|
||||
<p v-if="!shares.length" class="text-sm text-neutral-400">Only you.</p>
|
||||
<ul v-else class="flex flex-col gap-1">
|
||||
<li v-for="s in shares" :key="s.id" class="flex items-center gap-2 rounded-lg px-1 py-1">
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
import { ref } from "vue";
|
||||
import { errorMessage } from "../api/errors";
|
||||
import { useUiStore } from "../stores/ui";
|
||||
|
||||
/**
|
||||
* Run `work`, and say so in a toast if it fails: the server's own reason when it
|
||||
* gave one, else `fallback`. The one way a button's action reports a failure it
|
||||
* has no better place to show.
|
||||
*/
|
||||
export async function toastOnFailure(work: () => Promise<unknown>, fallback: string): Promise<void> {
|
||||
try {
|
||||
await work();
|
||||
} catch (e) {
|
||||
useUiStore().showToast(errorMessage(e, fallback));
|
||||
}
|
||||
}
|
||||
|
||||
/** A single action and whether it is running, for the button that starts it. */
|
||||
export function useAction() {
|
||||
const busy = ref(false);
|
||||
async function act(work: () => Promise<unknown>, fallback: string): Promise<void> {
|
||||
busy.value = true;
|
||||
try {
|
||||
await toastOnFailure(work, fallback);
|
||||
} finally {
|
||||
busy.value = false;
|
||||
}
|
||||
}
|
||||
return { busy, act };
|
||||
}
|
||||
|
||||
/**
|
||||
* The same for a list whose rows each carry an action: `busy` is the id of the row
|
||||
* whose action is running, or "" when none is, so only that row's buttons wait.
|
||||
*/
|
||||
export function useRowAction() {
|
||||
const busy = ref("");
|
||||
async function act(id: string, work: () => Promise<unknown>, fallback: string): Promise<void> {
|
||||
busy.value = id;
|
||||
try {
|
||||
await toastOnFailure(work, fallback);
|
||||
} finally {
|
||||
busy.value = "";
|
||||
}
|
||||
}
|
||||
return { busy, act };
|
||||
}
|
||||
@@ -290,4 +290,56 @@ body {
|
||||
.nav-link-active {
|
||||
@apply bg-neutral-200 text-neutral-900 dark:bg-neutral-800 dark:text-neutral-100;
|
||||
}
|
||||
/* The small bordered action on a row in Account, Admin and Sync: Rename, Revoke,
|
||||
* Sign out. Two colours, neutral and destructive; spacing a site needs beyond
|
||||
* these (shrink-0, self-start, py-1.5) stays a utility beside it. */
|
||||
.btn-sm {
|
||||
@apply rounded-md border border-neutral-300 px-2.5 py-1 text-xs text-neutral-700
|
||||
hover:bg-neutral-100 focus:outline-none focus-visible:ring-2 focus-visible:ring-brand
|
||||
disabled:opacity-50 dark:border-neutral-700 dark:text-neutral-200 dark:hover:bg-neutral-800;
|
||||
}
|
||||
.btn-sm-danger {
|
||||
@apply rounded-md border border-neutral-300 px-2.5 py-1 text-xs text-red-600
|
||||
hover:bg-red-50 focus:outline-none focus-visible:ring-2 focus-visible:ring-brand
|
||||
disabled:opacity-50 dark:border-neutral-700 dark:text-red-400 dark:hover:bg-red-950/40;
|
||||
}
|
||||
/* A plain text or number input on a settings page; its width is the site's. */
|
||||
.field {
|
||||
@apply rounded-lg border border-neutral-300 bg-white px-3 py-2 text-sm text-neutral-900
|
||||
shadow-sm focus:outline-none focus-visible:ring-2 focus-visible:ring-brand
|
||||
dark:border-neutral-700 dark:bg-neutral-800 dark:text-neutral-100;
|
||||
}
|
||||
/* A settings or account page: one centred column. */
|
||||
.page-shell {
|
||||
@apply mx-auto min-h-full max-w-2xl px-4 py-8;
|
||||
}
|
||||
/* The small caps heading over a group of rows or controls. */
|
||||
.section-label {
|
||||
@apply text-xs font-semibold uppercase tracking-wide text-neutral-400;
|
||||
}
|
||||
/* One bordered row in a list of things you can act on: a device, an account. */
|
||||
.row-card {
|
||||
@apply flex items-center justify-between gap-4 rounded-xl border border-neutral-200 px-4
|
||||
py-3 dark:border-neutral-800;
|
||||
}
|
||||
/* The line a list shows when it has nothing in it. */
|
||||
.list-empty {
|
||||
@apply py-6 text-center text-sm text-neutral-400;
|
||||
}
|
||||
/* Secondary text under a heading or beside a control. */
|
||||
.hint {
|
||||
@apply text-sm text-neutral-500 dark:text-neutral-400;
|
||||
}
|
||||
/* A field's or a form's own error, in a line of text. */
|
||||
.form-error {
|
||||
@apply text-sm text-red-600 dark:text-red-400;
|
||||
}
|
||||
/* A link that is a way out of a form: "Create one", "Back to sign in". */
|
||||
.text-link {
|
||||
@apply font-semibold text-brand-700 hover:underline dark:text-brand;
|
||||
}
|
||||
/* A form's error as a banner over its submit button. */
|
||||
.alert-error {
|
||||
@apply rounded-lg bg-red-50 px-3 py-2 text-sm text-red-700 dark:bg-red-950/50 dark:text-red-300;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import { errorMessage } from "../api/errors";
|
||||
import { formatDateTime } from "../notes/datetime";
|
||||
import { repo } from "../adapters";
|
||||
import type { StorageUse } from "../adapters/repo";
|
||||
import { useAction } from "../composables/useAction";
|
||||
|
||||
// The signed-in person's own account (not admin): the native clients linked to it
|
||||
// (the desktop and Android apps sync with a device bearer token issued here), its
|
||||
@@ -96,7 +97,7 @@ const currentPassword = ref("");
|
||||
const newPassword = ref("");
|
||||
const changing = ref(false);
|
||||
const passwordError = ref("");
|
||||
const signingOut = ref(false);
|
||||
const { busy: signingOut, act } = useAction();
|
||||
|
||||
function unlinkedNote(n: number): string {
|
||||
if (n === 0) return "";
|
||||
@@ -124,16 +125,11 @@ async function signOutElsewhere() {
|
||||
"Sign out of every other browser and unlink every device? Each app will need to sign in again.",
|
||||
);
|
||||
if (!ok) return;
|
||||
signingOut.value = true;
|
||||
try {
|
||||
await act(async () => {
|
||||
const unlinked = await session.signOutElsewhere();
|
||||
ui.showToast(`Signed out everywhere else.${unlinkedNote(unlinked)}`);
|
||||
await devices.load();
|
||||
} catch (e) {
|
||||
ui.showToast(errorMessage(e, "Couldn't sign out everywhere else."));
|
||||
} finally {
|
||||
signingOut.value = false;
|
||||
}
|
||||
}, "Couldn't sign out everywhere else.");
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
@@ -142,11 +138,11 @@ onMounted(() => {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="mx-auto min-h-full max-w-2xl px-4 py-8">
|
||||
<div class="page-shell">
|
||||
<PageHeader title="Account" />
|
||||
|
||||
<h2 class="mb-2 text-xs font-semibold uppercase tracking-wide text-neutral-400">Linked devices</h2>
|
||||
<p class="mb-6 max-w-xl text-sm text-neutral-500 dark:text-neutral-400">
|
||||
<h2 class="mb-2 section-label">Linked devices</h2>
|
||||
<p class="mb-6 max-w-xl hint">
|
||||
Link the Inkwell desktop or mobile app to sync your notes. Create a device token here, then
|
||||
paste it into the app when it asks to connect. You can revoke a device at any time.
|
||||
</p>
|
||||
@@ -199,7 +195,7 @@ onMounted(() => {
|
||||
<BaseButton type="submit" :loading="creating">Create token</BaseButton>
|
||||
</form>
|
||||
|
||||
<p v-if="error" class="mb-4 text-sm text-red-600 dark:text-red-400">{{ error }}</p>
|
||||
<p v-if="error" class="mb-4 form-error">{{ error }}</p>
|
||||
|
||||
<!-- Device list -->
|
||||
<div v-if="devices.loading" class="py-10 text-center text-sm text-neutral-400">Loading…</div>
|
||||
@@ -207,13 +203,13 @@ onMounted(() => {
|
||||
v-else-if="!devices.items.length"
|
||||
class="rounded-xl border border-dashed border-neutral-300 py-10 text-center dark:border-neutral-700"
|
||||
>
|
||||
<p class="text-sm text-neutral-500 dark:text-neutral-400">No devices linked yet.</p>
|
||||
<p class="hint">No devices linked yet.</p>
|
||||
</div>
|
||||
<ul v-else class="flex flex-col gap-2">
|
||||
<li
|
||||
v-for="d in devices.items"
|
||||
:key="d.id"
|
||||
class="flex items-center justify-between gap-4 rounded-xl border border-neutral-200 px-4 py-3 dark:border-neutral-800"
|
||||
class="row-card"
|
||||
>
|
||||
<div class="flex min-w-0 items-center gap-3">
|
||||
<span class="text-neutral-400"><Icon name="device" /></span>
|
||||
@@ -226,7 +222,7 @@ onMounted(() => {
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
class="shrink-0 rounded-md border border-neutral-300 px-2.5 py-1 text-xs text-red-600 hover:bg-red-50 focus:outline-none focus-visible:ring-2 focus-visible:ring-brand dark:border-neutral-700 dark:text-red-400 dark:hover:bg-red-950/40"
|
||||
class="shrink-0 btn-sm-danger"
|
||||
@click="revoke(d.id, d.name)"
|
||||
>
|
||||
Revoke
|
||||
@@ -235,9 +231,9 @@ onMounted(() => {
|
||||
</ul>
|
||||
|
||||
<template v-if="storage">
|
||||
<h2 class="mb-2 mt-10 text-xs font-semibold uppercase tracking-wide text-neutral-400">Storage</h2>
|
||||
<h2 class="mb-2 mt-10 section-label">Storage</h2>
|
||||
<div
|
||||
class="flex items-center justify-between gap-4 rounded-xl border border-neutral-200 px-4 py-3 dark:border-neutral-800"
|
||||
class="row-card"
|
||||
>
|
||||
<div class="min-w-0">
|
||||
<p class="text-sm font-medium text-neutral-800 dark:text-neutral-100">Attachments</p>
|
||||
@@ -247,8 +243,8 @@ onMounted(() => {
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<h2 class="mb-2 mt-10 text-xs font-semibold uppercase tracking-wide text-neutral-400">Password</h2>
|
||||
<p class="mb-4 text-sm text-neutral-500 dark:text-neutral-400">Changing it signs you out everywhere else.</p>
|
||||
<h2 class="mb-2 mt-10 section-label">Password</h2>
|
||||
<p class="mb-4 hint">Changing it signs you out everywhere else.</p>
|
||||
<form class="flex max-w-sm flex-col gap-3" @submit.prevent="changePassword">
|
||||
<BaseInput
|
||||
id="current-password"
|
||||
@@ -273,9 +269,9 @@ onMounted(() => {
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<h2 class="mb-2 mt-10 text-xs font-semibold uppercase tracking-wide text-neutral-400">Sessions</h2>
|
||||
<h2 class="mb-2 mt-10 section-label">Sessions</h2>
|
||||
<div
|
||||
class="flex items-center justify-between gap-4 rounded-xl border border-neutral-200 px-4 py-3 dark:border-neutral-800"
|
||||
class="row-card"
|
||||
>
|
||||
<div class="min-w-0">
|
||||
<p class="text-sm font-medium text-neutral-800 dark:text-neutral-100">Sign out everywhere else</p>
|
||||
|
||||
@@ -350,11 +350,11 @@ const gridBinds = computed(() => ({
|
||||
<template v-else>
|
||||
<template v-if="isMainBoard">
|
||||
<section v-if="pinnedNotes.length">
|
||||
<h2 class="mb-2 text-xs font-semibold uppercase tracking-wide text-neutral-400">Pinned</h2>
|
||||
<h2 class="mb-2 section-label">Pinned</h2>
|
||||
<NoteGrid :notes="pinnedNotes" v-bind="gridBinds" />
|
||||
</section>
|
||||
<section v-if="otherNotes.length" :class="pinnedNotes.length ? 'mt-8' : ''">
|
||||
<h2 v-if="pinnedNotes.length" class="mb-2 text-xs font-semibold uppercase tracking-wide text-neutral-400">
|
||||
<h2 v-if="pinnedNotes.length" class="mb-2 section-label">
|
||||
Others
|
||||
</h2>
|
||||
<NoteGrid :notes="otherNotes" v-bind="gridBinds" />
|
||||
|
||||
@@ -3,14 +3,13 @@ import { ref } from "vue";
|
||||
import { useRoute } from "vue-router";
|
||||
import { api } from "../api/client";
|
||||
import { errorMessage } from "../api/errors";
|
||||
import { useConfigStore } from "../stores/config";
|
||||
import BaseInput from "../components/BaseInput.vue";
|
||||
import AuthLayout from "../components/AuthLayout.vue";
|
||||
import BaseButton from "../components/BaseButton.vue";
|
||||
|
||||
// Ask for a password reset link by email (#5266). The server answers the same way
|
||||
// whether or not the address has an account, so this page does too.
|
||||
|
||||
const config = useConfigStore();
|
||||
const route = useRoute();
|
||||
|
||||
const email = ref(typeof route.query.email === "string" ? route.query.email : "");
|
||||
@@ -33,52 +32,40 @@ async function submit() {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<main class="flex min-h-full items-center justify-center px-4 py-12">
|
||||
<div class="w-full max-w-sm">
|
||||
<div class="mb-8 text-center">
|
||||
<img
|
||||
src="/icon.svg"
|
||||
:alt="config.siteName"
|
||||
class="mx-auto mb-3 h-12 w-12 rounded-xl"
|
||||
width="48"
|
||||
height="48"
|
||||
/>
|
||||
<h1 class="text-2xl font-bold tracking-tight">Forgot your password?</h1>
|
||||
<p class="mt-1 text-sm text-neutral-500 dark:text-neutral-400">We'll email you a link to choose a new one.</p>
|
||||
</div>
|
||||
<AuthLayout title="Forgot your password?">
|
||||
<template #subtitle>We'll email you a link to choose a new one.</template>
|
||||
|
||||
<p
|
||||
v-if="sent"
|
||||
role="status"
|
||||
class="rounded-lg bg-green-50 px-3 py-2 text-sm text-green-800 dark:bg-green-950/50 dark:text-green-300"
|
||||
>
|
||||
{{ sent }}
|
||||
</p>
|
||||
<form v-else class="flex flex-col gap-4" novalidate @submit.prevent="submit">
|
||||
<BaseInput
|
||||
id="email"
|
||||
v-model="email"
|
||||
label="Email"
|
||||
type="email"
|
||||
autocomplete="email"
|
||||
placeholder="you@example.com"
|
||||
required
|
||||
/>
|
||||
<p
|
||||
v-if="sent"
|
||||
role="status"
|
||||
class="rounded-lg bg-green-50 px-3 py-2 text-sm text-green-800 dark:bg-green-950/50 dark:text-green-300"
|
||||
v-if="error"
|
||||
role="alert"
|
||||
class="alert-error"
|
||||
>
|
||||
{{ sent }}
|
||||
{{ error }}
|
||||
</p>
|
||||
<form v-else class="flex flex-col gap-4" novalidate @submit.prevent="submit">
|
||||
<BaseInput
|
||||
id="email"
|
||||
v-model="email"
|
||||
label="Email"
|
||||
type="email"
|
||||
autocomplete="email"
|
||||
placeholder="you@example.com"
|
||||
required
|
||||
/>
|
||||
<p
|
||||
v-if="error"
|
||||
role="alert"
|
||||
class="rounded-lg bg-red-50 px-3 py-2 text-sm text-red-700 dark:bg-red-950/50 dark:text-red-300"
|
||||
>
|
||||
{{ error }}
|
||||
</p>
|
||||
<BaseButton type="submit" :loading="loading">Send reset link</BaseButton>
|
||||
</form>
|
||||
<BaseButton type="submit" :loading="loading">Send reset link</BaseButton>
|
||||
</form>
|
||||
|
||||
<p class="mt-6 text-center text-sm text-neutral-500 dark:text-neutral-400">
|
||||
<RouterLink to="/login" class="font-semibold text-brand-700 hover:underline dark:text-brand"
|
||||
>Back to sign in</RouterLink
|
||||
>
|
||||
</p>
|
||||
</div>
|
||||
</main>
|
||||
<template #footer>
|
||||
<RouterLink to="/login" class="text-link"
|
||||
>Back to sign in</RouterLink
|
||||
>
|
||||
</template>
|
||||
</AuthLayout>
|
||||
</template>
|
||||
|
||||
@@ -4,6 +4,7 @@ import { useRouter, useRoute } from "vue-router";
|
||||
import { useSessionStore } from "../stores/session";
|
||||
import { useConfigStore } from "../stores/config";
|
||||
import BaseInput from "../components/BaseInput.vue";
|
||||
import AuthLayout from "../components/AuthLayout.vue";
|
||||
import BaseButton from "../components/BaseButton.vue";
|
||||
import { errorMessage } from "../api/errors";
|
||||
|
||||
@@ -41,62 +42,52 @@ async function submit() {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<main class="flex min-h-full items-center justify-center px-4 py-12">
|
||||
<div class="w-full max-w-sm">
|
||||
<div class="mb-8 text-center">
|
||||
<img
|
||||
src="/icon.svg"
|
||||
:alt="config.siteName"
|
||||
class="mx-auto mb-3 h-12 w-12 rounded-xl"
|
||||
width="48"
|
||||
height="48"
|
||||
/>
|
||||
<h1 class="text-2xl font-bold tracking-tight">Welcome back</h1>
|
||||
<p class="mt-1 text-sm text-neutral-500 dark:text-neutral-400">Sign in to your thoughts.</p>
|
||||
</div>
|
||||
<AuthLayout title="Welcome back">
|
||||
<template #subtitle>Sign in to your thoughts.</template>
|
||||
|
||||
<form class="flex flex-col gap-4" novalidate @submit.prevent="submit">
|
||||
<BaseInput
|
||||
id="email"
|
||||
v-model="email"
|
||||
label="Email"
|
||||
type="email"
|
||||
autocomplete="email"
|
||||
placeholder="you@example.com"
|
||||
required
|
||||
/>
|
||||
<BaseInput
|
||||
id="password"
|
||||
v-model="password"
|
||||
label="Password"
|
||||
type="password"
|
||||
autocomplete="current-password"
|
||||
placeholder="••••••••"
|
||||
required
|
||||
/>
|
||||
<p
|
||||
v-if="error"
|
||||
role="alert"
|
||||
class="rounded-lg bg-red-50 px-3 py-2 text-sm text-red-700 dark:bg-red-950/50 dark:text-red-300"
|
||||
>
|
||||
{{ error }}
|
||||
</p>
|
||||
<BaseButton type="submit" :loading="loading">Sign in</BaseButton>
|
||||
<RouterLink
|
||||
v-if="config.passwordResetByEmail"
|
||||
:to="{ name: 'forgot-password', query: email ? { email } : undefined }"
|
||||
class="text-center text-sm text-neutral-500 hover:underline dark:text-neutral-400"
|
||||
>Forgot password?</RouterLink
|
||||
>
|
||||
</form>
|
||||
|
||||
<p v-if="config.allowRegistration" class="mt-6 text-center text-sm text-neutral-500 dark:text-neutral-400">
|
||||
No account?
|
||||
<RouterLink to="/register" class="font-semibold text-brand-700 hover:underline dark:text-brand"
|
||||
>Create one</RouterLink
|
||||
>
|
||||
<form class="flex flex-col gap-4" novalidate @submit.prevent="submit">
|
||||
<BaseInput
|
||||
id="email"
|
||||
v-model="email"
|
||||
label="Email"
|
||||
type="email"
|
||||
autocomplete="email"
|
||||
placeholder="you@example.com"
|
||||
required
|
||||
/>
|
||||
<BaseInput
|
||||
id="password"
|
||||
v-model="password"
|
||||
label="Password"
|
||||
type="password"
|
||||
autocomplete="current-password"
|
||||
placeholder="••••••••"
|
||||
required
|
||||
/>
|
||||
<p
|
||||
v-if="error"
|
||||
role="alert"
|
||||
class="alert-error"
|
||||
>
|
||||
{{ error }}
|
||||
</p>
|
||||
<BaseButton type="submit" :loading="loading">Sign in</BaseButton>
|
||||
<RouterLink
|
||||
v-if="config.passwordResetByEmail"
|
||||
:to="{ name: 'forgot-password', query: email ? { email } : undefined }"
|
||||
class="text-center text-sm text-neutral-500 hover:underline dark:text-neutral-400"
|
||||
>Forgot password?</RouterLink
|
||||
>
|
||||
</form>
|
||||
|
||||
<template v-if="config.allowRegistration" #footer>
|
||||
No account?
|
||||
<RouterLink to="/register" class="text-link"
|
||||
>Create one</RouterLink
|
||||
>
|
||||
</template>
|
||||
|
||||
<template #end>
|
||||
<!-- The build, on the one screen a person can reach WITHOUT an account.
|
||||
"I can't sign in" is a bug report like any other and it needs a build
|
||||
number; requiring a login to read one would withhold it from exactly the
|
||||
@@ -108,6 +99,6 @@ async function submit() {
|
||||
>
|
||||
{{ config.version || "unknown" }}
|
||||
</p>
|
||||
</div>
|
||||
</main>
|
||||
</template>
|
||||
</AuthLayout>
|
||||
</template>
|
||||
|
||||
@@ -4,6 +4,7 @@ import { useRoute, useRouter } from "vue-router";
|
||||
import { useSessionStore } from "../stores/session";
|
||||
import { useConfigStore } from "../stores/config";
|
||||
import BaseInput from "../components/BaseInput.vue";
|
||||
import AuthLayout from "../components/AuthLayout.vue";
|
||||
import BaseButton from "../components/BaseButton.vue";
|
||||
import { errorMessage } from "../api/errors";
|
||||
|
||||
@@ -41,64 +42,50 @@ async function submit() {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<main class="flex min-h-full items-center justify-center px-4 py-12">
|
||||
<div class="w-full max-w-sm">
|
||||
<div class="mb-8 text-center">
|
||||
<img
|
||||
src="/icon.svg"
|
||||
:alt="config.siteName"
|
||||
class="mx-auto mb-3 h-12 w-12 rounded-xl"
|
||||
width="48"
|
||||
height="48"
|
||||
/>
|
||||
<h1 class="text-2xl font-bold tracking-tight">{{ invite ? "You're invited" : "Create your space" }}</h1>
|
||||
<p class="mt-1 text-sm text-neutral-500 dark:text-neutral-400">
|
||||
{{ invite ? `Create your account on ${config.siteName}.` : "Start capturing in seconds." }}
|
||||
</p>
|
||||
</div>
|
||||
<AuthLayout :title="invite ? `You're invited` : 'Create your space'">
|
||||
<template #subtitle>{{ invite ? `Create your account on ${config.siteName}.` : "Start capturing in seconds." }}</template>
|
||||
|
||||
<form class="flex flex-col gap-4" novalidate @submit.prevent="submit">
|
||||
<BaseInput
|
||||
id="display_name"
|
||||
v-model="displayName"
|
||||
label="Name"
|
||||
autocomplete="name"
|
||||
placeholder="What should we call you?"
|
||||
/>
|
||||
<BaseInput
|
||||
id="email"
|
||||
v-model="email"
|
||||
label="Email"
|
||||
type="email"
|
||||
autocomplete="email"
|
||||
placeholder="you@example.com"
|
||||
required
|
||||
/>
|
||||
<BaseInput
|
||||
id="password"
|
||||
v-model="password"
|
||||
label="Password"
|
||||
type="password"
|
||||
autocomplete="new-password"
|
||||
:placeholder="`At least ${config.minPasswordLength} characters`"
|
||||
required
|
||||
/>
|
||||
<p
|
||||
v-if="error"
|
||||
role="alert"
|
||||
class="rounded-lg bg-red-50 px-3 py-2 text-sm text-red-700 dark:bg-red-950/50 dark:text-red-300"
|
||||
>
|
||||
{{ error }}
|
||||
</p>
|
||||
<BaseButton type="submit" :loading="loading">Create account</BaseButton>
|
||||
</form>
|
||||
|
||||
<p class="mt-6 text-center text-sm text-neutral-500 dark:text-neutral-400">
|
||||
Already have an account?
|
||||
<RouterLink to="/login" class="font-semibold text-brand-700 hover:underline dark:text-brand"
|
||||
>Sign in</RouterLink
|
||||
>
|
||||
<form class="flex flex-col gap-4" novalidate @submit.prevent="submit">
|
||||
<BaseInput
|
||||
id="display_name"
|
||||
v-model="displayName"
|
||||
label="Name"
|
||||
autocomplete="name"
|
||||
placeholder="What should we call you?"
|
||||
/>
|
||||
<BaseInput
|
||||
id="email"
|
||||
v-model="email"
|
||||
label="Email"
|
||||
type="email"
|
||||
autocomplete="email"
|
||||
placeholder="you@example.com"
|
||||
required
|
||||
/>
|
||||
<BaseInput
|
||||
id="password"
|
||||
v-model="password"
|
||||
label="Password"
|
||||
type="password"
|
||||
autocomplete="new-password"
|
||||
:placeholder="`At least ${config.minPasswordLength} characters`"
|
||||
required
|
||||
/>
|
||||
<p
|
||||
v-if="error"
|
||||
role="alert"
|
||||
class="alert-error"
|
||||
>
|
||||
{{ error }}
|
||||
</p>
|
||||
</div>
|
||||
</main>
|
||||
<BaseButton type="submit" :loading="loading">Create account</BaseButton>
|
||||
</form>
|
||||
|
||||
<template #footer>
|
||||
Already have an account?
|
||||
<RouterLink to="/login" class="text-link"
|
||||
>Sign in</RouterLink
|
||||
>
|
||||
</template>
|
||||
</AuthLayout>
|
||||
</template>
|
||||
|
||||
@@ -6,6 +6,7 @@ import { errorMessage } from "../api/errors";
|
||||
import { useSessionStore } from "../stores/session";
|
||||
import { useConfigStore } from "../stores/config";
|
||||
import BaseInput from "../components/BaseInput.vue";
|
||||
import AuthLayout from "../components/AuthLayout.vue";
|
||||
import BaseButton from "../components/BaseButton.vue";
|
||||
|
||||
// Where a password reset link an admin made lands (#5173). Setting the password signs
|
||||
@@ -47,62 +48,48 @@ async function submit() {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<main class="flex min-h-full items-center justify-center px-4 py-12">
|
||||
<div class="w-full max-w-sm">
|
||||
<div class="mb-8 text-center">
|
||||
<img
|
||||
src="/icon.svg"
|
||||
:alt="config.siteName"
|
||||
class="mx-auto mb-3 h-12 w-12 rounded-xl"
|
||||
width="48"
|
||||
height="48"
|
||||
/>
|
||||
<h1 class="text-2xl font-bold tracking-tight">Choose a new password</h1>
|
||||
<p class="mt-1 text-sm text-neutral-500 dark:text-neutral-400">
|
||||
You'll be signed out everywhere else, and your apps will ask you to sign in again.
|
||||
</p>
|
||||
</div>
|
||||
<AuthLayout title="Choose a new password">
|
||||
<template #subtitle>You'll be signed out everywhere else, and your apps will ask you to sign in again.</template>
|
||||
|
||||
<p
|
||||
v-if="!token"
|
||||
role="alert"
|
||||
class="alert-error"
|
||||
>
|
||||
This link is incomplete. Ask your admin for a new one.
|
||||
</p>
|
||||
<form v-else class="flex flex-col gap-4" novalidate @submit.prevent="submit">
|
||||
<BaseInput
|
||||
id="password"
|
||||
v-model="password"
|
||||
label="New password"
|
||||
type="password"
|
||||
autocomplete="new-password"
|
||||
:placeholder="`At least ${config.minPasswordLength} characters`"
|
||||
required
|
||||
/>
|
||||
<BaseInput
|
||||
id="confirm"
|
||||
v-model="confirm"
|
||||
label="Again"
|
||||
type="password"
|
||||
autocomplete="new-password"
|
||||
required
|
||||
/>
|
||||
<p
|
||||
v-if="!token"
|
||||
v-if="error"
|
||||
role="alert"
|
||||
class="rounded-lg bg-red-50 px-3 py-2 text-sm text-red-700 dark:bg-red-950/50 dark:text-red-300"
|
||||
class="alert-error"
|
||||
>
|
||||
This link is incomplete. Ask your admin for a new one.
|
||||
{{ error }}
|
||||
</p>
|
||||
<form v-else class="flex flex-col gap-4" novalidate @submit.prevent="submit">
|
||||
<BaseInput
|
||||
id="password"
|
||||
v-model="password"
|
||||
label="New password"
|
||||
type="password"
|
||||
autocomplete="new-password"
|
||||
:placeholder="`At least ${config.minPasswordLength} characters`"
|
||||
required
|
||||
/>
|
||||
<BaseInput
|
||||
id="confirm"
|
||||
v-model="confirm"
|
||||
label="Again"
|
||||
type="password"
|
||||
autocomplete="new-password"
|
||||
required
|
||||
/>
|
||||
<p
|
||||
v-if="error"
|
||||
role="alert"
|
||||
class="rounded-lg bg-red-50 px-3 py-2 text-sm text-red-700 dark:bg-red-950/50 dark:text-red-300"
|
||||
>
|
||||
{{ error }}
|
||||
</p>
|
||||
<BaseButton type="submit" :loading="loading">Set password</BaseButton>
|
||||
</form>
|
||||
<BaseButton type="submit" :loading="loading">Set password</BaseButton>
|
||||
</form>
|
||||
|
||||
<p class="mt-6 text-center text-sm text-neutral-500 dark:text-neutral-400">
|
||||
<RouterLink to="/login" class="font-semibold text-brand-700 hover:underline dark:text-brand"
|
||||
>Back to sign in</RouterLink
|
||||
>
|
||||
</p>
|
||||
</div>
|
||||
</main>
|
||||
<template #footer>
|
||||
<RouterLink to="/login" class="text-link"
|
||||
>Back to sign in</RouterLink
|
||||
>
|
||||
</template>
|
||||
</AuthLayout>
|
||||
</template>
|
||||
|
||||
@@ -94,13 +94,13 @@ onMounted(load);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="mx-auto min-h-full max-w-2xl px-4 py-8">
|
||||
<div class="page-shell">
|
||||
<PageHeader title="Settings" />
|
||||
|
||||
<AsyncState :loading="loading" :error="loadError" error-title="Couldn't load settings" @retry="load">
|
||||
<form class="flex flex-col gap-8" @submit.prevent="save">
|
||||
<section v-for="group in groups" :key="group.name" class="flex flex-col gap-5">
|
||||
<h2 class="text-xs font-semibold uppercase tracking-wide text-neutral-400">{{ group.name }}</h2>
|
||||
<h2 class="section-label">{{ group.name }}</h2>
|
||||
|
||||
<div v-for="it in group.entries" :key="it.key" class="flex flex-col gap-1">
|
||||
<div class="flex items-center justify-between gap-6">
|
||||
@@ -126,14 +126,14 @@ onMounted(load);
|
||||
type="number"
|
||||
:min="it.minimum ?? undefined"
|
||||
:max="it.maximum ?? undefined"
|
||||
class="w-28 rounded-lg border border-neutral-300 bg-white px-3 py-2 text-sm text-neutral-900 shadow-sm focus:outline-none focus-visible:ring-2 focus-visible:ring-brand dark:border-neutral-700 dark:bg-neutral-800 dark:text-neutral-100"
|
||||
class="w-28 field"
|
||||
:value="Number(it.value)"
|
||||
@input="it.value = Number(($event.target as HTMLInputElement).value)"
|
||||
/>
|
||||
<select
|
||||
v-else-if="it.choices"
|
||||
:id="it.key"
|
||||
class="w-56 rounded-lg border border-neutral-300 bg-white px-3 py-2 text-sm text-neutral-900 shadow-sm focus:outline-none focus-visible:ring-2 focus-visible:ring-brand dark:border-neutral-700 dark:bg-neutral-800 dark:text-neutral-100"
|
||||
class="w-56 field"
|
||||
:value="String(it.value)"
|
||||
@change="it.value = ($event.target as HTMLSelectElement).value"
|
||||
>
|
||||
@@ -145,7 +145,7 @@ onMounted(load);
|
||||
type="password"
|
||||
autocomplete="new-password"
|
||||
:placeholder="it.is_set ? 'Saved — type to replace' : ''"
|
||||
class="w-56 rounded-lg border border-neutral-300 bg-white px-3 py-2 text-sm text-neutral-900 shadow-sm focus:outline-none focus-visible:ring-2 focus-visible:ring-brand dark:border-neutral-700 dark:bg-neutral-800 dark:text-neutral-100"
|
||||
class="w-56 field"
|
||||
:value="String(it.value)"
|
||||
@input="it.value = ($event.target as HTMLInputElement).value"
|
||||
/>
|
||||
@@ -153,7 +153,7 @@ onMounted(load);
|
||||
v-else
|
||||
:id="it.key"
|
||||
type="text"
|
||||
class="w-56 rounded-lg border border-neutral-300 bg-white px-3 py-2 text-sm text-neutral-900 shadow-sm focus:outline-none focus-visible:ring-2 focus-visible:ring-brand dark:border-neutral-700 dark:bg-neutral-800 dark:text-neutral-100"
|
||||
class="w-56 field"
|
||||
:value="String(it.value)"
|
||||
@input="it.value = ($event.target as HTMLInputElement).value"
|
||||
/>
|
||||
@@ -178,7 +178,7 @@ onMounted(load);
|
||||
<BaseButton type="submit" :loading="saving" :disabled="!dirty">Save changes</BaseButton>
|
||||
<span v-if="saved && !dirty" class="text-sm text-green-600 dark:text-green-400">Saved.</span>
|
||||
<span v-else-if="!dirty && !error" class="text-sm text-neutral-400">No unsaved changes</span>
|
||||
<span v-if="error" class="text-sm text-red-600 dark:text-red-400">{{ error }}</span>
|
||||
<span v-if="error" class="form-error">{{ error }}</span>
|
||||
</div>
|
||||
</form>
|
||||
</AsyncState>
|
||||
|
||||
@@ -24,6 +24,7 @@ import {
|
||||
} from "../desktop/bridge";
|
||||
import { errorMessage } from "../api/errors";
|
||||
import { formatDateTime } from "../notes/datetime";
|
||||
import { toastOnFailure } from "../composables/useAction";
|
||||
|
||||
// Opt-in server sync for the desktop app. Being UNLINKED is the normal resting
|
||||
// state, not an incomplete setup — the app is local-first and fully usable having
|
||||
@@ -319,7 +320,7 @@ async function disconnect() {
|
||||
) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await toastOnFailure(async () => {
|
||||
const result = await syncBridge.unlink();
|
||||
status.value = result.status;
|
||||
linkedAs.value = "";
|
||||
@@ -331,9 +332,7 @@ async function disconnect() {
|
||||
? "Disconnected, and this device is signed out on the server."
|
||||
: "Disconnected. This device now works offline only.",
|
||||
);
|
||||
} catch (e) {
|
||||
ui.showToast(errorMessage(e, "Couldn't disconnect."));
|
||||
}
|
||||
}, "Couldn't disconnect.");
|
||||
}
|
||||
|
||||
// A background cycle finished — redraw from it, so this screen is never staler
|
||||
@@ -356,7 +355,7 @@ onBeforeUnmount(() => stopSyncListener?.());
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="mx-auto min-h-full max-w-2xl px-4 py-8">
|
||||
<div class="page-shell">
|
||||
<PageHeader title="Sync" />
|
||||
|
||||
<div v-if="loading" class="py-10 text-center text-sm text-neutral-400">Loading…</div>
|
||||
@@ -392,7 +391,7 @@ onBeforeUnmount(() => stopSyncListener?.());
|
||||
<p v-if="degraded.length" class="mt-3 text-xs text-amber-600 dark:text-amber-400">
|
||||
This server doesn't support: {{ degraded.join(", ") }}. Everything else syncs normally.
|
||||
</p>
|
||||
<p v-if="syncError" class="mt-3 text-sm text-red-600 dark:text-red-400">{{ syncError }}</p>
|
||||
<p v-if="syncError" class="mt-3 form-error">{{ syncError }}</p>
|
||||
<p v-else-if="autoError" class="mt-3 text-xs text-amber-600 dark:text-amber-400">
|
||||
The last automatic sync ({{ new Date(lastCycle!.at_ms).toLocaleTimeString() }}) didn't
|
||||
go through: {{ autoError }} It will keep trying on its own.
|
||||
@@ -428,7 +427,7 @@ onBeforeUnmount(() => stopSyncListener?.());
|
||||
<p class="text-sm font-medium text-neutral-800 dark:text-neutral-100">
|
||||
Working offline on this device
|
||||
</p>
|
||||
<p class="mt-1 text-sm text-neutral-500 dark:text-neutral-400">
|
||||
<p class="mt-1 hint">
|
||||
Everything works without a server — your notes are stored on this machine. Connect an
|
||||
Inkwell server if you want them to reach your other devices.
|
||||
</p>
|
||||
@@ -452,7 +451,7 @@ onBeforeUnmount(() => stopSyncListener?.());
|
||||
Uses https unless you type http:// yourself.
|
||||
</p>
|
||||
|
||||
<p v-if="probeError" class="text-sm text-red-600 dark:text-red-400">{{ probeError }}</p>
|
||||
<p v-if="probeError" class="form-error">{{ probeError }}</p>
|
||||
|
||||
<!-- What answered, BEFORE any credentials are handed over -->
|
||||
<div
|
||||
@@ -531,7 +530,7 @@ onBeforeUnmount(() => stopSyncListener?.());
|
||||
/>
|
||||
</fieldset>
|
||||
|
||||
<p v-if="linkError" class="text-sm text-red-600 dark:text-red-400">{{ linkError }}</p>
|
||||
<p v-if="linkError" class="form-error">{{ linkError }}</p>
|
||||
|
||||
<div>
|
||||
<BaseButton type="submit" :loading="linking" :disabled="!canLink">
|
||||
@@ -546,7 +545,7 @@ onBeforeUnmount(() => stopSyncListener?.());
|
||||
updates: a hotkey that writes to the local store needs no server. -->
|
||||
<section class="mt-10 border-t border-neutral-200 pt-8 dark:border-neutral-800">
|
||||
<h2 class="text-sm font-semibold">Quick capture</h2>
|
||||
<p class="mt-1 text-sm text-neutral-500 dark:text-neutral-400">
|
||||
<p class="mt-1 hint">
|
||||
A system-wide shortcut that opens a small window to write a note in, without
|
||||
bringing this one forward.
|
||||
</p>
|
||||
@@ -570,7 +569,7 @@ onBeforeUnmount(() => stopSyncListener?.());
|
||||
</BaseButton>
|
||||
</div>
|
||||
|
||||
<p v-if="shortcutError" class="mt-2 text-sm text-red-600 dark:text-red-400">
|
||||
<p v-if="shortcutError" class="mt-2 form-error">
|
||||
{{ shortcutError }}
|
||||
</p>
|
||||
|
||||
@@ -585,10 +584,10 @@ onBeforeUnmount(() => stopSyncListener?.());
|
||||
{{ shortcut.shortcut }} is saved but isn't active — something else on this
|
||||
system is holding it. Try a different combination.
|
||||
</p>
|
||||
<p v-else-if="shortcut.registered" class="mt-2 text-sm text-neutral-500 dark:text-neutral-400">
|
||||
<p v-else-if="shortcut.registered" class="mt-2 hint">
|
||||
Press {{ shortcut.shortcut }} anywhere to capture a note.
|
||||
</p>
|
||||
<p v-else class="mt-2 text-sm text-neutral-500 dark:text-neutral-400">
|
||||
<p v-else class="mt-2 hint">
|
||||
Off. There's no default on purpose — any combination picked for you is one
|
||||
taken away from something else on your machine.
|
||||
<button
|
||||
@@ -605,12 +604,12 @@ onBeforeUnmount(() => stopSyncListener?.());
|
||||
has never touched a server still updates itself. -->
|
||||
<section class="mt-10 border-t border-neutral-200 pt-8 dark:border-neutral-800">
|
||||
<h2 class="text-sm font-semibold">App updates</h2>
|
||||
<p class="mt-1 text-sm text-neutral-500 dark:text-neutral-400">
|
||||
<p class="mt-1 hint">
|
||||
This is version {{ update?.current_version ?? "—" }}.
|
||||
</p>
|
||||
|
||||
<fieldset v-if="offeredServer" class="mt-4">
|
||||
<legend class="text-xs font-semibold uppercase tracking-wide text-neutral-400">
|
||||
<legend class="section-label">
|
||||
Updates from
|
||||
</legend>
|
||||
<div class="mt-2 flex flex-col gap-2">
|
||||
@@ -650,7 +649,7 @@ onBeforeUnmount(() => stopSyncListener?.());
|
||||
|
||||
<!-- A server holds one build, so a channel only means something on the forge. -->
|
||||
<fieldset v-if="source === null" class="mt-4">
|
||||
<legend class="text-xs font-semibold uppercase tracking-wide text-neutral-400">
|
||||
<legend class="section-label">
|
||||
Channel
|
||||
</legend>
|
||||
<div class="mt-2 flex flex-col gap-2">
|
||||
@@ -704,7 +703,7 @@ onBeforeUnmount(() => stopSyncListener?.());
|
||||
</div>
|
||||
<p
|
||||
v-else-if="checkedOnce && !updateError"
|
||||
class="mt-4 text-sm text-neutral-500 dark:text-neutral-400"
|
||||
class="mt-4 hint"
|
||||
>
|
||||
<template v-if="source">You're on the newest build {{ source }} has.</template>
|
||||
<template v-else>
|
||||
@@ -712,7 +711,7 @@ onBeforeUnmount(() => stopSyncListener?.());
|
||||
</template>
|
||||
</p>
|
||||
|
||||
<p v-if="updateError" class="mt-4 text-sm text-red-600 dark:text-red-400">{{ updateError }}</p>
|
||||
<p v-if="updateError" class="mt-4 form-error">{{ updateError }}</p>
|
||||
|
||||
<div class="mt-4 flex flex-wrap gap-2">
|
||||
<BaseButton variant="ghost" :loading="checking" @click="checkUpdates">
|
||||
|
||||
@@ -137,7 +137,7 @@ onMounted(load);
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<p class="mb-5 text-sm text-neutral-500 dark:text-neutral-400">
|
||||
<p class="mb-5 hint">
|
||||
Your notes by when you captured them{{ hasRange ? " — filtered to the chosen dates" : "" }}.
|
||||
</p>
|
||||
|
||||
@@ -150,7 +150,7 @@ onMounted(load);
|
||||
<EmptyState v-if="items.length === 0" :title="empty.title" :subtitle="empty.subtitle" />
|
||||
<div v-else class="flex flex-col gap-8">
|
||||
<section v-for="group in groups" :key="group.key">
|
||||
<h2 class="mb-3 text-xs font-semibold uppercase tracking-wide text-neutral-400">{{ group.label }}</h2>
|
||||
<h2 class="mb-3 section-label">{{ group.label }}</h2>
|
||||
<NoteGrid :notes="group.notes" @open="openEditor" />
|
||||
</section>
|
||||
</div>
|
||||
|
||||
+2
-3
@@ -25,7 +25,7 @@ from .notes import bp as notes_bp
|
||||
from .proxy import is_https
|
||||
from .responses import json_error, not_found
|
||||
from .retention import run_sweeper
|
||||
from .settings import MAX_BODY_MB, get_public_config, get_setting, load_or_create_secret_key, refresh_live
|
||||
from .settings import MAX_BODY_MB, apply_session_ttl, get_public_config, get_setting, load_or_create_secret_key, refresh_live
|
||||
from .settings_api import bp as settings_bp
|
||||
from .shares_api import bp as shares_bp
|
||||
from .sync import bp as sync_bp, protocol_advertisement
|
||||
@@ -114,8 +114,7 @@ def create_app() -> Quart:
|
||||
async with session_scope() as db:
|
||||
app.secret_key = await load_or_create_secret_key(db)
|
||||
try:
|
||||
days = int(await get_setting(db, "session_ttl_days"))
|
||||
app.config["PERMANENT_SESSION_LIFETIME"] = timedelta(days=days)
|
||||
apply_session_ttl(app, await get_setting(db, "session_ttl_days"))
|
||||
except (ValueError, TypeError, KeyError):
|
||||
pass
|
||||
# The security settings the throttle and the proxy trust read on hot
|
||||
|
||||
@@ -18,11 +18,11 @@ from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import uuid
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from datetime import datetime, timezone
|
||||
|
||||
from sqlalchemy import delete, select
|
||||
|
||||
from .common import iso
|
||||
from .common import expired_before, iso
|
||||
from .db import session_scope
|
||||
from .models.audit_event import AuditEvent
|
||||
from .proxy import client_address
|
||||
@@ -99,9 +99,9 @@ async def sweep_once(*, now: datetime | None = None) -> int:
|
||||
"""Delete events older than `audit_retention_days`; 0 keeps them forever."""
|
||||
async with session_scope() as db:
|
||||
days = int(await get_setting(db, "audit_retention_days"))
|
||||
if days <= 0:
|
||||
cutoff = expired_before(now or datetime.now(timezone.utc), days)
|
||||
if cutoff is None:
|
||||
return 0
|
||||
cutoff = (now or datetime.now(timezone.utc)) - timedelta(days=days)
|
||||
deleted = (await db.execute(delete(AuditEvent).where(AuditEvent.at < cutoff))).rowcount
|
||||
await db.commit()
|
||||
return deleted
|
||||
|
||||
+2
-2
@@ -18,7 +18,7 @@ from .password_resets import INVALID as INVALID_RESET, claim as claim_reset, mai
|
||||
from .models.device_token import DeviceToken
|
||||
from .models.user import User
|
||||
from .proxy import client_address
|
||||
from .responses import json_error, not_found, parse_uuid
|
||||
from .responses import json_error, not_found, parse_uuid, too_many
|
||||
from .ratelimit import (
|
||||
register_by_address,
|
||||
reset_mail_by_account,
|
||||
@@ -196,7 +196,7 @@ def _throttled(retry_after: int):
|
||||
genuinely needs.
|
||||
"""
|
||||
logger.warning("throttled credential attempt from=%s retry_after=%ss", client_address(), retry_after)
|
||||
return (*json_error("too many attempts — try again shortly", 429), {"Retry-After": str(retry_after)})
|
||||
return too_many("too many attempts — try again shortly", retry_after)
|
||||
|
||||
|
||||
def _sign_in_block(email: str) -> int | None:
|
||||
|
||||
@@ -82,7 +82,7 @@ from .auth import login_required
|
||||
from .config import Config
|
||||
from .proxy import is_https
|
||||
from .ratelimit import downloads_by_account
|
||||
from .responses import json_error
|
||||
from .responses import json_error, too_many
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
@@ -394,10 +394,7 @@ async def client_download(platform_id: str):
|
||||
account = str(g.user_id)
|
||||
wait = downloads_by_account.retry_after(account)
|
||||
if wait is not None:
|
||||
response = jsonify({"error": "too many downloads from this account; try again later"})
|
||||
response.status_code = 429
|
||||
response.headers["Retry-After"] = str(wait)
|
||||
return response
|
||||
return too_many("too many downloads from this account; try again later", wait)
|
||||
downloads_by_account.record(account)
|
||||
|
||||
# From the SAME directory the metadata came from, or a drop-in appearing between
|
||||
|
||||
+27
-1
@@ -1,6 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime
|
||||
import asyncio
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
# Small, dependency-free value coercions shared across the blueprints. Kept in one
|
||||
# place so the "parse an ISO date" / "is this flag truthy" logic has a single
|
||||
@@ -47,3 +48,28 @@ def normalize_email(raw: str | None) -> str:
|
||||
one from a request goes through here, so "Ana@Example.com " and "ana@example.com"
|
||||
are one account at sign-up, sign-in, reset and invite alike."""
|
||||
return (raw or "").strip().lower()
|
||||
|
||||
|
||||
def detach(running: set[asyncio.Task], coro) -> asyncio.Task:
|
||||
"""Start `coro` without waiting for it, held in `running` until it finishes.
|
||||
|
||||
The event loop keeps only a weak reference to a task, so one nobody holds can be
|
||||
collected mid-flight. Each caller keeps its own set, which is what its `drain()`
|
||||
awaits in tests. Raises RuntimeError when there is no running loop."""
|
||||
task = asyncio.create_task(coro)
|
||||
running.add(task)
|
||||
task.add_done_callback(running.discard)
|
||||
return task
|
||||
|
||||
|
||||
def expired_before(now: datetime, retention_days: int) -> datetime | None:
|
||||
"""The cutoff: anything older than this has expired. `None` = retention is off.
|
||||
|
||||
Kept separate from the query so the window arithmetic — including the two ways
|
||||
to say "never" (0 and negative, the latter reachable by typing a stray minus in
|
||||
Settings) — is testable without a database. Trash and the audit log both expire
|
||||
through it.
|
||||
"""
|
||||
if retention_days <= 0:
|
||||
return None
|
||||
return now - timedelta(days=retention_days)
|
||||
|
||||
+14
-11
@@ -18,7 +18,8 @@ from .db import session_scope
|
||||
from .models.group import Group, GroupMember
|
||||
from .models.user import User
|
||||
from .responses import json_error, not_found, parse_uuid
|
||||
from .share_sync import bump_note, group_notes, joined_group, left_group, recipients, revoke
|
||||
from .serialize import serialize_person
|
||||
from .share_sync import bump_note, group_notes, joined_group, left_group, recipients, revoke_lost
|
||||
|
||||
bp = Blueprint("groups", __name__, url_prefix="/api/groups")
|
||||
|
||||
@@ -49,11 +50,17 @@ async def _serialize_groups(db, groups: list[Group]) -> list[dict]:
|
||||
members: dict = {}
|
||||
for group_id, user in rows:
|
||||
members.setdefault(group_id, []).append(
|
||||
{"id": str(user.id), "display_name": user.display_name, "email": user.email}
|
||||
serialize_person(user)
|
||||
)
|
||||
return [{"id": str(gr.id), "name": gr.name, "members": members.get(gr.id, [])} for gr in groups]
|
||||
|
||||
|
||||
async def _get_group(db, group_id: str) -> Group | None:
|
||||
"""The group a route's path names, or None for a malformed or unknown id."""
|
||||
gid = parse_uuid(group_id)
|
||||
return await db.get(Group, gid) if gid else None
|
||||
|
||||
|
||||
async def _answer(db, group: Group, status: int = 200):
|
||||
return jsonify((await _serialize_groups(db, [group]))[0]), status
|
||||
|
||||
@@ -87,9 +94,8 @@ async def rename_group(group_id: str):
|
||||
name = _name(await request.get_json(silent=True) or {})
|
||||
if name is None:
|
||||
return json_error("give the group a name", 400)
|
||||
gid = parse_uuid(group_id)
|
||||
async with session_scope() as db:
|
||||
group = await db.get(Group, gid) if gid else None
|
||||
group = await _get_group(db, group_id)
|
||||
if group is None:
|
||||
return not_found()
|
||||
if await _name_taken(db, name, but=group.id):
|
||||
@@ -104,9 +110,8 @@ async def rename_group(group_id: str):
|
||||
async def delete_group(group_id: str):
|
||||
"""Delete the group and every share made to it. Whoever could see a note only
|
||||
through it loses the note, and their devices are told."""
|
||||
gid = parse_uuid(group_id)
|
||||
async with session_scope() as db:
|
||||
group = await db.get(Group, gid) if gid else None
|
||||
group = await _get_group(db, group_id)
|
||||
if group is None:
|
||||
return not_found()
|
||||
note_ids = await group_notes(db, group.id)
|
||||
@@ -114,7 +119,7 @@ async def delete_group(group_id: str):
|
||||
await db.delete(group) # members and shares go with it (ON DELETE CASCADE)
|
||||
await db.flush()
|
||||
for nid in note_ids:
|
||||
await revoke(db, nid, before[nid] - await recipients(db, nid))
|
||||
await revoke_lost(db, nid, before[nid])
|
||||
# The owner's devices learn whether the note is still shared at all.
|
||||
await bump_note(db, nid)
|
||||
await db.commit()
|
||||
@@ -125,10 +130,9 @@ async def delete_group(group_id: str):
|
||||
@require_admin
|
||||
async def add_member(group_id: str):
|
||||
data = await request.get_json(silent=True) or {}
|
||||
gid = parse_uuid(group_id)
|
||||
uid = parse_uuid(str(data.get("user_id") or ""))
|
||||
async with session_scope() as db:
|
||||
group = await db.get(Group, gid) if gid else None
|
||||
group = await _get_group(db, group_id)
|
||||
if group is None:
|
||||
return not_found()
|
||||
if uid is None or await db.get(User, uid) is None:
|
||||
@@ -147,10 +151,9 @@ async def add_member(group_id: str):
|
||||
@bp.delete("/<group_id>/members/<user_id>")
|
||||
@require_admin
|
||||
async def remove_member(group_id: str, user_id: str):
|
||||
gid = parse_uuid(group_id)
|
||||
uid = parse_uuid(user_id)
|
||||
async with session_scope() as db:
|
||||
group = await db.get(Group, gid) if gid else None
|
||||
group = await _get_group(db, group_id)
|
||||
if group is None or uid is None:
|
||||
return not_found()
|
||||
membership = await db.scalar(
|
||||
|
||||
@@ -10,7 +10,7 @@ from __future__ import annotations
|
||||
from datetime import datetime, timezone
|
||||
|
||||
from sqlalchemy import delete as sa_delete
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy import func, select
|
||||
|
||||
from .models.label import Label, NoteLabel
|
||||
from .models.note import Note
|
||||
@@ -23,6 +23,13 @@ def live(owner_id):
|
||||
return (Label.owner_id == owner_id) & Label.purged_at.is_(None)
|
||||
|
||||
|
||||
def named(owner_id, name: str):
|
||||
"""`owner_id`'s live tag called `name`, in any case. Names are unique among an
|
||||
owner's live tags without regard to case, because every client's store is; this
|
||||
is the one place that says how two names compare."""
|
||||
return live(owner_id) & (func.lower(Label.name) == name.lower())
|
||||
|
||||
|
||||
async def tombstone_label(db, label: Label, edited_at: datetime | None = None) -> None:
|
||||
"""Delete a tag: detach it from every note and mark the row purged.
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ from sqlalchemy import func, select
|
||||
from .auth import login_required
|
||||
from .colors import normalize_color
|
||||
from .db import session_scope
|
||||
from .labeling import live, tombstone_label
|
||||
from .labeling import live, named, tombstone_label
|
||||
from .models.label import Label, NoteLabel
|
||||
from .responses import json_error, not_found, parse_uuid
|
||||
from .serialize import serialize_label
|
||||
@@ -95,7 +95,7 @@ async def create_label():
|
||||
# the path that MINTED the "Groceries" beside "groceries" pair that no synced
|
||||
# client can hold, since their `labels` index is unique on `lower(name)`.
|
||||
existing = await db.scalar(
|
||||
select(Label).where(live(g.user_id), func.lower(Label.name) == name.lower())
|
||||
select(Label).where(named(g.user_id, name))
|
||||
)
|
||||
if existing is not None:
|
||||
return jsonify(_serialize_label(existing)), 200
|
||||
@@ -129,8 +129,7 @@ async def update_label(label_id: str):
|
||||
# one be made is letting a pull fail later on a phone.
|
||||
clash = await db.scalar(
|
||||
select(Label).where(
|
||||
live(g.user_id),
|
||||
func.lower(Label.name) == name.lower(),
|
||||
named(g.user_id, name),
|
||||
Label.id != label.id,
|
||||
)
|
||||
)
|
||||
|
||||
@@ -17,6 +17,7 @@ import ssl
|
||||
from dataclasses import dataclass
|
||||
from email.message import EmailMessage
|
||||
|
||||
from .common import detach
|
||||
from .settings import get_setting, mail_configured
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -91,9 +92,7 @@ def send_later(job) -> None:
|
||||
For the forgot-password route, where waiting would also be an oracle: an address
|
||||
with an account would answer as slowly as a mail server, and one without, at once.
|
||||
`job` handles and logs its own failures."""
|
||||
task = asyncio.create_task(job)
|
||||
_running.add(task)
|
||||
task.add_done_callback(_running.discard)
|
||||
detach(_running, job)
|
||||
|
||||
|
||||
async def drain() -> None:
|
||||
|
||||
@@ -19,7 +19,6 @@ from datetime import datetime, timedelta, timezone
|
||||
from quart import Response, g, jsonify, request, send_file
|
||||
from sqlalchemy import func, literal_column, select
|
||||
|
||||
from ..acl import visible_to_user
|
||||
from ..auth import login_required
|
||||
from ..colors import normalize_color
|
||||
from ..common import coerce_bool, iso, parse_dt
|
||||
@@ -52,6 +51,7 @@ from .helpers import (
|
||||
apply_filter,
|
||||
derive_display_title,
|
||||
is_empty_note,
|
||||
note_visible,
|
||||
store_attachment,
|
||||
top_position,
|
||||
parse_list_items,
|
||||
@@ -121,9 +121,7 @@ async def list_notes():
|
||||
async with session_scope() as db:
|
||||
# Through the viewer's own pin, archive and place: on a note shared with them
|
||||
# those are theirs, not the owner's (#5176).
|
||||
stmt = join_state(select(Note), g.user_id).where(
|
||||
visible_to_user("note", Note.owner_id, Note.id, g.user_id)
|
||||
)
|
||||
stmt = join_state(select(Note), g.user_id).where(note_visible())
|
||||
stmt = apply_filter(stmt, filter_name, archived_for(g.user_id))
|
||||
# Trash is the owner's: a note its owner trashed leaves a recipient's board
|
||||
# rather than turning up in their Trash, where they could do nothing with it.
|
||||
@@ -392,7 +390,7 @@ async def reorder_notes():
|
||||
await db.scalars(
|
||||
select(Note).where(
|
||||
Note.id.in_(parsed),
|
||||
visible_to_user("note", Note.owner_id, Note.id, g.user_id),
|
||||
note_visible(),
|
||||
Note.purged_at.is_(None),
|
||||
)
|
||||
)
|
||||
|
||||
@@ -103,6 +103,22 @@ async def top_position(db, owner_id) -> int:
|
||||
)
|
||||
|
||||
|
||||
def note_visible(permission: str | None = None):
|
||||
"""Predicate: the current user may see the note, as its owner or through a share
|
||||
(at `permission`, when one is given). Every note read scoped to a viewer asks
|
||||
through here."""
|
||||
return visible_to_user("note", Note.owner_id, Note.id, g.user_id, permission=permission)
|
||||
|
||||
|
||||
async def _fetch_note(db, note_id: str, gate) -> Note | None:
|
||||
"""The one shape of a per-note fetch: a well-formed id, a note that isn't purged,
|
||||
and `gate` saying who may have it. None for anything else, so the route 404s."""
|
||||
nid = parse_uuid(note_id)
|
||||
if nid is None:
|
||||
return None
|
||||
return await db.scalar(select(Note).where(Note.id == nid, gate, Note.purged_at.is_(None)))
|
||||
|
||||
|
||||
async def _get_owned(db, note_id: str) -> Note | None:
|
||||
"""Fetch a note the current user OWNS, for every change only an owner may make:
|
||||
trash, delete, labels, reminders, attachments, previews, history and sharing
|
||||
@@ -116,44 +132,21 @@ async def _get_owned(db, note_id: str) -> Note | None:
|
||||
editing or restoring one 404s. The sync push path looks rows up directly rather
|
||||
than through here, which is what still lets a client re-create an id it owns.
|
||||
"""
|
||||
nid = parse_uuid(note_id)
|
||||
if nid is None:
|
||||
return None
|
||||
return await db.scalar(
|
||||
select(Note).where(Note.id == nid, Note.owner_id == g.user_id, Note.purged_at.is_(None))
|
||||
)
|
||||
return await _fetch_note(db, note_id, Note.owner_id == g.user_id)
|
||||
|
||||
|
||||
async def _get_visible(db, note_id: str) -> Note | None:
|
||||
"""Fetch a note the current user can see: theirs, or shared with them at any
|
||||
level. What a recipient may do to it from here is their own pin, archive and
|
||||
place (#5176); `_get_editable` and `_get_owned` gate the rest."""
|
||||
nid = parse_uuid(note_id)
|
||||
if nid is None:
|
||||
return None
|
||||
return await db.scalar(
|
||||
select(Note).where(
|
||||
Note.id == nid,
|
||||
visible_to_user("note", Note.owner_id, Note.id, g.user_id),
|
||||
Note.purged_at.is_(None),
|
||||
)
|
||||
)
|
||||
return await _fetch_note(db, note_id, note_visible())
|
||||
|
||||
|
||||
async def _get_editable(db, note_id: str) -> Note | None:
|
||||
"""Fetch a note the current user may change the TEXT of: its body and its
|
||||
checklist. The owner, or someone it is shared with at `edit`; a view share gets
|
||||
None, and so a 404, like a stranger (#5174)."""
|
||||
nid = parse_uuid(note_id)
|
||||
if nid is None:
|
||||
return None
|
||||
return await db.scalar(
|
||||
select(Note).where(
|
||||
Note.id == nid,
|
||||
visible_to_user("note", Note.owner_id, Note.id, g.user_id, permission=EDIT),
|
||||
Note.purged_at.is_(None),
|
||||
)
|
||||
)
|
||||
return await _fetch_note(db, note_id, note_visible(EDIT))
|
||||
|
||||
|
||||
def _slugify(text: str) -> str:
|
||||
|
||||
@@ -18,7 +18,7 @@ import re
|
||||
|
||||
from sqlalchemy import func, select
|
||||
|
||||
from ..labeling import live
|
||||
from ..labeling import named
|
||||
from ..models.label import Label, NoteLabel
|
||||
from ..models.note import Note
|
||||
from .helpers import derive_display_title
|
||||
@@ -124,7 +124,7 @@ async def _find_or_create_label(db, owner_id, name: str):
|
||||
"""Owner's live label id for `name` (case-insensitive match), creating it if absent.
|
||||
A deleted tag's tombstone never matches: tagging a note with it again makes a new tag."""
|
||||
existing = await db.scalar(
|
||||
select(Label.id).where(live(owner_id), func.lower(Label.name) == name.lower())
|
||||
select(Label.id).where(named(owner_id, name))
|
||||
)
|
||||
if existing is not None:
|
||||
return existing
|
||||
|
||||
@@ -19,6 +19,12 @@ def not_found():
|
||||
return json_error("not found", 404)
|
||||
|
||||
|
||||
def too_many(message: str, retry_after: int):
|
||||
"""429 with `Retry-After`, the one thing a client that was slowed down needs to
|
||||
know: how long to wait. Never which limit it hit."""
|
||||
return jsonify({"error": message}), 429, {"Retry-After": str(retry_after)}
|
||||
|
||||
|
||||
def parse_uuid(raw: object) -> uuid.UUID | None:
|
||||
"""Parse a path/body UUID, returning None on anything malformed. Pair with
|
||||
not_found() for the ubiquitous 'bad id in the URL → 404' guard."""
|
||||
|
||||
@@ -22,12 +22,13 @@ from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import logging
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from datetime import datetime, timezone
|
||||
|
||||
from sqlalchemy import delete as sa_delete
|
||||
from sqlalchemy import select
|
||||
|
||||
from . import audit
|
||||
from .common import expired_before
|
||||
from .config import Config
|
||||
from .db import session_scope
|
||||
from .models.label import NoteLabel
|
||||
@@ -56,18 +57,6 @@ SWEEP_STARTUP_DELAY_SECONDS = 60
|
||||
SWEEP_BATCH = 200
|
||||
|
||||
|
||||
def expired_before(now: datetime, retention_days: int) -> datetime | None:
|
||||
"""The cutoff: trash older than this has expired. `None` = retention is off.
|
||||
|
||||
Kept separate from the query so the window arithmetic — including the two ways
|
||||
to say "never" (0 and negative, the latter reachable by typing a stray minus in
|
||||
Settings) — is testable without a database.
|
||||
"""
|
||||
if retention_days <= 0:
|
||||
return None
|
||||
return now - timedelta(days=retention_days)
|
||||
|
||||
|
||||
async def purge_note(db, note: Note, edited_at: datetime | None = None) -> None:
|
||||
"""Turn a note into a content-less tombstone: delete its children (and the
|
||||
attachment files on disk), clear its content, stamp `purged_at`.
|
||||
|
||||
@@ -7,6 +7,7 @@ from __future__ import annotations
|
||||
|
||||
from .common import iso
|
||||
from .models.label import Label
|
||||
from .models.user import User
|
||||
|
||||
|
||||
def serialize_label(label: Label) -> dict:
|
||||
@@ -24,3 +25,10 @@ def serialize_label_sync(label: Label) -> dict:
|
||||
"purged_at": iso(label.purged_at),
|
||||
"created_at": iso(label.created_at),
|
||||
}
|
||||
|
||||
|
||||
def serialize_person(user: User) -> dict:
|
||||
"""Someone as another member sees them: a name and an email, which is what
|
||||
choosing them takes and all a fellow member needs to know. The share directory,
|
||||
a share's recipient and a group's members all show people this way."""
|
||||
return {"id": str(user.id), "display_name": user.display_name, "email": user.email}
|
||||
|
||||
@@ -3,7 +3,7 @@ from __future__ import annotations
|
||||
import json
|
||||
import secrets
|
||||
from dataclasses import dataclass
|
||||
from datetime import datetime, timezone
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from typing import Any, Literal
|
||||
|
||||
from .common import coerce_bool
|
||||
@@ -394,6 +394,12 @@ def live(key: str) -> Any:
|
||||
return _live[key]
|
||||
|
||||
|
||||
def apply_session_ttl(app, days) -> None:
|
||||
"""Sessions signed from now on last `days` days. At boot and on every admin save,
|
||||
so a changed lifetime applies without a restart (rule 25)."""
|
||||
app.config["PERMANENT_SESSION_LIFETIME"] = timedelta(days=int(days))
|
||||
|
||||
|
||||
async def refresh_live(db) -> None:
|
||||
"""Re-read the hot settings into the cache. Called at boot and after every save."""
|
||||
for key in _LIVE_KEYS:
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import timedelta
|
||||
|
||||
import logging
|
||||
|
||||
from quart import Blueprint, current_app, g, jsonify, request
|
||||
@@ -11,7 +9,7 @@ from .db import session_scope
|
||||
from .mailer import mail_settings, send
|
||||
from .responses import json_error
|
||||
from .models.user import User
|
||||
from .settings import get_admin_settings, get_setting, refresh_live, set_settings, validate_updates
|
||||
from .settings import apply_session_ttl, get_admin_settings, get_setting, refresh_live, set_settings, validate_updates
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -50,7 +48,7 @@ async def update_settings():
|
||||
|
||||
# Apply the live-tunable knob without a restart (rule 25).
|
||||
if "session_ttl_days" in clean:
|
||||
current_app.config["PERMANENT_SESSION_LIFETIME"] = timedelta(days=int(clean["session_ttl_days"]))
|
||||
apply_session_ttl(current_app, clean["session_ttl_days"])
|
||||
|
||||
return jsonify({"settings": result})
|
||||
|
||||
|
||||
@@ -80,6 +80,12 @@ async def granted(db, note_id: uuid.UUID, user_id: uuid.UUID) -> None:
|
||||
# cursor, and losing it leaves a revocation.
|
||||
|
||||
|
||||
async def revoke_lost(db, note_id: uuid.UUID, before: set[uuid.UUID]) -> None:
|
||||
"""After a share or a group goes: tell the devices of whoever could see the note
|
||||
`before` and no longer can. Someone still reached another way keeps it."""
|
||||
await revoke(db, note_id, before - await recipients(db, note_id))
|
||||
|
||||
|
||||
async def group_notes(db, group_id: uuid.UUID) -> list[uuid.UUID]:
|
||||
"""The notes shared with this group."""
|
||||
rows = await db.scalars(
|
||||
|
||||
@@ -25,15 +25,12 @@ from .models.share import Share
|
||||
from .models.user import User
|
||||
from .notes.helpers import _get_owned
|
||||
from .responses import json_error, not_found, parse_uuid
|
||||
from .share_sync import bump_note, granted, recipients, revoke
|
||||
from .serialize import serialize_person
|
||||
from .share_sync import bump_note, granted, recipients, revoke_lost
|
||||
|
||||
bp = Blueprint("shares", __name__, url_prefix="/api")
|
||||
|
||||
|
||||
def _member(user: User) -> dict:
|
||||
return {"id": str(user.id), "display_name": user.display_name, "email": user.email}
|
||||
|
||||
|
||||
def _group(group: Group, counts: dict) -> dict:
|
||||
return {"id": str(group.id), "name": group.name, "member_count": counts.get(group.id, 0)}
|
||||
|
||||
@@ -64,7 +61,7 @@ async def directory():
|
||||
).all()
|
||||
groups = (await db.scalars(select(Group).order_by(func.lower(Group.name)))).all()
|
||||
counts = await _member_counts(db, [gr.id for gr in groups])
|
||||
return jsonify({"members": [_member(u) for u in users], "groups": [_group(gr, counts) for gr in groups]})
|
||||
return jsonify({"members": [serialize_person(u) for u in users], "groups": [_group(gr, counts) for gr in groups]})
|
||||
|
||||
|
||||
async def _shares_of(db, note_id: uuid.UUID) -> list[dict]:
|
||||
@@ -83,7 +80,7 @@ async def _shares_of(db, note_id: uuid.UUID) -> list[dict]:
|
||||
return [
|
||||
{
|
||||
"id": str(share.id),
|
||||
"member": _member(user) if user is not None else None,
|
||||
"member": serialize_person(user) if user is not None else None,
|
||||
"group": _group(group, counts) if group is not None else None,
|
||||
"permission": share.permission,
|
||||
"created_at": iso(share.created_at),
|
||||
@@ -167,9 +164,7 @@ async def unshare_note(note_id: str, share_id: str):
|
||||
before = await recipients(db, note.id)
|
||||
await db.delete(share)
|
||||
await db.flush()
|
||||
# Only the people who can no longer see it: someone still reached through a
|
||||
# group keeps the note on their devices.
|
||||
await revoke(db, note.id, before - await recipients(db, note.id))
|
||||
await revoke_lost(db, note.id, before)
|
||||
# The owner's devices learn the note is no longer shared.
|
||||
await bump_note(db, note.id)
|
||||
await db.commit()
|
||||
|
||||
+17
-17
@@ -21,11 +21,10 @@ from quart import Blueprint, g, jsonify, request
|
||||
from sqlalchemy import delete as sa_delete
|
||||
from sqlalchemy import func, select
|
||||
|
||||
from .acl import visible_to_user
|
||||
from .auth import login_required
|
||||
from .common import iso, parse_dt
|
||||
from .db import session_scope
|
||||
from .labeling import live, reconcile_manual_labels, resolve_owned_label_ids, tombstone_label
|
||||
from .labeling import live, named, reconcile_manual_labels, resolve_owned_label_ids, tombstone_label
|
||||
from .models.label import Label, NoteLabel
|
||||
from .models.note import Note
|
||||
from .models.note_attachment import NoteAttachment
|
||||
@@ -38,7 +37,7 @@ from .notes import (
|
||||
normalize_recurrence,
|
||||
)
|
||||
from .notes.body import write_body
|
||||
from .notes.helpers import _get_editable, _get_visible, store_attachment
|
||||
from .notes.helpers import _get_editable, _get_visible, note_visible, store_attachment
|
||||
from .responses import json_error, not_found, parse_uuid
|
||||
from .retention import purge_note
|
||||
from .serialize import serialize_label_sync
|
||||
@@ -140,7 +139,7 @@ async def changes():
|
||||
# notes it would treat as its own: pinning them, labelling them, pushing them.
|
||||
with_shares = request.args.get("shares") == "1"
|
||||
if with_shares:
|
||||
visible = visible_to_user("note", Note.owner_id, Note.id, g.user_id)
|
||||
visible = note_visible()
|
||||
else:
|
||||
visible = Note.owner_id == g.user_id
|
||||
async with session_scope() as db:
|
||||
@@ -268,6 +267,14 @@ def _result(rid, entity: str, status: str, **extra) -> dict:
|
||||
return {"id": rid, "entity": entity, "status": status, **extra}
|
||||
|
||||
|
||||
async def _landed(db, row, entity: str, status: str) -> dict:
|
||||
"""The reply for a push that changed `row`: flush it, read back the revision the
|
||||
trigger gave it, and report that, so the client's cursor never runs ahead of it."""
|
||||
await db.flush()
|
||||
await db.refresh(row, ["sync_revision"])
|
||||
return _result(str(row.id), entity, status, sync_revision=row.sync_revision)
|
||||
|
||||
|
||||
async def _apply_note(db, ch: dict, previews: list[tuple[uuid.UUID, str]]) -> dict:
|
||||
"""Apply one pushed note. A note whose text changed is appended to `previews` as
|
||||
(id, final body), for the caller to queue link previews once the batch commits."""
|
||||
@@ -288,9 +295,7 @@ async def _apply_note(db, ch: dict, previews: list[tuple[uuid.UUID, str]]) -> di
|
||||
if not client_wins(edited_at, note.updated_at):
|
||||
return _result(str(nid), "note", "kept", sync_revision=note.sync_revision)
|
||||
await purge_note(db, note, edited_at)
|
||||
await db.flush()
|
||||
await db.refresh(note, ["sync_revision"])
|
||||
return _result(str(nid), "note", "applied", sync_revision=note.sync_revision)
|
||||
return await _landed(db, note, "note", "applied")
|
||||
|
||||
creating = note is None
|
||||
if creating:
|
||||
@@ -321,9 +326,7 @@ async def _apply_note(db, ch: dict, previews: list[tuple[uuid.UUID, str]]) -> di
|
||||
if edited_at is not None:
|
||||
note.updated_at = edited_at
|
||||
await _apply_note_manual_labels(db, note, ch)
|
||||
await db.flush()
|
||||
await db.refresh(note, ["sync_revision"])
|
||||
return _result(str(nid), "note", "created" if creating else "applied", sync_revision=note.sync_revision)
|
||||
return await _landed(db, note, "note", "created" if creating else "applied")
|
||||
|
||||
|
||||
async def _apply_shared_note(db, note: Note, ch: dict, edited_at, previews: list[tuple[uuid.UUID, str]]) -> dict:
|
||||
@@ -374,7 +377,7 @@ async def _apply_shared_note(db, note: Note, ch: dict, edited_at, previews: list
|
||||
join_state(select(revision_for()).select_from(Note), g.user_id).where(Note.id == note.id)
|
||||
)
|
||||
status = "kept" if kept and not applied else "applied"
|
||||
return {"id": nid, "entity": "note", "status": status, "sync_revision": revision}
|
||||
return _result(nid, "note", status, sync_revision=revision)
|
||||
|
||||
|
||||
async def _apply_label(db, ch: dict) -> dict:
|
||||
@@ -396,8 +399,7 @@ async def _apply_label(db, ch: dict) -> dict:
|
||||
if not client_wins(edited_at, label.updated_at):
|
||||
return _result(str(lid), "label", "kept", sync_revision=label.sync_revision)
|
||||
await tombstone_label(db, label, edited_at)
|
||||
await db.refresh(label, ["sync_revision"])
|
||||
return _result(str(lid), "label", "applied", sync_revision=label.sync_revision)
|
||||
return await _landed(db, label, "label", "applied")
|
||||
|
||||
name = (ch.get("name") or "").strip()
|
||||
creating = label is None
|
||||
@@ -407,7 +409,7 @@ async def _apply_label(db, ch: dict) -> dict:
|
||||
# id can't be an insert. A tombstone holds no name (0040), so it never clashes.
|
||||
if name:
|
||||
clash = await db.scalar(
|
||||
select(Label.id).where(live(g.user_id), func.lower(Label.name) == name.lower(), Label.id != lid)
|
||||
select(Label.id).where(named(g.user_id, name), Label.id != lid)
|
||||
)
|
||||
if clash is not None:
|
||||
return _result(str(lid), "label", "rejected", error="name in use")
|
||||
@@ -425,9 +427,7 @@ async def _apply_label(db, ch: dict) -> dict:
|
||||
label.color = normalize_color(ch.get("color"))
|
||||
if edited_at is not None:
|
||||
label.updated_at = edited_at
|
||||
await db.flush()
|
||||
await db.refresh(label, ["sync_revision"])
|
||||
return _result(str(lid), "label", "created" if creating else "applied", sync_revision=label.sync_revision)
|
||||
return await _landed(db, label, "label", "created" if creating else "applied")
|
||||
|
||||
|
||||
# Entities a push may only DELETE. Each is a note's child, so deleting one bumps its
|
||||
|
||||
@@ -30,6 +30,7 @@ import uuid
|
||||
|
||||
from sqlalchemy import select
|
||||
|
||||
from .common import detach
|
||||
from .db import session_scope
|
||||
from .models.note import Note
|
||||
from .models.note_link_preview import NoteLinkPreview
|
||||
@@ -118,10 +119,8 @@ def schedule(note_id: uuid.UUID, body: str | None) -> None:
|
||||
if not body or not detect_urls(body):
|
||||
return
|
||||
try:
|
||||
task = asyncio.create_task(_unfurl_new_urls(note_id, body))
|
||||
detach(_running, _unfurl_new_urls(note_id, body))
|
||||
except RuntimeError:
|
||||
# No running loop — a script or a test calling the write path directly. The
|
||||
# note is saved either way; only the preview is skipped.
|
||||
return
|
||||
_running.add(task)
|
||||
task.add_done_callback(_running.discard)
|
||||
|
||||
@@ -2,11 +2,11 @@ from datetime import datetime, timedelta, timezone
|
||||
|
||||
import pytest
|
||||
|
||||
from inkwell.common import expired_before
|
||||
from inkwell.retention import (
|
||||
SWEEP_BATCH,
|
||||
SWEEP_INTERVAL_SECONDS,
|
||||
SWEEP_STARTUP_DELAY_SECONDS,
|
||||
expired_before,
|
||||
sweep_expired_trash,
|
||||
)
|
||||
from inkwell.settings import REGISTRY, get_public_config, validate_updates
|
||||
|
||||
Reference in New Issue
Block a user