tenant

package
v0.0.0-...-8acab51 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package tenant provides multi-tenant functionality.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrTenantNotFound is returned when a tenant is not found.
	ErrTenantNotFound = errors.New("tenant not found")
	// ErrTenantExists is returned when a tenant already exists.
	ErrTenantExists = errors.New("tenant already exists")
	// ErrSlugExists is returned when a slug is already taken.
	ErrSlugExists = errors.New("slug already exists")
	// ErrMemberNotFound is returned when a member is not found.
	ErrMemberNotFound = errors.New("member not found")
	// ErrMemberExists is returned when a member already exists.
	ErrMemberExists = errors.New("member already exists in tenant")
	// ErrInvitationNotFound is returned when an invitation is not found.
	ErrInvitationNotFound = errors.New("invitation not found")
	// ErrInvitationExpired is returned when an invitation has expired.
	ErrInvitationExpired = errors.New("invitation expired")
	// ErrInvitationAlreadyAccepted is returned when an invitation was already accepted.
	ErrInvitationAlreadyAccepted = errors.New("invitation already accepted")
	// ErrCannotRemoveOwner is returned when trying to remove the tenant owner.
	ErrCannotRemoveOwner = errors.New("cannot remove tenant owner")
	// ErrCannotChangeOwnerRole is returned when trying to change owner's role.
	ErrCannotChangeOwnerRole = errors.New("cannot change owner role")
	// ErrLimitExceeded is returned when a tenant limit is exceeded.
	ErrLimitExceeded = errors.New("tenant limit exceeded")
)

Functions

func GetTenantIDFromContext

func GetTenantIDFromContext(ctx context.Context) uuid.UUID

GetTenantIDFromContext retrieves the tenant ID from context.

func GetTenantIDFromEchoContext

func GetTenantIDFromEchoContext(c echo.Context) uuid.UUID

GetTenantIDFromEchoContext retrieves the tenant ID from Echo context.

Types

type AcceptInvitationRequest

type AcceptInvitationRequest struct {
	Token string `json:"token" validate:"required"`
}

AcceptInvitationRequest represents a request to accept an invitation.

type ContextKey

type ContextKey string

ContextKey is the type for context keys.

const (
	// TenantIDKey is the context key for tenant ID.
	TenantIDKey ContextKey = "tenant_id"
	// TenantKey is the context key for tenant object.
	TenantKey ContextKey = "tenant"
	// MemberKey is the context key for member object.
	MemberKey ContextKey = "tenant_member"
)

type CreateTenantRequest

type CreateTenantRequest struct {
	Name        string  `json:"name" validate:"required,min=2,max=100"`
	Slug        string  `json:"slug" validate:"required,min=2,max=50,alphanum"`
	Description *string `json:"description,omitempty" validate:"omitempty,max=500"`
}

CreateTenantRequest represents a request to create a tenant.

type Handler

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

Handler handles HTTP requests for tenant management.

func NewHandler

func NewHandler(service *Service) *Handler

NewHandler creates a new tenant handler.

func (*Handler) AcceptInvitation

func (h *Handler) AcceptInvitation(c echo.Context) error

AcceptInvitation handles accepting an invitation.

func (*Handler) CancelInvitation

func (h *Handler) CancelInvitation(c echo.Context) error

CancelInvitation handles canceling an invitation.

func (*Handler) CreateTenant

func (h *Handler) CreateTenant(c echo.Context) error

CreateTenant handles tenant creation.

func (*Handler) DeleteTenant

func (h *Handler) DeleteTenant(c echo.Context) error

DeleteTenant handles deleting a tenant.

func (*Handler) GetLimits

func (h *Handler) GetLimits(c echo.Context) error

GetLimits handles getting tenant limits.

func (*Handler) GetSettings

func (h *Handler) GetSettings(c echo.Context) error

GetSettings handles getting tenant settings.

func (*Handler) GetTenant

func (h *Handler) GetTenant(c echo.Context) error

GetTenant handles getting a tenant by ID.

func (*Handler) InviteMember

func (h *Handler) InviteMember(c echo.Context) error

InviteMember handles inviting a new member.

func (*Handler) ListInvitations

func (h *Handler) ListInvitations(c echo.Context) error

ListInvitations handles listing pending invitations.

func (*Handler) ListMembers

func (h *Handler) ListMembers(c echo.Context) error

ListMembers handles listing members of a tenant.

func (*Handler) ListTenants

func (h *Handler) ListTenants(c echo.Context) error

ListTenants handles listing tenants for the current user.

func (*Handler) RegisterRoutes

func (h *Handler) RegisterRoutes(g *echo.Group)

RegisterRoutes registers the tenant routes.

func (*Handler) RemoveMember

func (h *Handler) RemoveMember(c echo.Context) error

RemoveMember handles removing a member from a tenant.

func (*Handler) TransferOwnership

func (h *Handler) TransferOwnership(c echo.Context) error

TransferOwnership handles transferring tenant ownership.

func (*Handler) UpdateLimits

func (h *Handler) UpdateLimits(c echo.Context) error

UpdateLimits handles updating tenant limits (admin only).

func (*Handler) UpdateMember

func (h *Handler) UpdateMember(c echo.Context) error

UpdateMember handles updating a member's role.

func (*Handler) UpdateSettings

func (h *Handler) UpdateSettings(c echo.Context) error

UpdateSettings handles updating tenant settings.

func (*Handler) UpdateTenant

func (h *Handler) UpdateTenant(c echo.Context) error

UpdateTenant handles updating a tenant.

type InviteMemberRequest

type InviteMemberRequest struct {
	Email string     `json:"email" validate:"required,email"`
	Role  MemberRole `json:"role" validate:"required,oneof=admin member"`
}

InviteMemberRequest represents a request to invite a member.

type ListMembersQuery

type ListMembersQuery struct {
	Page     int         `query:"page"`
	PageSize int         `query:"page_size"`
	Role     *MemberRole `query:"role"`
}

ListMembersQuery represents query parameters for listing members.

type ListMembersResponse

type ListMembersResponse struct {
	Members    []*TenantMemberWithUser `json:"members"`
	Total      int64                   `json:"total"`
	Page       int                     `json:"page"`
	PageSize   int                     `json:"page_size"`
	TotalPages int                     `json:"total_pages"`
}

ListMembersResponse represents a paginated list of members.

type ListTenantsQuery

type ListTenantsQuery struct {
	Page     int     `query:"page"`
	PageSize int     `query:"page_size"`
	Search   string  `query:"search"`
	Status   *Status `query:"status"`
	SortBy   string  `query:"sort_by"`
	SortDir  string  `query:"sort_dir"`
}

ListTenantsQuery represents query parameters for listing tenants.

type ListTenantsResponse

type ListTenantsResponse struct {
	Tenants    []*Tenant `json:"tenants"`
	Total      int64     `json:"total"`
	Page       int       `json:"page"`
	PageSize   int       `json:"page_size"`
	TotalPages int       `json:"total_pages"`
}

ListTenantsResponse represents a paginated list of tenants.

type MemberRole

type MemberRole string

MemberRole represents a user's role within a tenant.

const (
	// MemberRoleOwner has full control over the tenant.
	MemberRoleOwner MemberRole = "owner"
	// MemberRoleAdmin can manage tenant settings and members.
	MemberRoleAdmin MemberRole = "admin"
	// MemberRoleMember has standard access.
	MemberRoleMember MemberRole = "member"
)

type Middleware

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

Middleware provides tenant-related middleware.

func NewMiddleware

func NewMiddleware(service *Service) *Middleware

NewMiddleware creates a new tenant middleware.

func (*Middleware) OptionalTenant

func (m *Middleware) OptionalTenant() echo.MiddlewareFunc

OptionalTenant middleware sets tenant context if provided, but doesn't require it.

func (*Middleware) RequireRole

func (m *Middleware) RequireRole(requiredRole MemberRole) echo.MiddlewareFunc

RequireRole middleware ensures the user has at least the specified role in the tenant. Must be used after RequireTenant middleware.

func (*Middleware) RequireTenant

func (m *Middleware) RequireTenant() echo.MiddlewareFunc

RequireTenant middleware ensures a tenant is selected and the user is a member. It expects the tenant ID to be in the X-Tenant-ID header or tenant_id query parameter.

type Repository

type Repository interface {
	// Tenant operations
	// Create creates a new tenant.
	Create(ctx context.Context, tenant *Tenant) error
	// GetByID retrieves a tenant by ID.
	GetByID(ctx context.Context, id uuid.UUID) (*Tenant, error)
	// GetBySlug retrieves a tenant by slug.
	GetBySlug(ctx context.Context, slug string) (*Tenant, error)
	// Update updates a tenant.
	Update(ctx context.Context, tenant *Tenant) error
	// Delete soft-deletes a tenant.
	Delete(ctx context.Context, id uuid.UUID) error
	// List retrieves tenants with pagination and filtering.
	List(ctx context.Context, query *ListTenantsQuery) (*ListTenantsResponse, error)
	// ExistsBySlug checks if a slug exists.
	ExistsBySlug(ctx context.Context, slug string) (bool, error)
	// GetUserTenants retrieves all tenants a user belongs to.
	GetUserTenants(ctx context.Context, userID uuid.UUID) ([]*Tenant, error)

	// Member operations
	// AddMember adds a member to a tenant.
	AddMember(ctx context.Context, member *TenantMember) error
	// GetMember retrieves a member by tenant and user ID.
	GetMember(ctx context.Context, tenantID, userID uuid.UUID) (*TenantMember, error)
	// UpdateMember updates a member's role.
	UpdateMember(ctx context.Context, member *TenantMember) error
	// RemoveMember removes a member from a tenant.
	RemoveMember(ctx context.Context, tenantID, userID uuid.UUID) error
	// ListMembers retrieves members of a tenant with pagination.
	ListMembers(ctx context.Context, tenantID uuid.UUID, query *ListMembersQuery) (*ListMembersResponse, error)
	// CountMembers returns the number of members in a tenant.
	CountMembers(ctx context.Context, tenantID uuid.UUID) (int64, error)
	// IsMember checks if a user is a member of a tenant.
	IsMember(ctx context.Context, tenantID, userID uuid.UUID) (bool, error)

	// Invitation operations
	// CreateInvitation creates a new invitation.
	CreateInvitation(ctx context.Context, invitation *TenantInvitation) error
	// GetInvitationByID retrieves an invitation by ID.
	GetInvitationByID(ctx context.Context, id uuid.UUID) (*TenantInvitation, error)
	// GetInvitationByToken retrieves an invitation by token.
	GetInvitationByToken(ctx context.Context, token string) (*TenantInvitation, error)
	// GetPendingInvitationByEmail retrieves a pending invitation by email for a tenant.
	GetPendingInvitationByEmail(ctx context.Context, tenantID uuid.UUID, email string) (*TenantInvitation, error)
	// AcceptInvitation marks an invitation as accepted.
	AcceptInvitation(ctx context.Context, id uuid.UUID) error
	// DeleteInvitation deletes an invitation.
	DeleteInvitation(ctx context.Context, id uuid.UUID) error
	// ListPendingInvitations retrieves pending invitations for a tenant.
	ListPendingInvitations(ctx context.Context, tenantID uuid.UUID) ([]*TenantInvitation, error)
	// CleanupExpiredInvitations removes expired invitations.
	CleanupExpiredInvitations(ctx context.Context) error
}

Repository defines the interface for tenant data access.

type SQLiteRepository

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

SQLiteRepository implements Repository using SQLite.

func NewSQLiteRepository

func NewSQLiteRepository(db *sql.DB) *SQLiteRepository

NewSQLiteRepository creates a new SQLiteRepository.

func NewSQLiteRepositoryWithReadDB

func NewSQLiteRepositoryWithReadDB(writeDB, readDB *sql.DB) *SQLiteRepository

NewSQLiteRepositoryWithReadDB creates a new SQLiteRepository with separate write and read database handles.

func (*SQLiteRepository) AcceptInvitation

func (r *SQLiteRepository) AcceptInvitation(ctx context.Context, id uuid.UUID) error

AcceptInvitation marks an invitation as accepted.

func (*SQLiteRepository) AddMember

func (r *SQLiteRepository) AddMember(ctx context.Context, member *TenantMember) error

AddMember adds a member to a tenant.

func (*SQLiteRepository) CleanupExpiredInvitations

func (r *SQLiteRepository) CleanupExpiredInvitations(ctx context.Context) error

CleanupExpiredInvitations removes expired invitations.

func (*SQLiteRepository) CountMembers

func (r *SQLiteRepository) CountMembers(ctx context.Context, tenantID uuid.UUID) (int64, error)

CountMembers returns the number of members in a tenant.

func (*SQLiteRepository) Create

func (r *SQLiteRepository) Create(ctx context.Context, tenant *Tenant) error

Create creates a new tenant.

func (*SQLiteRepository) CreateInvitation

func (r *SQLiteRepository) CreateInvitation(ctx context.Context, invitation *TenantInvitation) error

CreateInvitation creates a new invitation.

func (*SQLiteRepository) Delete

func (r *SQLiteRepository) Delete(ctx context.Context, id uuid.UUID) error

Delete soft-deletes a tenant.

func (*SQLiteRepository) DeleteInvitation

func (r *SQLiteRepository) DeleteInvitation(ctx context.Context, id uuid.UUID) error

DeleteInvitation deletes an invitation.

func (*SQLiteRepository) ExistsBySlug

func (r *SQLiteRepository) ExistsBySlug(ctx context.Context, slug string) (bool, error)

ExistsBySlug checks if a slug exists.

func (*SQLiteRepository) GetByID

func (r *SQLiteRepository) GetByID(ctx context.Context, id uuid.UUID) (*Tenant, error)

GetByID retrieves a tenant by ID.

func (*SQLiteRepository) GetBySlug

func (r *SQLiteRepository) GetBySlug(ctx context.Context, slug string) (*Tenant, error)

GetBySlug retrieves a tenant by slug.

func (*SQLiteRepository) GetInvitationByID

func (r *SQLiteRepository) GetInvitationByID(ctx context.Context, id uuid.UUID) (*TenantInvitation, error)

GetInvitationByID retrieves an invitation by ID.

func (*SQLiteRepository) GetInvitationByToken

func (r *SQLiteRepository) GetInvitationByToken(ctx context.Context, token string) (*TenantInvitation, error)

GetInvitationByToken retrieves an invitation by token.

func (*SQLiteRepository) GetMember

func (r *SQLiteRepository) GetMember(ctx context.Context, tenantID, userID uuid.UUID) (*TenantMember, error)

GetMember retrieves a member by tenant and user ID.

func (*SQLiteRepository) GetPendingInvitationByEmail

func (r *SQLiteRepository) GetPendingInvitationByEmail(ctx context.Context, tenantID uuid.UUID, email string) (*TenantInvitation, error)

GetPendingInvitationByEmail retrieves a pending invitation by email for a tenant.

func (*SQLiteRepository) GetUserTenants

func (r *SQLiteRepository) GetUserTenants(ctx context.Context, userID uuid.UUID) ([]*Tenant, error)

GetUserTenants retrieves all tenants a user belongs to.

func (*SQLiteRepository) InitSchema

func (r *SQLiteRepository) InitSchema(ctx context.Context) error

InitSchema creates the necessary tables.

func (*SQLiteRepository) IsMember

func (r *SQLiteRepository) IsMember(ctx context.Context, tenantID, userID uuid.UUID) (bool, error)

IsMember checks if a user is a member of a tenant.

func (*SQLiteRepository) List

List retrieves tenants with pagination and filtering.

func (*SQLiteRepository) ListMembers

func (r *SQLiteRepository) ListMembers(ctx context.Context, tenantID uuid.UUID, query *ListMembersQuery) (*ListMembersResponse, error)

ListMembers retrieves members of a tenant with pagination.

func (*SQLiteRepository) ListPendingInvitations

func (r *SQLiteRepository) ListPendingInvitations(ctx context.Context, tenantID uuid.UUID) ([]*TenantInvitation, error)

ListPendingInvitations retrieves pending invitations for a tenant.

func (*SQLiteRepository) RemoveMember

func (r *SQLiteRepository) RemoveMember(ctx context.Context, tenantID, userID uuid.UUID) error

RemoveMember removes a member from a tenant.

func (*SQLiteRepository) Update

func (r *SQLiteRepository) Update(ctx context.Context, tenant *Tenant) error

Update updates a tenant.

func (*SQLiteRepository) UpdateMember

func (r *SQLiteRepository) UpdateMember(ctx context.Context, member *TenantMember) error

UpdateMember updates a member's role.

type Service

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

Service provides tenant management operations.

func NewService

func NewService(repo Repository, config *ServiceConfig) *Service

NewService creates a new tenant service.

func (*Service) AcceptInvitation

func (s *Service) AcceptInvitation(ctx context.Context, token string, userID uuid.UUID) (*Tenant, error)

AcceptInvitation accepts an invitation and adds the user to the tenant.

func (*Service) CancelInvitation

func (s *Service) CancelInvitation(ctx context.Context, invitationID uuid.UUID) error

CancelInvitation cancels a pending invitation.

func (*Service) CleanupExpiredInvitations

func (s *Service) CleanupExpiredInvitations(ctx context.Context) error

CleanupExpiredInvitations removes expired invitations.

func (*Service) Create

func (s *Service) Create(ctx context.Context, req *CreateTenantRequest, ownerID uuid.UUID) (*Tenant, error)

Create creates a new tenant and adds the creator as owner.

func (*Service) Delete

func (s *Service) Delete(ctx context.Context, id uuid.UUID) error

Delete soft-deletes a tenant.

func (*Service) GetByID

func (s *Service) GetByID(ctx context.Context, id uuid.UUID) (*Tenant, error)

GetByID retrieves a tenant by ID.

func (*Service) GetBySlug

func (s *Service) GetBySlug(ctx context.Context, slug string) (*Tenant, error)

GetBySlug retrieves a tenant by slug.

func (*Service) GetMember

func (s *Service) GetMember(ctx context.Context, tenantID, userID uuid.UUID) (*TenantMember, error)

GetMember retrieves a member by tenant and user ID.

func (*Service) GetTenantLimits

func (s *Service) GetTenantLimits(ctx context.Context, tenantID uuid.UUID) (*TenantLimits, error)

GetTenantLimits retrieves the limits for a tenant.

func (*Service) GetTenantSettings

func (s *Service) GetTenantSettings(ctx context.Context, tenantID uuid.UUID) (*TenantSettings, error)

GetTenantSettings retrieves the settings for a tenant.

func (*Service) GetUserTenants

func (s *Service) GetUserTenants(ctx context.Context, userID uuid.UUID) ([]*Tenant, error)

GetUserTenants retrieves all tenants a user belongs to.

func (*Service) HasPermission

func (s *Service) HasPermission(ctx context.Context, tenantID, userID uuid.UUID, requiredRole MemberRole) (bool, error)

HasPermission checks if a user has a specific role or higher in a tenant.

func (*Service) InviteMember

func (s *Service) InviteMember(ctx context.Context, tenantID uuid.UUID, req *InviteMemberRequest, invitedBy uuid.UUID) (*TenantInvitation, error)

InviteMember creates an invitation to join a tenant.

func (*Service) IsMember

func (s *Service) IsMember(ctx context.Context, tenantID, userID uuid.UUID) (bool, error)

IsMember checks if a user is a member of a tenant.

func (*Service) List

List retrieves tenants with pagination and filtering.

func (*Service) ListMembers

func (s *Service) ListMembers(ctx context.Context, tenantID uuid.UUID, query *ListMembersQuery) (*ListMembersResponse, error)

ListMembers retrieves members of a tenant with pagination.

func (*Service) ListPendingInvitations

func (s *Service) ListPendingInvitations(ctx context.Context, tenantID uuid.UUID) ([]*TenantInvitation, error)

ListPendingInvitations retrieves pending invitations for a tenant.

func (*Service) RemoveMember

func (s *Service) RemoveMember(ctx context.Context, tenantID, userID uuid.UUID) error

RemoveMember removes a member from a tenant.

func (*Service) TransferOwnership

func (s *Service) TransferOwnership(ctx context.Context, tenantID, currentOwnerID, newOwnerID uuid.UUID) error

TransferOwnership transfers tenant ownership to another member.

func (*Service) Update

func (s *Service) Update(ctx context.Context, id uuid.UUID, req *UpdateTenantRequest) (*Tenant, error)

Update updates a tenant.

func (*Service) UpdateMemberRole

func (s *Service) UpdateMemberRole(ctx context.Context, tenantID, userID uuid.UUID, role MemberRole) error

UpdateMemberRole updates a member's role.

func (*Service) UpdateTenantLimits

func (s *Service) UpdateTenantLimits(ctx context.Context, tenantID uuid.UUID, limits *TenantLimits) error

UpdateTenantLimits updates the limits for a tenant.

func (*Service) UpdateTenantSettings

func (s *Service) UpdateTenantSettings(ctx context.Context, tenantID uuid.UUID, settings *TenantSettings) error

UpdateTenantSettings updates the settings for a tenant.

type ServiceConfig

type ServiceConfig struct {
	InvitationExpiry time.Duration
	DefaultLimits    *TenantLimits
	DefaultSettings  *TenantSettings
}

ServiceConfig contains configuration for the tenant service.

func DefaultServiceConfig

func DefaultServiceConfig() *ServiceConfig

DefaultServiceConfig returns the default service configuration.

type Status

type Status string

Status represents the tenant status.

const (
	// StatusActive indicates an active tenant.
	StatusActive Status = "active"
	// StatusSuspended indicates a suspended tenant.
	StatusSuspended Status = "suspended"
	// StatusDeleted indicates a soft-deleted tenant.
	StatusDeleted Status = "deleted"
)

type Tenant

type Tenant struct {
	// ID is the unique identifier.
	ID uuid.UUID `json:"id" db:"id"`
	// Name is the tenant display name.
	Name string `json:"name" db:"name"`
	// Slug is the URL-friendly identifier.
	Slug string `json:"slug" db:"slug"`
	// Description is an optional description.
	Description *string `json:"description,omitempty" db:"description"`
	// Status is the tenant status.
	Status Status `json:"status" db:"status"`
	// Settings contains tenant-specific settings as JSON.
	Settings *string `json:"settings,omitempty" db:"settings"`
	// Limits contains resource limits as JSON.
	Limits *string `json:"limits,omitempty" db:"limits"`
	// OwnerID is the ID of the tenant owner.
	OwnerID uuid.UUID `json:"owner_id" db:"owner_id"`
	// CreatedAt is when the tenant was created.
	CreatedAt time.Time `json:"created_at" db:"created_at"`
	// UpdatedAt is when the tenant was last updated.
	UpdatedAt time.Time `json:"updated_at" db:"updated_at"`
	// DeletedAt is when the tenant was soft-deleted.
	DeletedAt *time.Time `json:"-" db:"deleted_at"`
}

Tenant represents a tenant (organization) in the system.

func GetTenantFromContext

func GetTenantFromContext(ctx context.Context) *Tenant

GetTenantFromContext retrieves the tenant from context.

func GetTenantFromEchoContext

func GetTenantFromEchoContext(c echo.Context) *Tenant

GetTenantFromEchoContext retrieves the tenant from Echo context.

func NewTenant

func NewTenant(name, slug string, ownerID uuid.UUID) *Tenant

NewTenant creates a new Tenant with default values.

func (*Tenant) IsActive

func (t *Tenant) IsActive() bool

IsActive returns true if the tenant is active.

type TenantInvitation

type TenantInvitation struct {
	// ID is the unique identifier.
	ID uuid.UUID `json:"id" db:"id"`
	// TenantID is the tenant ID.
	TenantID uuid.UUID `json:"tenant_id" db:"tenant_id"`
	// Email is the invited email address.
	Email string `json:"email" db:"email"`
	// Role is the role to assign upon acceptance.
	Role MemberRole `json:"role" db:"role"`
	// Token is the invitation token.
	Token string `json:"-" db:"token"`
	// InvitedBy is the ID of the user who created the invitation.
	InvitedBy uuid.UUID `json:"invited_by" db:"invited_by"`
	// ExpiresAt is when the invitation expires.
	ExpiresAt time.Time `json:"expires_at" db:"expires_at"`
	// AcceptedAt is when the invitation was accepted.
	AcceptedAt *time.Time `json:"accepted_at,omitempty" db:"accepted_at"`
	// CreatedAt is when the invitation was created.
	CreatedAt time.Time `json:"created_at" db:"created_at"`
}

TenantInvitation represents an invitation to join a tenant.

func NewTenantInvitation

func NewTenantInvitation(tenantID uuid.UUID, email string, role MemberRole, invitedBy uuid.UUID, token string, expiresAt time.Time) *TenantInvitation

NewTenantInvitation creates a new TenantInvitation.

func (*TenantInvitation) IsValid

func (i *TenantInvitation) IsValid() bool

IsValid returns true if the invitation is not expired and not accepted.

type TenantLimits

type TenantLimits struct {
	// MaxUsers is the maximum number of users.
	MaxUsers int `json:"max_users"`
	// MaxStorage is the maximum storage in bytes.
	MaxStorage int64 `json:"max_storage"`
	// MaxAPIRequests is the maximum API requests per day.
	MaxAPIRequests int `json:"max_api_requests"`
	// MaxWorkflows is the maximum number of workflows.
	MaxWorkflows int `json:"max_workflows"`
	// MaxChannels is the maximum number of channels.
	MaxChannels int `json:"max_channels"`
}

TenantLimits represents resource limits for a tenant.

func DefaultTenantLimits

func DefaultTenantLimits() *TenantLimits

DefaultTenantLimits returns the default limits for a new tenant.

type TenantMember

type TenantMember struct {
	// ID is the unique identifier.
	ID uuid.UUID `json:"id" db:"id"`
	// TenantID is the tenant ID.
	TenantID uuid.UUID `json:"tenant_id" db:"tenant_id"`
	// UserID is the user ID.
	UserID uuid.UUID `json:"user_id" db:"user_id"`
	// Role is the member's role within the tenant.
	Role MemberRole `json:"role" db:"role"`
	// JoinedAt is when the user joined the tenant.
	JoinedAt time.Time `json:"joined_at" db:"joined_at"`
	// InvitedBy is the ID of the user who invited this member.
	InvitedBy *uuid.UUID `json:"invited_by,omitempty" db:"invited_by"`
}

TenantMember represents a user's membership in a tenant.

func GetMemberFromContext

func GetMemberFromContext(ctx context.Context) *TenantMember

GetMemberFromContext retrieves the member from context.

func GetMemberFromEchoContext

func GetMemberFromEchoContext(c echo.Context) *TenantMember

GetMemberFromEchoContext retrieves the member from Echo context.

func NewTenantMember

func NewTenantMember(tenantID, userID uuid.UUID, role MemberRole, invitedBy *uuid.UUID) *TenantMember

NewTenantMember creates a new TenantMember.

type TenantMemberWithUser

type TenantMemberWithUser struct {
	TenantMember
	Username string  `json:"username"`
	Email    *string `json:"email,omitempty"`
}

TenantMemberWithUser represents a member with user details.

type TenantSettings

type TenantSettings struct {
	// DefaultLanguage is the default language for the tenant.
	DefaultLanguage string `json:"default_language"`
	// Timezone is the default timezone.
	Timezone string `json:"timezone"`
	// Features contains enabled feature flags.
	Features map[string]bool `json:"features"`
}

TenantSettings represents tenant-specific settings.

func DefaultTenantSettings

func DefaultTenantSettings() *TenantSettings

DefaultTenantSettings returns the default settings for a new tenant.

type TransferOwnershipRequest

type TransferOwnershipRequest struct {
	NewOwnerID uuid.UUID `json:"new_owner_id" validate:"required"`
}

TransferOwnershipRequest represents a request to transfer ownership.

type UpdateMemberRequest

type UpdateMemberRequest struct {
	Role MemberRole `json:"role" validate:"required,oneof=owner admin member"`
}

UpdateMemberRequest represents a request to update a member's role.

type UpdateTenantRequest

type UpdateTenantRequest struct {
	Name        *string `json:"name,omitempty" validate:"omitempty,min=2,max=100"`
	Description *string `json:"description,omitempty" validate:"omitempty,max=500"`
	Status      *Status `json:"status,omitempty"`
}

UpdateTenantRequest represents a request to update a tenant.

Jump to

Keyboard shortcuts

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