Documentation
¶
Index ¶
- Variables
- func IsPermissionSetInUse(err error) bool
- func IsPermissionSetNotFound(err error) bool
- func IsPermissionSetSlugExists(err error) bool
- func IsSystemSetImmutable(err error) bool
- type Item
- type ListFilter
- type ModificationType
- type PermissionSet
- func NewClonedPermissionSet(tenantID shared.ID, name, slug, description string, parentSetID shared.ID, ...) (*PermissionSet, error)
- func NewExtendedPermissionSet(tenantID shared.ID, name, slug, description string, parentSetID shared.ID) (*PermissionSet, error)
- func NewPermissionSet(tenantID shared.ID, name, slug, description string) (*PermissionSet, error)
- func Reconstitute(id shared.ID, tenantID *shared.ID, name, slug, description string, ...) *PermissionSet
- func (ps *PermissionSet) Activate()
- func (ps *PermissionSet) CanModify() bool
- func (ps *PermissionSet) ClonedFromVersion() *int
- func (ps *PermissionSet) CreatedAt() time.Time
- func (ps *PermissionSet) Deactivate()
- func (ps *PermissionSet) Description() string
- func (ps *PermissionSet) HasParent() bool
- func (ps *PermissionSet) ID() shared.ID
- func (ps *PermissionSet) IsActive() bool
- func (ps *PermissionSet) IsCloned() bool
- func (ps *PermissionSet) IsCustom() bool
- func (ps *PermissionSet) IsExtended() bool
- func (ps *PermissionSet) IsSystem() bool
- func (ps *PermissionSet) Name() string
- func (ps *PermissionSet) ParentSetID() *shared.ID
- func (ps *PermissionSet) SetType() SetType
- func (ps *PermissionSet) Slug() string
- func (ps *PermissionSet) TenantID() *shared.ID
- func (ps *PermissionSet) UpdateDescription(description string)
- func (ps *PermissionSet) UpdateName(name string) error
- func (ps *PermissionSet) UpdatedAt() time.Time
- type PermissionSetWithItems
- type Repository
- type SetType
- type Version
- type VersionChanges
Constants ¶
This section is empty.
Variables ¶
var ( ErrPermissionSetNotFound = fmt.Errorf("%w: permission set not found", shared.ErrNotFound) ErrPermissionSetSlugExists = fmt.Errorf("%w: permission set slug already exists", shared.ErrAlreadyExists) ErrSystemSetImmutable = fmt.Errorf("%w: system permission sets cannot be modified", shared.ErrForbidden) ErrParentNotFound = fmt.Errorf("%w: parent permission set not found", shared.ErrNotFound) ErrCircularInheritance = fmt.Errorf("%w: circular inheritance detected", shared.ErrValidation) ErrInvalidPermission = fmt.Errorf("%w: invalid permission ID", shared.ErrValidation) ErrPermissionAlreadyInSet = fmt.Errorf("%w: permission already in set", shared.ErrAlreadyExists) ErrPermissionNotInSet = fmt.Errorf("%w: permission not in set", shared.ErrNotFound) ErrVersionConflict = fmt.Errorf("%w: version conflict", shared.ErrConflict) ErrInactivePermissionSet = fmt.Errorf("%w: permission set is inactive", shared.ErrValidation) ErrCannotDeleteSystemSet = fmt.Errorf("%w: cannot delete system permission set", shared.ErrForbidden) ErrPermissionSetInUse = fmt.Errorf("%w: permission set is in use by groups", shared.ErrConflict) )
Domain errors for permission sets.
Functions ¶
func IsPermissionSetInUse ¶
IsPermissionSetInUse checks if the error is a permission set in use error.
func IsPermissionSetNotFound ¶
IsPermissionSetNotFound checks if the error is a not found error.
func IsPermissionSetSlugExists ¶
IsPermissionSetSlugExists checks if the error is a slug exists error.
func IsSystemSetImmutable ¶
IsSystemSetImmutable checks if the error is a system set immutable error.
Types ¶
type Item ¶
type Item struct {
// contains filtered or unexported fields
}
Item represents a permission included in a permission set.
func NewItem ¶
func NewItem(permissionSetID shared.ID, permissionID string, modType ModificationType) (*Item, error)
NewItem creates a new permission set item.
func ReconstituteItem ¶
func ReconstituteItem(permissionSetID shared.ID, permissionID string, modType ModificationType) *Item
ReconstituteItem recreates an Item from persistence.
func (*Item) ModificationType ¶
func (i *Item) ModificationType() ModificationType
ModificationType returns the modification type.
func (*Item) PermissionID ¶
PermissionID returns the permission ID.
func (*Item) PermissionSetID ¶
PermissionSetID returns the permission set ID.
type ListFilter ¶
type ListFilter struct {
// Tenant filter
TenantID *shared.ID // nil = system only, non-nil = tenant + system
IncludeSystem bool // Include system templates when filtering by tenant
// Type filters
SetTypes []SetType
// Search
Search string // Search in name, slug, description
// Status filter
IsActive *bool
// Parent filter
ParentSetID *shared.ID
// Pagination
Limit int
Offset int
// Sorting
OrderBy string // "name", "created_at", "updated_at"
OrderDesc bool
}
ListFilter contains filter options for listing permission sets.
func DefaultListFilter ¶
func DefaultListFilter() ListFilter
DefaultListFilter returns a default filter.
func SystemOnlyFilter ¶
func SystemOnlyFilter() ListFilter
SystemOnlyFilter returns a filter for system permission sets only.
type ModificationType ¶
type ModificationType string
ModificationType represents the type of permission modification.
const ( // ModificationAdd adds a permission. ModificationAdd ModificationType = "add" // ModificationRemove removes a permission. ModificationRemove ModificationType = "remove" )
func AllModificationTypes ¶
func AllModificationTypes() []ModificationType
AllModificationTypes returns all valid modification types.
func (ModificationType) IsValid ¶
func (m ModificationType) IsValid() bool
IsValid checks if the modification type is valid.
func (ModificationType) String ¶
func (m ModificationType) String() string
String returns the string representation.
type PermissionSet ¶
type PermissionSet struct {
// contains filtered or unexported fields
}
PermissionSet represents a reusable bundle of permissions.
func NewClonedPermissionSet ¶
func NewClonedPermissionSet(tenantID shared.ID, name, slug, description string, parentSetID shared.ID, sourceVersion int) (*PermissionSet, error)
NewClonedPermissionSet creates a permission set cloned from a parent.
func NewExtendedPermissionSet ¶
func NewExtendedPermissionSet(tenantID shared.ID, name, slug, description string, parentSetID shared.ID) (*PermissionSet, error)
NewExtendedPermissionSet creates a permission set that extends a parent.
func NewPermissionSet ¶
func NewPermissionSet(tenantID shared.ID, name, slug, description string) (*PermissionSet, error)
NewPermissionSet creates a new custom permission set.
func Reconstitute ¶
func Reconstitute( id shared.ID, tenantID *shared.ID, name, slug, description string, setType SetType, parentSetID *shared.ID, clonedFromVersion *int, isActive bool, createdAt, updatedAt time.Time, ) *PermissionSet
Reconstitute recreates a PermissionSet from persistence.
func (*PermissionSet) Activate ¶
func (ps *PermissionSet) Activate()
Activate activates the permission set.
func (*PermissionSet) CanModify ¶
func (ps *PermissionSet) CanModify() bool
CanModify checks if this permission set can be modified. System templates cannot be modified by tenants.
func (*PermissionSet) ClonedFromVersion ¶
func (ps *PermissionSet) ClonedFromVersion() *int
ClonedFromVersion returns the version this set was cloned from.
func (*PermissionSet) CreatedAt ¶
func (ps *PermissionSet) CreatedAt() time.Time
CreatedAt returns the creation timestamp.
func (*PermissionSet) Deactivate ¶
func (ps *PermissionSet) Deactivate()
Deactivate deactivates the permission set.
func (*PermissionSet) Description ¶
func (ps *PermissionSet) Description() string
Description returns the permission set description.
func (*PermissionSet) HasParent ¶
func (ps *PermissionSet) HasParent() bool
HasParent checks if this set has a parent.
func (*PermissionSet) ID ¶
func (ps *PermissionSet) ID() shared.ID
ID returns the permission set ID.
func (*PermissionSet) IsActive ¶
func (ps *PermissionSet) IsActive() bool
IsActive returns whether the permission set is active.
func (*PermissionSet) IsCloned ¶
func (ps *PermissionSet) IsCloned() bool
IsCloned checks if this is a cloned set.
func (*PermissionSet) IsCustom ¶
func (ps *PermissionSet) IsCustom() bool
IsCustom checks if this is a custom set.
func (*PermissionSet) IsExtended ¶
func (ps *PermissionSet) IsExtended() bool
IsExtended checks if this is an extended set.
func (*PermissionSet) IsSystem ¶
func (ps *PermissionSet) IsSystem() bool
IsSystem checks if this is a system template.
func (*PermissionSet) Name ¶
func (ps *PermissionSet) Name() string
Name returns the permission set name.
func (*PermissionSet) ParentSetID ¶
func (ps *PermissionSet) ParentSetID() *shared.ID
ParentSetID returns the parent permission set ID (if any).
func (*PermissionSet) SetType ¶
func (ps *PermissionSet) SetType() SetType
SetType returns the type of permission set.
func (*PermissionSet) Slug ¶
func (ps *PermissionSet) Slug() string
Slug returns the permission set slug.
func (*PermissionSet) TenantID ¶
func (ps *PermissionSet) TenantID() *shared.ID
TenantID returns the tenant ID (nil for system templates).
func (*PermissionSet) UpdateDescription ¶
func (ps *PermissionSet) UpdateDescription(description string)
UpdateDescription updates the permission set description.
func (*PermissionSet) UpdateName ¶
func (ps *PermissionSet) UpdateName(name string) error
UpdateName updates the permission set name.
func (*PermissionSet) UpdatedAt ¶
func (ps *PermissionSet) UpdatedAt() time.Time
UpdatedAt returns the last update timestamp.
type PermissionSetWithItems ¶
type PermissionSetWithItems struct {
PermissionSet *PermissionSet
Items []*Item
}
PermissionSetWithItems represents a permission set with its items.
func (*PermissionSetWithItems) EffectivePermissions ¶
func (ps *PermissionSetWithItems) EffectivePermissions() []permission.Permission
EffectivePermissions returns the effective permissions for this set. For custom/system sets: returns all added permissions. For extended sets: caller must resolve with parent permissions.
type Repository ¶
type Repository interface {
// Permission Set CRUD
Create(ctx context.Context, ps *PermissionSet) error
GetByID(ctx context.Context, id shared.ID) (*PermissionSet, error)
// GetByTenantAndID retrieves a permission set by tenant and ID.
GetByTenantAndID(ctx context.Context, tenantID, id shared.ID) (*PermissionSet, error)
GetBySlug(ctx context.Context, tenantID *shared.ID, slug string) (*PermissionSet, error)
Update(ctx context.Context, ps *PermissionSet) error
Delete(ctx context.Context, id shared.ID) error
// Permission Set queries
List(ctx context.Context, filter ListFilter) ([]*PermissionSet, error)
Count(ctx context.Context, filter ListFilter) (int64, error)
ExistsBySlug(ctx context.Context, tenantID *shared.ID, slug string) (bool, error)
ListByIDs(ctx context.Context, ids []shared.ID) ([]*PermissionSet, error)
ListSystemSets(ctx context.Context) ([]*PermissionSet, error)
ListByTenant(ctx context.Context, tenantID shared.ID, includeSystem bool) ([]*PermissionSet, error)
// Permission Set Items
AddItem(ctx context.Context, item *Item) error
RemoveItem(ctx context.Context, permissionSetID shared.ID, permissionID string) error
ListItems(ctx context.Context, permissionSetID shared.ID) ([]*Item, error)
GetWithItems(ctx context.Context, id shared.ID) (*PermissionSetWithItems, error)
BatchAddItems(ctx context.Context, items []*Item) error
ReplaceItems(ctx context.Context, permissionSetID shared.ID, items []*Item) error
// Version tracking
CreateVersion(ctx context.Context, version *Version) error
GetLatestVersion(ctx context.Context, permissionSetID shared.ID) (*Version, error)
ListVersions(ctx context.Context, permissionSetID shared.ID) ([]*Version, error)
// Inheritance queries
GetParent(ctx context.Context, permissionSetID shared.ID) (*PermissionSet, error)
ListChildren(ctx context.Context, parentSetID shared.ID) ([]*PermissionSet, error)
GetInheritanceChain(ctx context.Context, permissionSetID shared.ID) ([]*PermissionSet, error)
// Usage queries (for deletion checks)
CountGroupsUsing(ctx context.Context, permissionSetID shared.ID) (int64, error)
ListGroupIDsUsing(ctx context.Context, permissionSetID shared.ID) ([]shared.ID, error)
}
Repository defines the interface for permission set persistence.
type SetType ¶
type SetType string
SetType represents the type of a permission set.
const ( // SetTypeSystem represents platform-wide templates (tenant_id = NULL). SetTypeSystem SetType = "system" // SetTypeExtended inherits from parent, auto-syncs new permissions. SetTypeExtended SetType = "extended" // SetTypeCloned is an independent copy, manual updates. SetTypeCloned SetType = "cloned" // SetTypeCustom is built from scratch by tenant. SetTypeCustom SetType = "custom" )
func (SetType) IsExtended ¶
IsExtended checks if this is an extended set.
func (SetType) RequiresParent ¶
RequiresParent checks if this set type requires a parent.
type Version ¶
type Version struct {
// contains filtered or unexported fields
}
Version represents a version record for a permission set.
func NewVersion ¶
func NewVersion(permissionSetID shared.ID, version int, changes VersionChanges, changedBy *shared.ID) (*Version, error)
NewVersion creates a new version record.
func ReconstituteVersion ¶
func ReconstituteVersion( permissionSetID shared.ID, version int, changes VersionChanges, changedAt time.Time, changedBy *shared.ID, ) *Version
ReconstituteVersion recreates a Version from persistence.
func (*Version) Changes ¶
func (v *Version) Changes() VersionChanges
Changes returns the changes in this version.
func (*Version) PermissionSetID ¶
PermissionSetID returns the permission set ID.
type VersionChanges ¶
type VersionChanges struct {
Added []string `json:"added,omitempty"`
Removed []string `json:"removed,omitempty"`
Initial bool `json:"initial,omitempty"`
}
VersionChanges represents the changes in a version.