fix: list publicly shared read-only notes in the Read Only view (#27637)

This commit is contained in:
G30 authored and GitHub committed 2026-08-17 01:40:56 -06:00
1 parent 44f4d5b94f
commit c0d09a5de9
1 file changed
+11 -18
+11 -18
View File
@@ -839,7 +839,8 @@ class AccessGrantsTable:
): ):
""" """
Filter for items where user has read BUT NOT write access. Filter for items where user has read BUT NOT write access.
Public items are NOT considered read_only. A public (user:*) read grant counts as read access, so publicly shared
read-only items are listed rather than being reachable only by direct link.
Note: This method builds SQLAlchemy expressions and does NOT perform I/O itself, Note: This method builds SQLAlchemy expressions and does NOT perform I/O itself,
so it remains synchronous. The caller is responsible for executing the query so it remains synchronous. The caller is responsible for executing the query
@@ -850,7 +851,6 @@ class AccessGrantsTable:
from sqlalchemy import exists as sa_exists from sqlalchemy import exists as sa_exists
# Has read grant (not public)
read_grant_exists = ( read_grant_exists = (
select(AccessGrant.id) select(AccessGrant.id)
.where( .where(
@@ -858,6 +858,10 @@ class AccessGrantsTable:
AccessGrant.resource_id == DocumentModel.id, AccessGrant.resource_id == DocumentModel.id,
AccessGrant.permission == 'read', AccessGrant.permission == 'read',
or_( or_(
and_(
AccessGrant.principal_type == 'user',
AccessGrant.principal_id == '*',
),
*( *(
[ [
and_( and_(
@@ -884,7 +888,6 @@ class AccessGrantsTable:
.exists() .exists()
) )
# Does NOT have write grant
write_grant_exists = ( write_grant_exists = (
select(AccessGrant.id) select(AccessGrant.id)
.where( .where(
@@ -892,6 +895,10 @@ class AccessGrantsTable:
AccessGrant.resource_id == DocumentModel.id, AccessGrant.resource_id == DocumentModel.id,
AccessGrant.permission == 'write', AccessGrant.permission == 'write',
or_( or_(
and_(
AccessGrant.principal_type == 'user',
AccessGrant.principal_id == '*',
),
*( *(
[ [
and_( and_(
@@ -918,21 +925,7 @@ class AccessGrantsTable:
.exists() .exists()
) )
# Is NOT public conditions = [read_grant_exists, ~write_grant_exists]
public_grant_exists = (
select(AccessGrant.id)
.where(
AccessGrant.resource_type == resource_type,
AccessGrant.resource_id == DocumentModel.id,
AccessGrant.permission == 'read',
AccessGrant.principal_type == 'user',
AccessGrant.principal_id == '*',
)
.correlate(DocumentModel)
.exists()
)
conditions = [read_grant_exists, ~write_grant_exists, ~public_grant_exists]
# Not owner # Not owner
if user_id: if user_id: