Documentation
¶
Index ¶
- Variables
- func GenerateSlug(name string) string
- func IsGroupNotFound(err error) bool
- func IsGroupSlugExists(err error) bool
- func IsMemberAlreadyExists(err error) bool
- func IsMemberNotFound(err error) bool
- func IsValidSlug(slug string) bool
- type ExternalSource
- type Group
- func (g *Group) Activate()
- func (g *Group) ClearExternalSync()
- func (g *Group) CreatedAt() time.Time
- func (g *Group) Deactivate()
- func (g *Group) Description() string
- func (g *Group) ExternalID() *string
- func (g *Group) ExternalSource() *ExternalSource
- func (g *Group) GetMetadata(key string) (any, bool)
- func (g *Group) GroupType() GroupType
- func (g *Group) ID() shared.ID
- func (g *Group) IsActive() bool
- func (g *Group) IsAssetOwnerTeam() bool
- func (g *Group) IsExternalGroup() bool
- func (g *Group) IsSecurityTeam() bool
- func (g *Group) Metadata() map[string]any
- func (g *Group) Name() string
- func (g *Group) NotificationConfig() NotificationConfig
- func (g *Group) SetExternalSync(externalID string, source ExternalSource) error
- func (g *Group) SetMetadata(key string, value any)
- func (g *Group) Settings() GroupSettings
- func (g *Group) Slug() string
- func (g *Group) TenantID() shared.ID
- func (g *Group) UpdateDescription(description string)
- func (g *Group) UpdateName(name string) error
- func (g *Group) UpdateNotificationConfig(config NotificationConfig)
- func (g *Group) UpdateSettings(settings GroupSettings)
- func (g *Group) UpdateSlug(slug string) error
- func (g *Group) UpdatedAt() time.Time
- type GroupSettings
- type GroupType
- type GroupWithMembers
- type GroupWithPermissionSets
- type GroupWithRole
- type ListFilter
- type Member
- func (m *Member) AddedBy() *shared.ID
- func (m *Member) CanManageMembers() bool
- func (m *Member) CanManageSettings() bool
- func (m *Member) GroupID() shared.ID
- func (m *Member) IsLead() bool
- func (m *Member) IsOwner() bool
- func (m *Member) JoinedAt() time.Time
- func (m *Member) Role() MemberRole
- func (m *Member) UpdateRole(role MemberRole) error
- func (m *Member) UserID() shared.ID
- type MemberRole
- type MemberStats
- type MemberWithUser
- type NotificationConfig
- type Repository
Constants ¶
This section is empty.
Variables ¶
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 ¶
GenerateSlug generates a slug from a name.
func IsGroupNotFound ¶
IsGroupNotFound checks if the error is a group not found error.
func IsGroupSlugExists ¶
IsGroupSlugExists checks if the error is a slug exists error.
func IsMemberAlreadyExists ¶
IsMemberAlreadyExists checks if the error is a member already exists error.
func IsMemberNotFound ¶
IsMemberNotFound checks if the error is a member not found error.
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 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) ClearExternalSync ¶
func (g *Group) ClearExternalSync()
ClearExternalSync clears the external sync information.
func (*Group) Description ¶
Description returns the group description.
func (*Group) ExternalID ¶
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 ¶
GetMetadata gets a metadata value.
func (*Group) IsAssetOwnerTeam ¶
IsAssetOwnerTeam checks if this is an asset owner team.
func (*Group) IsExternalGroup ¶
IsExternalGroup checks if this group is synced from external source.
func (*Group) IsSecurityTeam ¶
IsSecurityTeam checks if this is a security team.
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 ¶
SetMetadata sets a metadata value.
func (*Group) Settings ¶
func (g *Group) Settings() GroupSettings
Settings returns the group settings.
func (*Group) UpdateDescription ¶
UpdateDescription updates the group description.
func (*Group) UpdateName ¶
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 ¶
UpdateSlug updates the group slug.
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" )
type GroupWithMembers ¶
type GroupWithMembers struct {
Group *Group
Members []*MemberWithUser
}
GroupWithMembers represents a group with its members.
type GroupWithPermissionSets ¶
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 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) CanManageMembers ¶
CanManageMembers checks if this member can manage other members.
func (*Member) CanManageSettings ¶
CanManageSettings checks if this member can manage group settings.
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.
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.