Documentation
¶
Overview ¶
Package organization adds organizations, members, roles, and invitations to Canopy.
The module implements canopy.Module and canopy.RouteModule. Add it through canopy.Config.Modules. The store must implement canopy.OrganizationStore.
The creator of an organization becomes the owner. Roles are owner, admin, and member by default. A default Authorizer maps roles to permissions. Override it for custom access control.
An invitation returns a token, which is its id. The application delivers the invitation to the invitee. The invitee accepts it while signed in with the invited email address. An invitation may carry a TeamID; acceptance then also adds the invitee to that team.
Teams group organization members for scoped access. A team belongs to exactly one organization. A team membership carries no role; the organization role stays authoritative.
The active organization is stored on the session. Read it from SessionData.Session.ActiveOrganizationID.
Index ¶
- Constants
- type Authorizer
- type Module
- func (m *Module) Authorize(ctx context.Context, orgID, userID, permission string) (*canopy.Member, error)
- func (m *Module) ID() string
- func (m *Module) Init(core canopy.Core) error
- func (m *Module) Routes() []canopy.Route
- func (m *Module) ValidateSession(ctx context.Context, data *canopy.SessionData) error
- type Options
- type RBAC
Constants ¶
const ( RoleOwner = "owner" RoleAdmin = "admin" RoleMember = "member" )
Roles. The creator of an organization becomes the owner.
const ( PermissionUpdateOrganization = "organization:update" PermissionDeleteOrganization = "organization:delete" PermissionInviteMember = "member:invite" PermissionRemoveMember = "member:remove" PermissionUpdateMemberRole = "member:update-role" PermissionViewMembers = "member:view" PermissionCreateTeam = "team:create" PermissionUpdateTeam = "team:update" PermissionDeleteTeam = "team:delete" PermissionViewTeams = "team:view" PermissionManageTeamMembers = "team:member:manage" )
Permissions.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Authorizer ¶
Authorizer decides if a role may perform a permission.
func DefaultAuthorizer ¶
func DefaultAuthorizer() Authorizer
DefaultAuthorizer returns the owner/admin/member RBAC. The owner has every permission. The admin can manage members, teams, and update the organization. The member can view members and teams.
type Module ¶
type Module struct {
// contains filtered or unexported fields
}
Module adds organizations, members, roles, and invitations. It implements canopy.Module, canopy.RouteModule, and canopy.SessionValidator.
func (*Module) Authorize ¶
func (m *Module) Authorize(ctx context.Context, orgID, userID, permission string) (*canopy.Member, error)
Authorize verifies current organization membership and permission. An application should call it for every tenant-scoped request rather than treating ActiveOrganizationID as proof of access.
func (*Module) ValidateSession ¶
ValidateSession clears an active organization when the session user is no longer a member. ActiveOrganizationID is session preference state, not an authorization decision.
type Options ¶
type Options struct {
Authorizer Authorizer // default: DefaultAuthorizer
AssignableRoles []string // default: admin and member
InvitationTTL time.Duration // default: 7 days
DisableUserCreate bool // block organization creation by ordinary users
}
Options configures the organization module.