Skip to content

public ​

go
import "github.com/prescriptoo/prescriptoo-api/services/authorization/public"

Package public exposes authorization DTOs and narrow service capabilities. Callers authenticate identities before permission checks. Resource services retain lifecycle checks and supply trusted ownership facts.

Index ​

Variables ​

go
var (
    // ErrInvalidInput identifies malformed authorization input.
    ErrInvalidInput = errors.New("invalid authorization input")
    // ErrInvalidPermission identifies an unknown permission or unsupported access restriction.
    ErrInvalidPermission = errors.New("unsupported permission")
    // ErrForbidden indicates the actor lacks required authority.
    ErrForbidden = errors.New("authorization denied")
    // ErrNotFound indicates a resource is absent from the requested scope.
    ErrNotFound = errors.New("authorization resource not found")
    // ErrConflict identifies an outdated version or conflicting definition.
    ErrConflict = errors.New("authorization version conflict")
    // ErrProtectedRole protects owner-designated authority from grant-management edits.
    ErrProtectedRole = errors.New("protected authorization role")
    // ErrUnavailable indicates a required authorization dependency failed.
    ErrUnavailable = errors.New("authorization service unavailable")
)

func IsAdminResourceOwner ​

go
func IsAdminResourceOwner(input AdminResourceOwnershipInput) bool

IsAdminResourceOwner compares ownership of a platform resource. An organization resource must use IsOrganizationResourceOwner instead.

func IsOrganizationResourceOwner ​

go
func IsOrganizationResourceOwner(input OrganizationResourceOwnershipInput) bool

IsOrganizationResourceOwner proves equality within one organization. It does not authenticate, verify membership, or grant a permission.

type Actor ​

Actor must contain an identity verified by the consuming service.

go
type Actor struct {
    UserID string
}

type AdminPermissionChecker ​

AdminPermissionChecker exposes only platform-admin grant evaluation.

go
type AdminPermissionChecker interface {
    HasAdminPermission(context.Context, HasAdminPermissionInput) (bool, error)
}

type AdminResourceOwnershipInput ​

AdminResourceOwnershipInput carries trusted identity user IDs for a platform resource.

go
type AdminResourceOwnershipInput struct {
    UserID      string
    OwnerUserID string
}

type AssignRoleInput ​

AssignRoleInput adds a role at the expected member-authorization version.

go
type AssignRoleInput struct {
    MemberQuery
    RoleID          string
    ExpectedVersion int64
}

type CreateRoleInput ​

CreateRoleInput defines a custom role and its initial permission bundle.

go
type CreateRoleInput struct {
    Query
    Name        string
    Slug        string
    Description string
    Permissions []PermissionGrant
}

type DeleteRoleInput ​

DeleteRoleInput deletes a role and its assignments at the expected role version.

go
type DeleteRoleInput struct {
    RoleQuery
    ExpectedVersion int64
}

type Effect ​

Effect determines whether a direct override allows or denies access.

go
type Effect string

Supported direct override effects.

go
const (
    EffectAllow Effect = "allow"
    EffectDeny  Effect = "deny"
)

type EffectivePermission ​

EffectivePermission is contextual: own and any decisions can differ.

go
type EffectivePermission struct {
    Permission PermissionKey `json:"permission"`
    Own        bool          `json:"own"`
    Any        bool          `json:"any"`
}

type HasAdminPermissionInput ​

HasAdminPermissionInput requests a grant check within platform administration.

go
type HasAdminPermissionInput struct {
    UserID     string
    Permission PermissionKey
    Access     ResourceAccess
}

type HasOrganizationPermissionInput ​

HasOrganizationPermissionInput requests a grant check within one organization. Access defaults to any. Own must be requested only after the ownership helper succeeds against a server-loaded resource. Any grants also match own checks; own grants never match any checks. Matching explicit denials override allows. For record actions, select Own for owners even when an Any grant exists; otherwise an Own denial cannot be evaluated for that record.

go
type HasOrganizationPermissionInput struct {
    UserID         string
    OrganizationID string
    Permission     PermissionKey
    Access         ResourceAccess
}

type MemberAuthorization ​

MemberAuthorization returns role assignments, overrides, versions and contextual decisions.

go
type MemberAuthorization struct {
    UserID               string                `json:"user_id"`
    Scope                Scope                 `json:"scope"`
    Version              int64                 `json:"version"`
    Roles                []Role                `json:"roles"`
    Overrides            []PermissionOverride  `json:"overrides"`
    EffectivePermissions []EffectivePermission `json:"effective_permissions"`
}

type MemberAuthorizationReader ​

MemberAuthorizationReader inspects a member's scoped authorization state.

go
type MemberAuthorizationReader interface {
    GetMemberAuthorization(context.Context, MemberQuery) (*MemberAuthorization, error)
}

type MemberPermissionRemover ​

MemberPermissionRemover removes a direct override to restore inheritance.

go
type MemberPermissionRemover interface {
    RemoveMemberPermission(context.Context, RemoveMemberPermissionInput) (*MemberAuthorization, error)
}

type MemberPermissionSetter ​

MemberPermissionSetter sets a direct scoped allow or deny override.

go
type MemberPermissionSetter interface {
    SetMemberPermission(context.Context, SetMemberPermissionInput) (*MemberAuthorization, error)
}

type MemberQuery ​

MemberQuery identifies the target identity within one membership scope.

go
type MemberQuery struct {
    Query
    TargetUserID string
}

type Membership ​

Membership is a live owner-provided grant eligibility record. ID must identify this membership incarnation so deletion/recreation cannot resurrect old grants.

go
type Membership struct {
    ID     string
    Active bool
    // IsOwner is reserved for owner-designated platform super admins / org admins.
    // Custom authorization roles cannot create this authority.
    IsOwner bool
}

type MembershipReader ​

MembershipReader performs pure membership queries without authorization callbacks. This avoids recursion when Admin/Organization consume this service.

go
type MembershipReader interface {
    GetAuthorizationMembership(context.Context, Scope, string) (Membership, error)
}

type OrganizationPermissionChecker ​

OrganizationPermissionChecker exposes only organization grant evaluation.

go
type OrganizationPermissionChecker interface {
    HasOrganizationPermission(context.Context, HasOrganizationPermissionInput) (bool, error)
}

type OrganizationPermissionTransactions ​

OrganizationPermissionTransactions reads current grants in the caller's transaction. Callers must first lock Organization and derive the live membership through its capability.

go
type OrganizationPermissionTransactions interface {
    HasOrganizationPermissionInTransaction(context.Context, pgx.Tx, HasOrganizationPermissionInput, Membership) (bool, error)
}

type OrganizationResourceOwnershipInput ​

OrganizationResourceOwnershipInput contains trusted, server-loaded identities. OwnerUserID is the resource's defined owner, not necessarily its creator.

go
type OrganizationResourceOwnershipInput struct {
    UserID                 string
    OrganizationID         string
    ResourceOrganizationID string
    OwnerUserID            string
}

type Permission ​

Permission is an application-defined catalog entry, never user-created code.

go
type Permission struct {
    Key         PermissionKey `json:"key"`
    ScopeType   ScopeType     `json:"scope_type"`
    Resource    string        `json:"resource"`
    Action      string        `json:"action"`
    SupportsOwn bool          `json:"supports_own"`
}

func Catalog ​

go
func Catalog() []Permission

Catalog returns a copy of the supported application permission definitions. Adding a new key requires application enforcement and a database migration.

func FindPermission ​

go
func FindPermission(key PermissionKey) (Permission, bool)

FindPermission finds a supported permission without accepting arbitrary keys.

type PermissionGrant ​

PermissionGrant grants one supported permission with an ownership restriction.

go
type PermissionGrant struct {
    Permission PermissionKey  `json:"permission" minLength:"1"`
    Access     ResourceAccess `json:"access" enum:"any,own"`
}

type PermissionKey ​

PermissionKey identifies an application-defined resource/action.

go
type PermissionKey string

type PermissionLister ​

PermissionLister exposes the supported permission catalog for an authorized actor.

go
type PermissionLister interface {
    ListPermissions(context.Context, Query) ([]Permission, error)
}

type PermissionOverride ​

PermissionOverride adds an explicit allow or deny for one member.

go
type PermissionOverride struct {
    PermissionGrant
    Effect Effect `json:"effect" enum:"allow,deny"`
}

type Query ​

Query carries a verified actor and an explicit authorization scope.

go
type Query struct {
    Audit audit.OperationContext `json:"-"`
    Actor Actor
    Scope Scope
}

type RemoveMemberPermissionInput ​

RemoveMemberPermissionInput removes an override and restores role inheritance.

go
type RemoveMemberPermissionInput struct {
    MemberQuery
    Permission      PermissionKey
    Access          ResourceAccess
    ExpectedVersion int64
}

type ResourceAccess ​

ResourceAccess selects an ownership relationship within the current scope.

go
type ResourceAccess string

Supported resource ownership relationships.

go
const (
    AccessAny ResourceAccess = "any"
    AccessOwn ResourceAccess = "own"
)

type RevokeRoleInput ​

RevokeRoleInput removes a role at the expected member-authorization version.

go
type RevokeRoleInput = AssignRoleInput

type Role ​

Role is a versioned permission bundle within one scope.

go
type Role struct {
    ID          string            `json:"id"`
    Name        string            `json:"name"`
    Slug        string            `json:"slug"`
    Description string            `json:"description"`
    Protected   bool              `json:"protected"`
    Version     int64             `json:"version"`
    Permissions []PermissionGrant `json:"permissions"`
}

type RoleAssigner ​

RoleAssigner assigns a role without exceeding the actor's delegation authority.

go
type RoleAssigner interface {
    AssignRole(context.Context, AssignRoleInput) (*MemberAuthorization, error)
}

type RoleCreator ​

RoleCreator creates a role after validating delegation authority.

go
type RoleCreator interface {
    CreateRole(context.Context, CreateRoleInput) (*Role, error)
}

type RoleDeleter ​

RoleDeleter atomically removes a role and its assignments.

go
type RoleDeleter interface {
    DeleteRole(context.Context, DeleteRoleInput) error
}

type RoleEditor ​

RoleEditor replaces versioned role metadata.

go
type RoleEditor interface {
    UpdateRole(context.Context, UpdateRoleInput) (*Role, error)
}

type RoleLister ​

RoleLister lists role definitions within one authorized scope.

go
type RoleLister interface {
    ListRoles(context.Context, Query) ([]Role, error)
}

type RolePermissionSetter ​

RolePermissionSetter replaces a role bundle after validating old and new grants.

go
type RolePermissionSetter interface {
    SetRolePermissions(context.Context, SetRolePermissionsInput) (*Role, error)
}

type RoleQuery ​

RoleQuery identifies a role within the actor's requested scope.

go
type RoleQuery struct {
    Query
    RoleID string
}

type RoleReader ​

RoleReader reads one role definition within its scope.

go
type RoleReader interface {
    GetRole(context.Context, RoleQuery) (*Role, error)
}

type RoleRevoker ​

RoleRevoker revokes one member role assignment.

go
type RoleRevoker interface {
    RevokeRole(context.Context, RevokeRoleInput) (*MemberAuthorization, error)
}

type Scope ​

Scope selects the platform or exactly one organization.

go
type Scope struct {
    Type           ScopeType `json:"type" enum:"admin,organization"`
    OrganizationID string    `json:"organization_id,omitempty"`
}

type ScopeType ​

ScopeType identifies the platform or organization permission domain.

go
type ScopeType string

Supported authorization scope domains.

go
const (
    ScopeAdmin        ScopeType = "admin"
    ScopeOrganization ScopeType = "organization"
)

type SetMemberPermissionInput ​

SetMemberPermissionInput sets a version-checked direct member override.

go
type SetMemberPermissionInput struct {
    MemberQuery
    Override        PermissionOverride
    ExpectedVersion int64
}

type SetRolePermissionsInput ​

SetRolePermissionsInput replaces a complete permission bundle at its expected version.

go
type SetRolePermissionsInput struct {
    RoleQuery
    Permissions     []PermissionGrant
    ExpectedVersion int64
}

type UpdateRoleInput ​

UpdateRoleInput replaces role metadata when the expected version matches.

go
type UpdateRoleInput struct {
    RoleQuery
    Name            string
    Description     string
    ExpectedVersion int64
}

Generated by gomarkdoc

Documentation follows the source. Planned contracts are marked explicitly.