rolestore

package
v2.36.12 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: AGPL-3.0 Imports: 9 Imported by: 1 module, 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

Index

Constants

This section is empty.

Variables

View Source
var SystemRoleNames = maps.Keys(systemRoles)

Functions

func ConvertDBPermissions added in v2.30.0

func ConvertDBPermissions(dbPerms []database.CustomRolePermission) []rbac.Permission

ConvertDBPermissions converts database permissions to RBAC permissions.

func ConvertDBRole

func ConvertDBRole(dbRole database.CustomRole) (rbac.Role, error)

ConvertDBRole should not be used by any human facing apis. It is used for authz purposes.

func ConvertPermissionsToDB added in v2.30.0

func ConvertPermissionsToDB(perms []rbac.Permission) []database.CustomRolePermission

ConvertPermissionsToDB converts RBAC permissions to the database format.

func CreateSystemRole added in v2.32.0

func CreateSystemRole(
	ctx context.Context,
	tx database.Store,
	org database.Organization,
	roleName string,
) error

CreateSystemRole inserts a new system role into the database with permissions produced by permsFunc based on the organization's current settings.

func CustomRoleCacheContext

func CustomRoleCacheContext(ctx context.Context) context.Context

CustomRoleCacheContext prevents needing to lookup custom roles within the same request lifecycle. Optimizing this to span requests should be done in the future.

func CustomRoleMW

func CustomRoleMW(next http.Handler) http.Handler

CustomRoleMW adds a custom role cache on the ctx to prevent duplicate db fetches.

func Expand

func Expand(ctx context.Context, db database.Store, names []rbac.RoleIdentifier) (rbac.Roles, error)

Expand will expand built in roles, and fetch custom roles from the database. If a custom role is defined, but does not exist, the role will be omitted on the response. This means deleted roles are silently dropped.

func IsSystemRoleName added in v2.32.0

func IsSystemRoleName(name string) bool

func PrefetchCustomRoles added in v2.36.0

func PrefetchCustomRoles(ctx context.Context, db database.Store) (context.Context, error)

PrefetchCustomRoles fetches every custom role in a single query and stores them in the returned context's role cache, so Expand calls on that context resolve custom roles without further database lookups. Roles deleted after the prefetch are still absent from the cache and fall back to an individual lookup on Expand.

func ReconcileSystemRole added in v2.32.0

func ReconcileSystemRole(
	ctx context.Context,
	tx database.Store,
	in database.CustomRole,
	org database.Organization,
) (database.CustomRole, bool, error)

ReconcileSystemRole compares the given role's permissions against the desired permissions produced by the permissions function based on the organization's settings. If they differ, the DB row is updated. Uses set-based comparison so permission ordering doesn't matter. Returns the correct role and a boolean indicating whether the reconciliation was necessary.

IMPORTANT: Callers must hold database.LockIDReconcileSystemRoles for the duration of the enclosing transaction.

func ReconcileSystemRoles added in v2.30.0

func ReconcileSystemRoles(ctx context.Context, log slog.Logger, db database.Store) error

ReconcileSystemRoles ensures that every organization's system roles in the DB are up-to-date with the current RBAC definitions and organization settings.

func TestingGetSystemRole added in v2.34.0

func TestingGetSystemRole(name string, orgID uuid.UUID, settings rbac.OrgSettings) (rbac.Role, error)

Types

This section is empty.

Jump to

Keyboard shortcuts

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