Skip to content

Commit

Permalink
onedrive: skip writing permissions with 'owner' role
Browse files Browse the repository at this point in the history
The 'owner' role is an implicit role that can't be removed, so don't try to.
  • Loading branch information
nielash authored and ncw committed May 10, 2024
1 parent 41d5d8b commit 76cea0c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 5 additions & 1 deletion backend/onedrive/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ func (m *Metadata) sortPermissions() (add, update, remove []*api.PermissionsType
if n.ID != "" {
// sanity check: ensure there's a matching "old" id with a non-matching role
if !slices.ContainsFunc(old, func(o *api.PermissionsType) bool {
return o.ID == n.ID && slices.Compare(o.Roles, n.Roles) != 0 && len(o.Roles) > 0 && len(n.Roles) > 0
return o.ID == n.ID && slices.Compare(o.Roles, n.Roles) != 0 && len(o.Roles) > 0 && len(n.Roles) > 0 && !slices.Contains(o.Roles, api.OwnerRole)
}) {
fs.Debugf(m.remote, "skipping update for invalid roles: %v (perm ID: %v)", n.Roles, n.ID)
continue
Expand All @@ -418,6 +418,10 @@ func (m *Metadata) sortPermissions() (add, update, remove []*api.PermissionsType
}
}
for _, o := range old {
if slices.Contains(o.Roles, api.OwnerRole) {
fs.Debugf(m.remote, "skipping remove permission -- can't remove 'owner' role")
continue
}
newHasOld := slices.ContainsFunc(new, func(n *api.PermissionsType) bool {
if n == nil || n.ID == "" {
return false // can't remove perms without an ID
Expand Down
3 changes: 2 additions & 1 deletion backend/onedrive/metadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ To update an existing permission, include both the Permission ID and the new
`roles` to be assigned. `roles` is the only property that can be changed.

To remove permissions, pass in a blob containing only the permissions you wish
to keep (which can be empty, to remove all.)
to keep (which can be empty, to remove all.) Note that the `owner` role will be
ignored, as it cannot be removed.

Note that both reading and writing permissions requires extra API calls, so if
you don't need to read or write permissions it is recommended to omit
Expand Down

0 comments on commit 76cea0c

Please sign in to comment.