Skip to content

feat(sharings): Add effective access resolver#4857

Merged
taratatach merged 3 commits into
masterfrom
feat/add-effective-access-resolver-for-nested-shared-folders
Jul 21, 2026
Merged

feat(sharings): Add effective access resolver#4857
taratatach merged 3 commits into
masterfrom
feat/add-effective-access-resolver-for-nested-shared-folders

Conversation

@taratatach

Copy link
Copy Markdown
Contributor

Add AccessResolver to compute the effective access to a file or
folder from the additive sharing scopes on its path. Resolve(targetID)
returns an *EffectiveAccess with CanRead/CanWrite aggregated
highest-wins across all active additive scopes where the current
instance is a member (via Sharing.MemberFor). The target's own
share (for shared files) and every shared ancestor directory are
considered. EffectiveAccess.Can(verb) maps GET to CanRead and
the write verbs to CanWrite. limited_access scopes are filtered
out in v1; NearestRestrictiveBoundary and ChildSharedRootsUnder
are reserved as no-op stubs for that future mode.

Fixes #4837

@taratatach taratatach self-assigned this Jul 21, 2026
@taratatach
taratatach requested a review from shepilov July 21, 2026 09:53
}
kept := make([]*Sharing, 0, len(sharings))
for _, s := range sharings {
if !s.Active {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should filter here also to only drive shares if we don't care about classical ones, and for classical ones we can have read-only rules

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the current implementation of the resolver makes much sense for drive shares as we built scopes from local vfs docs and their references to sharings while we don't have these docs on drives recipients (and the owner always has full access).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed, we'll need more to check permission for drives recipient members but it's planned in the next issue.

Comment thread model/sharing/effective_access.go
Comment thread model/sharing/sharing.go
  Nested shared folders need an explicit access mode to distinguish
  additive inheritance (the default, where parent access applies to
  children) from the future `limited_access` mode (a restrictive
  boundary). Add `AccessMode` field on `Sharing` with constants
  `AccessModeAdditive` and `AccessModeLimitedAccess`. The
  `EffectiveAccessMode()` method returns `additive` when the field is
  empty for backwards compatibility with existing sharings.
  Add `Sharing.MemberFor(inst)` to resolve the member of a sharing
  that corresponds to a given instance (the owner entry on the owner's
  Cozy, the matching recipient entry on a recipient's Cozy), or nil
  if the instance is not a member. Revoked members are not returned.
  `checkSharedDrivePermission` (web/sharings/drives.go) replicates
  similar logic but does not skip revoked members — a potential latent
  bug that will be addressed separately later.
  Add `AccessResolver` to compute the effective access to a file or
  folder from the additive sharing scopes on its path. `Resolve(targetID)`
  returns an `*EffectiveAccess` with `CanRead`/`CanWrite` aggregated
  highest-wins across all active additive scopes where the current
  instance is a member (via `Sharing.MemberFor`). The target's own
  share (for shared files) and every shared ancestor directory are
  considered. `EffectiveAccess.Can(verb)` maps `GET` to `CanRead` and
  the write verbs to `CanWrite`. `limited_access` scopes are filtered
  out in v1; `NearestRestrictiveBoundary` and `ChildSharedRootsUnder`
  are reserved as no-op stubs for that future mode.
@taratatach
taratatach force-pushed the feat/add-effective-access-resolver-for-nested-shared-folders branch from fc236de to b0d7542 Compare July 21, 2026 14:47
@taratatach
taratatach merged commit f769173 into master Jul 21, 2026
4 checks passed
@taratatach
taratatach deleted the feat/add-effective-access-resolver-for-nested-shared-folders branch July 21, 2026 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add effective access resolver for additive nested shared folders

2 participants