defaultstore

package
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package defaultstore implements the SQL-backed default store for the organizations plugin.

Dialect selection happens once in NewDefaultOrganizationStore; all methods are dialect-agnostic and delegate to the unexported querier interface.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DefaultOrganizationStore

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

DefaultOrganizationStore implements orgtypes.OrganizationStore using a SQL database.

All dialect logic is confined to the querier: this struct holds only the single chosen querier and delegates every operation to it.

func NewDefaultOrganizationStore

func NewDefaultOrganizationStore(db *sql.DB, dialect plugins.Dialect) (*DefaultOrganizationStore, error)

NewDefaultOrganizationStore creates a DefaultOrganizationStore for the given dialect.

func (*DefaultOrganizationStore) CanAccessTeam

func (s *DefaultOrganizationStore) CanAccessTeam(ctx context.Context, userID, teamID string) (bool, error)

CanAccessTeam checks whether a user can access a team.

Access requires being a member of the parent organization AND a member of the team, with any role in each — custom roles are not second-class here.

func (*DefaultOrganizationStore) CountInvitations

func (s *DefaultOrganizationStore) CountInvitations(ctx context.Context, orgID string, teamID string) (int, error)

CountInvitations returns the total number of invitations matching filters.

func (*DefaultOrganizationStore) CountOrganizationMembers

func (s *DefaultOrganizationStore) CountOrganizationMembers(ctx context.Context, orgID string) (int, error)

CountOrganizationMembers returns the total number of members in an organization.

func (*DefaultOrganizationStore) CountOrganizationMembersWithRole added in v2.1.0

func (s *DefaultOrganizationStore) CountOrganizationMembersWithRole(ctx context.Context, orgID, role string) (int, error)

CountOrganizationMembersWithRole counts members holding a role, across both the membership role and assignment rows, so a role in use cannot be deleted out from under its holders.

func (*DefaultOrganizationStore) CountTeamMembers

func (s *DefaultOrganizationStore) CountTeamMembers(ctx context.Context, teamID string) (int, error)

CountTeamMembers returns the total number of members in a team.

func (*DefaultOrganizationStore) CountTeams

func (s *DefaultOrganizationStore) CountTeams(ctx context.Context, orgID string) (int, error)

CountTeams returns the total number of teams within an organization.

func (*DefaultOrganizationStore) CountUserOrganizations

func (s *DefaultOrganizationStore) CountUserOrganizations(ctx context.Context, userID string) (int, error)

CountUserOrganizations returns the total number of organizations the user belongs to.

func (*DefaultOrganizationStore) CreateInvitation

func (s *DefaultOrganizationStore) CreateInvitation(ctx context.Context, inv orgtypes.Invitation) error

CreateInvitation stores a new invitation.

func (*DefaultOrganizationStore) CreateMember

func (s *DefaultOrganizationStore) CreateMember(ctx context.Context, id, userID, orgID, role string, createdAt, updatedAt time.Time) error

CreateMember adds a user as a member of an organization with the given role.

func (*DefaultOrganizationStore) CreateMemberPermissionOverride added in v2.1.0

func (s *DefaultOrganizationStore) CreateMemberPermissionOverride(ctx context.Context, o orgtypes.MemberPermissionOverride) error

CreateMemberPermissionOverride stores one override.

func (*DefaultOrganizationStore) CreateMemberRoleAssignment added in v2.2.0

func (s *DefaultOrganizationStore) CreateMemberRoleAssignment(ctx context.Context, id, orgID, userID, role, scopeType, scopeID string, createdAt, updatedAt time.Time) error

CreateMemberRoleAssignment stores an assignment. An empty scopeType/scopeID pair stores an organization-wide assignment; anything else stores a scoped one.

func (*DefaultOrganizationStore) CreateOrganization

func (s *DefaultOrganizationStore) CreateOrganization(ctx context.Context, id, name, slug string, createdAt, updatedAt time.Time) error

CreateOrganization creates a new organization with the given attributes.

func (*DefaultOrganizationStore) CreateOrganizationRole added in v2.1.0

func (s *DefaultOrganizationStore) CreateOrganizationRole(ctx context.Context, role orgtypes.OrganizationRole) error

CreateOrganizationRole stores a new custom role.

func (*DefaultOrganizationStore) CreateTeam

func (s *DefaultOrganizationStore) CreateTeam(ctx context.Context, id, orgID, name, description string, createdAt, updatedAt time.Time) error

CreateTeam creates a new team within an organization.

func (*DefaultOrganizationStore) CreateTeamMember

func (s *DefaultOrganizationStore) CreateTeamMember(ctx context.Context, id, teamID, userID, role string, createdAt, updatedAt time.Time) error

CreateTeamMember adds a user as a member of a team with the given role.

func (*DefaultOrganizationStore) DeleteInvitation

func (s *DefaultOrganizationStore) DeleteInvitation(ctx context.Context, id string) error

DeleteInvitation deletes an invitation by ID.

func (*DefaultOrganizationStore) DeleteMemberPermissionOverrides added in v2.1.0

func (s *DefaultOrganizationStore) DeleteMemberPermissionOverrides(ctx context.Context, orgID, userID string) error

DeleteMemberPermissionOverrides removes every override for a member.

func (*DefaultOrganizationStore) DeleteMemberRoleAssignment added in v2.2.0

func (s *DefaultOrganizationStore) DeleteMemberRoleAssignment(ctx context.Context, orgID, userID, id string) error

DeleteMemberRoleAssignment removes one role assignment.

Returns sql.ErrNoRows when no assignment matched, so callers can tell an unknown ID from a successful removal.

func (*DefaultOrganizationStore) DeleteOrganization

func (s *DefaultOrganizationStore) DeleteOrganization(ctx context.Context, id string, updatedAt time.Time) error

DeleteOrganization soft-deletes an organization by ID.

func (*DefaultOrganizationStore) DeleteOrganizationRole added in v2.1.0

func (s *DefaultOrganizationStore) DeleteOrganizationRole(ctx context.Context, orgID, name string) error

DeleteOrganizationRole removes a custom role.

func (*DefaultOrganizationStore) DeleteTeam

func (s *DefaultOrganizationStore) DeleteTeam(ctx context.Context, id string) error

DeleteTeam removes a team by its ID.

func (*DefaultOrganizationStore) GetInvitationByID

func (s *DefaultOrganizationStore) GetInvitationByID(ctx context.Context, id string) (orgtypes.Invitation, error)

GetInvitationByID retrieves an invitation by ID.

func (*DefaultOrganizationStore) GetInvitationByTokenHash

func (s *DefaultOrganizationStore) GetInvitationByTokenHash(ctx context.Context, tokenHash string) (orgtypes.Invitation, error)

GetInvitationByTokenHash retrieves an invitation by token hash.

func (*DefaultOrganizationStore) GetMember

func (s *DefaultOrganizationStore) GetMember(ctx context.Context, userID, orgID string) (orgtypes.Member, error)

GetMember retrieves the membership record for a user in an organization.

func (*DefaultOrganizationStore) GetOrganization

func (s *DefaultOrganizationStore) GetOrganization(ctx context.Context, id string) (orgtypes.Organization, error)

GetOrganization retrieves an organization by its ID.

func (*DefaultOrganizationStore) GetOrganizationBySlug

func (s *DefaultOrganizationStore) GetOrganizationBySlug(ctx context.Context, slug string) (orgtypes.Organization, error)

GetOrganizationBySlug retrieves an organization by its URL slug.

func (*DefaultOrganizationStore) GetOrganizationRole added in v2.1.0

func (s *DefaultOrganizationStore) GetOrganizationRole(ctx context.Context, orgID, name string) (orgtypes.OrganizationRole, error)

GetOrganizationRole retrieves a persisted role by name.

func (*DefaultOrganizationStore) GetTeam

GetTeam retrieves a team by its ID.

func (*DefaultOrganizationStore) GetTeamMember

func (s *DefaultOrganizationStore) GetTeamMember(ctx context.Context, teamID, userID string) (orgtypes.TeamMember, error)

GetTeamMember retrieves the membership record for a user in a team.

func (*DefaultOrganizationStore) HasOrgRole

func (s *DefaultOrganizationStore) HasOrgRole(ctx context.Context, userID, orgID string, roles ...string) (bool, error)

HasOrgRole checks whether the user has any of the given org-level roles. The membership role is checked first; additional organization-wide assignments (empty scope) count too.

func (*DefaultOrganizationStore) HasTeamRole

func (s *DefaultOrganizationStore) HasTeamRole(ctx context.Context, userID, teamID string, roles ...string) (bool, error)

HasTeamRole checks whether the user has any of the given team-level roles.

func (*DefaultOrganizationStore) IsOrganizationMember deprecated

func (s *DefaultOrganizationStore) IsOrganizationMember(ctx context.Context, userID, orgID string) (bool, error)

IsOrganizationMember reports whether the user is a member of the organization.

Deprecated: Use HasOrgRole instead. Returns true for any role.

func (*DefaultOrganizationStore) IsOwner

func (s *DefaultOrganizationStore) IsOwner(ctx context.Context, userID, orgID string) (bool, error)

IsOwner reports whether the user is the owner of the organization.

func (*DefaultOrganizationStore) IsOwnerOrAdmin deprecated

func (s *DefaultOrganizationStore) IsOwnerOrAdmin(ctx context.Context, userID, orgID string) (bool, error)

IsOwnerOrAdmin reports whether the user has the owner or admin role in the organization.

Deprecated: Use HasOrgRole instead.

func (*DefaultOrganizationStore) ListInvitations

func (s *DefaultOrganizationStore) ListInvitations(ctx context.Context, orgID string, teamID string, offset, limit int) ([]orgtypes.Invitation, error)

ListInvitations returns a paginated list of invitations for an org.

func (*DefaultOrganizationStore) ListMemberPermissionOverrides added in v2.1.0

func (s *DefaultOrganizationStore) ListMemberPermissionOverrides(ctx context.Context, orgID, userID string) ([]orgtypes.MemberPermissionOverride, error)

ListMemberPermissionOverrides returns the member's permission overrides.

func (*DefaultOrganizationStore) ListMemberRoleAssignments added in v2.2.0

func (s *DefaultOrganizationStore) ListMemberRoleAssignments(ctx context.Context, orgID, userID string) ([]orgtypes.RoleAssignment, error)

ListMemberRoleAssignments lists a member's assignments. Organization-wide rows (empty scope) are returned with a nil Scope.

func (*DefaultOrganizationStore) ListOrganizationMembers

func (s *DefaultOrganizationStore) ListOrganizationMembers(ctx context.Context, orgID string, offset, limit int) ([]orgtypes.Member, error)

ListOrganizationMembers returns a paginated list of members in an organization.

func (*DefaultOrganizationStore) ListOrganizationRoles added in v2.1.0

func (s *DefaultOrganizationStore) ListOrganizationRoles(ctx context.Context, orgID string) ([]orgtypes.OrganizationRole, error)

ListOrganizationRoles returns the organization's persisted custom roles.

func (*DefaultOrganizationStore) ListTeamMembers

func (s *DefaultOrganizationStore) ListTeamMembers(ctx context.Context, teamID string, offset, limit int) ([]orgtypes.TeamMember, error)

ListTeamMembers returns a paginated list of members in a team.

func (*DefaultOrganizationStore) ListTeams

func (s *DefaultOrganizationStore) ListTeams(ctx context.Context, orgID string, offset, limit int) ([]orgtypes.Team, error)

ListTeams returns a paginated list of teams within an organization.

func (*DefaultOrganizationStore) ListUserOrganizations

func (s *DefaultOrganizationStore) ListUserOrganizations(ctx context.Context, userID string, offset, limit int) ([]orgtypes.Organization, error)

ListUserOrganizations returns a paginated list of organizations the user belongs to.

func (*DefaultOrganizationStore) RemoveMember

func (s *DefaultOrganizationStore) RemoveMember(ctx context.Context, userID, orgID string) error

RemoveMember removes a user from an organization.

The two deletes are not wrapped in a transaction (this store has no transaction handle). Assignment rows go first: if the membership delete then fails, the member keeps their membership but loses their assignment grants — the fail-closed direction. The reverse order could resurrect stale grants if the user rejoins the organization.

func (*DefaultOrganizationStore) RemoveTeamMember

func (s *DefaultOrganizationStore) RemoveTeamMember(ctx context.Context, teamID, userID string) error

RemoveTeamMember removes a user from a team.

func (*DefaultOrganizationStore) RenameOrganizationRole added in v2.2.0

func (s *DefaultOrganizationStore) RenameOrganizationRole(ctx context.Context, orgID, oldName, newName string, updatedAt time.Time) error

RenameOrganizationRole renames a custom role, carrying the new name to its assignments, to any member whose primary role it is, and to organization- level invitations referencing it. The statements run in one transaction: a partial rename would leave references to a role name that no longer exists. Team-level invitations are untouched — their role column holds team role names, not org roles. Returns sql.ErrNoRows when the organization has no role named oldName.

func (*DefaultOrganizationStore) UpdateInvitationStatus

func (s *DefaultOrganizationStore) UpdateInvitationStatus(ctx context.Context, id, status string, updatedAt time.Time) error

UpdateInvitationStatus updates the status of an invitation.

func (*DefaultOrganizationStore) UpdateMemberRole

func (s *DefaultOrganizationStore) UpdateMemberRole(ctx context.Context, userID, orgID, role string, updatedAt time.Time) error

UpdateMemberRole updates the role of a member within an organization.

func (*DefaultOrganizationStore) UpdateOrganization

func (s *DefaultOrganizationStore) UpdateOrganization(ctx context.Context, id, name, slug string, updatedAt time.Time) error

UpdateOrganization updates the name, slug, and updatedAt timestamp for an organization.

func (*DefaultOrganizationStore) UpdateOrganizationRole added in v2.1.0

func (s *DefaultOrganizationStore) UpdateOrganizationRole(ctx context.Context, role orgtypes.OrganizationRole) error

UpdateOrganizationRole replaces a role's permissions.

func (*DefaultOrganizationStore) UpdateTeam

func (s *DefaultOrganizationStore) UpdateTeam(ctx context.Context, id, name, description string, updatedAt time.Time) error

UpdateTeam updates the name, description, and updatedAt timestamp for a team.

func (*DefaultOrganizationStore) UpdateTeamMemberRole

func (s *DefaultOrganizationStore) UpdateTeamMemberRole(ctx context.Context, teamID, userID, role string, updatedAt time.Time) error

UpdateTeamMemberRole updates the role of a member within a team.

Jump to

Keyboard shortcuts

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