sharing: share a note from the web, at view or edit, with anyone on the instance
CI & Build / Python lint (push) Successful in 3s
CI & Build / Build now, or wait for Android? (push) Successful in 4s
Android / Build, or is the channel already serving this? (push) Successful in 4s
Android / Kotlin + Rust (APK) (push) Skipped
Desktop (Tauri) / Build, or is the channel already serving this? (push) Successful in 2s
CI & Build / Web typecheck and unit tests (push) Successful in 9s
CI & Build / Python tests (push) Successful in 14s
CI & Build / integration (push) Failing after 54s
CI & Build / Build & push image (push) Skipped
Desktop (Tauri) / Web tests, clippy, Rust tests and rustfmt (push) Successful in 2m6s
Desktop (Tauri) / Update manifest (push) Canceled after 0s
Desktop (Tauri) / Windows installer (cross-compiled) (push) Canceled after 2m25s
Desktop (Tauri) / Tauri desktop (Linux) (push) Canceled after 2m33s
CI & Build / Python lint (push) Successful in 3s
CI & Build / Build now, or wait for Android? (push) Successful in 4s
Android / Build, or is the channel already serving this? (push) Successful in 4s
Android / Kotlin + Rust (APK) (push) Skipped
Desktop (Tauri) / Build, or is the channel already serving this? (push) Successful in 2s
CI & Build / Web typecheck and unit tests (push) Successful in 9s
CI & Build / Python tests (push) Successful in 14s
CI & Build / integration (push) Failing after 54s
CI & Build / Build & push image (push) Skipped
Desktop (Tauri) / Web tests, clippy, Rust tests and rustfmt (push) Successful in 2m6s
Desktop (Tauri) / Update manifest (push) Canceled after 0s
Desktop (Tauri) / Windows installer (cross-compiled) (push) Canceled after 2m25s
Desktop (Tauri) / Tauri desktop (Linux) (push) Canceled after 2m33s
The ACL has gated every read since M0, but nothing could write a share. Server: - shares_api: GET /api/users/directory (everyone but you, signed-in only), GET/POST /api/notes/<id>/shares and DELETE …/shares/<share_id>, owner only. Sharing again with the same person changes the permission (ON CONFLICT on the new unique index). - acl.visible_to_user takes permission=; granted_to and shared_ids feed the serializer. - Edit covers body and checklist (_get_editable). Everything else stays _get_owned. A view share's write is a 404 like a stranger's (#1984). An editor's PATCH naming anything but body is a 403. - Serialized notes carry permission, shared and shared_by. A recipient never gets the owner's labels, and a #tag an editor types files under the owner's (it always went to note.owner_id). - ?shared=with_me, also allowed in saved views. Trash and reminders are the owner's. purge_note drops the note's shares. - Migration 0034: one share per note and person (and per group), permission limited to view and edit, an index for "shared with me". Web: - ShareDialog (one, mounted by the shell): pick a member, Can view or Can edit, change or remove existing shares, with loading, error and empty states. - Card: "Shared by X" or "Shared" chip; owner-only actions and reminder buttons hidden for recipients; checkboxes inert at view. - Editor: read-only at view; text and checklist only at edit; Share button for the owner. - FilterBar: Shared with me. Repo seam gains `shares`; the offline desktop shows none of it (#5175 brings sharing there). Tests: owner, recipient and stranger across reads, every write at view and edit, tag filing, unshare, trash, delete and validation; web unit tests for the facet and permission helpers. #5174. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -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, Repo } from "./repo";
|
||||
import type { DeviceToken, ImportResult, Member, NoteShare, Repo } from "./repo";
|
||||
|
||||
const NEEDS_SERVER = "That's not available offline — connect a server to use it.";
|
||||
|
||||
@@ -91,4 +91,13 @@ export const local: Repo = {
|
||||
remove: (id) => invoke<void>("saved_filters_remove", { id }),
|
||||
rename: (id, name) => invoke<SavedFilter>("saved_filters_rename", { id, name }),
|
||||
},
|
||||
|
||||
// Sharing is between accounts on a server; the desktop gets it with sync (#5175).
|
||||
// The Share controls are not shown here, so these only answer a stray call.
|
||||
shares: {
|
||||
directory: () => Promise.resolve<Member[]>([]),
|
||||
list: () => Promise.resolve<NoteShare[]>([]),
|
||||
share: () => Promise.reject<NoteShare[]>(new Error(NEEDS_SERVER)),
|
||||
unshare: () => Promise.reject<NoteShare[]>(new Error(NEEDS_SERVER)),
|
||||
},
|
||||
};
|
||||
|
||||
@@ -46,6 +46,24 @@ export interface ChecklistItemChanges {
|
||||
}
|
||||
|
||||
|
||||
// ---- sharing (#5174) ---------------------------------------------------------
|
||||
|
||||
/** A person on this instance, as the member directory shows them. */
|
||||
export interface Member {
|
||||
id: string;
|
||||
display_name: string;
|
||||
email: string;
|
||||
}
|
||||
|
||||
export type SharePermission = "view" | "edit";
|
||||
|
||||
export interface NoteShare {
|
||||
id: string;
|
||||
member: Member;
|
||||
permission: SharePermission;
|
||||
created_at: string | null;
|
||||
}
|
||||
|
||||
export interface ImportResult {
|
||||
source: string;
|
||||
imported: number;
|
||||
@@ -116,6 +134,15 @@ export interface NotesRepo {
|
||||
titles(): Promise<TitleEntry[]>;
|
||||
}
|
||||
|
||||
export interface SharesRepo {
|
||||
/** Everyone on the instance but you. */
|
||||
directory(): Promise<Member[]>;
|
||||
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[]>;
|
||||
unshare(noteId: string, shareId: string): Promise<NoteShare[]>;
|
||||
}
|
||||
|
||||
export interface SavedFiltersRepo {
|
||||
list(): Promise<SavedFilter[]>;
|
||||
create(name: string, params: NoteFacets): Promise<SavedFilter>;
|
||||
@@ -130,4 +157,5 @@ export interface Repo {
|
||||
labels: LabelsRepo;
|
||||
notes: NotesRepo;
|
||||
savedFilters: SavedFiltersRepo;
|
||||
shares: SharesRepo;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,9 @@ import type { PublicConfig } from "../stores/config";
|
||||
import type {
|
||||
DeviceToken,
|
||||
ImportResult,
|
||||
Member,
|
||||
NoteChanges,
|
||||
NoteShare,
|
||||
NoteCreateInput,
|
||||
NoteListQuery,
|
||||
ChecklistItemChanges,
|
||||
@@ -35,6 +37,7 @@ function notesQuery(q: NoteListQuery): string {
|
||||
if (q.facets?.has_attachment) params.set("has_attachment", "true");
|
||||
if (q.facets?.created_after) params.set("created_after", q.facets.created_after);
|
||||
if (q.facets?.created_before) params.set("created_before", q.facets.created_before);
|
||||
if (q.facets?.shared) params.set("shared", q.facets.shared);
|
||||
if (q.sort) params.set("sort", q.sort);
|
||||
return params.toString();
|
||||
}
|
||||
@@ -115,4 +118,13 @@ export const rest: Repo = {
|
||||
remove: (id) => api.del<void>(`/api/saved-filters/${id}`),
|
||||
rename: (id, name) => api.patch<SavedFilter>(`/api/saved-filters/${id}`, { name }),
|
||||
},
|
||||
|
||||
shares: {
|
||||
directory: async () => (await api.get<{ members: Member[] }>("/api/users/directory")).members,
|
||||
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,
|
||||
unshare: async (noteId, shareId) =>
|
||||
(await api.del<{ shares: NoteShare[] }>(`/api/notes/${noteId}/shares/${shareId}`)).shares,
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user