organization

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2025 License: Apache-2.0 Imports: 31 Imported by: 0

README

Organization Plugin

The Organization plugin provides Clerk.js-style user-created organizations (workspaces) for AuthSome. It allows authenticated users to create their own organizations, invite members, manage teams, and control access through role-based permissions.

Features

  • User-Created Organizations: Any authenticated user can create their own organization
  • Member Management: Invite users, manage roles (owner, admin, member)
  • Team Management: Create teams within organizations for better structure
  • Role-Based Access Control: Owner, Admin, and Member roles with appropriate permissions
  • Invitation System: Secure token-based invitations with expiry
  • Multi-Organization Support: Users can belong to multiple organizations
  • Slug-Based Access: Access organizations via unique slugs

Architecture

This plugin is separate from the platform-level App (formerly Organization in multitenancy plugin). The hierarchy is:

Platform App (managed by multitenancy plugin)
└── User Organizations (managed by this plugin)
    ├── Members (users with roles)
    └── Teams (groups of members)

Models

Organization

User-created workspace/organization that belongs to a platform App.

type Organization struct {
    ID        xid.ID
    AppID     xid.ID  // Platform app this org belongs to
    Name      string
    Slug      string  // Unique slug for URL access
    Logo      *string
    Metadata  map[string]interface{}
    CreatedBy xid.ID  // User who created it
    // ... timestamps
}
OrganizationMember

Represents a user's membership in an organization.

type OrganizationMember struct {
    ID             xid.ID
    OrganizationID xid.ID
    UserID         xid.ID
    Role           string  // owner, admin, member
    Status         string  // active, suspended, pending
    // ... timestamps
}
OrganizationTeam

Teams within an organization for better member organization.

type OrganizationTeam struct {
    ID             xid.ID
    OrganizationID xid.ID
    Name           string
    Description    *string
    Metadata       map[string]interface{}
    // ... timestamps
}
OrganizationInvitation

Invitation to join an organization.

type OrganizationInvitation struct {
    ID             xid.ID
    OrganizationID xid.ID
    Email          string
    Role           string
    Token          string  // Secure invitation token
    Status         string  // pending, accepted, declined, expired
    InvitedBy      xid.ID
    ExpiresAt      time.Time
    // ... timestamps
}

Roles

Owner
  • Full control over the organization
  • Can delete the organization
  • Can manage all members and teams
  • Cannot be removed or have role changed
  • Assigned to creator automatically
Admin
  • Can invite and manage members
  • Can create and manage teams
  • Can update organization settings
  • Cannot delete organization
Member
  • Can view organization
  • Can view members and teams
  • Limited modification rights

API Endpoints

Organization Management
POST   /api/organizations                          # Create organization
GET    /api/organizations                          # List user's organizations
GET    /api/organizations/:id                      # Get organization details
GET    /api/organizations/slug/:slug               # Get organization by slug
PATCH  /api/organizations/:id                      # Update organization
DELETE /api/organizations/:id                      # Delete organization (owner only)
Member Management
GET    /api/organizations/:id/members              # List members
POST   /api/organizations/:id/members/invite       # Invite member
PATCH  /api/organizations/:id/members/:memberId   # Update member role
DELETE /api/organizations/:id/members/:memberId   # Remove member
Team Management
GET    /api/organizations/:id/teams                # List teams
POST   /api/organizations/:id/teams                # Create team
PATCH  /api/organizations/:id/teams/:teamId       # Update team
DELETE /api/organizations/:id/teams/:teamId       # Delete team
Invitations
POST   /api/organization-invitations/:token/accept    # Accept invitation
POST   /api/organization-invitations/:token/decline   # Decline invitation

Configuration

auth:
  organization:
    maxOrganizationsPerUser: 5       # Max orgs a user can create
    maxMembersPerOrganization: 50    # Max members per org
    maxTeamsPerOrganization: 20      # Max teams per org
    enableUserCreation: true         # Allow users to create orgs
    requireInvitation: true          # Require invitation to join
    invitationExpiryHours: 72        # Invitation validity (3 days)

Usage

Installation
import (
    "github.com/xraph/authsome"
    "github.com/xraph/authsome/plugins/organization"
)

auth := authsome.New(
    // ... other options
    authsome.WithPlugins(
        organization.NewPlugin(
            organization.WithMaxOrganizationsPerUser(10),
            organization.WithMaxMembersPerOrganization(100),
            organization.WithEnableUserCreation(true),
        ),
    ),
)
Creating an Organization
POST /api/organizations
Content-Type: application/json

{
  "name": "Acme Corporation",
  "slug": "acme",
  "logo": "https://example.com/logo.png",
  "metadata": {
    "industry": "Technology"
  }
}
Inviting a Member
POST /api/organizations/:orgId/members/invite
Content-Type: application/json

{
  "email": "user@example.com",
  "role": "member"
}
Accepting an Invitation
POST /api/organization-invitations/:token/accept

Permissions

Action Owner Admin Member
View organization
Update organization
Delete organization
Invite members
Remove members
Update member roles
Create teams
Manage teams

Integration with Other Plugins

SCIM Plugin

The SCIM plugin will be updated to provision users into organizations:

/scim/v2/organizations/:orgId/Users
/scim/v2/organizations/:orgId/Groups
Subscription Plugin (Future)

Organizations can be linked to subscriptions for billing:

type OrganizationSubscription struct {
    OrganizationID xid.ID
    PlanID         string
    Status         string
    // ...
}

Database Tables

  • user_organizations - Organization entities
  • user_organization_members - Member relationships
  • user_organization_teams - Team entities
  • user_organization_team_members - Team-member relationships (many-to-many)
  • user_organization_invitations - Invitation tokens

Differences from Platform Apps

Feature Platform App (Multitenancy) User Organization
Created by Platform admin Any authenticated user
Scope Platform-wide tenant User workspace
Members All platform users Invited users only
SCIM Platform-level provisioning Org-scoped provisioning
Billing Platform subscription Per-org subscription

TODO

  • Implement repository layer
  • Add middleware for organization context
  • Integrate with user service for user ID extraction
  • Add organization switcher API
  • Add organization statistics/metrics
  • Add audit log for organization actions
  • Add webhooks for organization events
  • Add organization settings/preferences

License

Same as AuthSome project.

Documentation

Index

Constants

View Source
const (
	RoleOwner  = organization.RoleOwner
	RoleAdmin  = organization.RoleAdmin
	RoleMember = organization.RoleMember
)

Organization member roles

View Source
const (
	StatusActive    = organization.StatusActive
	StatusSuspended = organization.StatusSuspended
	StatusPending   = organization.StatusPending
)

Organization member statuses

View Source
const (
	InvitationStatusPending   = organization.InvitationStatusPending
	InvitationStatusAccepted  = organization.InvitationStatusAccepted
	InvitationStatusExpired   = organization.InvitationStatusExpired
	InvitationStatusCancelled = organization.InvitationStatusCancelled
	InvitationStatusDeclined  = organization.InvitationStatusDeclined
)

Organization invitation statuses

View Source
const (
	ServiceNamePlugin            = "organization.plugin"
	ServiceNameService           = "organization.service"
	ServiceNameMemberService     = "organization.member_service"
	ServiceNameTeamService       = "organization.team_service"
	ServiceNameInvitationService = "organization.invitation_service"
)

Service name constants for DI container registration

Variables

View Source
var (
	ErrOrganizationNotFound    = organization.ErrOrganizationNotFound
	ErrMemberNotFound          = organization.ErrMemberNotFound
	ErrTeamNotFound            = organization.ErrTeamNotFound
	ErrInvalidRole             = organization.ErrInvalidRole
	ErrInvalidStatus           = organization.ErrInvalidStatus
	ErrOrganizationSlugExists  = organization.ErrOrganizationSlugExists
	ErrMemberAlreadyExists     = organization.ErrMemberAlreadyExists
	ErrNotOwner                = organization.ErrNotOwner
	ErrNotAdmin                = organization.ErrNotAdmin
	ErrCannotRemoveOwner       = organization.ErrCannotRemoveOwner
	ErrMaxOrganizationsReached = organization.ErrMaxOrganizationsReached
	ErrPermissionDenied        = organization.ErrPermissionDenied
)

Errors for organization plugin operations

View Source
var CannotRemoveOwner = organization.CannotRemoveOwner

CannotRemoveOwner returns an error indicating owner cannot be removed

View Source
var DefaultConfig = organization.DefaultConfig

DefaultConfig returns the default organization configuration

View Source
var FromSchemaInvitation = organization.FromSchemaInvitation

FromSchemaInvitation converts a schema invitation to domain invitation

View Source
var FromSchemaInvitations = organization.FromSchemaInvitations

FromSchemaInvitations converts multiple schema invitations to domain invitations

View Source
var FromSchemaMember = organization.FromSchemaMember

FromSchemaMember converts a schema member to domain member

View Source
var FromSchemaMembers = organization.FromSchemaMembers

FromSchemaMembers converts multiple schema members to domain members

View Source
var FromSchemaOrganization = organization.FromSchemaOrganization

FromSchemaOrganization converts a schema organization to domain organization

View Source
var FromSchemaOrganizations = organization.FromSchemaOrganizations

FromSchemaOrganizations converts multiple schema organizations to domain organizations

View Source
var FromSchemaTeam = organization.FromSchemaTeam

FromSchemaTeam converts a schema team to domain team

View Source
var FromSchemaTeamMember = organization.FromSchemaTeamMember

FromSchemaTeamMember converts a schema team member to domain team member

View Source
var FromSchemaTeamMembers = organization.FromSchemaTeamMembers

FromSchemaTeamMembers converts multiple schema team members to domain team members

View Source
var FromSchemaTeams = organization.FromSchemaTeams

FromSchemaTeams converts multiple schema teams to domain teams

InvalidRole returns an error indicating invalid role

View Source
var InvalidStatus = organization.InvalidStatus

InvalidStatus returns an error indicating invalid status

View Source
var InvitationExpired = organization.InvitationExpired

InvitationExpired returns an error indicating invitation has expired

View Source
var InvitationInvalidStatus = organization.InvitationInvalidStatus

InvitationInvalidStatus returns an error indicating invalid invitation status

View Source
var InvitationNotFound = organization.InvitationNotFound

InvitationNotFound returns an error indicating invitation was not found

View Source
var InvitationNotPending = organization.InvitationNotPending

InvitationNotPending returns an error indicating invitation is not pending

View Source
var IsValidInvitationStatus = organization.IsValidInvitationStatus

IsValidInvitationStatus checks if an invitation status is valid

IsValidRole checks if a role is valid

View Source
var IsValidStatus = organization.IsValidStatus

IsValidStatus checks if a status is valid

View Source
var MaxMembersReached = organization.MaxMembersReached

MaxMembersReached returns an error indicating maximum members limit reached

View Source
var MaxOrganizationsReached = organization.MaxOrganizationsReached

MaxOrganizationsReached returns an error indicating maximum organizations limit reached

View Source
var MaxTeamsReached = organization.MaxTeamsReached

MaxTeamsReached returns an error indicating maximum teams limit reached

View Source
var MemberAlreadyExists = organization.MemberAlreadyExists

MemberAlreadyExists returns an error indicating member already exists

View Source
var MemberNotFound = organization.MemberNotFound

MemberNotFound returns an error indicating member was not found

NotAdmin returns an error indicating user is not admin

NotOwner returns an error indicating user is not owner

View Source
var OrganizationAlreadyExists = organization.OrganizationAlreadyExists

OrganizationAlreadyExists returns an error indicating organization already exists

View Source
var OrganizationCreationDisabled = organization.OrganizationCreationDisabled

OrganizationCreationDisabled returns an error indicating organization creation is disabled

View Source
var OrganizationNotFound = organization.OrganizationNotFound

OrganizationNotFound returns an error indicating organization was not found

View Source
var OrganizationSlugExists = organization.OrganizationSlugExists

OrganizationSlugExists returns an error indicating organization slug already exists

View Source
var PermissionDenied = organization.PermissionDenied

PermissionDenied returns an error indicating permission denied

View Source
var TeamAlreadyExists = organization.TeamAlreadyExists

TeamAlreadyExists returns an error indicating team already exists

View Source
var TeamMemberNotFound = organization.TeamMemberNotFound

TeamMemberNotFound returns an error indicating team member was not found

TeamNotFound returns an error indicating team was not found

Unauthorized returns an unauthorized error

View Source
var UnauthorizedAction = organization.UnauthorizedAction

UnauthorizedAction returns an error for unauthorized action

View Source
var ValidInvitationStatuses = organization.ValidInvitationStatuses

ValidInvitationStatuses returns all valid invitation statuses

ValidRoles returns all valid member roles

View Source
var ValidStatuses = organization.ValidStatuses

ValidStatuses returns all valid member statuses

Functions

func ActionButtons added in v0.0.5

func ActionButtons(actions []ui.OrganizationAction) g.Node

ActionButtons renders action buttons in the organization header

func EmptyStateMessage added in v0.0.5

func EmptyStateMessage(icon g.Node, title, description string) g.Node

EmptyStateMessage renders an empty state message for tabs with no content

func ErrorWidget added in v0.0.5

func ErrorWidget(message string) g.Node

ErrorWidget renders an error state for a widget

func LoadingWidget added in v0.0.5

func LoadingWidget() g.Node

LoadingWidget renders a loading state for a widget

func MergeQuickLinks(defaultLinks []ui.OrganizationQuickLink, extensionLinks []ui.OrganizationQuickLink) []ui.OrganizationQuickLink

MergeQuickLinks merges default quick links with extension quick links Returns a combined, sorted list

func NewService

func NewService(
	orgRepo Repository,
	memberRepo MemberRepository,
	teamRepo TeamRepository,
	inviteRepo InvitationRepository,
	config Config,
	rbacSvc *rbac.Service,
	roleRepo rbac.RoleRepository,
) *organization.Service

NewService creates a new organization service

func QuickLinkGrid added in v0.0.5

func QuickLinkGrid(links []ui.OrganizationQuickLink, basePath string, orgID, appID string) g.Node

QuickLinkGrid renders a grid of quick access cards Requires context to build URLs

func ResolveInvitationService added in v0.0.3

func ResolveInvitationService(container forge.Container) (*organization.InvitationService, error)

ResolveInvitationService resolves the invitation service from the container

func ResolveMemberService added in v0.0.3

func ResolveMemberService(container forge.Container) (*organization.MemberService, error)

ResolveMemberService resolves the member service from the container

func ResolveOrganizationService added in v0.0.3

func ResolveOrganizationService(container forge.Container) (*organization.Service, error)

ResolveOrganizationService resolves the organization service from the container

func ResolveTeamService added in v0.0.3

func ResolveTeamService(container forge.Container) (*organization.TeamService, error)

ResolveTeamService resolves the team service from the container

func TabNavigation added in v0.0.5

func TabNavigation(tabs []ui.OrganizationTab, activeTab string, baseURL string) g.Node

TabNavigation renders a tab navigation bar for organization pages The activeTab parameter should match the Path of the active tab

func WidgetGrid added in v0.0.5

func WidgetGrid(widgets []ui.OrganizationWidget, ctx ui.OrgExtensionContext) g.Node

WidgetGrid renders a grid of organization widgets with proper sizing Widgets with Size 1 take 1/3 width, Size 2 takes 2/3, Size 3 takes full width

Types

type AcceptInvitationRequest added in v0.0.7

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

type CompositeOrganizationService added in v0.0.3

type CompositeOrganizationService = organization.CompositeOrganizationService

CompositeOrganizationService is the full interface for the organization service

type Config

type Config = organization.Config

Config holds the organization service configuration

type CreateOrganizationHandlerRequest added in v0.0.7

type CreateOrganizationHandlerRequest struct {
	organization.CreateOrganizationRequest
}

Handler-level request types with path parameters

type CreateOrganizationRequest

type CreateOrganizationRequest = organization.CreateOrganizationRequest

CreateOrganizationRequest represents the request to create an organization

type CreateTeamHandlerRequest added in v0.0.7

type CreateTeamHandlerRequest struct {
	ID string `path:"id" validate:"required"`
	organization.CreateTeamRequest
}

type CreateTeamRequest

type CreateTeamRequest = organization.CreateTeamRequest

CreateTeamRequest represents the request to create a team

type DashboardExtension

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

DashboardExtension implements the ui.DashboardExtension interface This allows the organization plugin to add its own screens to the dashboard

func NewDashboardExtension

func NewDashboardExtension(plugin *Plugin) *DashboardExtension

NewDashboardExtension creates a new dashboard extension for organization

func (*DashboardExtension) AddCustomPermission

func (e *DashboardExtension) AddCustomPermission(c forge.Context) error

AddCustomPermission handles creating custom permissions inline

func (*DashboardExtension) CancelInvitation

func (e *DashboardExtension) CancelInvitation(c forge.Context) error

CancelInvitation handles invitation cancellation

func (*DashboardExtension) CreateOrganization

func (e *DashboardExtension) CreateOrganization(c forge.Context) error

CreateOrganization handles organization creation

func (*DashboardExtension) CreateRoleTemplate

func (e *DashboardExtension) CreateRoleTemplate(c forge.Context) error

CreateRoleTemplate handles role template creation

func (*DashboardExtension) CreateTeam

func (e *DashboardExtension) CreateTeam(c forge.Context) error

CreateTeam handles team creation

func (*DashboardExtension) DashboardWidgets

func (e *DashboardExtension) DashboardWidgets() []ui.DashboardWidget

DashboardWidgets returns widgets to show on the main dashboard

func (*DashboardExtension) DeleteOrganization

func (e *DashboardExtension) DeleteOrganization(c forge.Context) error

DeleteOrganization handles organization deletion

func (*DashboardExtension) DeleteRoleTemplate

func (e *DashboardExtension) DeleteRoleTemplate(c forge.Context) error

DeleteRoleTemplate handles role template deletion

func (*DashboardExtension) DeleteTeam

func (e *DashboardExtension) DeleteTeam(c forge.Context) error

DeleteTeam handles team deletion

func (*DashboardExtension) ExtensionID

func (e *DashboardExtension) ExtensionID() string

ExtensionID returns the unique identifier for this extension

func (*DashboardExtension) InviteMember

func (e *DashboardExtension) InviteMember(c forge.Context) error

InviteMember handles member invitation

func (*DashboardExtension) NavigationItems

func (e *DashboardExtension) NavigationItems() []ui.NavigationItem

NavigationItems returns navigation items to register

func (*DashboardExtension) RemoveMember

func (e *DashboardExtension) RemoveMember(c forge.Context) error

RemoveMember handles member removal

func (*DashboardExtension) RenderDashboardWidget

func (e *DashboardExtension) RenderDashboardWidget(basePath string, currentApp *app.App) g.Node

Dashboard widget rendering

func (*DashboardExtension) RenderSettingsSection

func (e *DashboardExtension) RenderSettingsSection(basePath string, currentApp *app.App) g.Node

Settings rendering

func (*DashboardExtension) Routes

func (e *DashboardExtension) Routes() []ui.Route

Routes returns routes to register under /dashboard/app/:appId/

func (*DashboardExtension) SavePluginSettings

func (e *DashboardExtension) SavePluginSettings(c forge.Context) error

SavePluginSettings handles plugin settings updates

func (*DashboardExtension) ServeCreateOrganizationPage

func (e *DashboardExtension) ServeCreateOrganizationPage(c forge.Context) error

ServeCreateOrganizationPage renders the create organization page

func (*DashboardExtension) ServeCreateRoleTemplate

func (e *DashboardExtension) ServeCreateRoleTemplate(c forge.Context) error

ServeCreateRoleTemplate renders the create role template form

func (*DashboardExtension) ServeEditRoleTemplate

func (e *DashboardExtension) ServeEditRoleTemplate(c forge.Context) error

ServeEditRoleTemplate renders the edit role template form

func (*DashboardExtension) ServeOrganizationDetailPage

func (e *DashboardExtension) ServeOrganizationDetailPage(c forge.Context) error

ServeOrganizationDetailPage renders the organization detail page

func (*DashboardExtension) ServeOrganizationInvitationsPage

func (e *DashboardExtension) ServeOrganizationInvitationsPage(c forge.Context) error

ServeOrganizationInvitationsPage renders the invitations page

func (*DashboardExtension) ServeOrganizationMembersPage

func (e *DashboardExtension) ServeOrganizationMembersPage(c forge.Context) error

ServeOrganizationMembersPage renders the members management page

func (*DashboardExtension) ServeOrganizationRolesPage added in v0.0.3

func (e *DashboardExtension) ServeOrganizationRolesPage(c forge.Context) error

ServeOrganizationRolesPage renders the roles page

func (*DashboardExtension) ServeOrganizationSettings

func (e *DashboardExtension) ServeOrganizationSettings(c forge.Context) error

ServeOrganizationSettings renders the organization settings page

func (*DashboardExtension) ServeOrganizationTabContent added in v0.0.5

func (e *DashboardExtension) ServeOrganizationTabContent(c forge.Context) error

ServeOrganizationTabContent renders extension tab content

func (*DashboardExtension) ServeOrganizationTeamsPage

func (e *DashboardExtension) ServeOrganizationTeamsPage(c forge.Context) error

ServeOrganizationTeamsPage renders the teams management page

func (*DashboardExtension) ServeOrganizationsListPage

func (e *DashboardExtension) ServeOrganizationsListPage(c forge.Context) error

ServeOrganizationsListPage renders the organizations list page

func (*DashboardExtension) ServeRoleTemplatesSettings

func (e *DashboardExtension) ServeRoleTemplatesSettings(c forge.Context) error

ServeRoleTemplatesSettings renders the role templates settings page

func (*DashboardExtension) SetRegistry

func (e *DashboardExtension) SetRegistry(registry *dashboard.ExtensionRegistry)

SetRegistry sets the extension registry reference (called by dashboard after registration)

func (*DashboardExtension) SettingsPages

func (e *DashboardExtension) SettingsPages() []ui.SettingsPage

SettingsPages returns full settings pages for the new sidebar layout

func (*DashboardExtension) SettingsSections

func (e *DashboardExtension) SettingsSections() []ui.SettingsSection

SettingsSections returns settings sections to add to the settings page Deprecated: Use SettingsPages() instead

func (*DashboardExtension) UpdateMemberRole

func (e *DashboardExtension) UpdateMemberRole(c forge.Context) error

UpdateMemberRole handles member role updates

func (*DashboardExtension) UpdateOrganization

func (e *DashboardExtension) UpdateOrganization(c forge.Context) error

UpdateOrganization handles organization updates

func (*DashboardExtension) UpdateRoleTemplate

func (e *DashboardExtension) UpdateRoleTemplate(c forge.Context) error

UpdateRoleTemplate handles role template updates

func (*DashboardExtension) UpdateTeam

func (e *DashboardExtension) UpdateTeam(c forge.Context) error

UpdateTeam handles team updates

type DeclineInvitationRequest added in v0.0.7

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

type DeleteOrganizationRequest added in v0.0.7

type DeleteOrganizationRequest struct {
	ID string `path:"id" validate:"required"`
}

type DeleteTeamRequest added in v0.0.7

type DeleteTeamRequest struct {
	ID     string `path:"id" validate:"required"`
	TeamID string `path:"teamId" validate:"required"`
}

type ErrorResponse

type ErrorResponse = responses.ErrorResponse

DTOs for organization routes - use shared responses from core

type GetOrganizationBySlugRequest added in v0.0.7

type GetOrganizationBySlugRequest struct {
	Slug string `path:"slug" validate:"required"`
}

type GetOrganizationRequest added in v0.0.7

type GetOrganizationRequest struct {
	ID string `path:"id" validate:"required"`
}

type Invitation added in v0.0.3

type Invitation = organization.Invitation

Invitation represents an invitation to join an organization

type InvitationOperations added in v0.0.3

type InvitationOperations = organization.InvitationOperations

InvitationOperations defines operations for managing invitations

type InvitationRepository

type InvitationRepository = organization.InvitationRepository

InvitationRepository type alias

type InvitationResponse

type InvitationResponse struct {
	Invitation *organization.Invitation `json:"invitation"`
	Message    string                   `json:"message,omitempty"`
}

type InviteMemberHandlerRequest added in v0.0.7

type InviteMemberHandlerRequest struct {
	ID string `path:"id" validate:"required"`
	organization.InviteMemberRequest
}

type InviteMemberRequest

type InviteMemberRequest = organization.InviteMemberRequest

InviteMemberRequest represents the request to invite a member

type ListInvitationsFilter added in v0.0.3

type ListInvitationsFilter = organization.ListInvitationsFilter

ListInvitationsFilter represents filters for listing invitations

type ListMembersFilter added in v0.0.3

type ListMembersFilter = organization.ListMembersFilter

ListMembersFilter represents filters for listing members

type ListMembersRequest added in v0.0.7

type ListMembersRequest struct {
	ID    string `path:"id" validate:"required"`
	Page  int    `query:"page"`
	Limit int    `query:"limit"`
	Role  string `query:"role"`
}

type ListOrganizationsFilter added in v0.0.3

type ListOrganizationsFilter = organization.ListOrganizationsFilter

ListOrganizationsFilter represents filters for listing organizations

type ListOrganizationsRequest added in v0.0.7

type ListOrganizationsRequest struct {
	Page  int `query:"page"`
	Limit int `query:"limit"`
}

type ListTeamMembersFilter added in v0.0.3

type ListTeamMembersFilter = organization.ListTeamMembersFilter

ListTeamMembersFilter represents filters for listing team members

type ListTeamsFilter added in v0.0.3

type ListTeamsFilter = organization.ListTeamsFilter

ListTeamsFilter represents filters for listing teams

type ListTeamsRequest added in v0.0.7

type ListTeamsRequest struct {
	ID    string `path:"id" validate:"required"`
	Page  int    `query:"page"`
	Limit int    `query:"limit"`
}

type Member added in v0.0.3

type Member = organization.Member

Member represents a user's membership in an organization

type MemberOperations added in v0.0.3

type MemberOperations = organization.MemberOperations

MemberOperations defines operations for managing organization members

type MemberRepository

type MemberRepository = organization.MemberRepository

MemberRepository type alias

type MembersListResponse

type MembersListResponse []schema.OrganizationMember

MembersListResponse represents a list of members

type MembersResponse

type MembersResponse struct {
	Members []*organization.Member `json:"members"`
	Total   int                    `json:"total,omitempty"`
}

type MessageResponse

type MessageResponse = responses.MessageResponse

Response types Use shared response type

type MockService

type MockService struct {

	// Error injection for testing
	CreateOrgError        error
	FindOrgError          error
	AddMemberError        error
	InviteMemberError     error
	AcceptInvitationError error
	// contains filtered or unexported fields
}

MockService provides a mock implementation of organization.Service for testing

func NewMockService

func NewMockService() *MockService

NewMockService creates a new mock organization service

func (*MockService) AcceptInvitation

func (m *MockService) AcceptInvitation(ctx context.Context, token string, userID xid.ID) (*organization.Member, error)

func (*MockService) AddMember

func (m *MockService) AddMember(ctx context.Context, orgID, userID xid.ID, role string) (*organization.Member, error)

AddMember mocks adding a member

func (*MockService) AddTeamMember

func (m *MockService) AddTeamMember(ctx context.Context, teamID, memberID, adderUserID xid.ID) error

func (*MockService) CancelInvitation

func (m *MockService) CancelInvitation(ctx context.Context, id, cancellerUserID xid.ID) error

func (*MockService) CheckPermission added in v0.0.3

func (m *MockService) CheckPermission(ctx context.Context, orgID, userID xid.ID, action, resource string) (bool, error)

RBAC Permission methods

func (*MockService) CheckPermissionWithContext added in v0.0.3

func (m *MockService) CheckPermissionWithContext(ctx context.Context, orgID, userID xid.ID, action, resource string, contextVars map[string]string) (bool, error)

func (*MockService) CleanupExpiredInvitations

func (m *MockService) CleanupExpiredInvitations(ctx context.Context) (int, error)

func (*MockService) CreateOrganization

func (m *MockService) CreateOrganization(ctx context.Context, req *organization.CreateOrganizationRequest, creatorUserID, appID, environmentID xid.ID) (*organization.Organization, error)

CreateOrganization mocks creating an organization

func (*MockService) CreateTeam

func (m *MockService) CreateTeam(ctx context.Context, orgID xid.ID, req *organization.CreateTeamRequest, creatorUserID xid.ID) (*organization.Team, error)

func (*MockService) DeclineInvitation

func (m *MockService) DeclineInvitation(ctx context.Context, token string) error

func (*MockService) DeleteOrganization

func (m *MockService) DeleteOrganization(ctx context.Context, id, userID xid.ID) error

DeleteOrganization mocks deleting an organization

func (*MockService) DeleteTeam

func (m *MockService) DeleteTeam(ctx context.Context, id, deleterUserID xid.ID) error

func (*MockService) FindInvitationByID

func (m *MockService) FindInvitationByID(ctx context.Context, id xid.ID) (*organization.Invitation, error)

func (*MockService) FindInvitationByToken

func (m *MockService) FindInvitationByToken(ctx context.Context, token string) (*organization.Invitation, error)

func (*MockService) FindMember

func (m *MockService) FindMember(ctx context.Context, orgID, userID xid.ID) (*organization.Member, error)

FindMember mocks finding a member by org and user ID

func (*MockService) FindMemberByID

func (m *MockService) FindMemberByID(ctx context.Context, id xid.ID) (*organization.Member, error)

FindMemberByID mocks finding a member by ID

func (*MockService) FindOrganizationByID

func (m *MockService) FindOrganizationByID(ctx context.Context, id xid.ID) (*organization.Organization, error)

FindOrganizationByID mocks finding an organization by ID

func (*MockService) FindOrganizationBySlug

func (m *MockService) FindOrganizationBySlug(ctx context.Context, appID, environmentID xid.ID, slug string) (*organization.Organization, error)

FindOrganizationBySlug mocks finding an organization by slug

func (*MockService) FindTeamByID

func (m *MockService) FindTeamByID(ctx context.Context, id xid.ID) (*organization.Team, error)

func (*MockService) FindTeamByName

func (m *MockService) FindTeamByName(ctx context.Context, orgID xid.ID, name string) (*organization.Team, error)

func (*MockService) FindTeamMember added in v0.0.3

func (m *MockService) FindTeamMember(ctx context.Context, teamID, memberID xid.ID) (*organization.TeamMember, error)

func (*MockService) FindTeamMemberByID added in v0.0.3

func (m *MockService) FindTeamMemberByID(ctx context.Context, id xid.ID) (*organization.TeamMember, error)

func (*MockService) ForceDeleteOrganization added in v0.0.5

func (m *MockService) ForceDeleteOrganization(ctx context.Context, id xid.ID) error

ForceDeleteOrganization mocks force deleting an organization without permission checks

func (*MockService) GetUserMemberships

func (m *MockService) GetUserMemberships(ctx context.Context, userID xid.ID, filter *pagination.PaginationParams) (*pagination.PageResponse[*organization.Member], error)

GetUserMemberships mocks getting user memberships

func (*MockService) InviteMember

func (m *MockService) InviteMember(ctx context.Context, orgID xid.ID, req *organization.InviteMemberRequest, inviterUserID xid.ID) (*organization.Invitation, error)

func (*MockService) IsAdmin

func (m *MockService) IsAdmin(ctx context.Context, orgID, userID xid.ID) (bool, error)

IsAdmin mocks checking admin status

func (*MockService) IsMember

func (m *MockService) IsMember(ctx context.Context, orgID, userID xid.ID) (bool, error)

IsMember mocks checking membership

func (*MockService) IsOwner

func (m *MockService) IsOwner(ctx context.Context, orgID, userID xid.ID) (bool, error)

IsOwner mocks checking ownership

func (*MockService) IsTeamMember

func (m *MockService) IsTeamMember(ctx context.Context, teamID, memberID xid.ID) (bool, error)

func (*MockService) ListMemberTeams added in v0.0.3

func (m *MockService) ListMemberTeams(ctx context.Context, memberID xid.ID, filter *pagination.PaginationParams) (*pagination.PageResponse[*organization.Team], error)

func (*MockService) ListMembers

ListMembers mocks listing members

func (*MockService) ListOrganizations

ListOrganizations mocks listing organizations

func (*MockService) ListTeams

func (*MockService) ListUserOrganizations

func (m *MockService) ListUserOrganizations(ctx context.Context, userID xid.ID, filter *pagination.PaginationParams) (*pagination.PageResponse[*organization.Organization], error)

ListUserOrganizations mocks listing user organizations

func (*MockService) RemoveMember

func (m *MockService) RemoveMember(ctx context.Context, id, removerUserID xid.ID) error

RemoveMember mocks removing a member

func (*MockService) RemoveTeamMember

func (m *MockService) RemoveTeamMember(ctx context.Context, teamID, memberID, removerUserID xid.ID) error

func (*MockService) RemoveUserFromAllOrganizations

func (m *MockService) RemoveUserFromAllOrganizations(ctx context.Context, userID xid.ID) error

RemoveUserFromAllOrganizations mocks removing user from all orgs

func (*MockService) RequireAdmin

func (m *MockService) RequireAdmin(ctx context.Context, orgID, userID xid.ID) error

RequireAdmin mocks requiring admin status

func (*MockService) RequireOwner

func (m *MockService) RequireOwner(ctx context.Context, orgID, userID xid.ID) error

RequireOwner mocks requiring owner status

func (*MockService) RequirePermission added in v0.0.3

func (m *MockService) RequirePermission(ctx context.Context, orgID, userID xid.ID, action, resource string) error

func (*MockService) ResendInvitation

func (m *MockService) ResendInvitation(ctx context.Context, id, resenderUserID xid.ID) (*organization.Invitation, error)

func (*MockService) UpdateMember

func (m *MockService) UpdateMember(ctx context.Context, id xid.ID, req *organization.UpdateMemberRequest, updaterUserID xid.ID) (*organization.Member, error)

UpdateMember mocks updating a member

func (*MockService) UpdateMemberRole added in v0.0.3

func (m *MockService) UpdateMemberRole(ctx context.Context, orgID, memberID xid.ID, newRole string, updaterUserID xid.ID) (*organization.Member, error)

UpdateMemberRole mocks updating only the role of a member

func (*MockService) UpdateOrganization

UpdateOrganization mocks updating an organization

func (*MockService) UpdateTeam

func (m *MockService) UpdateTeam(ctx context.Context, id xid.ID, req *organization.UpdateTeamRequest, updaterUserID xid.ID) (*organization.Team, error)

type Organization added in v0.0.3

type Organization = organization.Organization

Organization represents an organization (workspace/tenant)

type OrganizationHandler

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

OrganizationHandler handles organization-related HTTP requests

func NewOrganizationHandler

func NewOrganizationHandler(orgService *organization.Service) *OrganizationHandler

NewOrganizationHandler creates a new organization handler

func (*OrganizationHandler) AcceptInvitation

func (h *OrganizationHandler) AcceptInvitation(c forge.Context) error

AcceptInvitation handles invitation acceptance requests

func (*OrganizationHandler) CreateOrganization

func (h *OrganizationHandler) CreateOrganization(c forge.Context) error

CreateOrganization handles organization creation requests

func (*OrganizationHandler) CreateTeam

func (h *OrganizationHandler) CreateTeam(c forge.Context) error

CreateTeam handles team creation requests

func (*OrganizationHandler) DeclineInvitation

func (h *OrganizationHandler) DeclineInvitation(c forge.Context) error

DeclineInvitation handles invitation decline requests

func (*OrganizationHandler) DeleteOrganization

func (h *OrganizationHandler) DeleteOrganization(c forge.Context) error

DeleteOrganization handles organization deletion requests

func (*OrganizationHandler) DeleteTeam

func (h *OrganizationHandler) DeleteTeam(c forge.Context) error

DeleteTeam handles team deletion requests

func (*OrganizationHandler) GetOrganization

func (h *OrganizationHandler) GetOrganization(c forge.Context) error

GetOrganization handles get organization requests

func (*OrganizationHandler) GetOrganizationBySlug

func (h *OrganizationHandler) GetOrganizationBySlug(c forge.Context) error

GetOrganizationBySlug handles get organization by slug requests

func (*OrganizationHandler) InviteMember

func (h *OrganizationHandler) InviteMember(c forge.Context) error

InviteMember handles member invitation requests

func (*OrganizationHandler) ListMembers

func (h *OrganizationHandler) ListMembers(c forge.Context) error

ListMembers handles list organization members requests

func (*OrganizationHandler) ListOrganizations

func (h *OrganizationHandler) ListOrganizations(c forge.Context) error

ListOrganizations handles list organizations requests (user's organizations)

func (*OrganizationHandler) ListTeams

func (h *OrganizationHandler) ListTeams(c forge.Context) error

ListTeams handles list teams requests

func (*OrganizationHandler) RemoveMember

func (h *OrganizationHandler) RemoveMember(c forge.Context) error

RemoveMember handles member removal requests

func (*OrganizationHandler) UpdateMember

func (h *OrganizationHandler) UpdateMember(c forge.Context) error

UpdateMember handles member update requests

func (*OrganizationHandler) UpdateOrganization

func (h *OrganizationHandler) UpdateOrganization(c forge.Context) error

UpdateOrganization handles organization update requests

func (*OrganizationHandler) UpdateTeam

func (h *OrganizationHandler) UpdateTeam(c forge.Context) error

UpdateTeam handles team update requests

type OrganizationOperations added in v0.0.3

type OrganizationOperations = organization.OrganizationOperations

OrganizationOperations defines operations for managing organizations

type OrganizationUIRegistry added in v0.0.5

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

OrganizationUIRegistry manages organization UI extensions from plugins It collects widgets, tabs, actions, and quick links from registered plugins and provides them in sorted, filtered order for rendering

func NewOrganizationUIRegistry added in v0.0.5

func NewOrganizationUIRegistry() *OrganizationUIRegistry

NewOrganizationUIRegistry creates a new organization UI registry

func (*OrganizationUIRegistry) GetActions added in v0.0.5

GetActions returns all registered actions, sorted by order Filters out actions that require admin if the user is not an admin

GetQuickLinks returns all registered quick links, sorted by order Filters out links that require admin if the user is not an admin

func (*OrganizationUIRegistry) GetSettingsSections added in v0.0.5

GetSettingsSections returns all registered settings sections, sorted by order Filters out sections that require admin if the user is not an admin

func (*OrganizationUIRegistry) GetTabByPath added in v0.0.5

GetTabByPath returns a tab by its path, or nil if not found

func (*OrganizationUIRegistry) GetTabs added in v0.0.5

GetTabs returns all registered tabs, sorted by order Filters out tabs that require admin if the user is not an admin

func (*OrganizationUIRegistry) GetWidgets added in v0.0.5

GetWidgets returns all registered widgets, sorted by order Filters out widgets that require admin if the user is not an admin

func (*OrganizationUIRegistry) HasExtension added in v0.0.5

func (r *OrganizationUIRegistry) HasExtension(id string) bool

HasExtension checks if an extension with the given ID is registered

func (*OrganizationUIRegistry) ListExtensions added in v0.0.5

func (r *OrganizationUIRegistry) ListExtensions() []string

ListExtensions returns the IDs of all registered extensions

func (*OrganizationUIRegistry) Register added in v0.0.5

Register registers an organization UI extension Returns an error if an extension with the same ID is already registered

type OrganizationsListResponse

type OrganizationsListResponse []schema.Organization

OrganizationsListResponse represents a list of organizations

type Plugin

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

Plugin implements the user-created organizations plugin

func NewPlugin

func NewPlugin(opts ...PluginOption) *Plugin

NewPlugin creates a new organization plugin instance with optional configuration

func ResolveOrganizationPlugin added in v0.0.3

func ResolveOrganizationPlugin(container forge.Container) (*Plugin, error)

ResolveOrganizationPlugin resolves the organization plugin from the container

func (*Plugin) DashboardExtension

func (p *Plugin) DashboardExtension() ui.DashboardExtension

DashboardExtension returns the dashboard extension interface implementation

func (*Plugin) GetInvitationService added in v0.0.3

func (p *Plugin) GetInvitationService() *organization.InvitationService

GetInvitationService returns the invitation service directly

func (*Plugin) GetMemberService added in v0.0.3

func (p *Plugin) GetMemberService() *organization.MemberService

GetMemberService returns the member service directly

func (*Plugin) GetOrganizationService added in v0.0.3

func (p *Plugin) GetOrganizationService() *organization.Service

GetOrganizationService returns the organization service directly

func (*Plugin) GetOrganizationUIRegistry added in v0.0.5

func (p *Plugin) GetOrganizationUIRegistry() *OrganizationUIRegistry

GetOrganizationUIRegistry returns the UI registry for accessing registered extensions This is used by the dashboard extension to render extension widgets, tabs, and actions

func (*Plugin) GetServices added in v0.0.3

func (p *Plugin) GetServices() map[string]interface{}

GetServices returns a map of all available services for inspection

func (*Plugin) GetTeamService added in v0.0.3

func (p *Plugin) GetTeamService() *organization.TeamService

GetTeamService returns the team service directly

func (*Plugin) ID

func (p *Plugin) ID() string

ID returns the plugin identifier

func (*Plugin) Init

func (p *Plugin) Init(authInstance core.Authsome) error

Init initializes the plugin with dependencies

func (*Plugin) Migrate

func (p *Plugin) Migrate() error

Migrate runs the plugin's database migrations

func (*Plugin) RegisterHooks

func (p *Plugin) RegisterHooks(hookRegistry *hooks.HookRegistry) error

RegisterHooks registers the plugin's hooks

func (*Plugin) RegisterRoles added in v0.0.3

func (p *Plugin) RegisterRoles(reg interface{}) error

RegisterRoles implements the PluginWithRoles interface This registers organization-related permissions for platform roles

func (*Plugin) RegisterRoutes

func (p *Plugin) RegisterRoutes(router forge.Router) error

RegisterRoutes registers the plugin's HTTP routes

func (*Plugin) RegisterServiceDecorators

func (p *Plugin) RegisterServiceDecorators(services *registry.ServiceRegistry) error

RegisterServiceDecorators registers service decorators

func (*Plugin) RegisterServices added in v0.0.3

func (p *Plugin) RegisterServices(container forge.Container) error

RegisterServices registers all organization services in the DI container

func (*Plugin) SendInvitationNotification added in v0.0.6

func (p *Plugin) SendInvitationNotification(ctx context.Context, invitation *organization.Invitation, inviter *user.User, org *organization.Organization) error

SendInvitationNotification sends an org.invite notification when an invitation is created This should be called by handlers after creating an invitation

type PluginOption

type PluginOption func(*Plugin)

PluginOption is a functional option for configuring the plugin

func WithDefaultConfig

func WithDefaultConfig(cfg Config) PluginOption

WithDefaultConfig sets the default configuration for the plugin

func WithEnableUserCreation

func WithEnableUserCreation(enabled bool) PluginOption

WithEnableUserCreation sets whether user creation is enabled

func WithEnforceUniqueSlug added in v0.0.3

func WithEnforceUniqueSlug(enforce bool) PluginOption

WithEnforceUniqueSlug sets whether to enforce unique slugs within app+environment scope

func WithInvitationExpiryHours

func WithInvitationExpiryHours(hours int) PluginOption

WithInvitationExpiryHours sets the invitation expiry hours

func WithMaxMembersPerOrganization

func WithMaxMembersPerOrganization(max int) PluginOption

WithMaxMembersPerOrganization sets the maximum members per organization

func WithMaxOrganizationsPerUser

func WithMaxOrganizationsPerUser(max int) PluginOption

WithMaxOrganizationsPerUser sets the maximum organizations per user

func WithMaxTeamsPerOrganization

func WithMaxTeamsPerOrganization(max int) PluginOption

WithMaxTeamsPerOrganization sets the maximum teams per organization

func WithRequireInvitation

func WithRequireInvitation(required bool) PluginOption

WithRequireInvitation sets whether invitation is required

type RemoveMemberRequest added in v0.0.7

type RemoveMemberRequest struct {
	ID       string `path:"id" validate:"required"`
	MemberID string `path:"memberId" validate:"required"`
}

type Repository

Repository type aliases for core organization repositories

type Service

type Service = organization.Service

Service wraps the core organization service

type StatusResponse

type StatusResponse = responses.StatusResponse

type Team added in v0.0.3

type Team = organization.Team

Team represents a team within an organization

type TeamMember added in v0.0.3

type TeamMember = organization.TeamMember

TeamMember represents a member's assignment to a team

type TeamOperations added in v0.0.3

type TeamOperations = organization.TeamOperations

TeamOperations defines operations for managing teams

type TeamRepository

type TeamRepository = organization.TeamRepository

TeamRepository type alias

type TeamsListResponse

type TeamsListResponse []schema.OrganizationTeam

TeamsListResponse represents a list of teams

type TeamsResponse

type TeamsResponse struct {
	Teams []*organization.Team `json:"teams"`
	Total int                  `json:"total,omitempty"`
}

type UpdateMemberHandlerRequest added in v0.0.7

type UpdateMemberHandlerRequest struct {
	ID       string `path:"id" validate:"required"`
	MemberID string `path:"memberId" validate:"required"`
	organization.UpdateMemberRequest
}

type UpdateMemberRequest

type UpdateMemberRequest = organization.UpdateMemberRequest

UpdateMemberRequest represents the request to update a member

type UpdateOrganizationHandlerRequest added in v0.0.7

type UpdateOrganizationHandlerRequest struct {
	ID string `path:"id" validate:"required"`
	organization.UpdateOrganizationRequest
}

type UpdateOrganizationRequest

type UpdateOrganizationRequest = organization.UpdateOrganizationRequest

UpdateOrganizationRequest represents the request to update an organization

type UpdateTeamHandlerRequest added in v0.0.7

type UpdateTeamHandlerRequest struct {
	ID     string `path:"id" validate:"required"`
	TeamID string `path:"teamId" validate:"required"`
	organization.UpdateTeamRequest
}

type UpdateTeamRequest

type UpdateTeamRequest = organization.UpdateTeamRequest

UpdateTeamRequest represents the request to update a team

type UserInfo added in v0.0.3

type UserInfo = organization.UserInfo

UserInfo contains basic user information for display purposes (embedded in Member/TeamMember)

Jump to

Keyboard shortcuts

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