role

package
v0.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 15, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrSystemRoleProtected = errors.New("system role is protected")
	ErrRoleInUse           = errors.New("role is in use")
)
View Source
var (
	ErrNotFound      = errors.New("role not found")
	ErrAlreadyExists = errors.New("role already exists")
)

Functions

This section is empty.

Types

type CreateInput

type CreateInput struct {
	Name        string   `json:"name"`
	Description string   `json:"description"`
	PermIDs     []string `json:"permission_ids,omitempty"`
}

type Permission

type Permission struct {
	ID           string `json:"id"`
	Name         string `json:"name"`
	Description  string `json:"description"`
	ResourceType string `json:"resource_type"`
	Action       string `json:"action"`

} // @name RolePermission

type PostgresStore

type PostgresStore struct {
	// contains filtered or unexported fields
}

func (*PostgresStore) AttachedPermissionIDs

func (s *PostgresStore) AttachedPermissionIDs(ctx context.Context, roleID string) ([]string, error)

func (*PostgresStore) Create

func (s *PostgresStore) Create(ctx context.Context, input CreateInput) (*Role, error)

func (*PostgresStore) Get

func (s *PostgresStore) Get(ctx context.Context, id string) (*Role, error)

func (*PostgresStore) GetByName

func (s *PostgresStore) GetByName(ctx context.Context, name string) (*Role, error)

func (*PostgresStore) HasUsers

func (s *PostgresStore) HasUsers(ctx context.Context, roleID string) (bool, error)

func (*PostgresStore) List

func (s *PostgresStore) List(ctx context.Context, includeDeleted bool) ([]*Role, error)

func (*PostgresStore) ListPermissions

func (s *PostgresStore) ListPermissions(ctx context.Context) ([]Permission, error)

func (*PostgresStore) ReplacePermissions

func (s *PostgresStore) ReplacePermissions(ctx context.Context, roleID string, permIDs []string) error

func (*PostgresStore) SoftDelete

func (s *PostgresStore) SoftDelete(ctx context.Context, id string) error

func (*PostgresStore) Update

func (s *PostgresStore) Update(ctx context.Context, id string, input UpdateInput) (*Role, error)

type Role

type Role struct {
	ID          string       `json:"id"`
	Name        string       `json:"name"`
	Description string       `json:"description"`
	IsSystem    bool         `json:"is_system"`
	UserCount   int          `json:"user_count,omitempty"`
	Permissions []Permission `json:"permissions,omitempty"`
	DeletedAt   *time.Time   `json:"deleted_at,omitempty"`
	CreatedAt   time.Time    `json:"created_at"`
	UpdatedAt   time.Time    `json:"updated_at"`

} // @name Role

type Service

type Service interface {
	List(ctx context.Context) ([]*Role, error)
	Get(ctx context.Context, id string) (*Role, error)
	Create(ctx context.Context, input CreateInput) (*Role, error)
	Update(ctx context.Context, id string, input UpdateInput) (*Role, error)
	Delete(ctx context.Context, id string) error
	ReplacePermissions(ctx context.Context, roleID string, permIDs []string) error
	ListPermissions(ctx context.Context) ([]Permission, error)
}

func NewService

func NewService(store Store) Service

type Store

type Store interface {
	List(ctx context.Context, includeDeleted bool) ([]*Role, error)
	Get(ctx context.Context, id string) (*Role, error)
	GetByName(ctx context.Context, name string) (*Role, error)
	Create(ctx context.Context, input CreateInput) (*Role, error)
	Update(ctx context.Context, id string, input UpdateInput) (*Role, error)
	SoftDelete(ctx context.Context, id string) error
	AttachedPermissionIDs(ctx context.Context, roleID string) ([]string, error)
	ReplacePermissions(ctx context.Context, roleID string, permIDs []string) error
	HasUsers(ctx context.Context, roleID string) (bool, error)
	ListPermissions(ctx context.Context) ([]Permission, error)
}

func NewPostgresStore

func NewPostgresStore(db *pgxpool.Pool) Store

type UpdateInput

type UpdateInput struct {
	Name        *string `json:"name,omitempty"`
	Description *string `json:"description,omitempty"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL