Invitation
Overview
The Invitation
domain in comby handles the process of inviting users to join an organization or Tenant. It supports the lifecycle of an invitation, from creation and sending to acceptance or declination. The Invitation aggregate is at the core of this domain, providing the structure for managing invitations, tracking their state, and handling related domain events.
An Invitation
can belong to only one Tenant. However, a user can be invited to multiple Tenants. This design enables a user to be associated with multiple Tenants through separate invitations.
Structure
The Invitation
aggregate consists of the following elements:
References:
- GroupUuids: A list of group UUIDs to which the invited account will be added upon accepting the invitation.
- IdentityUuid: The UUID of the identity that created the invitation.
- AccountUuid: The UUID of the account that accepts the invitation.
Value Objects:
- Token: A unique token associated with the invitation, typically used for verification or authentication.
- Email: The email address of the invitee.
- State: Tracks the current state of the invitation, such as created, sent, accepted, or declined.
The domain defines several states to represent the lifecycle of an invitation:
- created: The invitation has been created but not yet sent. sent: The invitation has been sent to the invitee.
- sent: The invitation has been sent to the invitee.
- accepted: The invitee has accepted the invitation, and the associated account has been added to the relevant groups.
- declined: The invitee has declined the invitation. These states enable precise tracking of invitation progress and ensure consistent processing across the system.
Commands
- InvitationCommandAccept
- InvitationCommandCreate
- InvitationCommandDecline
- InvitationCommandRemove
- InvitationCommandRemoveAttribute
- InvitationCommandSend
- InvitationCommandSetAttribute
- InvitationCommandUpdate
InvitationCommandAccept
Domain Command Struct:
type InvitationCommandAccept struct {
InvitationUuid string `json:"invitationUuid"`
AccountUuid string `json:"accountUuid"`
Token string `json:"token"`
}
Domain Command Handling Method:
func (cs *commandHandler) InvitationCommandAccept(ctx context.Context, cmd comby.Command, domainCmd *InvitationCommandAccept) ([]comby.Event, error)
InvitationCommandCreate
Domain Command Struct:
type InvitationCommandCreate struct {
InvitationUuid string `json:"invitationUuid"`
IdentityUuid string `json:"identityUuid"`
GroupUuids []string `json:"groupUuids"`
Email string `json:"email"`
Attributes string `json:"attributes,omitempty"`
}
Domain Command Handling Method:
func (cs *commandHandler) InvitationCommandCreate(ctx context.Context, cmd comby.Command, domainCmd *InvitationCommandCreate) ([]comby.Event, error)
InvitationCommandDecline
Domain Command Struct:
type InvitationCommandDecline struct {
InvitationUuid string `json:"invitationUuid"`
AccountUuid string `json:"accountUuid"`
Token string `json:"token"`
}
Domain Command Handling Method:
func (cs *commandHandler) InvitationCommandDecline(ctx context.Context, cmd comby.Command, domainCmd *InvitationCommandDecline) ([]comby.Event, error)
InvitationCommandRemove
Domain Command Struct:
type InvitationCommandRemove struct {
InvitationUuid string `json:"invitationUuid"`
}
Domain Command Handling Method:
func (cs *commandHandler) InvitationCommandRemove(ctx context.Context, cmd comby.Command, domainCmd *InvitationCommandRemove) ([]comby.Event, error)
InvitationCommandRemoveAttribute
Domain Command Struct:
type InvitationCommandRemoveAttribute struct {
InvitationUuid string `json:"invitationUuid"`
Key string `json:"key"`
}
Domain Command Handling Method:
func (cs *commandHandler) InvitationCommandRemoveAttribute(ctx context.Context, cmd comby.Command, domainCmd *InvitationCommandRemoveAttribute) ([]comby.Event, error)
InvitationCommandSend
Domain Command Struct:
type InvitationCommandSend struct {
InvitationUuid string `json:"invitationUuid"`
}
Domain Command Handling Method:
func (cs *commandHandler) InvitationCommandSend(ctx context.Context, cmd comby.Command, domainCmd *InvitationCommandSend) ([]comby.Event, error)
InvitationCommandSetAttribute
Domain Command Struct:
type InvitationCommandSetAttribute struct {
InvitationUuid string `json:"invitationUuid"`
Key string `json:"key"`
Value any `json:"value"`
}
Domain Command Handling Method:
func (cs *commandHandler) InvitationCommandSetAttribute(ctx context.Context, cmd comby.Command, domainCmd *InvitationCommandSetAttribute) ([]comby.Event, error)
InvitationCommandUpdate
Domain Command Struct:
type InvitationCommandUpdate struct {
InvitationUuid string `json:"invitationUuid"`
Attributes string `json:"attributes,omitempty"`
PatchedFields []string `json:"patchedFields"`
}
Domain Command Handling Method:
func (cs *commandHandler) InvitationCommandUpdate(ctx context.Context, cmd comby.Command, domainCmd *InvitationCommandUpdate) ([]comby.Event, error)
Queries
Domain Query Structs:
Domain Query Responses:
InvitationQueryList
Domain Query Struct:
type InvitationQueryList struct {
TenantUuid string `json:"tenantUuid"`
Page int64 `json:"page,omitempty"`
PageSize int64 `json:"pageSize,omitempty"`
OrderBy string `json:"orderBy,omitempty"`
Attributes string `json:"attributes,omitempty"`
}
Domain Query Handling Method:
func (qs *queryHandler) InvitationQueryList(ctx context.Context, qry comby.Query, domainQry *InvitationQueryList) (*InvitationQueryListResponse, error)
InvitationQueryModel
Domain Query Struct:
type InvitationQueryModel struct {
InvitationUuid string `json:"invitationUuid"`
}
Domain Query Handling Method:
func (qs *queryHandler) InvitationQueryModel(ctx context.Context, qry comby.Query, domainQry *InvitationQueryModel) (*InvitationQueryItemResponse, error)
InvitationQueryModelByInvitationToken
Domain Query Struct:
type InvitationQueryModelByInvitationToken struct {
InvitationToken string `json:"invitationToken"`
}
Domain Query Handling Method:
func (qs *queryHandler) InvitationQueryModelByInvitationToken(ctx context.Context, qry comby.Query, domainQry *InvitationQueryModelByInvitationToken) (*InvitationQueryItemResponse, error)
InvitationQueryListResponse
type InvitationQueryListResponse struct {
Items []*readmodel.InvitationModel `json:"items,omitempty"`
Total int64 `json:"total,omitempty"`
Page int64 `json:"page,omitempty"`
PageSize int64 `json:"pageSize,omitempty"`
}
InvitationQueryItemResponse
type InvitationQueryItemResponse struct {
Item *readmodel.InvitationModel `json:"item,omitempty"`
}
Events
- InvitationAcceptedEvent
- InvitationCreatedEvent
- InvitationDeclinedEvent
- InvitationRemovedEvent
- InvitationAttributeRemovedEvent
- InvitationSentEvent
- InvitationAttributeSetEvent
- InvitationUpdatedEvent
InvitationAcceptedEvent
Domain Event Struct:
type InvitationAcceptedEvent struct {
AccountUuid string `json:"accountUuid"`
}
Domain Event Handling Method:
func (agg *Invitation) InvitationAcceptedEvent(ctx context.Context, evt comby.Event, domainEvt *InvitationAcceptedEvent) (error)
InvitationCreatedEvent
Domain Event Struct:
type InvitationCreatedEvent struct {
IdentityUuid string `json:"identityUuid"`
GroupUuids []string `json:"groupUuids"`
Token string `json:"token"`
Email string `json:"email"`
Attributes string `json:"attributes,omitempty"`
}
Domain Event Handling Method:
func (agg *Invitation) InvitationCreatedEvent(ctx context.Context, evt comby.Event, domainEvt *InvitationCreatedEvent) (error)
InvitationDeclinedEvent
Domain Event Struct:
type InvitationDeclinedEvent struct {
AccountUuid string `json:"accountUuid"`
}
Domain Event Handling Method:
func (agg *Invitation) InvitationDeclinedEvent(ctx context.Context, evt comby.Event, domainEvt *InvitationDeclinedEvent) (error)
InvitationRemovedEvent
Domain Event Struct:
type InvitationRemovedEvent struct {
Reason string `json:"reason,omitempty"`
}
Domain Event Handling Method:
func (agg *Invitation) InvitationRemovedEvent(ctx context.Context, evt comby.Event, domainEvt *InvitationRemovedEvent) (error)
InvitationAttributeRemovedEvent
Domain Event Struct:
type InvitationAttributeRemovedEvent struct {
Key string `json:"key"`
}
Domain Event Handling Method:
func (agg *Invitation) InvitationAttributeRemovedEvent(ctx context.Context, evt comby.Event, domainEvt *InvitationAttributeRemovedEvent) (error)
InvitationSentEvent
Domain Event Struct:
type InvitationSentEvent struct {
State string `json:"state"`
}
Domain Event Handling Method:
func (agg *Invitation) InvitationSentEvent(ctx context.Context, evt comby.Event, domainEvt *InvitationSentEvent) (error)
InvitationAttributeSetEvent
Domain Event Struct:
type InvitationAttributeSetEvent struct {
Key string `json:"key"`
Value any `json:"value"`
}
Domain Event Handling Method:
func (agg *Invitation) InvitationAttributeSetEvent(ctx context.Context, evt comby.Event, domainEvt *InvitationAttributeSetEvent) (error)
InvitationUpdatedEvent
Domain Event Struct:
type InvitationUpdatedEvent struct {
Attributes string `json:"attributes,omitempty"`
}
Domain Event Handling Method:
func (agg *Invitation) InvitationUpdatedEvent(ctx context.Context, evt comby.Event, domainEvt *InvitationUpdatedEvent) (error)
Aggregate
Aggregate Struct:
type Invitation struct {
*comby.BaseAggregate
// GroupUuids groups to which the invited account will be added
GroupUuids []string
// IdentityUuid who created the invitation
IdentityUuid string
// AccountUuid who accepted the invitation
AccountUuid string
// Value Objects
Token string
Email string
State string
}
Methods
Accept
func (agg *Invitation) Accept(accountUuid string) (error)
Create
func (agg *Invitation) Create(identityUuid string, groupUuids []string, token, email, attributes string) (error)
Decline
func (agg *Invitation) Decline(accountUuid string) (error)
Remove
func (agg *Invitation) Remove() (error)
RemoveAttribute
func (agg *Invitation) RemoveAttribute(key string) (error)
Send
func (agg *Invitation) Send() (error)
SetAttribute
func (agg *Invitation) SetAttribute(key string, value any) (error)
Update
func (agg *Invitation) Update(attributes string) (error)
Event Handlers
Reactor
Domain Event | Method |
---|---|
aggregateInvitation.InvitationCreatedEvent | InvitationCreatedEvent |
aggregateInvitation.InvitationAcceptedEvent | InvitationAcceptedEvent |
InvitationReadmodel
Domain Event | Method |
---|---|
tenantAggregate.TenantCreatedEvent | TenantCreatedEvent |
tenantAggregate.TenantUpdatedEvent | TenantUpdatedEvent |
tenantAggregate.TenantRemovedEvent | TenantRemovedEvent |
invitationAggregate.InvitationSentEvent | InvitationSentEvent |
invitationAggregate.InvitationAcceptedEvent | InvitationAcceptedEvent |
invitationAggregate.InvitationAttributeRemovedEvent | InvitationAttributeRemovedEvent |
invitationAggregate.InvitationAttributeSetEvent | InvitationAttributeSetEvent |
invitationAggregate.InvitationCreatedEvent | InvitationCreatedEvent |
invitationAggregate.InvitationUpdatedEvent | InvitationUpdatedEvent |
invitationAggregate.InvitationRemovedEvent | InvitationRemovedEvent |
invitationAggregate.InvitationDeclinedEvent | InvitationDeclinedEvent |
identityAggregate.IdentityCreatedEvent | IdentityCreatedEvent |
identityAggregate.IdentityProfileUpdatedEvent | IdentityProfileUpdatedEvent |
identityAggregate.IdentityRemovedEvent | IdentityRemovedEvent |
groupAggregate.GroupUpdatedEvent | GroupUpdatedEvent |
groupAggregate.GroupRemovedEvent | GroupRemovedEvent |
groupAggregate.GroupAddedEvent | GroupAddedEvent |
accountAggregate.AccountCredentialsUpdatedEvent | AccountCredentialsUpdatedEvent |