Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(projects): offer Request access on a project without access (#9191)

gbirmana1308f24a674
diff --git a/apps/web/src/features/access-requests/access-requests.tsx b/apps/web/src/features/access-requests/access-requests.tsx
index 5f12d11706..74d38cdef3 100644
--- a/apps/web/src/features/access-requests/access-requests.tsx
+++ b/apps/web/src/features/access-requests/access-requests.tsx
@@ -43,41 +43,52 @@ export function AccessRequestError(props: { source: SharingSource }) {
);
}
-/** Request initial access from a denied file route without loading its metadata. */
-export function DocumentAccessDenied(props: {
- documentId: string;
+/** Request initial access from a denied route without loading the item. */
+export function AccessDenied(props: {
+ source: SharingSource;
+ noun?: string;
onAccessGranted: () => void;
}) {
const authenticated = useIsAuthenticated();
- const source = useShareRequests(
- () => shareEntity('document', props.documentId),
- () => true
- );
createEffect(
on(
- () => source.state()?.accessLevel,
+ () => props.source.state()?.accessLevel,
(level) => {
if (level) props.onAccessGranted();
}
)
);
return (
- <Unauthorized>
+ <Unauthorized noun={props.noun}>
<Show when={authenticated()}>
<div class="mt-6 flex w-full flex-col gap-3 text-sm">
- <Show when={source.loading()}>
+ <Show when={props.source.loading()}>
<span class="text-ink-muted">Loading access requests…</span>
</Show>
<RequestAccessView
- source={source}
+ source={props.source}
allowedLevels={['view', 'comment', 'edit']}
/>
- <PermissionRequestsView source={source} />
- <AccessRequestError source={source} />
+ <PermissionRequestsView source={props.source} />
+ <AccessRequestError source={props.source} />
</div>
</Show>
</Unauthorized>
);
}
+/** Request initial access from a denied file route without loading its metadata. */
+export function DocumentAccessDenied(props: {
+ documentId: string;
+ onAccessGranted: () => void;
+}) {
+ const source = useShareRequests(
+ () => shareEntity('document', props.documentId),
+ () => true
+ );
+ return (
+ <AccessDenied source={source} onAccessGranted={props.onAccessGranted} />
+ );
+}
+
export { useSharedAccessUpdates } from './queries/access-updates';
diff --git a/apps/web/src/features/projects/project-detail.tsx b/apps/web/src/features/projects/project-detail.tsx
index 506b1ca56d..22d87e6b18 100644
--- a/apps/web/src/features/projects/project-detail.tsx
+++ b/apps/web/src/features/projects/project-detail.tsx
@@ -24,7 +24,7 @@ import { fireAndForget } from '@core/util/fireAndForget';
import StackIcon from '@icon/system/regular/stack.svg';
import { SYSTEM_PROPERTY_IDS } from '@property/identifiers';
import type { Property } from '@property/types';
-import { Button, Tabs } from '@ui';
+import { Tabs } from '@ui';
import { createSignal, Match, Show, Suspense, Switch } from 'solid-js';
import type { TaskCreateOptions } from '../tasks-view/types';
import { DeleteProjectsDialog } from './components/delete-projects-dialog';
@@ -47,6 +47,7 @@ import { openProject } from './open-project';
import { ProjectDiscussion } from './project-collaboration';
import { ProjectDescription } from './project-description';
import { useProjectShareModal } from './project-share';
+import { ProjectUnavailable } from './project-unavailable';
import { Projects } from './projects';
import { ProjectWorkspace } from './views/project-workspace';
@@ -342,18 +343,11 @@ function ProjectDetailHost(props: ProjectDetailProps) {
)}
</Match>
<Match when={true}>
- <div role="alert" class="p-6">
- <p>
- Project unavailable. It may have been deleted, or you may no
- longer have access.
- </p>
- <Button
- variant="ghost"
- onClick={() => fireAndForget(source.refresh(), 'projects')}
- >
- Try again
- </Button>
- </div>
+ <ProjectUnavailable
+ projectId={props.route.id}
+ section={props.route.section}
+ onRetry={source.refresh}
+ />
</Match>
</Switch>
</Suspense>
diff --git a/apps/web/src/features/projects/project-unavailable.test.tsx b/apps/web/src/features/projects/project-unavailable.test.tsx
new file mode 100644
index 0000000000..3905b26b0f
--- /dev/null
+++ b/apps/web/src/features/projects/project-unavailable.test.tsx
@@ -0,0 +1,89 @@
+import type { SharingSource } from '@app/features/access-requests/context/contracts';
+import { fakeSharingSource } from '@app/features/access-requests/tests/source';
+import { cleanup, fireEvent, render } from '@solidjs/testing-library';
+import { createSignal } from 'solid-js';
+import { afterEach, expect, it, vi } from 'vitest';
+
+let source: SharingSource;
+vi.mock('@app/features/access-requests/queries/source', () => ({
+ createSharingSource: () => source,
+}));
+vi.mock('@core/auth', () => ({ useIsAuthenticated: () => () => true }));
+vi.mock('@core/context/user', () => ({ useEmail: () => () => undefined }));
+vi.mock('./components/project-skeletons', () => ({
+ ProjectContentSkeleton: () => <div aria-busy="true">Loading project</div>,
+}));
+
+import { ProjectUnavailable } from './project-unavailable';
+
+afterEach(cleanup);
+const projectId = '01992d2f-8444-7000-8000-000000000001';
+
+function renderUnavailable(onRetry = vi.fn(async () => {})) {
+ const view = render(() => (
+ <ProjectUnavailable
+ projectId={projectId}
+ section="overview"
+ onRetry={onRetry}
+ />
+ ));
+ return { ...view, onRetry };
+}
+
+it('lets a viewer without access request it and reloads the project once granted', async () => {
+ const fake = fakeSharingSource({ accessLevel: null });
+ source = fake.source;
+ const reload = Promise.withResolvers<void>();
+ const view = renderUnavailable(vi.fn(() => reload.promise));
+ expect(view.getByText("You don't have access to this project")).toBeTruthy();
+ expect(view.queryByRole('alert')).toBeNull();
+ fireEvent.click(view.getByRole('button', { name: 'Request access' }));
+ expect(source.submit).toHaveBeenCalledWith('view', undefined);
+ fake.setState((current) => ({ ...current, accessLevel: 'view' }));
+ expect(view.onRetry).toHaveBeenCalledOnce();
+ // The request view holds while the project reloads.
+ expect(view.getByText("You don't have access to this project")).toBeTruthy();
+ expect(view.queryByText(/Project unavailable/)).toBeNull();
+ // A reload that leaves the project unavailable offers Try again.
+ reload.resolve();
+ expect(await view.findByRole('button', { name: 'Try again' })).toBeTruthy();
+ expect(view.queryByText("You don't have access to this project")).toBeNull();
+});
+
+it('keeps the unavailable notice for a project whose request state cannot load', () => {
+ source = {
+ ...fakeSharingSource().source,
+ state: () => undefined,
+ error: () => 'Could not load access requests.',
+ };
+ const view = renderUnavailable();
+ expect(view.getByRole('alert').textContent).toContain('Project unavailable');
+ expect(view.queryByRole('button', { name: 'Request access' })).toBeNull();
+ fireEvent.click(view.getByRole('button', { name: 'Try again' }));
+ expect(view.onRetry).toHaveBeenCalledOnce();
+ expect(source.refresh).toHaveBeenCalledOnce();
+});
+
+it('keeps the unavailable notice when the viewer already has access', () => {
+ source = fakeSharingSource({ accessLevel: 'view' }).source;
+ const view = renderUnavailable();
+ expect(view.getByRole('alert').textContent).toContain('Project unavailable');
+ expect(view.queryByRole('button', { name: 'Request access' })).toBeNull();
+});
+
+it('shows the project skeleton until the request state decides the view', () => {
+ const [loading, setLoading] = createSignal(true);
+ const [loaded, setLoaded] = createSignal(false);
+ const fake = fakeSharingSource({ accessLevel: null });
+ source = {
+ ...fake.source,
+ state: () => (loaded() ? fake.source.state() : undefined),
+ loading,
+ };
+ const view = renderUnavailable();
+ expect(view.getByText('Loading project')).toBeTruthy();
+ expect(view.queryByRole('alert')).toBeNull();
+ setLoaded(true);
+ setLoading(false);
+ expect(view.getByRole('button', { name: 'Request access' })).toBeTruthy();
+});
diff --git a/apps/web/src/features/projects/project-unavailable.tsx b/apps/web/src/features/projects/project-unavailable.tsx
new file mode 100644
index 0000000000..0a4b4a76f2
--- /dev/null
+++ b/apps/web/src/features/projects/project-unavailable.tsx
@@ -0,0 +1,76 @@
+import {
+ AccessDenied,
+ useShareRequests,
+} from '@app/features/access-requests/access-requests';
+import { shareEntity } from '@app/features/access-requests/core/types';
+import { fireAndForget } from '@core/util/fireAndForget';
+import { Button } from '@ui';
+import { createMemo, createSignal, Match, Switch } from 'solid-js';
+import { ProjectContentSkeleton } from './components/project-skeletons';
+import type { ProjectSection } from './core/project';
+
+/**
+ * A project that did not load. Its access-request state loads only while the
+ * project exists, so a viewer without access can request it and a deleted
+ * project keeps the unavailable notice.
+ */
+export function ProjectUnavailable(props: {
+ projectId: string;
+ section: ProjectSection;
+ onRetry(): Promise<void>;
+}) {
+ const requests = useShareRequests(
+ () => shareEntity('initiative', props.projectId),
+ () => true
+ );
+ const [reloadedId, setReloadedId] = createSignal<string>();
+ // Stays denied after a grant, so the request view holds while the project
+ // reloads; a reload that settles without the project falls back to Try again.
+ const deniedId = createMemo<string | undefined>((denied) => {
+ const state = requests.state();
+ if (state && state.accessLevel == null) return props.projectId;
+ return denied === props.projectId && reloadedId() !== props.projectId
+ ? denied
+ : undefined;
+ });
+ const reloadGranted = async () => {
+ const projectId = props.projectId;
+ try {
+ await props.onRetry();
+ } finally {
+ setReloadedId(projectId);
+ }
+ };
+ const retry = async () => {
+ await Promise.all([props.onRetry(), requests.refresh()]);
+ };
+ return (
+ <Switch
+ fallback={
+ <div role="alert" class="p-6">
+ <p>
+ Project unavailable. It may have been deleted, or you may no longer
+ have access.
+ </p>
+ <Button
+ variant="ghost"
+ onClick={() => fireAndForget(retry(), 'projects')}
+ >
+ Try again
+ </Button>
+ </div>
+ }
+ >
+ <Match when={deniedId()}>
+ <AccessDenied
+ source={requests}
+ noun="project"
+ onAccessGranted={() => fireAndForget(reloadGranted(), 'projects')}
+ />
+ </Match>
+ <Match when={requests.loading()}>
+ <ProjectContentSkeleton section={props.section} />
+ </Match>
+ </Switch>
+ );
+}
diff --git a/docs/agent-guide/tasks.md b/docs/agent-guide/tasks.md
index 635771af5c..b974269f99 100644
--- a/docs/agent-guide/tasks.md
+++ b/docs/agent-guide/tasks.md
@@ -771,6 +771,11 @@ editor inserts a project mention. A link to a project discussion stays a link.
Project properties live in the shared floating information panel and honor
project access. Editors can rename the project; its owner can delete it.
Deleting a project leaves its tasks in the workspace.
+Opening a project without access shows `You don't have access to this project`
+with the same Request access row and access level as documents. The owner
+reviews it under Share's `Permission requests`, and once granted the open
+project loads in place. Losing access while the project is open switches to
+that view. A deleted project shows `Project unavailable` with Try again.
Project information panels start closed and float over the content at every
width, both in the Tasks project view and standalone initiative blocks. Opening