Skip to content

Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.

fix: Centralized owner/admin checks, Removed dead parameters, add seat regression coverage

Chadpihad67b9fb76410
diff --git a/src/components/notes/CreateSpaceDialog.tsx b/src/components/notes/CreateSpaceDialog.tsx
index eb71b0e07..26ffb32aa 100644
--- a/src/components/notes/CreateSpaceDialog.tsx
+++ b/src/components/notes/CreateSpaceDialog.tsx
@@ -26,6 +26,7 @@ import { useAuth } from "../../hooks/useAuth";
import { useDelayedFlag } from "../../hooks/useDelayedFlag";
import { EmojiPickerInput } from "./EmojiPickerInput";
import { orderMemberCandidates } from "../../lib/memberCandidates";
+import { canManageWorkspace } from "../../lib/spacePermissions";
import {
manageableWorkspaces as findManageableWorkspaces,
selectWorkspaceForSpaceCreation,
@@ -170,9 +171,7 @@ export default function CreateSpaceDialog({
// cancelling closes everything.
const handleWorkspaceDialogChange = (nextOpen: boolean) => {
if (nextOpen) return;
- const created = useWorkspaceStore
- .getState()
- .workspaces.some((w) => w.role === "owner" || w.role === "admin");
+ const created = useWorkspaceStore.getState().workspaces.some((w) => canManageWorkspace(w.role));
if (!created) onOpenChange(false);
};
diff --git a/src/components/notes/SpaceMembersDialog.tsx b/src/components/notes/SpaceMembersDialog.tsx
index 1714a4c48..038516bef 100644
--- a/src/components/notes/SpaceMembersDialog.tsx
+++ b/src/components/notes/SpaceMembersDialog.tsx
@@ -21,7 +21,11 @@ import {
import { useToast } from "../ui/useToast";
import { useWorkspaceStore } from "../../stores/workspaceStore";
import { useSpaces } from "../../stores/noteStore";
-import { canManageSpace, canManageTeamRoster } from "../../lib/spacePermissions";
+import {
+ canManageSpace,
+ canManageTeamRoster,
+ canManageWorkspace,
+} from "../../lib/spacePermissions";
import type { SpaceItem, SpaceTeamRef, Team, TeamMember } from "../../types/electron";
interface SpaceMembersDialogProps {
@@ -60,7 +64,7 @@ export default function SpaceMembersDialog({ space, open, onOpenChange }: SpaceM
const [accessBusyTeamId, setAccessBusyTeamId] = useState<string | null>(null);
const canManage = canManageSpace(space, workspace?.role ?? null);
- const isWorkspaceAdmin = workspace?.role === "owner" || workspace?.role === "admin";
+ const isWorkspaceAdmin = canManageWorkspace(workspace?.role);
// Team creation and workspace invites are 403'd below workspace admin.
const canInviteToWorkspace = isWorkspaceAdmin;
diff --git a/src/components/notes/SpacesTree.tsx b/src/components/notes/SpacesTree.tsx
index 503545b23..0d77ae560 100644
--- a/src/components/notes/SpacesTree.tsx
+++ b/src/components/notes/SpacesTree.tsx
@@ -43,7 +43,11 @@ import { useTeamSpacesCapability } from "../../hooks/useTeamSpacesCapability";
import { useAuth } from "../../hooks/useAuth";
import { useWorkspace } from "../../hooks/useWorkspace";
import { EmojiPickerInput } from "./EmojiPickerInput";
-import { canManageSpace, canMoveBetweenSpaces } from "../../lib/spacePermissions";
+import {
+ canManageSpace,
+ canManageWorkspace,
+ canMoveBetweenSpaces,
+} from "../../lib/spacePermissions";
import { groupTeamSpacesByWorkspace } from "../../lib/workspaceSelection";
import { localMutationErrorKey } from "../../lib/localMutationError";
import { readIsSubscribed, subscribeIsSubscribed } from "../../lib/subscriptionFlag";
@@ -1164,7 +1168,7 @@ export default function SpacesTree({
const canCreateTeamSpace =
isSignedIn &&
workspacesLoaded &&
- (workspaces.length === 0 || workspaces.some((w) => w.role === "owner" || w.role === "admin"));
+ (workspaces.length === 0 || workspaces.some((w) => canManageWorkspace(w.role)));
// Local-only spaces (no cloud id) stay fully manageable; cloud spaces
// follow space/workspace roles. Cosmetic — the server enforces.
@@ -2014,7 +2018,7 @@ export default function SpacesTree({
>
{workspace.name}
</span>
- {(workspace.role === "owner" || workspace.role === "admin") && (
+ {canManageWorkspace(workspace.role) && (
<Button
variant="ghost"
size="icon"
diff --git a/src/components/settings/TeamMembersDialog.tsx b/src/components/settings/TeamMembersDialog.tsx
index 45e00718b..132a19283 100644
--- a/src/components/settings/TeamMembersDialog.tsx
+++ b/src/components/settings/TeamMembersDialog.tsx
@@ -12,7 +12,7 @@ import InviteTeammateDialog from "../InviteTeammateDialog";
import TeamRosterSection from "../TeamRosterSection";
import { leaveTeam } from "../../services/spaceActions";
import { useWorkspaceStore } from "../../stores/workspaceStore";
-import { canManageTeamRoster } from "../../lib/spacePermissions";
+import { canManageTeamRoster, canManageWorkspace } from "../../lib/spacePermissions";
import type { Team, TeamMember, Workspace } from "../../types/electron";
interface TeamMembersDialogProps {
@@ -41,7 +41,7 @@ export default function TeamMembersDialog({
const [inviteEmail, setInviteEmail] = useState<string | undefined>(undefined);
const showLeaveSpinner = useDelayedFlag(isLeaving);
- const isWorkspaceAdmin = workspace.role === "owner" || workspace.role === "admin";
+ const isWorkspaceAdmin = canManageWorkspace(workspace.role);
const myTeamRole = teamMembers.find((m) => m.user_id === user?.id)?.role ?? null;
const canManage = canManageTeamRoster(myTeamRole, workspace.role);
// Anyone with an explicit membership row can drop it — including workspace
diff --git a/src/components/settings/WorkspaceMembersTab.tsx b/src/components/settings/WorkspaceMembersTab.tsx
index 5213c2c70..11754dd17 100644
--- a/src/components/settings/WorkspaceMembersTab.tsx
+++ b/src/components/settings/WorkspaceMembersTab.tsx
@@ -20,6 +20,7 @@ import {
DropdownMenuItem,
} from "../ui/dropdown-menu";
import { cn } from "../lib/utils";
+import { canManageWorkspace } from "../../lib/spacePermissions";
interface Props {
workspace: Workspace;
@@ -47,7 +48,7 @@ export default function WorkspaceMembersTab({ workspace, onNavigateToBilling }:
const [membersLoading, setMembersLoading] = useState(false);
const [membersError, setMembersError] = useState(false);
const [invitationsError, setInvitationsError] = useState(false);
- const canManage = workspace.role === "owner" || workspace.role === "admin";
+ const canManage = canManageWorkspace(workspace.role);
async function loadMembers() {
setMembersLoading(true);
diff --git a/src/components/settings/WorkspaceSection.tsx b/src/components/settings/WorkspaceSection.tsx
index 273c2b511..97bd82034 100644
--- a/src/components/settings/WorkspaceSection.tsx
+++ b/src/components/settings/WorkspaceSection.tsx
@@ -24,6 +24,7 @@ import {
} from "../ui/dropdown-menu";
import { cn } from "../lib/utils";
import { storeSeatIntent } from "../../utils/billingSeatIntent";
+import { canManageWorkspace } from "../../lib/spacePermissions";
import WorkspaceMembersTab from "./WorkspaceMembersTab";
import WorkspaceTeamsTab from "./WorkspaceTeamsTab";
import WorkspaceDeveloperTab from "./WorkspaceDeveloperTab";
@@ -158,7 +159,7 @@ export default function WorkspaceSection({ initialSubTab, onNavigateToBilling }:
}
const workspace = workspaces.find((w) => w.id === activeWorkspaceId) ?? workspaces[0];
- const canManage = workspace.role === "owner" || workspace.role === "admin";
+ const canManage = canManageWorkspace(workspace.role);
const visibleTabs = SUB_TABS.filter((id) => id !== "developer" || canManage);
const tab: WorkspaceTab = visibleTabs.includes(storedTab as WorkspaceTab)
? (storedTab as WorkspaceTab)
@@ -259,7 +260,7 @@ function GeneralTab({ workspace }: { workspace: Workspace }) {
const [deleting, setDeleting] = useState(false);
const [leaving, setLeaving] = useState(false);
const isOwner = workspace.role === "owner";
- const canEdit = isOwner || workspace.role === "admin";
+ const canEdit = canManageWorkspace(workspace.role);
const dirty = name !== workspace.name || slug !== workspace.slug;
const slugInvalid = slug.length > 0 && !SLUG_PATTERN.test(slug);
diff --git a/src/components/settings/WorkspaceTeamsTab.tsx b/src/components/settings/WorkspaceTeamsTab.tsx
index 0a29546cf..c646da6b5 100644
--- a/src/components/settings/WorkspaceTeamsTab.tsx
+++ b/src/components/settings/WorkspaceTeamsTab.tsx
@@ -10,6 +10,7 @@ import { useToast } from "../ui/useToast";
import { ConfirmDialog } from "../ui/dialog";
import CreateTeamDialog from "../CreateTeamDialog";
import TeamMembersDialog from "./TeamMembersDialog";
+import { canManageWorkspace } from "../../lib/spacePermissions";
import type { Team, Workspace } from "../../types/electron";
interface Props {
@@ -27,7 +28,7 @@ export default function WorkspaceTeamsTab({ workspace }: Props) {
const [createOpen, setCreateOpen] = useState(false);
const [membersTeam, setMembersTeam] = useState<Team | null>(null);
const [deletingId, setDeletingId] = useState<string | null>(null);
- const canManage = workspace.role === "owner" || workspace.role === "admin";
+ const canManage = canManageWorkspace(workspace.role);
const loadTeams = useCallback(async () => {
setLoadFailed(false);
diff --git a/src/lib/spacePermissions.ts b/src/lib/spacePermissions.ts
index 62fce9540..b00b40a9f 100644
--- a/src/lib/spacePermissions.ts
+++ b/src/lib/spacePermissions.ts
@@ -1,5 +1,9 @@
import type { SpaceItem, TeamRole, WorkspaceRole } from "../types/electron";
+export function canManageWorkspace(workspaceRole: WorkspaceRole | null | undefined): boolean {
+ return workspaceRole === "owner" || workspaceRole === "admin";
+}
+
/**
* Whether the current user can manage a team space (rename, delete, assign
* teams): an explicit space admin (best role across the space's assigned
@@ -7,7 +11,7 @@ import type { SpaceItem, TeamRole, WorkspaceRole } from "../types/electron";
* Client checks are cosmetic — the server enforces.
*/
export function canManageSpace(space: SpaceItem, workspaceRole: WorkspaceRole | null): boolean {
- return space.my_role === "admin" || workspaceRole === "owner" || workspaceRole === "admin";
+ return space.my_role === "admin" || canManageWorkspace(workspaceRole);
}
/**
@@ -18,7 +22,7 @@ export function canManageTeamRoster(
teamMyRole: TeamRole | null | undefined,
workspaceRole: WorkspaceRole | null
): boolean {
- return teamMyRole === "admin" || workspaceRole === "owner" || workspaceRole === "admin";
+ return teamMyRole === "admin" || canManageWorkspace(workspaceRole);
}
/**
diff --git a/src/lib/workspaceSelection.ts b/src/lib/workspaceSelection.ts
index e686971b6..6d9acbf61 100644
--- a/src/lib/workspaceSelection.ts
+++ b/src/lib/workspaceSelection.ts
@@ -1,7 +1,8 @@
import type { Workspace } from "../types/electron";
+import { canManageWorkspace } from "./spacePermissions.ts";
export function manageableWorkspaces(workspaces: Workspace[]): Workspace[] {
- return workspaces.filter((workspace) => workspace.role === "owner" || workspace.role === "admin");
+ return workspaces.filter((workspace) => canManageWorkspace(workspace.role));
}
export interface TeamSpaceGroup<S> {
@@ -20,12 +21,7 @@ export function groupTeamSpacesByWorkspace<S extends { workspace_id?: string | n
}))
// Empty groups stay visible for owners/admins so the per-workspace
// create button always has a row to live on.
- .filter(
- (group) =>
- group.spaces.length > 0 ||
- group.workspace.role === "owner" ||
- group.workspace.role === "admin"
- );
+ .filter((group) => group.spaces.length > 0 || canManageWorkspace(group.workspace.role));
const workspaceIds = new Set(workspaces.map((workspace) => workspace.id));
const ungrouped = teamSpaces.filter(
(space) => space.workspace_id == null || !workspaceIds.has(space.workspace_id)
diff --git a/src/services/ReasoningService.ts b/src/services/ReasoningService.ts
index d591f3c78..85615589f 100644
--- a/src/services/ReasoningService.ts
+++ b/src/services/ReasoningService.ts
@@ -25,6 +25,14 @@ import { extractApiErrorMessage } from "./ai/apiErrorMessage";
import { clearTinfoilClientCache } from "./ai/tinfoilClient";
import { resolveChatRoute } from "../helpers/chatRouting";
+export type ToolMetadata = Record<string, unknown> | Array<Record<string, unknown>>;
+
+interface ToolExecutionResult {
+ data: string;
+ displayText: string;
+ metadata?: ToolMetadata;
+}
+
export type AgentStreamChunk =
| { type: "content"; text: string }
| { type: "tool_calls"; calls: Array<{ id: string; name: string; arguments: string }> }
@@ -33,7 +41,7 @@ export type AgentStreamChunk =
callId: string;
toolName: string;
displayText: string;
- metadata?: Record<string, unknown> | Array<Record<string, unknown>>;
+ metadata?: ToolMetadata;
}
| { type: "done"; finishReason?: string };
@@ -824,10 +832,7 @@ class ReasoningService extends BaseReasoningService {
config: {
systemPrompt: string;
tools?: Array<{ name: string; description: string; parameters: Record<string, unknown> }>;
- executeToolCall?: (
- name: string,
- args: string
- ) => Promise<{ data: string; displayText: string; metadata?: Record<string, unknown> | Array<Record<string, unknown>> }>;
+ executeToolCall?: (name: string, args: string) => Promise<ToolExecutionResult>;
}
): AsyncGenerator<AgentStreamChunk, void, unknown> {
const maxSteps = config.tools?.length ? ReasoningService.MAX_TOOL_STEPS : 1;
@@ -861,11 +866,7 @@ class ReasoningService extends BaseReasoningService {
}
for (const call of pendingToolCalls) {
- let toolResult: {
- data: string;
- displayText: string;
- metadata?: Record<string, unknown> | Array<Record<string, unknown>>;
- };
+ let toolResult: ToolExecutionResult;
try {
toolResult = await config.executeToolCall(call.name, call.arguments);
} catch (error) {
diff --git a/src/services/SpacesService.ts b/src/services/SpacesService.ts
index 5a36f7ba4..defbb3599 100644
--- a/src/services/SpacesService.ts
+++ b/src/services/SpacesService.ts
@@ -1,9 +1,5 @@
-import { cloudGet, cloudPost, cloudPatch, cloudDelete } from "./cloudApi.js";
-import type { SpaceTeamRef, TeamMember } from "../types/electron";
-
-interface DataWrap<T> {
- data: T;
-}
+import { cloudGet, cloudPost, cloudPatch, cloudDelete, type DataWrap } from "./cloudApi.js";
+import type { SpaceTeamRef, TeamMember, TeamRole } from "../types/electron";
export interface MySpace {
id: string;
@@ -12,7 +8,7 @@ export interface MySpace {
slug: string;
description: string | null;
emoji: string | null;
- my_role: "admin" | "member";
+ my_role: TeamRole;
member_count: number;
teams: SpaceTeamRef[];
created_at: string;
@@ -25,8 +21,8 @@ export interface SpaceMemberEntry extends TeamMember {
via_teams: {
team_id: string;
name: string;
- role: "admin" | "member";
- access?: "admin" | "member";
+ role: TeamRole;
+ access?: TeamRole;
}[];
}
@@ -60,11 +56,7 @@ async function remove(spaceId: string): Promise<void> {
// The teams POST upserts: with access it also updates an existing
// assignment's cap; without it the server keeps the current value.
-async function assignTeam(
- spaceId: string,
- teamId: string,
- access?: "admin" | "member"
-): Promise<void> {
+async function assignTeam(spaceId: string, teamId: string, access?: TeamRole): Promise<void> {
await cloudPost(`/api/spaces/${spaceId}/teams`, {
team_id: teamId,
...(access ? { access } : {}),
diff --git a/src/services/TeamsService.ts b/src/services/TeamsService.ts
index 8fd23ac3d..b6895caed 100644
--- a/src/services/TeamsService.ts
+++ b/src/services/TeamsService.ts
@@ -1,10 +1,6 @@
-import { cloudGet, cloudPost, cloudPatch, cloudDelete } from "./cloudApi.js";
+import { cloudGet, cloudPost, cloudDelete, type DataWrap } from "./cloudApi.js";
import type { Team, TeamMember } from "../types/electron";
-interface DataWrap<T> {
- data: T;
-}
-
async function list(workspaceId: string): Promise<Team[]> {
const res = await cloudGet<DataWrap<Team[]>>(`/api/workspaces/${workspaceId}/teams`);
return res.data;
@@ -12,20 +8,12 @@ async function list(workspaceId: string): Promise<Team[]> {
async function create(
workspaceId: string,
- input: { name: string; description?: string; emoji?: string | null }
+ input: { name: string; description?: string }
): Promise<Team> {
const res = await cloudPost<DataWrap<Team>>(`/api/workspaces/${workspaceId}/teams`, input);
return res.data;
}
-async function update(
- teamId: string,
- patch: { name?: string; description?: string; emoji?: string | null }
-): Promise<Team> {
- const res = await cloudPatch<DataWrap<Team>>(`/api/teams/${teamId}`, patch);
- return res.data;
-}
-
async function remove(teamId: string): Promise<void> {
await cloudDelete(`/api/teams/${teamId}`);
}
@@ -50,7 +38,6 @@ async function removeMember(teamId: string, userId: string): Promise<void> {
export const TeamsService = {
list,
create,
- update,
remove,
listMembers,
addMember,
diff --git a/src/services/spaceActions.ts b/src/services/spaceActions.ts
index 068282a35..e163040ce 100644
--- a/src/services/spaceActions.ts
+++ b/src/services/spaceActions.ts
@@ -39,6 +39,5 @@ export const {
removeTeamMember,
setTeamMemberRole,
leaveTeam,
- renameTeam,
deleteTeam,
} = actions;
diff --git a/src/services/spaceActionsCore.ts b/src/services/spaceActionsCore.ts
index 988d32b72..d9311e720 100644
--- a/src/services/spaceActionsCore.ts
+++ b/src/services/spaceActionsCore.ts
@@ -13,7 +13,6 @@ interface MutationResult {
export interface SpaceActionsDependencies {
teams: {
create: (workspaceId: string, input: { name: string }) => Promise<CloudTeam>;
- update: (teamId: string, input: { name: string }) => Promise<unknown>;
remove: (teamId: string) => Promise<void>;
addMember: (teamId: string, userId: string, role?: TeamRole) => Promise<void>;
removeMember: (teamId: string, userId: string) => Promise<void>;
@@ -209,11 +208,6 @@ export function createSpaceActions(deps: SpaceActionsDependencies) {
deps.sync.requestSyncAll("manual");
}
- async function renameTeam(teamId: string, name: string): Promise<void> {
- await deps.teams.update(teamId, { name });
- await refreshSpaceMirror();
- }
-
async function deleteTeam(teamId: string): Promise<void> {
await deps.teams.remove(teamId);
await refreshSpaceMirror();
@@ -231,7 +225,6 @@ export function createSpaceActions(deps: SpaceActionsDependencies) {
removeTeamMember,
setTeamMemberRole,
leaveTeam,
- renameTeam,
deleteTeam,
};
}
diff --git a/src/stores/noteStore.ts b/src/stores/noteStore.ts
index 4332464c1..215790714 100644
--- a/src/stores/noteStore.ts
+++ b/src/stores/noteStore.ts
@@ -116,10 +116,6 @@ function noteContainerKey(note: NoteItem): string {
: spaceContainerKey(note.space_id);
}
-function activeContainerKey(state: NoteState): string | null {
- return state.activeContext ? contextContainerKey(state.activeContext) : null;
-}
-
function findNoteInState(state: NoteState, id: number): NoteItem | null {
for (const items of Object.values(state.notesByContainer)) {
const note = items.find((n) => n.id === id);
@@ -134,7 +130,7 @@ function applyContainers(
extra: Partial<NoteState> = {}
): void {
const state = useNoteStore.getState();
- const context = (extra.activeContext ?? state.activeContext) as ActiveContext | null;
+ const context = state.activeContext;
const activeKey = context ? contextContainerKey(context) : null;
const update: Partial<NoteState> = { notesByContainer, ...extra };
if (activeKey && notesByContainer[activeKey] && notesByContainer[activeKey] !== state.notes) {
@@ -150,7 +146,7 @@ function ensureIpcListeners() {
const disposers: Array<() => void> = [];
- if (window.electronAPI?.onNoteAdded) {
+ if (window.electronAPI.onNoteAdded) {
const dispose = window.electronAPI.onNoteAdded((note) => {
if (note) {
addNote(note);
@@ -162,7 +158,7 @@ function ensureIpcListeners() {
}
}
- if (window.electronAPI?.onNoteUpdated) {
+ if (window.electronAPI.onNoteUpdated) {
const dispose = window.electronAPI.onNoteUpdated((note) => {
if (note) {
const previous = findNoteInState(useNoteStore.getState(), note.id);
@@ -186,7 +182,7 @@ function ensureIpcListeners() {
}
}
- if (window.electronAPI?.onNoteDeleted) {
+ if (window.electronAPI.onNoteDeleted) {
const dispose = window.electronAPI.onNoteDeleted(({ id }) => {
removeNote(id);
loadFolders();
@@ -204,7 +200,7 @@ function ensureIpcListeners() {
// Routing through updateNoteInStore also refreshes an open clean editor
// (PersonalNotesView's external-update resync); a dirty editor keeps its
// buffer and the conflict-banner path covers it.
- if (window.electronAPI?.onNoteSynced) {
+ if (window.electronAPI.onNoteSynced) {
const dispose = window.electronAPI.onNoteSynced((note) => {
if (!note) return;
const state = useNoteStore.getState();
@@ -224,7 +220,7 @@ function ensureIpcListeners() {
}
}
- if (window.electronAPI?.onFolderSynced) {
+ if (window.electronAPI.onFolderSynced) {
const dispose = window.electronAPI.onFolderSynced((folder) => {
if (!folder) return;
void loadFolders();
@@ -243,7 +239,7 @@ function ensureIpcListeners() {
// echo of local deletes) — drop the container and refresh counts. The
// UI-originated deleteFolder already cleaned up by the time the echo
// arrives, so every step here is idempotent.
- if (window.electronAPI?.onFolderDeleted) {
+ if (window.electronAPI.onFolderDeleted) {
const dispose = window.electronAPI.onFolderDeleted(({ id }) => {
if (id == null) return;
const state = useNoteStore.getState();
@@ -273,7 +269,7 @@ function ensureIpcListeners() {
// Conflict signals rebroadcast through the main process because the sync
// pull usually runs in the overlay window, not the one showing the editor.
// Broadcasts echo to the emitting window; both setters are idempotent.
- if (window.electronAPI?.onSyncEvent) {
+ if (window.electronAPI.onSyncEvent) {
const dispose = window.electronAPI.onSyncEvent(({ name, payload }) => {
if (name === "note-conflict") {
const data = payload as { clientNoteId?: string; cloudNote?: CloudNote } | undefined;
@@ -290,7 +286,7 @@ function ensureIpcListeners() {
}
}
- if (window.electronAPI?.onSpacePurged) {
+ if (window.electronAPI.onSpacePurged) {
const dispose = window.electronAPI.onSpacePurged(({ spaceId }) => {
handleSpacePurged(spaceId);
});
@@ -300,7 +296,7 @@ function ensureIpcListeners() {
}
// Space rows written by a sync pull or membership mutation.
- if (window.electronAPI?.onSpaceSynced) {
+ if (window.electronAPI.onSpaceSynced) {
const dispose = window.electronAPI.onSpaceSynced((space) => {
if (space) void loadSpaces();
});
@@ -318,7 +314,7 @@ function ensureIpcListeners() {
export async function loadSpaces(): Promise<SpaceItem[]> {
const gen = ++spacesLoadGeneration;
- const items = (await window.electronAPI?.getSpaces?.()) ?? [];
+ const items = (await window.electronAPI.getSpaces?.()) ?? [];
// A newer load may have resolved first.
if (gen !== spacesLoadGeneration) return items;
useNoteStore.setState({ spaces: items });
@@ -357,8 +353,8 @@ export async function loadContainerNotes(
const id = Number(idStr);
const items =
kind === "f"
- ? ((await window.electronAPI?.getNotes(noteType, limit, id)) ?? [])
- : ((await window.electronAPI?.getNotes(noteType, limit, null, id)) ?? []);
+ ? ((await window.electronAPI.getNotes(noteType, limit, id)) ?? [])
+ : ((await window.electronAPI.getNotes(noteType, limit, null, id)) ?? []);
// A newer load for this container may have resolved first.
if (containerLoadGenerations.get(key) === gen) {
applyContainers({ ...useNoteStore.getState().notesByContainer, [key]: items });
@@ -485,7 +481,7 @@ export async function initializeNotes(
}
const gen = ++loadGeneration;
- const items = (await window.electronAPI?.getNotes(noteType, limit, folderId)) ?? [];
+ const items = (await window.electronAPI.getNotes(noteType, limit, folderId)) ?? [];
if (gen !== loadGeneration) return items;
useNoteStore.setState({ notes: items });
return items;
@@ -853,7 +849,7 @@ export function useMigration(): { total: number; done: number } | null {
}
export async function startMigration(): Promise<void> {
- const allNotes = (await window.electronAPI?.getNotes(null, 9999, null)) ?? [];
+ const allNotes = (await window.electronAPI.getNotes(null, 9999, null)) ?? [];
const unsynced = allNotes.filter((n) => !n.cloud_id);
if (unsynced.length === 0) return;
@@ -931,7 +927,7 @@ export async function persistNoteShareState(
noteId: number,
updates: { is_shared: number; share_token?: string | null }
): Promise<void> {
- await window.electronAPI?.updateNoteShareState(noteId, updates);
+ await window.electronAPI.updateNoteShareState(noteId, updates);
}
export function getShareCacheEntry(cloudId: string): NoteShareCacheEntry | null {
@@ -940,12 +936,20 @@ export function getShareCacheEntry(cloudId: string): NoteShareCacheEntry | null
export function updateShareCache(
cloudId: string,
- updater: (current: NoteShareCacheEntry | undefined) => NoteShareCacheEntry
+ updater: (current: NoteShareCacheEntry | undefined) => Partial<NoteShareCacheEntry>
): void {
const { shareByCloudId } = useNoteStore.getState();
const next = new Map(shareByCloudId);
const current = next.get(cloudId);
- next.set(cloudId, { ...current, ...updater(current) });
+ const updated = { ...current, ...updater(current) };
+ if (
+ updated.share === undefined ||
+ updated.invitations === undefined ||
+ updated.rawToken === undefined
+ ) {
+ throw new Error("A new share cache entry requires share, invitations, and rawToken");
+ }
+ next.set(cloudId, updated);
useNoteStore.setState({ shareByCloudId: next });
}
diff --git a/src/utils/billingSeatIntent.ts b/src/utils/billingSeatIntent.ts
index 6abf06fbb..c303232a0 100644
--- a/src/utils/billingSeatIntent.ts
+++ b/src/utils/billingSeatIntent.ts
@@ -30,6 +30,11 @@ export function readSeatIntent(): SeatIntent | null {
}
return intent as SeatIntent;
} catch {
+ try {
+ clearSeatIntent();
+ } catch {
+ // Storage itself is unavailable; there is nothing else to clean up.
+ }
return null;
}
}
diff --git a/test/lib/spacePermissions.test.js b/test/lib/spacePermissions.test.js
index 330d14a3b..e64d2f7a7 100644
--- a/test/lib/spacePermissions.test.js
+++ b/test/lib/spacePermissions.test.js
@@ -3,9 +3,18 @@ const assert = require("node:assert/strict");
const {
canManageSpace,
canManageTeamRoster,
+ canManageWorkspace,
canMoveBetweenSpaces,
} = require("../../src/lib/spacePermissions.ts");
+test("canManageWorkspace: owners and admins can manage", () => {
+ assert.equal(canManageWorkspace("owner"), true);
+ assert.equal(canManageWorkspace("admin"), true);
+ assert.equal(canManageWorkspace("member"), false);
+ assert.equal(canManageWorkspace(null), false);
+ assert.equal(canManageWorkspace(undefined), false);
+});
+
test("canManageSpace: space admin or workspace owner/admin", () => {
const space = (myRole) => ({ my_role: myRole });
assert.equal(canManageSpace(space("admin"), null), true);
diff --git a/test/services/spaceActions.test.js b/test/services/spaceActions.test.js
index 29ff0e1d6..91f0bbb56 100644
--- a/test/services/spaceActions.test.js
+++ b/test/services/spaceActions.test.js
@@ -18,7 +18,6 @@ function makeHarness() {
calls.push(["team.create", workspaceId, input]);
return { id: "new-team" };
},
- update: async (teamId, input) => calls.push(["team.update", teamId, input]),
remove: async (teamId) => calls.push(["team.remove", teamId]),
addMember: async (teamId, userId, role) =>
calls.push(["team.addMember", teamId, userId, role]),
@@ -219,16 +218,15 @@ test("team mutations refresh the full mirror and schedule sync only when needed"
await actions.removeTeamMember("team-1", "user-1");
await actions.setTeamMemberRole("team-1", "user-1", "admin");
await actions.leaveTeam("team-1", "user-1");
- await actions.renameTeam("team-1", "Renamed");
await actions.deleteTeam("team-1");
assert.equal(
calls.filter(([name]) => name === "roster.invalidate").length,
- 8,
+ 7,
"every membership or assignment change invalidates before refreshing"
);
- assert.equal(calls.filter(([name]) => name === "mirror.upsert").length, 8);
- assert.equal(calls.filter(([name]) => name === "local.load").length, 8);
+ assert.equal(calls.filter(([name]) => name === "mirror.upsert").length, 7);
+ assert.equal(calls.filter(([name]) => name === "local.load").length, 7);
assert.equal(
calls.filter(([name]) => name === "sync").length,
3,
diff --git a/test/utils/billingSeatIntent.test.js b/test/utils/billingSeatIntent.test.js
new file mode 100644
index 000000000..0ddf27018
--- /dev/null
+++ b/test/utils/billingSeatIntent.test.js
@@ -0,0 +1,30 @@
+const test = require("node:test");
+const assert = require("node:assert/strict");
+
+const load = () => import("../../src/utils/billingSeatIntent.ts");
+
+function installLocalStorage() {
+ const values = new Map();
+ const previous = global.localStorage;
+ global.localStorage = {
+ getItem: (key) => values.get(key) ?? null,
+ setItem: (key, value) => values.set(key, String(value)),
+ removeItem: (key) => values.delete(key),
+ };
+ return {
+ restore: () => {
+ global.localStorage = previous;
+ },
+ };
+}
+
+test("readSeatIntent clears malformed stored JSON", async (t) => {
+ const { restore } = installLocalStorage();
+ t.after(restore);
+ const { readSeatIntent } = await load();
+
+ localStorage.setItem("settings.billingSeatIntent", "{not-json");
+
+ assert.equal(readSeatIntent(), null);
+ assert.equal(localStorage.getItem("settings.billingSeatIntent"), null);
+});