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

Method canEditInCollection

internal/server/server.go:4163–4186  ·  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

4161// could edit it, comment on it and create beside it. Outside their reach the
4162// grant decides, through ResolveUserPermission, and only 'edit' writes.
4163func (s *Server) canEditInCollection(r *http.Request, workspaceID, itemID, collectionID string) (bool, error) {
4164 role := workspaceRole(r)
4165 if role != "guest" && requireRole(r, "editor") {
4166 reaches, err := s.editorRoleReaches(r, workspaceID, collectionID)
4167 if err != nil {
4168 return false, err
4169 }
4170 if reaches {
4171 return true, nil
4172 }
4173 }
4174
4175 // Guests, viewers, and editors outside their collection access: the
4176 // grant cascade decides.
4177 user := currentUser(r)
4178 if user == nil {
4179 return false, nil
4180 }
4181 perm, err := s.store.ResolveUserPermission(workspaceID, user.ID, itemID, collectionID)
4182 if err != nil {
4183 return false, err
4184 }
4185 return permissionLevel(perm) >= permissionLevel("edit"), nil
4186}
4187
4188// editorRoleReaches reports whether the caller's editor/owner role applies to
4189// collectionID: always for a member with 'all' collection access, and for a

Callers 9

canReorderItemMethod · 0.95
requireEditPermissionMethod · 0.95
handleGetRoleQueueMethod · 0.95
decideAttachmentWriteMethod · 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