organization

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: MIT Imports: 9 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const (
	RoleOwner  = "owner"
	RoleAdmin  = "admin"
	RoleMember = "member"
)

Roles. The creator of an organization becomes the owner.

View Source
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

type Authorizer interface {
	HasPermission(role, permission string) bool
}

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 New

func New(o Options) *Module

New returns an organization module.

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) ID

func (m *Module) ID() string

func (*Module) Init

func (m *Module) Init(core canopy.Core) error

func (*Module) Routes

func (m *Module) Routes() []canopy.Route

func (*Module) ValidateSession

func (m *Module) ValidateSession(ctx context.Context, data *canopy.SessionData) error

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.

type RBAC

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

RBAC is a static role-to-permission map.

func (RBAC) HasPermission

func (r RBAC) HasPermission(role, permission string) bool

Jump to

Keyboard shortcuts

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