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(call): surface caller access level so the block badge is correct (#4790)

gbirman2ee90cac5cd8
diff --git a/apps/web/src/features/block-call/component/CallBlockAdapter.tsx b/apps/web/src/features/block-call/component/CallBlockAdapter.tsx
index 07d1e118ac..5ea79cdd27 100644
--- a/apps/web/src/features/block-call/component/CallBlockAdapter.tsx
+++ b/apps/web/src/features/block-call/component/CallBlockAdapter.tsx
@@ -2,25 +2,16 @@ import { globalSplitManager } from '@app/signal/splitLayout';
import { URL_PARAMS } from '@block-call/constants';
import { SidePanel } from '@components/app/side-panel';
import { useBlockId } from '@core/block';
-import Unauthorized from '@core/component/AccessErrorViews/Unauthorized';
+import { DocumentBlockContainer } from '@core/component/DocumentBlockContainer';
import { createMethodRegistration } from '@core/orchestrator';
import { blockHandleSignal } from '@core/signal/load';
-import { ThrownResultError } from '@core/util/result';
import { useCallRecordQuery } from '@queries/call/call';
import { useSearchParams } from '@solidjs/router';
-import { createSignal, Match, Switch } from 'solid-js';
+import { createSignal, Show } from 'solid-js';
import { CallRecordingBody } from './CallRecording/CallRecordingBody';
-import { CallRecordingSplitHeaderLoading } from './CallRecording/CallRecordingSplitHeader';
import { ModalsProvider } from './ModalsProvider';
import { CallSidePanelSections } from './sidepanel/CallSidePanelSections';
-function isUnauthorized(error: Error | null): boolean {
- if (error instanceof ThrownResultError) {
- return error.errors[0]?.code === 'UNAUTHORIZED';
- }
- return false;
-}
-
export type CallBlockProps = {
[URL_PARAMS.transcriptId]?: string;
};
@@ -60,11 +51,15 @@ export function CallBlockAdapter(props: CallBlockProps) {
},
});
+ // Loading / Unauthorized / not-found / error are rendered by
+ // DocumentBlockContainer from the block loader's result (like every other
+ // block). load() primes the record query, so callRecord.data is present
+ // whenever the container renders this content.
return (
- <ModalsProvider>
- <div class="h-full flex flex-col @container">
- <Switch>
- <Match when={callRecord.data}>
+ <DocumentBlockContainer>
+ <ModalsProvider>
+ <div class="h-full flex flex-col @container">
+ <Show when={callRecord.data}>
{(data) => (
<SidePanel.Layout>
<CallSidePanelSections record={data} />
@@ -76,27 +71,9 @@ export function CallBlockAdapter(props: CallBlockProps) {
</div>
</SidePanel.Layout>
)}
- </Match>
- <Match when={callRecord.isLoading}>
- <CallRecordingSplitHeaderLoading />
- <div class="flex flex-1 min-h-0 items-center justify-center text-sm text-ink-faint">
- Loading call...
- </div>
- </Match>
- <Match when={callRecord.isError && isUnauthorized(callRecord.error)}>
- <CallRecordingSplitHeaderLoading />
- <div class="flex flex-1 min-h-0 overflow-hidden">
- <Unauthorized />
- </div>
- </Match>
- <Match when={callRecord.isError}>
- <CallRecordingSplitHeaderLoading />
- <div class="flex flex-1 min-h-0 items-center justify-center text-sm text-failure">
- Failed to load call recording.
- </div>
- </Match>
- </Switch>
- </div>
- </ModalsProvider>
+ </Show>
+ </div>
+ </ModalsProvider>
+ </DocumentBlockContainer>
);
}
diff --git a/apps/web/src/features/block-call/definition.ts b/apps/web/src/features/block-call/definition.ts
index 37269a7631..8a29611ea5 100644
--- a/apps/web/src/features/block-call/definition.ts
+++ b/apps/web/src/features/block-call/definition.ts
@@ -1,6 +1,14 @@
-import { defineBlock, type ExtractLoadType, LoadErrors } from '@core/block';
+import {
+ defineBlock,
+ type ExtractLoadType,
+ LoadErrors,
+ loadResult,
+} from '@core/block';
import { ENABLE_CALLS } from '@core/constant/featureFlags';
-import { ok } from 'neverthrow';
+import { callKeys } from '@queries/call/keys';
+import { queryClient } from '@queries/client';
+import { callServiceClient } from '@service-call/client';
+import { err, ok } from 'neverthrow';
import { CallBlockAdapter } from './component/CallBlockAdapter';
@@ -11,10 +19,21 @@ export const definition = defineBlock({
component: CallBlockAdapter,
async load(source, _intent) {
if (!ENABLE_CALLS()) return LoadErrors.MISSING;
- if (source.type === 'dss') {
- return ok({ id: source.id });
- }
- return LoadErrors.MISSING;
+ if (source.type !== 'dss') return LoadErrors.MISSING;
+
+ const callId = source.id;
+ const result = await loadResult(callServiceClient.getCallRecord(callId));
+ if (result.isErr()) return err(result.error);
+ const record = result.value;
+
+ // Prime the record query so the component renders from cache without a
+ // second fetch, and return userAccessLevel so BlockLoader wires the header
+ // badge like every other block — no component-side permission plumbing.
+ queryClient.setQueryData(callKeys.record(callId).queryKey, record);
+ return ok({
+ id: callId,
+ userAccessLevel: record.userAccessLevel ?? undefined,
+ });
},
accepted: {},
});
diff --git a/apps/web/src/lib/queries/call/call.ts b/apps/web/src/lib/queries/call/call.ts
index 5df7027cc6..97b0b11946 100644
--- a/apps/web/src/lib/queries/call/call.ts
+++ b/apps/web/src/lib/queries/call/call.ts
@@ -151,6 +151,10 @@ export function useCallRecordQuery(callId: Accessor<string>) {
queryKey: callKeys.record(callId()).queryKey,
queryFn: async () =>
await throwOnErr(() => callServiceClient.getCallRecord(callId())),
+ // The call block's load() primes this cache; a stale time keeps that
+ // primed record from triggering an immediate duplicate fetch on mount.
+ // Mutations still invalidate, so sharing edits stay reactive.
+ staleTime: 60_000,
}));
}
diff --git a/apps/web/src/lib/service-clients/service-storage/generated/schemas/callRecord.ts b/apps/web/src/lib/service-clients/service-storage/generated/schemas/callRecord.ts
index eba96ca4c6..ddb40bb124 100644
--- a/apps/web/src/lib/service-clients/service-storage/generated/schemas/callRecord.ts
+++ b/apps/web/src/lib/service-clients/service-storage/generated/schemas/callRecord.ts
@@ -16,6 +16,7 @@ import type { CallRecordRecordingUrl } from './callRecordRecordingUrl';
import type { CallRecordStatus } from './callRecordStatus';
import type { CallRecordSummary } from './callRecordSummary';
import type { CallRecordTranscriptSegment } from './callRecordTranscriptSegment';
+import type { CallRecordUserAccessLevel } from './callRecordUserAccessLevel';
/**
* Full record of a call, unifying rows from `calls` (active) and
@@ -64,4 +65,5 @@ once summarization has run; active calls always return `None`. */
summary?: CallRecordSummary;
/** Transcript segments ordered by `sequence_num`. */
transcript: CallRecordTranscriptSegment[];
+ userAccessLevel?: CallRecordUserAccessLevel;
}
diff --git a/apps/web/src/lib/service-clients/service-storage/generated/schemas/callRecordUserAccessLevel.ts b/apps/web/src/lib/service-clients/service-storage/generated/schemas/callRecordUserAccessLevel.ts
new file mode 100644
index 0000000000..a3672b166a
--- /dev/null
+++ b/apps/web/src/lib/service-clients/service-storage/generated/schemas/callRecordUserAccessLevel.ts
@@ -0,0 +1,9 @@
+/**
+ * Generated by orval v7.21.0 🍺
+ * Do not edit manually.
+ * document_storage_service
+ * OpenAPI spec version: 0.1.0
+ */
+import type { AccessLevel } from './accessLevel';
+
+export type CallRecordUserAccessLevel = null | AccessLevel;
diff --git a/apps/web/src/lib/service-clients/service-storage/generated/schemas/index.ts b/apps/web/src/lib/service-clients/service-storage/generated/schemas/index.ts
index 7f7727acce..fcd126ae0c 100644
--- a/apps/web/src/lib/service-clients/service-storage/generated/schemas/index.ts
+++ b/apps/web/src/lib/service-clients/service-storage/generated/schemas/index.ts
@@ -175,6 +175,7 @@ export * from './callRecordTranscriptSegment';
export * from './callRecordTranscriptSegmentDiarizedSpeakerId';
export * from './callRecordTranscriptSegmentEndedAt';
export * from './callRecordTranscriptSegmentSegmentId';
+export * from './callRecordUserAccessLevel';
export * from './callStatus';
export * from './callTokenResponse';
export * from './channel';
diff --git a/apps/web/src/lib/service-clients/service-storage/generated/zod.ts b/apps/web/src/lib/service-clients/service-storage/generated/zod.ts
index b62a2466aa..7cc3d01160 100644
--- a/apps/web/src/lib/service-clients/service-storage/generated/zod.ts
+++ b/apps/web/src/lib/service-clients/service-storage/generated/zod.ts
@@ -1064,6 +1064,14 @@ export const getCallRecordResponse = zod
.describe('A transcript segment as returned in a [`CallRecord`].')
)
.describe('Transcript segments ordered by `sequence_num`.'),
+ userAccessLevel: zod
+ .union([
+ zod.null(),
+ zod
+ .enum(['view', 'comment', 'edit', 'owner'])
+ .describe('Ordered from least to most access top -> bottom'),
+ ])
+ .optional(),
})
.describe(
'Full record of a call, unifying rows from `calls` (active) and\n`call_records` (archived) into a single response shape.'
diff --git a/apps/web/src/lib/service-clients/service-storage/openapi.json b/apps/web/src/lib/service-clients/service-storage/openapi.json
index 437c1ee038..ee32f287cd 100644
--- a/apps/web/src/lib/service-clients/service-storage/openapi.json
+++ b/apps/web/src/lib/service-clients/service-storage/openapi.json
@@ -11196,6 +11196,17 @@
"$ref": "#/components/schemas/CallRecordTranscriptSegment"
},
"description": "Transcript segments ordered by `sequence_num`."
+ },
+ "userAccessLevel": {
+ "oneOf": [
+ {
+ "type": "null"
+ },
+ {
+ "$ref": "#/components/schemas/AccessLevel",
+ "description": "The caller's effective access level on this call. Set only on the\nsingle-record read; `None` in list contexts."
+ }
+ ]
}
}
},
diff --git a/crates/call/src/domain/models.rs b/crates/call/src/domain/models.rs
index c6e05659f1..7d4ed32828 100644
--- a/crates/call/src/domain/models.rs
+++ b/crates/call/src/domain/models.rs
@@ -9,6 +9,7 @@ use item_filters::{
};
use macro_user_id::user_id::MacroUserIdStr;
use models_pagination::{Query, SimpleSortMethod};
+use models_permissions::share_permission::access_level::AccessLevel;
use uuid::Uuid;
/// Represents an active call in a channel.
@@ -402,6 +403,10 @@ pub struct CallRecord {
/// Viewer-relative call status when fetched in the context of a specific user.
#[serde(skip_serializing_if = "Option::is_none")]
pub status: Option<CallStatus>,
+ /// The caller's effective access level on this call. Set only on the
+ /// single-record read; `None` in list contexts.
+ #[serde(skip_serializing_if = "Option::is_none")]
+ pub user_access_level: Option<AccessLevel>,
/// Participants (both active and historic).
pub participants: Vec<CallRecordParticipant>,
/// Transcript segments ordered by `sequence_num`.
diff --git a/crates/call/src/domain/service.rs b/crates/call/src/domain/service.rs
index 57c6350485..85c5f26922 100644
--- a/crates/call/src/domain/service.rs
+++ b/crates/call/src/domain/service.rs
@@ -5,7 +5,7 @@ mod test;
use connection::domain::ports::ConnectionService;
use entity_access::domain::models::{
- EditAccessLevel, EntityAccessReceipt, EntityType, ViewAccessLevel,
+ EditAccessLevel, EntityAccessReceipt, EntityPermission, EntityType, ViewAccessLevel,
};
use entity_access::domain::ports::EntityAccessService;
use macro_user_id::cowlike::CowLike;
@@ -1062,6 +1062,11 @@ impl<
.map_err(|e| CallError::Internal(e.into()))?
.ok_or_else(|| CallError::NotFound(call_id.to_string()))?;
+ record.user_access_level = match receipt.entity_permission() {
+ EntityPermission::AccessLevel { access_level } => Some(*access_level),
+ _ => None,
+ };
+
if let Some(recording_key) = &record.recording_key {
record.recording_url = self
.recording_storage
diff --git a/crates/call/src/outbound/pg_call_repo.rs b/crates/call/src/outbound/pg_call_repo.rs
index d17fd5cfaf..59631743cc 100644
--- a/crates/call/src/outbound/pg_call_repo.rs
+++ b/crates/call/src/outbound/pg_call_repo.rs
@@ -1157,6 +1157,7 @@ impl CallRepository for PgCallRepo {
tx.commit().await?;
return Ok(Some(CallRecord {
call_id: active.id,
+ user_access_level: None,
channel_id: active.channel_id,
room_name: active.room_name,
created_by: active.created_by,
@@ -1242,6 +1243,7 @@ impl CallRepository for PgCallRepo {
tx.commit().await?;
Ok(Some(CallRecord {
call_id: archived.id,
+ user_access_level: None,
channel_id: archived.channel_id,
room_name: archived.room_name,
created_by: archived.created_by,
@@ -1612,6 +1614,7 @@ impl CallRepository for PgCallRepo {
records.push(CallRecord {
call_id: row.call_id,
+ user_access_level: None,
channel_id: row.channel_id,
room_name: row.room_name,
created_by: row.created_by,
diff --git a/crates/models_soup/src/call_record/test.rs b/crates/models_soup/src/call_record/test.rs
index cb3f3635a5..28108bbdbe 100644
--- a/crates/models_soup/src/call_record/test.rs
+++ b/crates/models_soup/src/call_record/test.rs
@@ -35,6 +35,7 @@ fn record_with_participants(user_ids: &[&str]) -> CallRecord {
})
.collect(),
transcript: Vec::new(),
+ user_access_level: None,
}
}