web, core, desktop: share a note with a group, and Settings → Groups

The Share dialog lists people and groups in one picker and shows a group share
as its name and member count. Settings gains a Groups section for the admin:
create, rename, delete, and add or remove people.

The core client reads the directory's groups and group shares (ShareTarget:
a member or a group); the desktop command takes user_id or group_id.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-07 18:25:16 -04:00
co-authored by Claude Opus 5.5
parent 5f3cfe8bb7
commit 442cca4398
9 changed files with 413 additions and 57 deletions
+9 -3
View File
@@ -16,7 +16,7 @@ import type { Device } from "../stores/devices";
import type { TitleEntry } from "../stores/titles";
import type { User } from "../stores/session";
import type { PublicConfig } from "../stores/config";
import type { DeviceToken, ImportResult, Member, NoteShare, Repo } from "./repo";
import type { DeviceToken, Directory, ImportResult, NoteShare, Repo } from "./repo";
const NEEDS_SERVER = "That's not available offline — connect a server to use it.";
@@ -95,9 +95,15 @@ export const local: Repo = {
// Sharing is between accounts on a server, so these go to the linked one (#5175).
// Unlinked, each rejects with the core's explanation, which the dialog shows.
shares: {
directory: () => invoke<Member[]>("shares_directory"),
directory: () => invoke<Directory>("shares_directory"),
list: (noteId) => invoke<NoteShare[]>("shares_list", { noteId }),
share: (noteId, userId, permission) => invoke<NoteShare[]>("shares_share", { noteId, userId, permission }),
share: (noteId, target, permission) =>
invoke<NoteShare[]>("shares_share", {
noteId,
userId: "user_id" in target ? target.user_id : null,
groupId: "group_id" in target ? target.group_id : null,
permission,
}),
unshare: (noteId, shareId) => invoke<NoteShare[]>("shares_unshare", { noteId, shareId }),
},
};
+23 -5
View File
@@ -55,11 +55,29 @@ export interface Member {
email: string;
}
/** A group the admin made, as the directory shows it (#5177). */
export interface ShareGroup {
id: string;
name: string;
member_count: number;
}
/** Everyone a note can be shared with: the other people, and every group. */
export interface Directory {
members: Member[];
groups: ShareGroup[];
}
/** Who a share goes to: one person, or a group (whoever is in it at the time). */
export type ShareTarget = { user_id: string } | { group_id: string };
export type SharePermission = "view" | "edit";
/** One share of a note: exactly one of `member` and `group` is set. */
export interface NoteShare {
id: string;
member: Member;
member: Member | null;
group: ShareGroup | null;
permission: SharePermission;
created_at: string | null;
}
@@ -135,11 +153,11 @@ export interface NotesRepo {
}
export interface SharesRepo {
/** Everyone on the instance but you. */
directory(): Promise<Member[]>;
/** Everyone on the instance but you, and every group. */
directory(): Promise<Directory>;
list(noteId: string): Promise<NoteShare[]>;
/** Share with one member, or change their permission. Answers the note's shares. */
share(noteId: string, userId: string, permission: SharePermission): Promise<NoteShare[]>;
/** Share with a person or a group, or change their permission. Answers the note's shares. */
share(noteId: string, target: ShareTarget, permission: SharePermission): Promise<NoteShare[]>;
unshare(noteId: string, shareId: string): Promise<NoteShare[]>;
}
+4 -4
View File
@@ -14,8 +14,8 @@ import type { User } from "../stores/session";
import type { PublicConfig } from "../stores/config";
import type {
DeviceToken,
Directory,
ImportResult,
Member,
NoteChanges,
NoteShare,
NoteCreateInput,
@@ -120,10 +120,10 @@ export const rest: Repo = {
},
shares: {
directory: async () => (await api.get<{ members: Member[] }>("/api/users/directory")).members,
directory: () => api.get<Directory>("/api/users/directory"),
list: async (noteId) => (await api.get<{ shares: NoteShare[] }>(`/api/notes/${noteId}/shares`)).shares,
share: async (noteId, userId, permission) =>
(await api.post<{ shares: NoteShare[] }>(`/api/notes/${noteId}/shares`, { user_id: userId, permission })).shares,
share: async (noteId, target, permission) =>
(await api.post<{ shares: NoteShare[] }>(`/api/notes/${noteId}/shares`, { ...target, permission })).shares,
unshare: async (noteId, shareId) =>
(await api.del<{ shares: NoteShare[] }>(`/api/notes/${noteId}/shares/${shareId}`)).shares,
},