Documentation
¶
Index ¶
- Constants
- Variables
- func AppAlreadyExists(identifier string) *errs.AuthsomeError
- func AppNotFound() *errs.AuthsomeError
- func AppSlugExists(slug string) *errs.AuthsomeError
- func BuildAppResource(resourceType, resourceID string) string
- func BuildAppWildcard(resourceType string) string
- func CannotDeletePlatformApp() *errs.AuthsomeError
- func CannotRemoveOwner() *errs.AuthsomeError
- func InvalidRole(role string) *errs.AuthsomeError
- func InvalidStatus(status string) *errs.AuthsomeError
- func InvitationExpired() *errs.AuthsomeError
- func InvitationInvalidStatus(expected, actual string) *errs.AuthsomeError
- func InvitationNotFound() *errs.AuthsomeError
- func InvitationNotPending() *errs.AuthsomeError
- func MaxMembersReached(limit int) *errs.AuthsomeError
- func MaxTeamsReached(limit int) *errs.AuthsomeError
- func MemberAlreadyExists(userID string) *errs.AuthsomeError
- func MemberNotFound() *errs.AuthsomeError
- func NotAdmin() *errs.AuthsomeError
- func NotOwner() *errs.AuthsomeError
- func PlatformAppAlreadyExists() *errs.AuthsomeError
- func PlatformAppImmutable() *errs.AuthsomeError
- func RegisterAppPermissions(registry rbac.RoleRegistryInterface) error
- func TeamAlreadyExists(name string) *errs.AuthsomeError
- func TeamMemberNotFound() *errs.AuthsomeError
- func TeamNotFound() *errs.AuthsomeError
- func Unauthorized() *errs.AuthsomeError
- func UnauthorizedAction(action string) *errs.AuthsomeError
- type App
- type AppOperations
- type AppRepository
- type AppService
- func (s *AppService) CountApps(ctx context.Context) (int, error)
- func (s *AppService) CreateApp(ctx context.Context, req *CreateAppRequest) (*App, error)
- func (s *AppService) DeleteApp(ctx context.Context, id xid.ID) error
- func (s *AppService) FindAppByID(ctx context.Context, id xid.ID) (*App, error)
- func (s *AppService) FindAppBySlug(ctx context.Context, slug string) (*App, error)
- func (s *AppService) GetCookieConfig(ctx context.Context, appID xid.ID) (*session.CookieConfig, error)
- func (s *AppService) GetPlatformApp(ctx context.Context) (*App, error)
- func (s *AppService) IsPlatformApp(ctx context.Context, appID xid.ID) (bool, error)
- func (s *AppService) ListApps(ctx context.Context, filter *ListAppsFilter) (*pagination.PageResponse[*App], error)
- func (s *AppService) SetGlobalCookieConfig(config *session.CookieConfig)
- func (s *AppService) SetHookRegistry(hookRegistry *hooks.HookRegistry)
- func (s *AppService) SetPlatformApp(ctx context.Context, newPlatformAppID xid.ID) error
- func (s *AppService) UpdateApp(ctx context.Context, id xid.ID, req *UpdateAppRequest) (*App, error)
- func (s *AppService) UpdateConfig(cfg Config)
- type Config
- type CreateAppRequest
- type CreateTeamRequest
- type Invitation
- type InvitationOperations
- type InvitationRepository
- type InvitationService
- func (s *InvitationService) AcceptInvitation(ctx context.Context, token string, userID xid.ID) (*Member, error)
- func (s *InvitationService) CancelInvitation(ctx context.Context, id, cancellerUserID xid.ID) error
- func (s *InvitationService) CleanupExpiredInvitations(ctx context.Context) (int, error)
- func (s *InvitationService) CreateInvitation(ctx context.Context, inv *Invitation) error
- func (s *InvitationService) DeclineInvitation(ctx context.Context, token string) error
- func (s *InvitationService) FindInvitationByID(ctx context.Context, id xid.ID) (*Invitation, error)
- func (s *InvitationService) FindInvitationByToken(ctx context.Context, token string) (*Invitation, error)
- func (s *InvitationService) ListInvitations(ctx context.Context, filter *ListInvitationsFilter) (*pagination.PageResponse[*Invitation], error)
- func (s *InvitationService) ResendInvitation(ctx context.Context, id, resenderUserID xid.ID) (*Invitation, error)
- type InvitationStatus
- type InviteMemberRequest
- type ListAppsFilter
- type ListInvitationsFilter
- type ListMemberTeamsFilter
- type ListMembersFilter
- type ListTeamMembersFilter
- type ListTeamsFilter
- type Member
- type MemberOperations
- type MemberRepository
- type MemberRole
- type MemberService
- func (s *MemberService) CountMembers(ctx context.Context, appID xid.ID) (int, error)
- func (s *MemberService) CreateMember(ctx context.Context, member *Member) (*Member, error)
- func (s *MemberService) DeleteMember(ctx context.Context, id xid.ID) error
- func (s *MemberService) FindMember(ctx context.Context, appID, userID xid.ID) (*Member, error)
- func (s *MemberService) FindMemberByID(ctx context.Context, id xid.ID) (*Member, error)
- func (s *MemberService) GetUserMemberships(ctx context.Context, userID xid.ID) ([]*Member, error)
- func (s *MemberService) IsAdmin(ctx context.Context, appID, userID xid.ID) (bool, error)
- func (s *MemberService) IsOwner(ctx context.Context, appID, userID xid.ID) (bool, error)
- func (s *MemberService) IsUserMember(ctx context.Context, appID, userID xid.ID) (bool, error)
- func (s *MemberService) ListMembers(ctx context.Context, filter *ListMembersFilter) (*pagination.PageResponse[*Member], error)
- func (s *MemberService) RequireAdmin(ctx context.Context, appID, userID xid.ID) error
- func (s *MemberService) RequireOwner(ctx context.Context, appID, userID xid.ID) error
- func (s *MemberService) UpdateMember(ctx context.Context, member *Member) error
- type MemberStatus
- type Service
- type ServiceImpl
- func (s *ServiceImpl) AcceptInvitation(ctx context.Context, token string, userID xid.ID) (*Member, error)
- func (s *ServiceImpl) AddTeamMember(ctx context.Context, tm *TeamMember) (*TeamMember, error)
- func (s *ServiceImpl) CancelInvitation(ctx context.Context, id, cancellerUserID xid.ID) error
- func (s *ServiceImpl) CheckPermission(ctx context.Context, userID, appID xid.ID, ...) (bool, error)
- func (s *ServiceImpl) CheckPermissionWithContext(ctx context.Context, userID, appID xid.ID, ...) (bool, error)
- func (s *ServiceImpl) CleanupExpiredInvitations(ctx context.Context) (int, error)
- func (s *ServiceImpl) CountApps(ctx context.Context) (int, error)
- func (s *ServiceImpl) CountMembers(ctx context.Context, appID xid.ID) (int, error)
- func (s *ServiceImpl) CountTeamMembers(ctx context.Context, teamID xid.ID) (int, error)
- func (s *ServiceImpl) CountTeams(ctx context.Context, appID xid.ID) (int, error)
- func (s *ServiceImpl) CreateApp(ctx context.Context, req *CreateAppRequest) (*App, error)
- func (s *ServiceImpl) CreateInvitation(ctx context.Context, inv *Invitation) error
- func (s *ServiceImpl) CreateMember(ctx context.Context, member *Member) (*Member, error)
- func (s *ServiceImpl) CreateTeam(ctx context.Context, team *Team) error
- func (s *ServiceImpl) DeclineInvitation(ctx context.Context, token string) error
- func (s *ServiceImpl) DeleteApp(ctx context.Context, id xid.ID) error
- func (s *ServiceImpl) DeleteMember(ctx context.Context, id xid.ID) error
- func (s *ServiceImpl) DeleteTeam(ctx context.Context, id xid.ID) error
- func (s *ServiceImpl) FindAppByID(ctx context.Context, id xid.ID) (*App, error)
- func (s *ServiceImpl) FindAppBySlug(ctx context.Context, slug string) (*App, error)
- func (s *ServiceImpl) FindInvitationByID(ctx context.Context, id xid.ID) (*Invitation, error)
- func (s *ServiceImpl) FindInvitationByToken(ctx context.Context, token string) (*Invitation, error)
- func (s *ServiceImpl) FindMember(ctx context.Context, appID, userID xid.ID) (*Member, error)
- func (s *ServiceImpl) FindMemberByID(ctx context.Context, id xid.ID) (*Member, error)
- func (s *ServiceImpl) FindTeamByID(ctx context.Context, id xid.ID) (*Team, error)
- func (s *ServiceImpl) FindTeamByName(ctx context.Context, appID xid.ID, name string) (*Team, error)
- func (s *ServiceImpl) GetPlatformApp(ctx context.Context) (*App, error)
- func (s *ServiceImpl) GetUserMemberships(ctx context.Context, userID xid.ID) ([]*Member, error)
- func (s *ServiceImpl) IsAdmin(ctx context.Context, appID, userID xid.ID) (bool, error)
- func (s *ServiceImpl) IsOwner(ctx context.Context, appID, userID xid.ID) (bool, error)
- func (s *ServiceImpl) IsPlatformApp(ctx context.Context, appID xid.ID) (bool, error)
- func (s *ServiceImpl) IsTeamMember(ctx context.Context, teamID, memberID xid.ID) (bool, error)
- func (s *ServiceImpl) IsUserMember(ctx context.Context, appID, userID xid.ID) (bool, error)
- func (s *ServiceImpl) ListApps(ctx context.Context, filter *ListAppsFilter) (*pagination.PageResponse[*App], error)
- func (s *ServiceImpl) ListInvitations(ctx context.Context, filter *ListInvitationsFilter) (*pagination.PageResponse[*Invitation], error)
- func (s *ServiceImpl) ListMemberTeams(ctx context.Context, filter *ListMemberTeamsFilter) (*pagination.PageResponse[*Team], error)
- func (s *ServiceImpl) ListMembers(ctx context.Context, filter *ListMembersFilter) (*pagination.PageResponse[*Member], error)
- func (s *ServiceImpl) ListTeamMembers(ctx context.Context, filter *ListTeamMembersFilter) (*pagination.PageResponse[*TeamMember], error)
- func (s *ServiceImpl) ListTeams(ctx context.Context, filter *ListTeamsFilter) (*pagination.PageResponse[*Team], error)
- func (s *ServiceImpl) RemoveTeamMember(ctx context.Context, teamID, memberID xid.ID) error
- func (s *ServiceImpl) RequireAdmin(ctx context.Context, appID, userID xid.ID) error
- func (s *ServiceImpl) RequireOwner(ctx context.Context, appID, userID xid.ID) error
- func (s *ServiceImpl) RequirePermission(ctx context.Context, userID, appID xid.ID, ...) error
- func (s *ServiceImpl) RequirePermissionWithContext(ctx context.Context, userID, appID xid.ID, ...) error
- func (s *ServiceImpl) ResendInvitation(ctx context.Context, id, resenderUserID xid.ID) (*Invitation, error)
- func (s *ServiceImpl) SetPlatformApp(ctx context.Context, newPlatformAppID xid.ID) error
- func (s *ServiceImpl) UpdateApp(ctx context.Context, id xid.ID, req *UpdateAppRequest) (*App, error)
- func (s *ServiceImpl) UpdateConfig(cfg Config)
- func (s *ServiceImpl) UpdateMember(ctx context.Context, member *Member) error
- func (s *ServiceImpl) UpdateTeam(ctx context.Context, team *Team) error
- type Team
- type TeamMember
- type TeamOperations
- type TeamRepository
- type TeamService
- func (s *TeamService) AddTeamMember(ctx context.Context, tm *TeamMember) (*TeamMember, error)
- func (s *TeamService) CountTeamMembers(ctx context.Context, teamID xid.ID) (int, error)
- func (s *TeamService) CountTeams(ctx context.Context, appID xid.ID) (int, error)
- func (s *TeamService) CreateTeam(ctx context.Context, team *Team) error
- func (s *TeamService) DeleteTeam(ctx context.Context, id xid.ID) error
- func (s *TeamService) FindTeamByID(ctx context.Context, id xid.ID) (*Team, error)
- func (s *TeamService) FindTeamByName(ctx context.Context, appID xid.ID, name string) (*Team, error)
- func (s *TeamService) IsSCIMManaged(team *Team) bool
- func (s *TeamService) IsTeamMember(ctx context.Context, teamID, memberID xid.ID) (bool, error)
- func (s *TeamService) IsTeamMemberSCIMManaged(teamMember *TeamMember) bool
- func (s *TeamService) ListMemberTeams(ctx context.Context, filter *ListMemberTeamsFilter) (*pagination.PageResponse[*Team], error)
- func (s *TeamService) ListTeamMembers(ctx context.Context, filter *ListTeamMembersFilter) (*pagination.PageResponse[*TeamMember], error)
- func (s *TeamService) ListTeams(ctx context.Context, filter *ListTeamsFilter) (*pagination.PageResponse[*Team], error)
- func (s *TeamService) RemoveTeamMember(ctx context.Context, teamID, memberID xid.ID) error
- func (s *TeamService) UpdateTeam(ctx context.Context, team *Team) error
- type UpdateAppRequest
- type UpdateMemberRequest
- type UpdateTeamRequest
Constants ¶
const ( MemberRoleOwner = schema.MemberRoleOwner MemberRoleAdmin = schema.MemberRoleAdmin MemberRoleMember = schema.MemberRoleMember )
const ( MemberStatusActive = schema.MemberStatusActive MemberStatusSuspended = schema.MemberStatusSuspended MemberStatusPending = schema.MemberStatusPending )
const ( InvitationStatusPending = schema.InvitationStatusPending InvitationStatusAccepted = schema.InvitationStatusAccepted InvitationStatusExpired = schema.InvitationStatusExpired InvitationStatusCancelled = schema.InvitationStatusCancelled InvitationStatusDeclined = schema.InvitationStatusDeclined )
const ( CodeAppNotFound = "APP_NOT_FOUND" CodeAppAlreadyExists = "APP_ALREADY_EXISTS" CodeAppSlugExists = "APP_SLUG_EXISTS" CodePlatformAppImmutable = "PLATFORM_APP_IMMUTABLE" CodeMemberNotFound = "MEMBER_NOT_FOUND" CodeMemberAlreadyExists = "MEMBER_ALREADY_EXISTS" CodeMaxMembersReached = "MAX_MEMBERS_REACHED" CodeMaxTeamsReached = "MAX_TEAMS_REACHED" CodeInvalidRole = "INVALID_ROLE" CodeInvalidStatus = "INVALID_STATUS" CodeCannotRemoveOwner = "CANNOT_REMOVE_OWNER" CodeInvitationInvalid = "INVITATION_INVALID_STATUS" CodeTeamMemberNotFound = "TEAM_MEMBER_NOT_FOUND" CodeNotOwner = "NOT_OWNER" CodeNotAdmin = "NOT_ADMIN" CodeInvitationNotPending = "INVITATION_NOT_PENDING" )
const ( // Generic actions ActionRead = "read" ActionCreate = "create" ActionUpdate = "update" ActionDelete = "delete" // Member-specific actions ActionUpdateRole = "update_role" ActionInvite = "invite" // Team-specific actions ActionAddMember = "add_member" ActionRemoveMember = "remove_member" // Invitation-specific actions ActionAccept = "accept" ActionDecline = "decline" ActionCancel = "cancel" ActionResend = "resend" // App-specific actions ActionConfigure = "configure" ActionTransfer = "transfer" )
Action constants for app resources
const ( ResourceTypeApp = "app" ResourceTypeMember = "member" ResourceTypeTeam = "team" ResourceTypeInvitation = "invitation" )
Resource type constants for app resources
Variables ¶
var ( ErrAppNotFound = &errs.AuthsomeError{Code: CodeAppNotFound} ErrSlugAlreadyExists = &errs.AuthsomeError{Code: CodeAppSlugExists} ErrMemberNotFound = &errs.AuthsomeError{Code: CodeMemberNotFound} ErrMemberAlreadyExists = &errs.AuthsomeError{Code: CodeMemberAlreadyExists} ErrMaxMembersReached = &errs.AuthsomeError{Code: CodeMaxMembersReached} ErrCannotRemoveOwner = &errs.AuthsomeError{Code: CodeCannotRemoveOwner} ErrTeamNotFound = &errs.AuthsomeError{Code: errs.CodeTeamNotFound} ErrMaxTeamsReached = &errs.AuthsomeError{Code: CodeMaxTeamsReached} ErrTeamMemberNotFound = &errs.AuthsomeError{Code: CodeTeamMemberNotFound} ErrInvitationNotFound = &errs.AuthsomeError{Code: errs.CodeInvitationNotFound} ErrInvitationExpired = &errs.AuthsomeError{Code: errs.CodeInvitationExpired} ErrInvitationInvalid = &errs.AuthsomeError{Code: CodeInvitationInvalid} ErrInvitationNotPending = &errs.AuthsomeError{Code: CodeInvitationNotPending} ErrNotOwner = &errs.AuthsomeError{Code: CodeNotOwner} ErrNotAdmin = &errs.AuthsomeError{Code: CodeNotAdmin} ErrInvalidRole = &errs.AuthsomeError{Code: CodeInvalidRole} ErrInvalidStatus = &errs.AuthsomeError{Code: CodeInvalidStatus} )
Functions ¶
func AppAlreadyExists ¶
func AppAlreadyExists(identifier string) *errs.AuthsomeError
func AppSlugExists ¶
func AppSlugExists(slug string) *errs.AuthsomeError
func BuildAppResource ¶
BuildAppResource builds a resource identifier for app-scoped resources
func BuildAppWildcard ¶
BuildAppWildcard builds a wildcard resource identifier for all app resources of a type
func CannotDeletePlatformApp ¶
func CannotDeletePlatformApp() *errs.AuthsomeError
func CannotRemoveOwner ¶
func CannotRemoveOwner() *errs.AuthsomeError
func InvalidStatus ¶
func InvalidStatus(status string) *errs.AuthsomeError
func InvitationExpired ¶
func InvitationExpired() *errs.AuthsomeError
func InvitationInvalidStatus ¶
func InvitationInvalidStatus(expected, actual string) *errs.AuthsomeError
func InvitationNotFound ¶
func InvitationNotFound() *errs.AuthsomeError
Invitation errors (reuse from errs package where applicable)
func InvitationNotPending ¶
func InvitationNotPending() *errs.AuthsomeError
func MaxMembersReached ¶
func MaxMembersReached(limit int) *errs.AuthsomeError
func MaxTeamsReached ¶
func MaxTeamsReached(limit int) *errs.AuthsomeError
func MemberAlreadyExists ¶
func MemberAlreadyExists(userID string) *errs.AuthsomeError
func NotAdmin ¶
func NotAdmin() *errs.AuthsomeError
func NotOwner ¶
func NotOwner() *errs.AuthsomeError
func PlatformAppAlreadyExists ¶
func PlatformAppAlreadyExists() *errs.AuthsomeError
func PlatformAppImmutable ¶
func PlatformAppImmutable() *errs.AuthsomeError
func RegisterAppPermissions ¶
func RegisterAppPermissions(registry rbac.RoleRegistryInterface) error
RegisterAppPermissions registers app-level role definitions with the RBAC registry. This extends platform roles (owner, admin, member) with app-specific permissions.
func TeamAlreadyExists ¶
func TeamAlreadyExists(name string) *errs.AuthsomeError
func TeamMemberNotFound ¶
func TeamMemberNotFound() *errs.AuthsomeError
func TeamNotFound ¶
func TeamNotFound() *errs.AuthsomeError
Team errors (reuse from errs package where applicable)
func UnauthorizedAction ¶
func UnauthorizedAction(action string) *errs.AuthsomeError
Types ¶
type App ¶
type App struct {
ID xid.ID `json:"id"`
Name string `json:"name"`
Slug string `json:"slug"`
Logo string `json:"logo,omitempty"`
IsPlatform bool `json:"isPlatform"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
// Audit fields
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
DeletedAt *time.Time `json:"deletedAt,omitempty"`
}
App represents an app entity DTO (Data Transfer Object) This is separate from schema.App to maintain proper separation of concerns
func FromSchemaApp ¶
FromSchemaApp converts a schema.App model to App DTO
func FromSchemaApps ¶
FromSchemaApps converts a slice of schema.App to App DTOs
type AppOperations ¶
type AppOperations interface {
// UpdateConfig updates the app service configuration
UpdateConfig(cfg Config)
// CreateApp creates a new application based on the provided request and returns the created app or an error.
CreateApp(ctx context.Context, req *CreateAppRequest) (*App, error)
// GetPlatformApp retrieves the platform-level app entity, often representing the default or primary tenant.
GetPlatformApp(ctx context.Context) (*App, error)
// FindAppByID retrieves an app by its unique identifier. Returns the app if found or an error if not.
FindAppByID(ctx context.Context, id xid.ID) (*App, error)
// FindAppBySlug retrieves an app by its unique slug from the repository.
// Returns the app if found, or an error if not found or if an issue occurred.
FindAppBySlug(ctx context.Context, slug string) (*App, error)
// UpdateApp updates an existing app's details identified by its ID using the specified update request parameters.
UpdateApp(ctx context.Context, id xid.ID, req *UpdateAppRequest) (*App, error)
// DeleteApp deletes an app identified by the specified ID. Platform app cannot be deleted unless another app is made platform first.
DeleteApp(ctx context.Context, id xid.ID) error
// ListApps fetches a paginated list of apps with optional filtering.
ListApps(ctx context.Context, filter *ListAppsFilter) (*pagination.PageResponse[*App], error)
// CountApps returns the total number of apps available in the system or database.
// It takes a context to handle deadlines, cancelation signals, and other request-scoped values.
CountApps(ctx context.Context) (int, error)
// SetPlatformApp transfers platform status to the specified app. Only one app can be platform at a time.
SetPlatformApp(ctx context.Context, newPlatformAppID xid.ID) error
// IsPlatformApp checks if the specified app is the platform app.
IsPlatformApp(ctx context.Context, appID xid.ID) (bool, error)
}
AppOperations defines app management operations
type AppRepository ¶
type AppRepository interface {
CreateApp(ctx context.Context, app *schema.App) error
GetPlatformApp(ctx context.Context) (*schema.App, error)
FindAppByID(ctx context.Context, id xid.ID) (*schema.App, error)
FindAppBySlug(ctx context.Context, slug string) (*schema.App, error)
UpdateApp(ctx context.Context, app *schema.App) error
DeleteApp(ctx context.Context, id xid.ID) error
ListApps(ctx context.Context, filter *ListAppsFilter) (*pagination.PageResponse[*schema.App], error)
CountApps(ctx context.Context) (int, error)
}
AppRepository handles app aggregate operations
type AppService ¶
type AppService struct {
// contains filtered or unexported fields
}
AppService handles app aggregate operations
func NewAppService ¶
func NewAppService(repo AppRepository, cfg Config, rbacSvc *rbac.Service) *AppService
NewAppService creates a new app service
func (*AppService) CountApps ¶
func (s *AppService) CountApps(ctx context.Context) (int, error)
CountApps returns total number of apps
func (*AppService) CreateApp ¶
func (s *AppService) CreateApp(ctx context.Context, req *CreateAppRequest) (*App, error)
CreateApp creates a new app
func (*AppService) DeleteApp ¶
DeleteApp deletes an app by ID Platform app cannot be deleted unless another app is made platform first
func (*AppService) FindAppByID ¶
FindAppByID returns an app by ID
func (*AppService) FindAppBySlug ¶
FindAppBySlug returns an app by slug
func (*AppService) GetCookieConfig ¶ added in v0.0.2
func (s *AppService) GetCookieConfig(ctx context.Context, appID xid.ID) (*session.CookieConfig, error)
GetCookieConfig retrieves the cookie configuration for a specific app It merges app-specific overrides from metadata with the global configuration
func (*AppService) GetPlatformApp ¶
func (s *AppService) GetPlatformApp(ctx context.Context) (*App, error)
GetPlatformApp retrieves the platform-level app entity
func (*AppService) IsPlatformApp ¶
IsPlatformApp checks if the specified app is the platform app
func (*AppService) ListApps ¶
func (s *AppService) ListApps(ctx context.Context, filter *ListAppsFilter) (*pagination.PageResponse[*App], error)
ListApps returns a paginated list of apps
func (*AppService) SetGlobalCookieConfig ¶ added in v0.0.2
func (s *AppService) SetGlobalCookieConfig(config *session.CookieConfig)
SetGlobalCookieConfig sets the global cookie configuration This is called during Auth initialization to provide the global default
func (*AppService) SetHookRegistry ¶
func (s *AppService) SetHookRegistry(hookRegistry *hooks.HookRegistry)
SetHookRegistry sets the hook registry for executing hooks
func (*AppService) SetPlatformApp ¶
SetPlatformApp transfers platform status to the specified app Only one app can be platform at a time
func (*AppService) UpdateApp ¶
func (s *AppService) UpdateApp(ctx context.Context, id xid.ID, req *UpdateAppRequest) (*App, error)
UpdateApp updates an app
func (*AppService) UpdateConfig ¶
func (s *AppService) UpdateConfig(cfg Config)
UpdateConfig updates the app service configuration
type Config ¶
type Config struct {
// PlatformAppID is the ID of the platform app (super admin)
PlatformAppID xid.ID `json:"platformAppId"`
// DefaultAppName is the name of the default app in standalone mode
DefaultAppName string `json:"defaultAppName"`
// EnableAppCreation allows users to create new apps (multitenancy mode)
EnableAppCreation bool `json:"enableAppCreation"`
// MaxMembersPerApp limits the number of members per app
MaxMembersPerApp int `json:"maxMembersPerApp"`
// MaxTeamsPerApp limits the number of teams per app
MaxTeamsPerApp int `json:"maxTeamsPerApp"`
// RequireInvitation requires invitation for joining apps
RequireInvitation bool `json:"requireInvitation"`
// InvitationExpiryHours sets how long invitations are valid
InvitationExpiryHours int `json:"invitationExpiryHours"`
// AutoCreateDefaultApp auto-creates default app on server start
AutoCreateDefaultApp bool `json:"autoCreateDefaultApp"`
// DefaultEnvironmentName is the name of the default dev environment
DefaultEnvironmentName string `json:"defaultEnvironmentName"`
}
Config represents app service configuration
type CreateAppRequest ¶
type CreateAppRequest struct {
Name string `json:"name"`
Slug string `json:"slug"`
Logo string `json:"logo"`
Metadata map[string]interface{} `json:"metadata"`
}
CreateAppRequest represents a create app request
type CreateTeamRequest ¶
type CreateTeamRequest struct {
AppID xid.ID `json:"appId"`
Name string `json:"name"`
Description *string `json:"description,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
ProvisionedBy string `json:"provisionedBy,omitempty"` // e.g., "scim"
ExternalID string `json:"externalID,omitempty"` // External system ID
}
CreateTeamRequest represents a create team request
type Invitation ¶
type Invitation struct {
ID xid.ID `json:"id"`
AppID xid.ID `json:"appId"`
Email string `json:"email"`
Role MemberRole `json:"role"`
Token string `json:"token"`
InviterID xid.ID `json:"inviterId"`
Status InvitationStatus `json:"status"`
ExpiresAt time.Time `json:"expiresAt"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
// Audit fields
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
DeletedAt *time.Time `json:"deletedAt,omitempty"`
}
Invitation represents an app invitation DTO (Data Transfer Object)
func FromSchemaInvitation ¶
func FromSchemaInvitation(si *schema.Invitation) *Invitation
FromSchemaInvitation converts a schema.Invitation model to Invitation DTO
func FromSchemaInvitations ¶
func FromSchemaInvitations(invitations []*schema.Invitation) []*Invitation
FromSchemaInvitations converts a slice of schema.Invitation to Invitation DTOs
func (*Invitation) ToSchema ¶
func (inv *Invitation) ToSchema() *schema.Invitation
ToSchema converts the Invitation DTO to a schema.Invitation model
type InvitationOperations ¶
type InvitationOperations interface {
// CreateInvitation creates an app invitation
CreateInvitation(ctx context.Context, inv *Invitation) error
// FindInvitationByID finds an invitation by ID
FindInvitationByID(ctx context.Context, id xid.ID) (*Invitation, error)
// FindInvitationByToken finds an invitation by token
FindInvitationByToken(ctx context.Context, token string) (*Invitation, error)
// ListInvitations lists invitations for an app with pagination
ListInvitations(ctx context.Context, filter *ListInvitationsFilter) (*pagination.PageResponse[*Invitation], error)
// AcceptInvitation accepts an invitation and creates a member
AcceptInvitation(ctx context.Context, token string, userID xid.ID) (*Member, error)
// DeclineInvitation declines an invitation
DeclineInvitation(ctx context.Context, token string) error
// CancelInvitation cancels an invitation (only admins/owners)
CancelInvitation(ctx context.Context, id, cancellerUserID xid.ID) error
// ResendInvitation resends an invitation by creating a new token and updating expiry
ResendInvitation(ctx context.Context, id, resenderUserID xid.ID) (*Invitation, error)
// CleanupExpiredInvitations removes expired invitations
CleanupExpiredInvitations(ctx context.Context) (int, error)
}
InvitationOperations defines invitation management operations
type InvitationRepository ¶
type InvitationRepository interface {
CreateInvitation(ctx context.Context, inv *schema.Invitation) error
FindInvitationByID(ctx context.Context, id xid.ID) (*schema.Invitation, error)
FindInvitationByToken(ctx context.Context, token string) (*schema.Invitation, error)
ListInvitations(ctx context.Context, filter *ListInvitationsFilter) (*pagination.PageResponse[*schema.Invitation], error)
UpdateInvitation(ctx context.Context, inv *schema.Invitation) error
DeleteInvitation(ctx context.Context, id xid.ID) error
DeleteExpiredInvitations(ctx context.Context) (int, error)
}
InvitationRepository handles invitation aggregate operations
type InvitationService ¶
type InvitationService struct {
// contains filtered or unexported fields
}
InvitationService handles invitation aggregate operations
func NewInvitationService ¶
func NewInvitationService( repo InvitationRepository, memberRepo MemberRepository, memberSvc *MemberService, appRepo AppRepository, cfg Config, rbacSvc *rbac.Service, ) *InvitationService
NewInvitationService creates a new invitation service
func (*InvitationService) AcceptInvitation ¶
func (s *InvitationService) AcceptInvitation(ctx context.Context, token string, userID xid.ID) (*Member, error)
AcceptInvitation accepts an invitation and creates a member
func (*InvitationService) CancelInvitation ¶
CancelInvitation cancels an invitation (only admins/owners)
func (*InvitationService) CleanupExpiredInvitations ¶
func (s *InvitationService) CleanupExpiredInvitations(ctx context.Context) (int, error)
CleanupExpiredInvitations removes expired invitations
func (*InvitationService) CreateInvitation ¶
func (s *InvitationService) CreateInvitation(ctx context.Context, inv *Invitation) error
CreateInvitation creates an app invitation
func (*InvitationService) DeclineInvitation ¶
func (s *InvitationService) DeclineInvitation(ctx context.Context, token string) error
DeclineInvitation declines an invitation
func (*InvitationService) FindInvitationByID ¶
func (s *InvitationService) FindInvitationByID(ctx context.Context, id xid.ID) (*Invitation, error)
FindInvitationByID finds an invitation by ID
func (*InvitationService) FindInvitationByToken ¶
func (s *InvitationService) FindInvitationByToken(ctx context.Context, token string) (*Invitation, error)
FindInvitationByToken finds an invitation by token
func (*InvitationService) ListInvitations ¶
func (s *InvitationService) ListInvitations(ctx context.Context, filter *ListInvitationsFilter) (*pagination.PageResponse[*Invitation], error)
ListInvitations lists invitations for an app with pagination
func (*InvitationService) ResendInvitation ¶
func (s *InvitationService) ResendInvitation(ctx context.Context, id, resenderUserID xid.ID) (*Invitation, error)
ResendInvitation resends an invitation by creating a new token and updating expiry
type InviteMemberRequest ¶
type InviteMemberRequest struct {
AppID xid.ID `json:"appId"`
Email string `json:"email"`
Role string `json:"role"`
InviterID xid.ID `json:"inviterId"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
InviteMemberRequest represents an invite member request
type ListAppsFilter ¶
type ListAppsFilter struct {
pagination.PaginationParams
IsPlatform *bool `json:"isPlatform,omitempty" query:"is_platform"`
}
ListAppsFilter represents filter parameters for listing apps
type ListInvitationsFilter ¶
type ListInvitationsFilter struct {
pagination.PaginationParams
AppID xid.ID `json:"appId" query:"app_id"`
Status *schema.InvitationStatus `json:"status,omitempty" query:"status"`
Email *string `json:"email,omitempty" query:"email"`
}
ListInvitationsFilter represents filter parameters for listing invitations
type ListMemberTeamsFilter ¶
type ListMemberTeamsFilter struct {
pagination.PaginationParams
MemberID xid.ID `json:"memberId" query:"member_id"`
}
ListMemberTeamsFilter represents filter parameters for listing teams a member belongs to
type ListMembersFilter ¶
type ListMembersFilter struct {
pagination.PaginationParams
AppID xid.ID `json:"appId" query:"app_id"`
Role *schema.MemberRole `json:"role,omitempty" query:"role"`
Status *schema.MemberStatus `json:"status,omitempty" query:"status"`
}
ListMembersFilter represents filter parameters for listing members
type ListTeamMembersFilter ¶
type ListTeamMembersFilter struct {
pagination.PaginationParams
TeamID xid.ID `json:"teamId" query:"team_id"`
}
ListTeamMembersFilter represents filter parameters for listing team members
type ListTeamsFilter ¶
type ListTeamsFilter struct {
pagination.PaginationParams
AppID xid.ID `json:"appId" query:"app_id"`
}
ListTeamsFilter represents filter parameters for listing teams
type Member ¶
type Member struct {
ID xid.ID `json:"id"`
AppID xid.ID `json:"appId"`
UserID xid.ID `json:"userId"`
Role MemberRole `json:"role"`
Status MemberStatus `json:"status"`
JoinedAt time.Time `json:"joinedAt"`
// Audit fields
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
DeletedAt *time.Time `json:"deletedAt,omitempty"`
}
Member represents an app member DTO (Data Transfer Object) This is separate from schema.Member to maintain proper separation of concerns
func FromSchemaMember ¶
FromSchemaMember converts a schema.Member model to Member DTO
func FromSchemaMembers ¶
FromSchemaMembers converts a slice of schema.Member to Member DTOs
type MemberOperations ¶
type MemberOperations interface {
// CreateMember creates a new member within the specified context and associates it with the provided member details.
CreateMember(ctx context.Context, member *Member) (*Member, error)
// FindMemberByID retrieves a member by their unique identifier. Returns the member or an error if not found.
FindMemberByID(ctx context.Context, id xid.ID) (*Member, error)
// FindMember retrieves a Member within an app using the provided appID and userID. Returns the Member or an error.
FindMember(ctx context.Context, appID, userID xid.ID) (*Member, error)
// ListMembers fetches a paginated list of members for the specified context with optional filtering.
ListMembers(ctx context.Context, filter *ListMembersFilter) (*pagination.PageResponse[*Member], error)
// GetUserMemberships retrieves all app memberships for a given user ID. Returns a slice of Member or an error.
GetUserMemberships(ctx context.Context, userID xid.ID) ([]*Member, error)
// UpdateMember updates an existing member's details. Takes a context and the member object with updated fields.
UpdateMember(ctx context.Context, member *Member) error
// DeleteMember removes a member from the app using the provided member ID. Returns an error if deletion fails.
DeleteMember(ctx context.Context, id xid.ID) error
// CountMembers returns the total number of members in a specific app identified by appID.
CountMembers(ctx context.Context, appID xid.ID) (int, error)
// IsOwner checks if a user is the owner of an app
IsOwner(ctx context.Context, appID, userID xid.ID) (bool, error)
// IsAdmin checks if a user is an admin or owner of an app
IsAdmin(ctx context.Context, appID, userID xid.ID) (bool, error)
// RequireOwner checks if a user is the owner of an app and returns an error if not
RequireOwner(ctx context.Context, appID, userID xid.ID) error
// RequireAdmin checks if a user is an admin or owner of an app and returns an error if not
RequireAdmin(ctx context.Context, appID, userID xid.ID) error
}
MemberOperations defines member management operations
type MemberRepository ¶
type MemberRepository interface {
CreateMember(ctx context.Context, member *schema.Member) error
FindMember(ctx context.Context, appID, userID xid.ID) (*schema.Member, error)
FindMemberByID(ctx context.Context, id xid.ID) (*schema.Member, error)
ListMembers(ctx context.Context, filter *ListMembersFilter) (*pagination.PageResponse[*schema.Member], error)
ListMembersByUser(ctx context.Context, userID xid.ID) ([]*schema.Member, error)
UpdateMember(ctx context.Context, member *schema.Member) error
DeleteMember(ctx context.Context, id xid.ID) error
CountMembers(ctx context.Context, appID xid.ID) (int, error)
}
MemberRepository handles member aggregate operations
type MemberService ¶
type MemberService struct {
// contains filtered or unexported fields
}
MemberService handles member aggregate operations
func NewMemberService ¶
func NewMemberService( repo MemberRepository, appRepo AppRepository, roleRepo rbac.RoleRepository, userRoleRepo rbac.UserRoleRepository, cfg Config, rbacSvc *rbac.Service, ) *MemberService
NewMemberService creates a new member service
func (*MemberService) CountMembers ¶
CountMembers returns total number of members in an app
func (*MemberService) CreateMember ¶
CreateMember adds a new member to an app This operation is idempotent - if the member already exists, returns the existing member
func (*MemberService) DeleteMember ¶
DeleteMember deletes a member by ID
func (*MemberService) FindMember ¶
FindMember finds a member by appID and userID
func (*MemberService) FindMemberByID ¶
FindMemberByID finds a member by ID
func (*MemberService) GetUserMemberships ¶
GetUserMemberships retrieves all apps where the user is a member
func (*MemberService) IsAdmin ¶
IsAdmin checks if a user is an admin or owner of an app This is a convenience method that checks the member role directly
func (*MemberService) IsOwner ¶
IsOwner checks if a user is the owner of an app This is a convenience method that checks the member role directly
func (*MemberService) IsUserMember ¶
IsUserMember checks if a user is an active member of an app
func (*MemberService) ListMembers ¶
func (s *MemberService) ListMembers(ctx context.Context, filter *ListMembersFilter) (*pagination.PageResponse[*Member], error)
ListMembers lists members in an app with pagination and filtering
func (*MemberService) RequireAdmin ¶
RequireAdmin checks if a user is an admin or owner of an app and returns an error if not For RBAC-based checks, use CheckPermission/RequirePermission from rbac.go instead with specific actions
func (*MemberService) RequireOwner ¶
RequireOwner checks if a user is the owner of an app and returns an error if not For RBAC-based checks, use CheckPermission/RequirePermission from rbac.go instead with specific actions
func (*MemberService) UpdateMember ¶
func (s *MemberService) UpdateMember(ctx context.Context, member *Member) error
UpdateMember updates a member
type Service ¶
type Service interface {
// UpdateConfig updates the app service configuration
UpdateConfig(cfg Config)
// GetPlatformApp retrieves the platform-level app entity, often representing the default or primary tenant.
GetPlatformApp(ctx context.Context) (*App, error)
// CreateApp creates a new application based on the provided request and returns the created app or an error.
CreateApp(ctx context.Context, req *CreateAppRequest) (*App, error)
// FindAppByID retrieves an app by its unique identifier. Returns the app if found or an error if not.
FindAppByID(ctx context.Context, id xid.ID) (*App, error)
// FindAppBySlug retrieves an app by its unique slug from the repository.
// Returns the app if found, or an error if not found or if an issue occurred.
FindAppBySlug(ctx context.Context, slug string) (*App, error)
// UpdateApp updates an existing app's details identified by its ID using the specified update request parameters.
UpdateApp(ctx context.Context, id xid.ID, req *UpdateAppRequest) (*App, error)
// DeleteApp deletes an app identified by the specified ID. Returns an error if the deletion fails.
DeleteApp(ctx context.Context, id xid.ID) error
// ListApps fetches a paginated list of apps with optional filtering.
ListApps(ctx context.Context, filter *ListAppsFilter) (*pagination.PageResponse[*App], error)
// CountApps returns the total number of apps available in the system or database.
// It takes a context to handle deadlines, cancelation signals, and other request-scoped values.
CountApps(ctx context.Context) (int, error)
// CreateMember creates a new member within the specified context and associates it with the provided member details.
CreateMember(ctx context.Context, member *Member) (*Member, error)
// FindMemberByID retrieves a member by their unique identifier. Returns the member or an error if not found.
FindMemberByID(ctx context.Context, id xid.ID) (*Member, error)
// FindMember retrieves a Member within an app using the provided appID and userID. Returns the Member or an error.
FindMember(ctx context.Context, appID, userID xid.ID) (*Member, error)
// ListMembers retrieves a paginated list of members with optional filtering by role and status.
ListMembers(ctx context.Context, filter *ListMembersFilter) (*pagination.PageResponse[*Member], error)
// CountMembers counts the number of members associated with a specific application by its appID.
CountMembers(ctx context.Context, appID xid.ID) (int, error)
// GetUserMemberships retrieves all apps where the user is a member.
// Returns a list of members with their associated app details.
GetUserMemberships(ctx context.Context, userID xid.ID) ([]*Member, error)
// UpdateMember updates the details of an existing app member in the system.
UpdateMember(ctx context.Context, member *Member) error
// DeleteMember removes a member identified by the given ID from the system. Returns an error if the operation fails.
DeleteMember(ctx context.Context, id xid.ID) error
// CreateTeam creates a new team and associates it with an app. Returns an error if the operation fails.
CreateTeam(ctx context.Context, team *Team) error
// FindTeamByID retrieves a team by its unique identifier.
// Returns the corresponding team or an error if not found.
FindTeamByID(ctx context.Context, id xid.ID) (*Team, error)
// ListTeams retrieves a paginated list of teams associated with a specific app.
ListTeams(ctx context.Context, filter *ListTeamsFilter) (*pagination.PageResponse[*Team], error)
// CountTeams returns the total number of teams associated with a specific app identified by the given appID.
CountTeams(ctx context.Context, appID xid.ID) (int, error)
// UpdateTeam updates an existing team with new information provided in the Team object. Returns an error if the update fails.
UpdateTeam(ctx context.Context, team *Team) error
// DeleteTeam removes a team with the specified ID from the system. Returns an error if the operation fails.
DeleteTeam(ctx context.Context, id xid.ID) error
// AddTeamMember adds a member to a specific team within the system based on provided team member details.
// Returns the created team member and an error if the operation fails.
AddTeamMember(ctx context.Context, tm *TeamMember) (*TeamMember, error)
// RemoveTeamMember removes a specified member from a team identified by the given teamID and memberID. Returns an error if the operation fails.
RemoveTeamMember(ctx context.Context, teamID, memberID xid.ID) error
// ListTeamMembers retrieves a paginated list of members for the specified team.
ListTeamMembers(ctx context.Context, filter *ListTeamMembersFilter) (*pagination.PageResponse[*TeamMember], error)
// CountTeamMembers returns the total number of members in a specific team identified by teamID.
CountTeamMembers(ctx context.Context, teamID xid.ID) (int, error)
// IsUserMember checks if a user is a member of an app with active status.
// Returns true if the user is an active member, false otherwise.
IsUserMember(ctx context.Context, appID, userID xid.ID) (bool, error)
// CreateInvitation creates a new invitation for an application.
CreateInvitation(ctx context.Context, inv *Invitation) error
// FindInvitationByID retrieves an invitation by its ID.
FindInvitationByID(ctx context.Context, id xid.ID) (*Invitation, error)
// FindInvitationByToken retrieves an invitation by its unique token.
FindInvitationByToken(ctx context.Context, token string) (*Invitation, error)
// ListInvitations retrieves a paginated list of invitations for an app with optional filtering.
ListInvitations(ctx context.Context, filter *ListInvitationsFilter) (*pagination.PageResponse[*Invitation], error)
// AcceptInvitation accepts an invitation and creates a member.
// Returns the created member or an error if the invitation is invalid, expired, or already used.
AcceptInvitation(ctx context.Context, token string, userID xid.ID) (*Member, error)
// DeclineInvitation declines a pending invitation.
DeclineInvitation(ctx context.Context, token string) error
// CancelInvitation cancels a pending invitation (requires admin/owner permissions).
CancelInvitation(ctx context.Context, id, cancellerUserID xid.ID) error
// ResendInvitation resends an invitation by generating a new token and updating expiry (requires admin/owner permissions).
ResendInvitation(ctx context.Context, id, resenderUserID xid.ID) (*Invitation, error)
// CleanupExpiredInvitations removes all expired invitations from the system.
// Returns the number of invitations deleted.
CleanupExpiredInvitations(ctx context.Context) (int, error)
// IsOwner checks if a user is the owner of an app.
IsOwner(ctx context.Context, appID, userID xid.ID) (bool, error)
// IsAdmin checks if a user is an admin or owner of an app.
IsAdmin(ctx context.Context, appID, userID xid.ID) (bool, error)
// RequireOwner checks if a user is the owner of an app and returns an error if not.
RequireOwner(ctx context.Context, appID, userID xid.ID) error
// RequireAdmin checks if a user is an admin or owner of an app and returns an error if not.
RequireAdmin(ctx context.Context, appID, userID xid.ID) error
// IsTeamMember checks if a member is part of a team.
IsTeamMember(ctx context.Context, teamID, memberID xid.ID) (bool, error)
// ListMemberTeams lists all teams a member belongs to with pagination.
ListMemberTeams(ctx context.Context, filter *ListMemberTeamsFilter) (*pagination.PageResponse[*Team], error)
// FindTeamByName finds a team by name within an app.
FindTeamByName(ctx context.Context, appID xid.ID, name string) (*Team, error)
// CheckPermission checks if a user has permission to perform an action on a resource.
CheckPermission(ctx context.Context, userID, appID xid.ID, action, resourceType, resourceID string) (bool, error)
// CheckPermissionWithContext checks permission with additional context variables for conditional permissions.
CheckPermissionWithContext(ctx context.Context, userID, appID xid.ID, action, resourceType, resourceID string, contextVars map[string]string) (bool, error)
// RequirePermission checks if a user has permission and returns an error if denied.
RequirePermission(ctx context.Context, userID, appID xid.ID, action, resourceType, resourceID string) error
// RequirePermissionWithContext checks permission with context variables and returns error if denied.
RequirePermissionWithContext(ctx context.Context, userID, appID xid.ID, action, resourceType, resourceID string, contextVars map[string]string) error
}
Service defines the complete contract for all app-related service operations This interface combines all focused operations and is useful for backward compatibility or when a component needs access to all operations. New code should prefer using the focused interfaces (AppOperations, MemberOperations, etc.)
type ServiceImpl ¶
type ServiceImpl struct {
App *AppService
Member *MemberService
Team *TeamService
Invitation *InvitationService
}
ServiceImpl provides access to all app-related services Internally delegates to focused services for better separation of concerns
func NewService ¶
func NewService( appRepo AppRepository, memberRepo MemberRepository, teamRepo TeamRepository, invitationRepo InvitationRepository, roleRepo rbac.RoleRepository, userRoleRepo rbac.UserRoleRepository, cfg Config, rbacSvc *rbac.Service, ) *ServiceImpl
NewService creates a new service with all focused services
func (*ServiceImpl) AcceptInvitation ¶
func (*ServiceImpl) AddTeamMember ¶
func (s *ServiceImpl) AddTeamMember(ctx context.Context, tm *TeamMember) (*TeamMember, error)
func (*ServiceImpl) CancelInvitation ¶
func (*ServiceImpl) CheckPermission ¶
func (s *ServiceImpl) CheckPermission(ctx context.Context, userID, appID xid.ID, action, resourceType, resourceID string) (bool, error)
CheckPermission checks if a user has permission to perform an action on a resource. This would typically be implemented in a shared RBAC helper or in the MemberService
func (*ServiceImpl) CheckPermissionWithContext ¶
func (s *ServiceImpl) CheckPermissionWithContext(ctx context.Context, userID, appID xid.ID, action, resourceType, resourceID string, contextVars map[string]string) (bool, error)
CheckPermissionWithContext checks permission with additional context variables for conditional permissions.
func (*ServiceImpl) CleanupExpiredInvitations ¶
func (s *ServiceImpl) CleanupExpiredInvitations(ctx context.Context) (int, error)
func (*ServiceImpl) CountMembers ¶
func (*ServiceImpl) CountTeamMembers ¶
func (*ServiceImpl) CountTeams ¶
func (*ServiceImpl) CreateApp ¶
func (s *ServiceImpl) CreateApp(ctx context.Context, req *CreateAppRequest) (*App, error)
func (*ServiceImpl) CreateInvitation ¶
func (s *ServiceImpl) CreateInvitation(ctx context.Context, inv *Invitation) error
func (*ServiceImpl) CreateMember ¶
func (*ServiceImpl) CreateTeam ¶
func (s *ServiceImpl) CreateTeam(ctx context.Context, team *Team) error
func (*ServiceImpl) DeclineInvitation ¶
func (s *ServiceImpl) DeclineInvitation(ctx context.Context, token string) error
func (*ServiceImpl) DeleteMember ¶
func (*ServiceImpl) DeleteTeam ¶
func (*ServiceImpl) FindAppByID ¶
func (*ServiceImpl) FindAppBySlug ¶
func (*ServiceImpl) FindInvitationByID ¶
func (s *ServiceImpl) FindInvitationByID(ctx context.Context, id xid.ID) (*Invitation, error)
func (*ServiceImpl) FindInvitationByToken ¶
func (s *ServiceImpl) FindInvitationByToken(ctx context.Context, token string) (*Invitation, error)
func (*ServiceImpl) FindMember ¶
func (*ServiceImpl) FindMemberByID ¶
func (*ServiceImpl) FindTeamByID ¶
func (*ServiceImpl) FindTeamByName ¶
func (*ServiceImpl) GetPlatformApp ¶
func (s *ServiceImpl) GetPlatformApp(ctx context.Context) (*App, error)
func (*ServiceImpl) GetUserMemberships ¶
func (*ServiceImpl) IsPlatformApp ¶
func (*ServiceImpl) IsTeamMember ¶
func (*ServiceImpl) IsUserMember ¶
func (*ServiceImpl) ListApps ¶
func (s *ServiceImpl) ListApps(ctx context.Context, filter *ListAppsFilter) (*pagination.PageResponse[*App], error)
func (*ServiceImpl) ListInvitations ¶
func (s *ServiceImpl) ListInvitations(ctx context.Context, filter *ListInvitationsFilter) (*pagination.PageResponse[*Invitation], error)
func (*ServiceImpl) ListMemberTeams ¶
func (s *ServiceImpl) ListMemberTeams(ctx context.Context, filter *ListMemberTeamsFilter) (*pagination.PageResponse[*Team], error)
func (*ServiceImpl) ListMembers ¶
func (s *ServiceImpl) ListMembers(ctx context.Context, filter *ListMembersFilter) (*pagination.PageResponse[*Member], error)
func (*ServiceImpl) ListTeamMembers ¶
func (s *ServiceImpl) ListTeamMembers(ctx context.Context, filter *ListTeamMembersFilter) (*pagination.PageResponse[*TeamMember], error)
func (*ServiceImpl) ListTeams ¶
func (s *ServiceImpl) ListTeams(ctx context.Context, filter *ListTeamsFilter) (*pagination.PageResponse[*Team], error)
func (*ServiceImpl) RemoveTeamMember ¶
func (*ServiceImpl) RequireAdmin ¶
func (*ServiceImpl) RequireOwner ¶
func (*ServiceImpl) RequirePermission ¶
func (s *ServiceImpl) RequirePermission(ctx context.Context, userID, appID xid.ID, action, resourceType, resourceID string) error
RequirePermission checks if a user has permission and returns an error if denied.
func (*ServiceImpl) RequirePermissionWithContext ¶
func (s *ServiceImpl) RequirePermissionWithContext(ctx context.Context, userID, appID xid.ID, action, resourceType, resourceID string, contextVars map[string]string) error
RequirePermissionWithContext checks permission with context variables and returns error if denied.
func (*ServiceImpl) ResendInvitation ¶
func (s *ServiceImpl) ResendInvitation(ctx context.Context, id, resenderUserID xid.ID) (*Invitation, error)
func (*ServiceImpl) SetPlatformApp ¶
func (*ServiceImpl) UpdateApp ¶
func (s *ServiceImpl) UpdateApp(ctx context.Context, id xid.ID, req *UpdateAppRequest) (*App, error)
func (*ServiceImpl) UpdateConfig ¶
func (s *ServiceImpl) UpdateConfig(cfg Config)
func (*ServiceImpl) UpdateMember ¶
func (s *ServiceImpl) UpdateMember(ctx context.Context, member *Member) error
func (*ServiceImpl) UpdateTeam ¶
func (s *ServiceImpl) UpdateTeam(ctx context.Context, team *Team) error
type Team ¶
type Team struct {
ID xid.ID `json:"id"`
AppID xid.ID `json:"appId"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
// Provisioning tracking
ProvisionedBy *string `json:"provisionedBy,omitempty"` // e.g., "scim"
ExternalID *string `json:"externalID,omitempty"` // External system ID
// Audit fields
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
DeletedAt *time.Time `json:"deletedAt,omitempty"`
}
Team represents a team within an app DTO (Data Transfer Object)
func FromSchemaTeam ¶
FromSchemaTeam converts a schema.Team model to Team DTO
func FromSchemaTeams ¶
FromSchemaTeams converts a slice of schema.Team to Team DTOs
type TeamMember ¶
type TeamMember struct {
ID xid.ID `json:"id"`
TeamID xid.ID `json:"teamId"`
MemberID xid.ID `json:"memberId"`
// Provisioning tracking
ProvisionedBy *string `json:"provisionedBy,omitempty"` // e.g., "scim"
// Audit fields
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
DeletedAt *time.Time `json:"deletedAt,omitempty"`
}
TeamMember represents a team member DTO (Data Transfer Object) Note: Role is on the Member entity, not TeamMember
func FromSchemaTeamMember ¶
func FromSchemaTeamMember(stm *schema.TeamMember) *TeamMember
FromSchemaTeamMember converts a schema.TeamMember model to TeamMember DTO
func FromSchemaTeamMembers ¶
func FromSchemaTeamMembers(members []*schema.TeamMember) []*TeamMember
FromSchemaTeamMembers converts a slice of schema.TeamMember to TeamMember DTOs
func (*TeamMember) ToSchema ¶
func (tm *TeamMember) ToSchema() *schema.TeamMember
ToSchema converts the TeamMember DTO to a schema.TeamMember model
type TeamOperations ¶
type TeamOperations interface {
// CreateTeam creates a new team within the given context using the provided team details. Returns an error if creation fails.
CreateTeam(ctx context.Context, team *Team) error
// FindTeamByID retrieves a team by its unique identifier. Returns the team or an error if not found.
FindTeamByID(ctx context.Context, id xid.ID) (*Team, error)
// FindTeamByName finds a team by name within an app
FindTeamByName(ctx context.Context, appID xid.ID, name string) (*Team, error)
// ListTeams fetches a paginated list of teams with optional filtering based on the provided context.
ListTeams(ctx context.Context, filter *ListTeamsFilter) (*pagination.PageResponse[*Team], error)
// UpdateTeam updates an existing team's details. Takes a context and the team object with updated fields.
UpdateTeam(ctx context.Context, team *Team) error
// DeleteTeam removes a team identified by the specified ID. Returns an error if deletion fails.
DeleteTeam(ctx context.Context, id xid.ID) error
// CountTeams returns the total number of teams in a specific app identified by appID.
CountTeams(ctx context.Context, appID xid.ID) (int, error)
// AddTeamMember adds a member to a team. Returns the created TeamMember or an error if the operation fails.
AddTeamMember(ctx context.Context, tm *TeamMember) (*TeamMember, error)
// RemoveTeamMember removes a member from a team using the provided teamID and memberID. Returns an error if removal fails.
RemoveTeamMember(ctx context.Context, teamID, memberID xid.ID) error
// ListTeamMembers fetches a paginated list of team members with optional filtering.
ListTeamMembers(ctx context.Context, filter *ListTeamMembersFilter) (*pagination.PageResponse[*TeamMember], error)
// CountTeamMembers returns the total number of members in a specific team identified by teamID.
CountTeamMembers(ctx context.Context, teamID xid.ID) (int, error)
// IsTeamMember checks if a member is part of a team
IsTeamMember(ctx context.Context, teamID, memberID xid.ID) (bool, error)
// ListMemberTeams lists all teams a member belongs to with pagination
ListMemberTeams(ctx context.Context, filter *ListMemberTeamsFilter) (*pagination.PageResponse[*Team], error)
}
TeamOperations defines team management operations
type TeamRepository ¶
type TeamRepository interface {
CreateTeam(ctx context.Context, team *schema.Team) error
FindTeamByID(ctx context.Context, id xid.ID) (*schema.Team, error)
FindTeamByName(ctx context.Context, appID xid.ID, name string) (*schema.Team, error)
ListTeams(ctx context.Context, filter *ListTeamsFilter) (*pagination.PageResponse[*schema.Team], error)
UpdateTeam(ctx context.Context, team *schema.Team) error
DeleteTeam(ctx context.Context, id xid.ID) error
CountTeams(ctx context.Context, appID xid.ID) (int, error)
// Team member operations (part of team aggregate)
AddTeamMember(ctx context.Context, tm *schema.TeamMember) error
RemoveTeamMember(ctx context.Context, teamID, memberID xid.ID) error
ListTeamMembers(ctx context.Context, filter *ListTeamMembersFilter) (*pagination.PageResponse[*schema.TeamMember], error)
CountTeamMembers(ctx context.Context, teamID xid.ID) (int, error)
IsTeamMember(ctx context.Context, teamID, memberID xid.ID) (bool, error)
ListMemberTeams(ctx context.Context, filter *ListMemberTeamsFilter) (*pagination.PageResponse[*schema.Team], error)
}
TeamRepository handles team aggregate operations (including team members)
type TeamService ¶
type TeamService struct {
// contains filtered or unexported fields
}
TeamService handles team aggregate operations
func NewTeamService ¶
func NewTeamService(repo TeamRepository, memberRepo MemberRepository, cfg Config, rbacSvc *rbac.Service) *TeamService
NewTeamService creates a new team service
func (*TeamService) AddTeamMember ¶
func (s *TeamService) AddTeamMember(ctx context.Context, tm *TeamMember) (*TeamMember, error)
AddTeamMember adds a member to a team
func (*TeamService) CountTeamMembers ¶
CountTeamMembers returns total number of members in a team
func (*TeamService) CountTeams ¶
CountTeams returns total number of teams in an app
func (*TeamService) CreateTeam ¶
func (s *TeamService) CreateTeam(ctx context.Context, team *Team) error
CreateTeam creates a new team
func (*TeamService) DeleteTeam ¶
DeleteTeam deletes a team by ID Note: Deleting SCIM-managed teams should emit a warning at the handler level
func (*TeamService) FindTeamByID ¶
FindTeamByID finds a team by ID
func (*TeamService) FindTeamByName ¶
FindTeamByName finds a team by name within an app
func (*TeamService) IsSCIMManaged ¶ added in v0.0.2
func (s *TeamService) IsSCIMManaged(team *Team) bool
IsSCIMManaged checks if a team is managed via SCIM provisioning
func (*TeamService) IsTeamMember ¶
IsTeamMember checks if a member is part of a team
func (*TeamService) IsTeamMemberSCIMManaged ¶ added in v0.0.2
func (s *TeamService) IsTeamMemberSCIMManaged(teamMember *TeamMember) bool
IsTeamMemberSCIMManaged checks if a team membership is managed via SCIM provisioning
func (*TeamService) ListMemberTeams ¶
func (s *TeamService) ListMemberTeams(ctx context.Context, filter *ListMemberTeamsFilter) (*pagination.PageResponse[*Team], error)
ListMemberTeams lists all teams a member belongs to with pagination
func (*TeamService) ListTeamMembers ¶
func (s *TeamService) ListTeamMembers(ctx context.Context, filter *ListTeamMembersFilter) (*pagination.PageResponse[*TeamMember], error)
ListTeamMembers lists members of a team with pagination
func (*TeamService) ListTeams ¶
func (s *TeamService) ListTeams(ctx context.Context, filter *ListTeamsFilter) (*pagination.PageResponse[*Team], error)
ListTeams lists teams in an app with pagination
func (*TeamService) RemoveTeamMember ¶
RemoveTeamMember removes a member from a team
func (*TeamService) UpdateTeam ¶
func (s *TeamService) UpdateTeam(ctx context.Context, team *Team) error
UpdateTeam updates a team Returns an error if the update fails Note: Updating SCIM-managed teams should emit a warning at the handler level
type UpdateAppRequest ¶
type UpdateAppRequest struct {
Name *string `json:"name"`
Logo *string `json:"logo"`
Metadata map[string]interface{} `json:"metadata"`
}
UpdateAppRequest represents an update app request
type UpdateMemberRequest ¶
type UpdateMemberRequest struct {
Role *string `json:"role,omitempty"`
Status *string `json:"status,omitempty"`
}
UpdateMemberRequest represents an update member request
type UpdateTeamRequest ¶
type UpdateTeamRequest struct {
Name *string `json:"name,omitempty"`
Description *string `json:"description,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
UpdateTeamRequest represents an update team request