Documentation
¶
Overview ¶
Package organization provides optional PostgreSQL tenant membership and session context.
Index ¶
- Constants
- func Contract() plugin.Definition
- func PruneExpired(ctx context.Context, store storage.Store, before time.Time, limit int) (int64, error)
- type Invitation
- type IssuedInvitation
- type Membership
- type Organization
- type Plugin
- func (p *Plugin) AcceptInvitation(ctx context.Context, id string, token sigil.Secret) (Tenant, error)
- func (p *Plugin) Active(ctx context.Context) (Tenant, error)
- func (p *Plugin) Bind(a *sigil.Auth) error
- func (p *Plugin) Create(ctx context.Context, name string) (Tenant, error)
- func (p *Plugin) Definition() plugin.Definition
- func (p *Plugin) Get(ctx context.Context, id string) (Tenant, error)
- func (p *Plugin) Invite(ctx context.Context, id, email string) (IssuedInvitation, error)
- func (p *Plugin) RemoveMember(ctx context.Context, id, userID string) error
- func (p *Plugin) Rename(ctx context.Context, id, name string) (Tenant, error)
- func (p *Plugin) RevokeInvitation(ctx context.Context, id, invitationID string) error
- func (p *Plugin) SetActive(ctx context.Context, id string) (Tenant, error)
- func (p *Plugin) TransferOwnership(ctx context.Context, id, userID string) (Tenant, error)
- func (p *Plugin) WithActive(ctx context.Context, op plugin.Operation, fn func(storage.Tx, Tenant) error) error
- func (p *Plugin) WithTenant(ctx context.Context, id string, op plugin.Operation, ...) error
- type Tenant
Constants ¶
const ( InviteOperation plugin.Operation = "organization.invite" AcceptOperation plugin.Operation = "organization.accept" RevokeInvitationOperation plugin.Operation = "organization.invitation.revoke" RemoveMemberOperation plugin.Operation = "organization.member.remove" TransferOwnershipOperation plugin.Operation = "organization.ownership.transfer" InvitationLifetime = 24 * time.Hour )
const CreateOperation plugin.Operation = "organization.create"
const ID = "organization"
const RenameOperation plugin.Operation = "organization.rename"
const SelectOperation plugin.Operation = "organization.select"
Variables ¶
This section is empty.
Functions ¶
func Contract ¶
func Contract() plugin.Definition
Types ¶
type Invitation ¶
type Invitation struct {
ID string `json:"id"`
OrganizationID string `json:"organizationId"`
Email string `json:"email"`
ExpiresAt time.Time `json:"expiresAt"`
}
Invitation contains public metadata. IssuedInvitation.Token is returned only after commit; the host delivers it to Email without logging or URL analytics.
type IssuedInvitation ¶
type IssuedInvitation struct {
Invitation Invitation `json:"invitation"`
Token sigil.Secret `json:"-"`
}
type Membership ¶
type Organization ¶
type Plugin ¶
type Plugin struct {
// contains filtered or unexported fields
}
func (*Plugin) AcceptInvitation ¶
func (p *Plugin) AcceptInvitation(ctx context.Context, id string, token sigil.Secret) (Tenant, error)
AcceptInvitation requires the authenticated account's current verified email. Consumption and membership insertion commit together. Existing members retain their role; acceptance never promotes a member or downgrades an owner.
func (*Plugin) Create ¶
Create atomically creates an organization and the caller's owner membership.
func (*Plugin) Definition ¶
func (p *Plugin) Definition() plugin.Definition
func (*Plugin) Invite ¶
Invite issues a member invitation bound to a canonical email and tenant. Reissuing for the same tenant/email invalidates every earlier invitation.
func (*Plugin) RemoveMember ¶
RemoveMember permits an owner to remove a member, or a member to leave. The sole owner must transfer first. Cascades clear every active selection.
func (*Plugin) RevokeInvitation ¶
func (*Plugin) TransferOwnership ¶
TransferOwnership atomically promotes an existing member and demotes the caller. Exactly one owner exists at commit. Outstanding invitations are revoked so authority granted by the former owner does not survive transfer.
func (*Plugin) WithActive ¶
func (p *Plugin) WithActive(ctx context.Context, op plugin.Operation, fn func(storage.Tx, Tenant) error) error
WithActive resolves the session selection and rechecks membership on every call. A missing selection (including removal) fails closed with forbidden.
func (*Plugin) WithTenant ¶
func (p *Plugin) WithTenant(ctx context.Context, id string, op plugin.Operation, fn func(storage.Tx, Tenant) error) error
WithTenant authorizes live membership and runs trusted application work in the same transaction. Always scope resource queries to tenant.Organization.ID. Never retain tx or use this snapshot as a later authorization decision.
type Tenant ¶
type Tenant struct {
Organization Organization `json:"organization"`
Membership Membership `json:"membership"`
}