groups

package
v0.0.18 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package groups is the group scenario: CRUD, the member relationship indexes and the owners join resource.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = domain.ErrNotFound

ErrNotFound is the storage port's not-found sentinel.

Functions

This section is empty.

Types

type Attrs

type Attrs struct {
	Name        *string
	MaxUsers    OptionalInt
	MaxLicenses OptionalInt
	MaxMachines OptionalInt
	Metadata    map[string]any
}

Attrs is the decoded write payload of POST/PATCH /groups.

type OptionalInt

type OptionalInt struct {
	Set   bool
	Null  bool
	Value int
}

OptionalInt is a tri-state integer attribute: absent, JSON null (clears the limit) or a value.

type Page

type Page struct {
	Rows  []domain.Group
	Total int
}

Page is one result page with its total.

type Scenario

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

Scenario runs the group scenarios.

func New

func New(store Store, publisher events.Publisher, clock func() time.Time) Scenario

New builds the scenario.

func (Scenario) AttachOwners

func (s Scenario) AttachOwners(
	ctx context.Context, account domain.Account, principal access.Principal, groupID uuid.UUID,
	userIDs []uuid.UUID,
) ([]domain.GroupOwner, error)

AttachOwners attaches users as the group's owners, answering the created join rows.

func (Scenario) Create

func (s Scenario) Create(
	ctx context.Context, account domain.Account, principal access.Principal, attrs Attrs,
) (domain.Group, error)

Create validates and writes a new group.

func (Scenario) Delete

func (s Scenario) Delete(
	ctx context.Context, account domain.Account, principal access.Principal, id uuid.UUID,
) error

Delete removes the group.

func (Scenario) DetachOwners

func (s Scenario) DetachOwners(
	ctx context.Context, account domain.Account, principal access.Principal, groupID uuid.UUID,
	userIDs []uuid.UUID,
) error

DetachOwners detaches the given owner users; an unknown one is a 422 pointing at its body slot.

func (Scenario) LicenseGroup

func (s Scenario) LicenseGroup(
	ctx context.Context, account domain.Account, principal access.Principal, id uuid.UUID,
) (domain.Group, error)

LicenseGroup resolves and authorizes the group of the license relationship routes.

func (Scenario) LicenseIDs

func (s Scenario) LicenseIDs(
	ctx context.Context, account domain.Account, principal access.Principal, id uuid.UUID, limit int,
) ([]uuid.UUID, error)

LicenseIDs answers the group's license ids.

func (Scenario) List

func (s Scenario) List(
	ctx context.Context, account domain.Account, principal access.Principal, p paging.Params,
) (Page, error)

List answers the principal-scoped page.

func (Scenario) MachineIDs

func (s Scenario) MachineIDs(
	ctx context.Context, account domain.Account, principal access.Principal, id uuid.UUID, limit int,
) ([]uuid.UUID, error)

MachineIDs answers the group's machine ids.

func (Scenario) Owner

func (s Scenario) Owner(
	ctx context.Context, account domain.Account, principal access.Principal, groupID, ownerID uuid.UUID,
) (domain.GroupOwner, error)

Owner loads one group-owner row.

func (Scenario) Owners

func (s Scenario) Owners(
	ctx context.Context, account domain.Account, principal access.Principal, id uuid.UUID, limit int,
) ([]domain.GroupOwner, error)

Owners answers the group's owners (the join resource).

func (Scenario) Search

func (s Scenario) Search(
	ctx context.Context, account domain.Account, principal access.Principal, matches []uuid.UUID, p paging.Params,
) (Page, error)

Search pages the account's groups among a search's matches.

func (Scenario) Show

func (s Scenario) Show(
	ctx context.Context, account domain.Account, principal access.Principal, id uuid.UUID,
) (domain.Group, error)

Show loads one group under the GroupPolicy.

func (Scenario) Update

func (s Scenario) Update(
	ctx context.Context, account domain.Account, principal access.Principal, id uuid.UUID, attrs Attrs,
) (domain.Group, error)

Update applies the write payload.

func (Scenario) Users

func (s Scenario) Users(
	ctx context.Context, account domain.Account, principal access.Principal, id uuid.UUID, limit int,
) ([]domain.User, error)

Users answers the group's member users (limit mode size).

type Store

type Store interface {
	// Do runs fn in one transaction; the writes and the webhook
	// events of one action commit together.
	Do(ctx context.Context, fn func(ctx context.Context) error) error
	// GroupByID loads a group; ErrNotFound.
	GroupByID(ctx context.Context, accountID, id uuid.UUID) (domain.Group, error)
	// ListGroups answers the principal-scoped page.
	ListGroups(ctx context.Context, accountID uuid.UUID, memberUser uuid.NullUUID, ids []uuid.UUID, p paging.Params) ([]domain.Group, error) //nolint:lll // the scope's arguments
	// CountGroups answers the scope's total.
	CountGroups(ctx context.Context, accountID uuid.UUID, memberUser uuid.NullUUID, ids []uuid.UUID) (int, error)
	// InsertGroup writes a new group row.
	InsertGroup(ctx context.Context, group domain.Group) error
	// UpdateGroup writes every mutable column.
	UpdateGroup(ctx context.Context, group domain.Group) error
	// DeleteGroup removes the group (members' group_id nulled).
	DeleteGroup(ctx context.Context, accountID, id uuid.UUID) error
	// ListGroupUsers answers the group's member users.
	ListGroupUsers(ctx context.Context, accountID, groupID uuid.UUID, limit int) ([]domain.User, error)
	// ListGroupLicenseIDs answers the group's license ids.
	ListGroupLicenseIDs(ctx context.Context, accountID, groupID uuid.UUID, limit int) ([]uuid.UUID, error)
	// ListGroupMachineIDs answers the group's machine ids.
	ListGroupMachineIDs(ctx context.Context, accountID, groupID uuid.UUID, limit int) ([]uuid.UUID, error)
	// InsertGroupOwner attaches a user as owner.
	InsertGroupOwner(ctx context.Context, owner domain.GroupOwner) error
	// GetGroupOwner loads a group-owner row.
	GetGroupOwner(ctx context.Context, accountID, groupID, ownerID uuid.UUID) (domain.GroupOwner, error)
	// GetGroupOwnerByUser loads the group-owner row of a user.
	GetGroupOwnerByUser(ctx context.Context, accountID, groupID, userID uuid.UUID) (domain.GroupOwner, error)
	// ListGroupOwners answers the group's owners.
	ListGroupOwners(ctx context.Context, accountID, groupID uuid.UUID, limit int) ([]domain.GroupOwner, error)
	// DeleteGroupOwnersByUsers detaches the given users; it answers the
	// number of rows removed.
	DeleteGroupOwnersByUsers(ctx context.Context, accountID, groupID uuid.UUID, userIDs []uuid.UUID) (int64, error)
	// UserByID loads a user (owner attach validates them).
	UserByID(ctx context.Context, accountID, id uuid.UUID) (domain.User, error)
	// GroupIDsOfUser answers the group ids the user belongs to or owns.
	GroupIDsOfUser(ctx context.Context, accountID, userID uuid.UUID) ([]uuid.UUID, error)
	// OwnedGroupIDsOfUser excludes membership-only groups.
	OwnedGroupIDsOfUser(ctx context.Context, accountID, userID uuid.UUID) ([]uuid.UUID, error)
	// UserLicenseIDs answers the user's license ids.
	UserLicenseIDs(ctx context.Context, accountID, userID uuid.UUID) ([]uuid.UUID, error)
	// UserProductIDs answers the product ids behind the user's licenses.
	UserProductIDs(ctx context.Context, accountID, userID uuid.UUID) ([]uuid.UUID, error)
}

Store is the scenario's consumer-side storage port.

Jump to

Keyboard shortcuts

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