// SPDX-License-Identifier: AGPL-3.0-or-later package access import "docwell/server/internal/apperr" // Properties, tags and collections organize a workspace's pages. Anyone who // works in the workspace (members and above) may shape them; guests, who see // only pages shared with them, may only read them. // OrganizeWorkspace allows adding, renaming and removing a workspace's page // properties and tags, and making collections. func OrganizeWorkspace(wsRole string) error { switch { case wsRole == "": return apperr.NotFound("workspace not found") case !AtLeast(wsRole, WorkspaceMember): return apperr.Forbidden("guests cannot change the workspace's properties, tags or collections") } return nil } // EditCollection allows changing or deleting a collection: its creator may, // and workspace admins may change shared ones. func EditCollection(callerID, wsRole, creator string, shared bool) error { if err := OrganizeWorkspace(wsRole); err != nil { return err } if callerID == creator || (shared && AtLeast(wsRole, WorkspaceAdmin)) { return nil } return apperr.Forbidden("only the collection's creator can change it") } // KeepJournal allows having a journal in a workspace (members and above). func KeepJournal(wsRole string) error { return OrganizeWorkspace(wsRole) } // JournalSpaceRole is the caller's role in someone's journal space. It belongs // to its owner: workspace admins get no role from the cascade, so it stays // out of their sidebar and search. A role given in the space itself (the // owner's, or someone the owner added) still counts, and pages shared from it // are reached through page grants as usual. func JournalSpaceRole(wsRole, owner, callerID, memberRole string) string { switch { case wsRole == "": return "" case ValidSpaceRole(memberRole): return memberRole case owner == callerID: // The owner is the space's admin even if their membership row is gone. return SpaceAdmin } return "" }