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(access-requests): report the recorded owner as owner and restore task creators' grants (#9155)

gbirman9aa2c2a8740a
diff --git a/crates/access_requests/AGENTS.md b/crates/access_requests/AGENTS.md
index 23e058ed5d..03e3fd7740 100644
--- a/crates/access_requests/AGENTS.md
+++ b/crates/access_requests/AGENTS.md
@@ -19,6 +19,10 @@ the durable notification/realtime dispatcher.
- Asking for initial access cannot require an existing View receipt. Request
state hides owner details and other people's requests from ordinary callers
without access; recorded reviewers can review without a separate View grant.
+- Request state reports Owner for the recorded user owner of a document, chat,
+ or folder, whatever that owner's grant row says, because those entities' read
+ extractors do the same. The web app compares the two levels and reloads on a
+ mismatch.
- Notification delivery is composed in document storage. Stable event IDs and
durable withdrawal prevent delayed delivery from resurrecting old requests.
diff --git a/crates/access_requests/src/domain/service.rs b/crates/access_requests/src/domain/service.rs
index f6405a69ae..1be7dbdc9c 100644
--- a/crates/access_requests/src/domain/service.rs
+++ b/crates/access_requests/src/domain/service.rs
@@ -122,6 +122,16 @@ impl<R: RequestRepository, A: EntityAccessService, C: Clock> AccessRequestServic
) -> Result<(R::Transaction, Option<AccessLevel>), RequestError> {
let level = self.level(user, entity).await?;
let tx = self.repository.begin(entity).await?;
+ // Document, chat, and folder reads grant their recorded owner Owner before
+ // consulting grants, so request state must agree even when the owner's
+ // grant row says less.
+ let level = match (&tx.facts().owner, entity.entity_type) {
+ (
+ Owner::User(owner),
+ ShareEntityType::Document | ShareEntityType::Chat | ShareEntityType::Project,
+ ) if owner == user => Some(AccessLevel::Owner),
+ _ => level,
+ };
Ok((tx, level))
}
fn require_reviewer(
diff --git a/crates/access_requests/tests/workflow.rs b/crates/access_requests/tests/workflow.rs
index b2f2b34e67..eb0ea15365 100644
--- a/crates/access_requests/tests/workflow.rs
+++ b/crates/access_requests/tests/workflow.rs
@@ -573,6 +573,38 @@ async fn folder_grants_propagate_without_overwriting_direct_child_access(pool: P
);
}
+#[sqlx::test(migrator = "MACRO_DB_MIGRATIONS", fixtures("document"))]
+async fn recorded_owner_reports_owner_access_over_its_grant_row(pool: PgPool) {
+ sqlx::query!(
+ "UPDATE entity_access SET access_level = 'edit' WHERE source_id = 'macro|[email protected]'"
+ )
+ .execute(&pool)
+ .await
+ .unwrap();
+ let (s, _) = setup(pool.clone());
+ let owner = s.state(user("owner"), entity(), 0).await.unwrap();
+ assert_eq!(owner.access_level, Some(AccessLevel::Owner));
+ assert!(owner.can_review);
+ sqlx::query!("DELETE FROM entity_access WHERE source_id = 'macro|[email protected]'")
+ .execute(&pool)
+ .await
+ .unwrap();
+ assert_eq!(
+ s.state(user("owner"), entity(), 0)
+ .await
+ .unwrap()
+ .access_level,
+ Some(AccessLevel::Owner)
+ );
+ assert_eq!(
+ s.state(user("reader"), entity(), 0)
+ .await
+ .unwrap()
+ .access_level,
+ Some(AccessLevel::View)
+ );
+}
+
#[sqlx::test(migrator = "MACRO_DB_MIGRATIONS", fixtures("document"))]
async fn bot_sponsor_can_review_without_a_separate_user_grant(pool: PgPool) {
sqlx::query!("INSERT INTO bots (id, kind, owner_user_id, name, handle) VALUES ('00000000-0000-0000-0000-000000000020', 'owned', 'macro|[email protected]', 'Owner bot', 'request-owner')")
diff --git a/crates/macro_db_client/migrations/20261029215933_restore_task_owner_grants.sql b/crates/macro_db_client/migrations/20261029215933_restore_task_owner_grants.sql
new file mode 100644
index 0000000000..34cc006c57
--- /dev/null
+++ b/crates/macro_db_client/migrations/20261029215933_restore_task_owner_grants.sql
@@ -0,0 +1,18 @@
+-- Until 2026-09-11 the task-assignee grant ran a bulk user upsert whose owner
+-- guard sat in the conflict target, where it only steers index inference. A
+-- creator who assigned a task to themselves had their own direct row rewritten
+-- from owner to edit. Document reads still report the recorded owner as owner,
+-- but every reader of the grant table sees an editor. Raise those direct rows
+-- back to owner. Owners with no direct row at all are older, mostly
+-- folder-granted data with a different history, and are left alone.
+SET LOCAL lock_timeout = '5s';
+
+UPDATE entity_access ea
+SET access_level = 'owner', updated_at = NOW()
+FROM "Document" d
+WHERE ea.entity_type = 'document'
+ AND ea.source_type = 'user'
+ AND ea.granted_from_project_id IS NULL
+ AND ea.entity_id::text = d.id
+ AND ea.source_id = d.owner
+ AND ea.access_level <> 'owner';