group

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrGroupNotFound       = fmt.Errorf("%w: group not found", shared.ErrNotFound)
	ErrGroupSlugExists     = fmt.Errorf("%w: group slug already exists", shared.ErrAlreadyExists)
	ErrMemberNotFound      = fmt.Errorf("%w: group member not found", shared.ErrNotFound)
	ErrMemberAlreadyExists = fmt.Errorf("%w: user is already a member of this group", shared.ErrAlreadyExists)
	ErrLastOwner           = fmt.Errorf("%w: cannot remove the last owner of the group", shared.ErrValidation)
	ErrCannotRemoveSelf    = fmt.Errorf("%w: cannot remove yourself from the group", shared.ErrValidation)
	ErrMaxMembersReached   = fmt.Errorf("%w: maximum number of members reached", shared.ErrValidation)
	ErrInactiveGroup       = fmt.Errorf("%w: group is inactive", shared.ErrValidation)
	ErrExternalGroupSync   = fmt.Errorf("%w: cannot modify externally synced group", shared.ErrValidation)
)

Domain errors for groups.

Functions

func GenerateSlug

func GenerateSlug(name string) string

GenerateSlug generates a slug from a name.

func IsGroupNotFound

func IsGroupNotFound(err error) bool

IsGroupNotFound checks if the error is a group not found error.

func IsGroupSlugExists

func IsGroupSlugExists(err error) bool

IsGroupSlugExists checks if the error is a slug exists error.

func IsMemberAlreadyExists

func IsMemberAlreadyExists(err error) bool

IsMemberAlreadyExists checks if the error is a member already exists error.

func IsMemberNotFound

func IsMemberNotFound(err error) bool

IsMemberNotFound checks if the error is a member not found error.

func IsValidSlug

func IsValidSlug(slug string) bool

IsValidSlug checks if a slug is valid.

Types

type ExternalSource

type ExternalSource string

ExternalSource represents the source of external sync.

const (
	ExternalSourceGitHub  ExternalSource = "github"
	ExternalSourceGitLab  ExternalSource = "gitlab"
	ExternalSourceAzureAD ExternalSource = "azure_ad"
	ExternalSourceOkta    ExternalSource = "okta"
)

func (ExternalSource) IsValid

func (s ExternalSource) IsValid() bool

IsValid checks if the external source is valid.

func (ExternalSource) String

func (s ExternalSource) String() string

String returns the string representation.

type Group

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

Group represents a user group for access control.

func NewGroup

func NewGroup(tenantID shared.ID, name, slug string, groupType GroupType) (*Group, error)

NewGroup creates a new Group entity.

func Reconstitute

func Reconstitute(
	id shared.ID,
	tenantID shared.ID,
	name, slug, description string,
	groupType GroupType,
	externalID *string,
	externalSource *ExternalSource,
	settings GroupSettings,
	notificationConfig NotificationConfig,
	metadata map[string]any,
	isActive bool,
	createdAt, updatedAt time.Time,
) *Group

Reconstitute recreates a Group from persistence.

func (*Group) Activate

func (g *Group) Activate()

Activate activates the group.

func (*Group) ClearExternalSync

func (g *Group) ClearExternalSync()

ClearExternalSync clears the external sync information.

func (*Group) CreatedAt

func (g *Group) CreatedAt() time.Time

CreatedAt returns the creation timestamp.

func (*Group) Deactivate

func (g *Group) Deactivate()

Deactivate deactivates the group.

func (*Group) Description

func (g *Group) Description() string

Description returns the group description.

func (*Group) ExternalID

func (g *Group) ExternalID() *string

ExternalID returns the external system ID (if synced).

func (*Group) ExternalSource

func (g *Group) ExternalSource() *ExternalSource

ExternalSource returns the external sync source.

func (*Group) GetMetadata

func (g *Group) GetMetadata(key string) (any, bool)

GetMetadata gets a metadata value.

func (*Group) GroupType

func (g *Group) GroupType() GroupType

GroupType returns the group type.

func (*Group) ID

func (g *Group) ID() shared.ID

ID returns the group ID.

func (*Group) IsActive

func (g *Group) IsActive() bool

IsActive returns whether the group is active.

func (*Group) IsAssetOwnerTeam

func (g *Group) IsAssetOwnerTeam() bool

IsAssetOwnerTeam checks if this is an asset owner team.

func (*Group) IsExternalGroup

func (g *Group) IsExternalGroup() bool

IsExternalGroup checks if this group is synced from external source.

func (*Group) IsSecurityTeam

func (g *Group) IsSecurityTeam() bool

IsSecurityTeam checks if this is a security team.

func (*Group) Metadata

func (g *Group) Metadata() map[string]any

Metadata returns a copy of the metadata.

func (*Group) Name

func (g *Group) Name() string

Name returns the group name.

func (*Group) NotificationConfig

func (g *Group) NotificationConfig() NotificationConfig

NotificationConfig returns the notification configuration.

func (*Group) SetExternalSync

func (g *Group) SetExternalSync(externalID string, source ExternalSource) error

SetExternalSync sets the external sync information.

func (*Group) SetMetadata

func (g *Group) SetMetadata(key string, value any)

SetMetadata sets a metadata value.

func (*Group) Settings

func (g *Group) Settings() GroupSettings

Settings returns the group settings.

func (*Group) Slug

func (g *Group) Slug() string

Slug returns the group slug.

func (*Group) TenantID

func (g *Group) TenantID() shared.ID

TenantID returns the tenant ID.

func (*Group) UpdateDescription

func (g *Group) UpdateDescription(description string)

UpdateDescription updates the group description.

func (*Group) UpdateName

func (g *Group) UpdateName(name string) error

UpdateName updates the group name.

func (*Group) UpdateNotificationConfig

func (g *Group) UpdateNotificationConfig(config NotificationConfig)

UpdateNotificationConfig updates the notification configuration.

func (*Group) UpdateSettings

func (g *Group) UpdateSettings(settings GroupSettings)

UpdateSettings updates the group settings.

func (*Group) UpdateSlug

func (g *Group) UpdateSlug(slug string) error

UpdateSlug updates the group slug.

func (*Group) UpdatedAt

func (g *Group) UpdatedAt() time.Time

UpdatedAt returns the last update timestamp.

type GroupSettings

type GroupSettings struct {
	AllowSelfJoin   bool `json:"allow_self_join"`
	RequireApproval bool `json:"require_approval"`
	MaxMembers      *int `json:"max_members,omitempty"`
}

GroupSettings represents configurable settings for a group.

func DefaultGroupSettings

func DefaultGroupSettings() GroupSettings

DefaultGroupSettings returns default settings for a new group.

type GroupType

type GroupType string

GroupType represents the type of a group.

const (
	// GroupTypeSecurityTeam represents security sub-teams with feature access.
	GroupTypeSecurityTeam GroupType = "security_team"
	// GroupTypeTeam represents dev/owner teams for asset ownership.
	GroupTypeTeam GroupType = "team"
	// GroupTypeDepartment represents organizational units.
	GroupTypeDepartment GroupType = "department"
	// GroupTypeProject represents project-based teams.
	GroupTypeProject GroupType = "project"
	// GroupTypeExternal represents external contractors/vendors.
	GroupTypeExternal GroupType = "external"
)

func AllGroupTypes

func AllGroupTypes() []GroupType

AllGroupTypes returns all valid group types.

func (GroupType) IsValid

func (t GroupType) IsValid() bool

IsValid checks if the group type is valid.

func (GroupType) String

func (t GroupType) String() string

String returns the string representation.

type GroupWithMembers

type GroupWithMembers struct {
	Group   *Group
	Members []*MemberWithUser
}

GroupWithMembers represents a group with its members.

type GroupWithPermissionSets

type GroupWithPermissionSets struct {
	Group            *Group
	PermissionSetIDs []shared.ID
}

GroupWithPermissionSets represents a group with its assigned permission sets.

type GroupWithRole

type GroupWithRole struct {
	Group *Group
	Role  MemberRole
}

GroupWithRole represents a group with the user's role in it.

type ListFilter

type ListFilter struct {
	// Type filters
	GroupTypes []GroupType

	// Search
	Search string // Search in name, slug, description

	// External sync filter
	ExternalSource *ExternalSource
	HasExternalID  *bool

	// Status filter
	IsActive *bool

	// Pagination
	Limit  int
	Offset int

	// Sorting
	OrderBy   string // "name", "created_at", "updated_at"
	OrderDesc bool
}

ListFilter contains filter options for listing groups.

func DefaultListFilter

func DefaultListFilter() ListFilter

DefaultListFilter returns a default filter.

type Member

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

Member represents a user's membership in a group.

func NewMember

func NewMember(groupID, userID shared.ID, role MemberRole, addedBy *shared.ID) (*Member, error)

NewMember creates a new group member.

func ReconstituteMember

func ReconstituteMember(
	groupID shared.ID,
	userID shared.ID,
	role MemberRole,
	joinedAt time.Time,
	addedBy *shared.ID,
) *Member

ReconstituteMember recreates a Member from persistence.

func (*Member) AddedBy

func (m *Member) AddedBy() *shared.ID

AddedBy returns the user ID who added this member.

func (*Member) CanManageMembers

func (m *Member) CanManageMembers() bool

CanManageMembers checks if this member can manage other members.

func (*Member) CanManageSettings

func (m *Member) CanManageSettings() bool

CanManageSettings checks if this member can manage group settings.

func (*Member) GroupID

func (m *Member) GroupID() shared.ID

GroupID returns the group ID.

func (*Member) IsLead

func (m *Member) IsLead() bool

IsLead checks if this member is a lead.

func (*Member) IsOwner

func (m *Member) IsOwner() bool

IsOwner checks if this member is an owner.

func (*Member) JoinedAt

func (m *Member) JoinedAt() time.Time

JoinedAt returns when the member joined the group.

func (*Member) Role

func (m *Member) Role() MemberRole

Role returns the member's role in the group.

func (*Member) UpdateRole

func (m *Member) UpdateRole(role MemberRole) error

UpdateRole updates the member's role.

func (*Member) UserID

func (m *Member) UserID() shared.ID

UserID returns the user ID.

type MemberRole

type MemberRole string

MemberRole represents a user's role within a group.

const (
	// MemberRoleOwner can manage group settings and members.
	MemberRoleOwner MemberRole = "owner"
	// MemberRoleLead can add/remove members.
	MemberRoleLead MemberRole = "lead"
	// MemberRoleMember is a standard member.
	MemberRoleMember MemberRole = "member"
)

func AllMemberRoles

func AllMemberRoles() []MemberRole

AllMemberRoles returns all valid member roles.

func (MemberRole) CanManageMembers

func (r MemberRole) CanManageMembers() bool

CanManageMembers checks if this role can manage group members.

func (MemberRole) CanManageSettings

func (r MemberRole) CanManageSettings() bool

CanManageSettings checks if this role can manage group settings.

func (MemberRole) IsValid

func (r MemberRole) IsValid() bool

IsValid checks if the member role is valid.

func (MemberRole) String

func (r MemberRole) String() string

String returns the string representation.

type MemberStats

type MemberStats struct {
	TotalMembers int            `json:"total_members"`
	RoleCounts   map[string]int `json:"role_counts"`
}

MemberStats contains statistics about group members.

type MemberWithUser

type MemberWithUser struct {
	Member      *Member
	Email       string
	Name        string
	AvatarURL   string
	LastLoginAt *time.Time
}

MemberWithUser represents a group member with user details.

type NotificationConfig

type NotificationConfig struct {
	SlackChannel    string `json:"slack_channel,omitempty"`
	NotifyCritical  bool   `json:"notify_critical"`
	NotifyHigh      bool   `json:"notify_high"`
	NotifyMedium    bool   `json:"notify_medium"`
	NotifyLow       bool   `json:"notify_low"`
	NotifySLAWarn   bool   `json:"notify_sla_warning"`
	NotifySLABreach bool   `json:"notify_sla_breach"`
	WeeklyDigest    bool   `json:"weekly_digest"`
}

NotificationConfig represents notification settings for a group.

func DefaultNotificationConfig

func DefaultNotificationConfig() NotificationConfig

DefaultNotificationConfig returns default notification settings.

type Repository

type Repository interface {
	// Group CRUD operations
	Create(ctx context.Context, g *Group) error
	GetByID(ctx context.Context, id shared.ID) (*Group, error)
	GetBySlug(ctx context.Context, tenantID shared.ID, slug string) (*Group, error)
	Update(ctx context.Context, g *Group) error
	Delete(ctx context.Context, id shared.ID) error

	// Group queries
	List(ctx context.Context, tenantID shared.ID, filter ListFilter) ([]*Group, error)
	Count(ctx context.Context, tenantID shared.ID, filter ListFilter) (int64, error)
	ExistsBySlug(ctx context.Context, tenantID shared.ID, slug string) (bool, error)
	ListByIDs(ctx context.Context, ids []shared.ID) ([]*Group, error)

	// External sync queries
	GetByExternalID(ctx context.Context, tenantID shared.ID, source ExternalSource, externalID string) (*Group, error)

	// Member operations
	AddMember(ctx context.Context, member *Member) error
	GetMember(ctx context.Context, groupID, userID shared.ID) (*Member, error)
	UpdateMember(ctx context.Context, member *Member) error
	RemoveMember(ctx context.Context, groupID, userID shared.ID) error
	ListMembers(ctx context.Context, groupID shared.ID) ([]*Member, error)
	ListMembersWithUserInfo(ctx context.Context, groupID shared.ID) ([]*MemberWithUser, error)
	CountMembers(ctx context.Context, groupID shared.ID) (int64, error)
	GetMemberStats(ctx context.Context, groupID shared.ID) (*MemberStats, error)
	IsMember(ctx context.Context, groupID, userID shared.ID) (bool, error)

	// User-centric queries
	ListGroupsByUser(ctx context.Context, tenantID, userID shared.ID) ([]*GroupWithRole, error)
	ListGroupIDsByUser(ctx context.Context, tenantID, userID shared.ID) ([]shared.ID, error)

	// Permission set assignment
	AssignPermissionSet(ctx context.Context, groupID, permissionSetID shared.ID, assignedBy *shared.ID) error
	RemovePermissionSet(ctx context.Context, groupID, permissionSetID shared.ID) error
	ListPermissionSetIDs(ctx context.Context, groupID shared.ID) ([]shared.ID, error)
	ListGroupsWithPermissionSet(ctx context.Context, permissionSetID shared.ID) ([]*Group, error)
}

Repository defines the interface for group persistence.

Jump to

Keyboard shortcuts

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