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

Method commitmentOwnerQ

internal/server/commitment_access.go:19–33  ·  view source on GitHub ↗

commitmentOwnerQ reports whether the caller owns the workspace, by owner_id or by an owner membership, and returns that membership.

(r *http.Request, q store.Queryer, workspaceID string)

Source from the content-addressed store, hash-verified

17// commitmentOwnerQ reports whether the caller owns the workspace, by owner_id
18// or by an owner membership, and returns that membership.
19func (s *Server) commitmentOwnerQ(r *http.Request, q store.Queryer, workspaceID string) (bool, *models.WorkspaceMember, error) {
20 user := currentUser(r)
21 if user == nil {
22 return workspaceRole(r) == "owner", nil, nil
23 }
24 var ownerID string
25 if err := q.QueryRow(s.store.D().Rebind(`SELECT COALESCE(owner_id,'') FROM workspaces WHERE id=?`), workspaceID).Scan(&ownerID); err != nil {
26 return false, nil, err
27 }
28 member, err := s.store.GetWorkspaceMemberQ(q, workspaceID, user.ID)
29 if err != nil {
30 return false, nil, err
31 }
32 return ownerID == user.ID || (member != nil && member.Role == "owner"), member, nil
33}
34
35// commitmentOwnerRemoves is the one predicate for reaching past collection
36// restrictions and onto deleted ends. It applies only to removal, and an app

Callers 2

buildCommitmentAccessMethod · 0.95

Calls 7

currentUserFunction · 0.85
workspaceRoleFunction · 0.85
DMethod · 0.80
GetWorkspaceMemberQMethod · 0.80
ScanMethod · 0.65
QueryRowMethod · 0.65
RebindMethod · 0.65

Tested by

no test coverage detected