MCPcopy Create free account
hub / github.com/PerpetualSoftware/pad / canEditInCollection

Method canEditInCollection

internal/server/server.go:4105–4128  ·  view source on GitHub ↗

canEditInCollection is requireEditPermission's decision without the response, for callers that report per row (bulk) rather than per request. An editor or owner ROLE applies only inside the collections the member's access reaches (TASK-3376, PR #1756). Before it, the role short-circuited before the

(r *http.Request, workspaceID, itemID, collectionID string)

Source from the content-addressed store, hash-verified

4103// could edit it, comment on it and create beside it. Outside their reach the
4104// grant decides, through ResolveUserPermission, and only 'edit' writes.
4105func (s *Server) canEditInCollection(r *http.Request, workspaceID, itemID, collectionID string) (bool, error) {
4106 role := workspaceRole(r)
4107 if role != "guest" && requireRole(r, "editor") {
4108 reaches, err := s.editorRoleReaches(r, workspaceID, collectionID)
4109 if err != nil {
4110 return false, err
4111 }
4112 if reaches {
4113 return true, nil
4114 }
4115 }
4116
4117 // Guests, viewers, and editors outside their collection access: the
4118 // grant cascade decides.
4119 user := currentUser(r)
4120 if user == nil {
4121 return false, nil
4122 }
4123 perm, err := s.store.ResolveUserPermission(workspaceID, user.ID, itemID, collectionID)
4124 if err != nil {
4125 return false, err
4126 }
4127 return permissionLevel(perm) >= permissionLevel("edit"), nil
4128}
4129
4130// editorRoleReaches reports whether the caller's editor/owner role applies to
4131// collectionID: always for a member with 'all' collection access, and for a

Callers 7

canReorderItemMethod · 0.95
requireEditPermissionMethod · 0.95
appReadmitBeforeWriteMethod · 0.95
handleBulkItemsMethod · 0.95
bulkMoveCollectionMethod · 0.95

Calls 6

editorRoleReachesMethod · 0.95
workspaceRoleFunction · 0.85
requireRoleFunction · 0.85
currentUserFunction · 0.85
permissionLevelFunction · 0.85
ResolveUserPermissionMethod · 0.80

Tested by

no test coverage detected