Sharing backend: shares CRUD + ACL enforcement everywhere (#16)
Build image / build-and-push (push) Successful in 4s

Co-authored-by: Steve Dudenhoeffer <[email protected]>
This commit was merged in pull request #35.
This commit is contained in:
2026-07-19 03:49:54 +00:00
committed by steve
parent 48ba08e8f2
commit 2a86f87b50
11 changed files with 733 additions and 24 deletions
+26
View File
@@ -21,6 +21,17 @@ var (
// reference it (the FK is ON DELETE RESTRICT). Mapped to 409.
ErrPlantInUse = errors.New("plant is referenced by plantings")
// ErrShareUserNotFound means no account exists for the email a share invite
// targeted (v1 shares an existing user only — no invitation emails). Mapped to
// 404 with a clear "no account with that email" message.
ErrShareUserNotFound = errors.New("no account with that email")
// ErrCannotShareWithSelf means the owner tried to share a garden with their
// own account. Mapped to 400.
ErrCannotShareWithSelf = errors.New("cannot share a garden with yourself")
// ErrShareExists means the garden is already shared with that user. Mapped to
// 409 (change the existing share's role instead).
ErrShareExists = errors.New("garden already shared with that user")
// ErrInvalidInput means the caller supplied structurally invalid data (empty
// required field, malformed value). Mapped to 400.
ErrInvalidInput = errors.New("invalid input")
@@ -60,6 +71,9 @@ const (
RoleViewer = "viewer"
RoleEditor = "editor"
// RoleOwner is not a garden_shares row (ownership is implicit via
// gardens.owner_id); it's the value Garden.MyRole carries for an owner.
RoleOwner = "owner"
KindBed = "bed"
KindGrowBag = "grow_bag"
@@ -116,6 +130,10 @@ type Garden struct {
Version int64 `json:"version"`
CreatedAt string `json:"createdAt"`
UpdatedAt string `json:"updatedAt"`
// MyRole is the requesting actor's effective role on this garden ("owner",
// "editor", or "viewer"). Computed by the service, never persisted.
MyRole string `json:"myRole,omitempty"`
}
// GardenShare grants a non-owner user viewer or editor access to a garden.
@@ -130,6 +148,14 @@ type GardenShare struct {
UpdatedAt string `json:"updatedAt"`
}
// ShareWithUser is a garden share plus the target user's identity, for the
// sharing UI's list (which shows who a garden is shared with).
type ShareWithUser struct {
GardenShare
Email string `json:"email"`
DisplayName string `json:"displayName"`
}
// GardenObject is any placeable object in a garden (bed, container, tree, path…).
// Positioned by center point + rotation about center, in garden space.
type GardenObject struct {