Files
Docwell/Server/internal/apperr/apperr.go
T
tajniak81andClaude Opus 5.5 03f3434c10 Add organizations with cascading user rights
Same model as DriverVault, with organizations above workspaces:

- users get a role (user, admin, superadmin) and at most one
  organization; existing instance admins become superadmins
- rights cascade: superadmins own everything, org admins own their
  organization's workspaces, others get their workspace role
  (owner > admin > member > guest) while they stay in the org
- nobody grants a role above their own, acts on someone ranked above
  them, or changes their own role; rules live in internal/access as
  pure, tested functions
- self-service organizations: an org-less user creates one and becomes
  its admin; the last admin can delete it and is demoted
- endpoints for users, orgs, workspaces and members; token cache is
  dropped when a user's rights change
- admin panel: Users and Organizations pages scoped to the caller
- web app: organization page, workspace list, workspace settings with
  member management (EN/PL)
- fix: organization name missing after login/refresh, and stale tokens
  redirecting public pages to sign-in

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-30 22:53:11 +01:00

44 lines
1.2 KiB
Go

// Package apperr defines the errors business logic returns to the HTTP layer:
// each carries an HTTP-friendly kind, a stable code and a human message.
package apperr
import "errors"
type Kind int
const (
KindInvalid Kind = iota + 1
KindForbidden
KindNotFound
KindConflict
)
type Error struct {
Kind Kind
Code string
Message string
// Fields holds per-field messages for KindInvalid.
Fields map[string]string
}
func (e *Error) Error() string { return e.Code + ": " + e.Message }
func Forbidden(msg string) *Error {
return &Error{Kind: KindForbidden, Code: "forbidden", Message: msg}
}
func NotFound(msg string) *Error { return &Error{Kind: KindNotFound, Code: "not_found", Message: msg} }
func Conflict(msg string) *Error { return &Error{Kind: KindConflict, Code: "conflict", Message: msg} }
func Invalid(msg string) *Error { return &Error{Kind: KindInvalid, Code: "invalid", Message: msg} }
// InvalidFields is a validation error with a message per field.
func InvalidFields(fields map[string]string) *Error {
return &Error{Kind: KindInvalid, Code: "validation", Message: "validation failed", Fields: fields}
}
// As returns err as an *Error when it is one.
func As(err error) (*Error, bool) {
var e *Error
ok := errors.As(err, &e)
return e, ok
}