eligibility

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: AGPL-3.0 Imports: 8 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

Overview

Package eligibility evaluates explicit action rules using supplied current facts. It has no identity, verification, catalog or network dependency.

Index

Constants

This section is empty.

Variables

View Source
var ErrConflict = errors.New("eligibility_conflict")
View Source
var ErrForbidden = errors.New("eligibility_forbidden")
View Source
var ErrRule = errors.New("invalid_eligibility_rule")
View Source
var ErrUnavailable = errors.New("eligibility_unavailable")

Functions

func Actions added in v0.2.1

func Actions() []string

func ValidAction added in v0.2.1

func ValidAction(action string) bool

func ValidSchool added in v0.2.1

func ValidSchool(school string) bool

ValidSchool checks that school is "*" or a non-blank, control-free UTF-8 identifier up to 128 bytes.

func Validate

func Validate(rule Rule) error

func ValidateAction added in v0.2.1

func ValidateAction(action string, rule Rule) error

ValidateAction verifies both structural rule invariants and that every configured condition is supported by the target action's fact providers.

Types

type Admission

type Admission struct {
	School string
	Rules  Rules
	Facts  Facts
}

Admission evaluates independently named actions without any business-module types. Rules and Facts must both be explicitly wired (use Defaults{} in tests when static defaults are intended). An empty target school evaluates against the server-owned Admission.School so directory and favorite callers can resolve the served school before checking object ownership; any explicit school mismatch is rejected.

func (Admission) Check

func (a Admission) Check(ctx context.Context, subject, school, action string) (Result, error)

func (Admission) Preview added in v0.2.1

func (a Admission) Preview(ctx context.Context, subject, school string, actions []string) (EvaluationBatch, error)

Preview evaluates a bounded batch of actions for an authenticated user so UI entrypoints can display missing conditions or retry prompts before form input. Temporary fact-provider failures mark the affected conditions as unavailable instead of masquerading as missing credentials.

type CachedRules

type CachedRules struct {
	Repo Repository
	Now  func() time.Time
	// contains filtered or unexported fields
}

CachedRules keeps effective rules for at most five seconds. All local writes invalidate the cache, including writes whose commit result is unknown.

func (*CachedRules) Apply

func (c *CachedRules) Apply(ctx context.Context, in Update) (Rule, error)

func (*CachedRules) Effective

func (c *CachedRules) Effective(ctx context.Context, action, school string) (Rule, error)

func (*CachedRules) Invalidate

func (c *CachedRules) Invalidate()

func (*CachedRules) Reset added in v0.2.1

func (c *CachedRules) Reset(ctx context.Context, in ResetUpdate) (Rule, error)

func (*CachedRules) SchoolRules added in v0.2.1

func (c *CachedRules) SchoolRules(ctx context.Context, school string) (Configuration, error)

type Change

type Change struct {
	ExpectedVersion string      `json:"expected_version"`
	Conditions      []Condition `json:"conditions"`
	Reason          string      `json:"reason,omitempty"`
}

type Condition

type Condition string
const (
	Content  Condition = "content_access"
	Campus   Condition = "campus_eligibility"
	Phone    Condition = "phone_bound"
	Identity Condition = "identity_verified"
)

func SupportedConditions added in v0.2.1

func SupportedConditions(action string) ([]Condition, error)

SupportedConditions returns the explicit condition whitelist for an action.

type Configuration

type Configuration struct {
	School  string          `json:"school"`
	Version string          `json:"version"`
	Rules   map[string]Rule `json:"rules"`
}

type Defaults

type Defaults struct{}

func (Defaults) Effective

func (Defaults) Effective(_ context.Context, action, _ string) (Rule, error)

type Evaluation added in v0.2.1

type Evaluation struct {
	Action                string      `json:"action"`
	School                string      `json:"school"`
	Allowed               bool        `json:"allowed"`
	RuleVersion           string      `json:"rule_version"`
	SatisfiedConditions   []Condition `json:"satisfied_conditions"`
	MissingConditions     []Condition `json:"missing_conditions"`
	UnavailableConditions []Condition `json:"unavailable_conditions"`
}

type EvaluationBatch added in v0.2.1

type EvaluationBatch struct {
	School string       `json:"school"`
	Items  []Evaluation `json:"items"`
}

type Fact

type Fact uint8
const (
	Unknown Fact = iota
	Unsatisfied
	Satisfied
)

type Facts

type Facts interface {
	Facts(context.Context, string, string, []Condition) (map[Condition]Fact, error)
}

type Repository

type Repository interface {
	Rules
	Apply(context.Context, Update) (Rule, error)
}

type Reset added in v0.2.1

type Reset struct {
	ExpectedVersion string `json:"expected_version"`
	Reason          string `json:"reason"`
}

type ResetRepository added in v0.2.1

type ResetRepository interface {
	Reset(context.Context, ResetUpdate) (Rule, error)
}

type ResetUpdate added in v0.2.1

type ResetUpdate struct {
	Actor, Key, School, Action string
	Reset                      Reset
	At                         time.Time
}

type Result

type Result struct {
	Allowed     bool
	Satisfied   []Condition
	Missing     []Condition
	Unavailable []Condition
	Version     string
}

func Evaluate

func Evaluate(rule Rule, facts map[Condition]Fact) (Result, error)

func (Result) Evaluation added in v0.2.1

func (r Result) Evaluation(school, action string) Evaluation

type Rule

type Rule struct {
	Version             string      `json:"version"`
	Conditions          []Condition `json:"conditions"`
	Source              RuleSource  `json:"source,omitempty"`
	GlobalConditions    []Condition `json:"global_conditions,omitempty"`
	SupportedConditions []Condition `json:"supported_conditions,omitempty"`
}

type RuleSource added in v0.2.1

type RuleSource string
const (
	SourceInitialDefault RuleSource = "initial_default"
	SourceGlobal         RuleSource = "global"
	SourceSchoolOverride RuleSource = "school_override"
)

type Rules

type Rules interface {
	Effective(context.Context, string, string) (Rule, error)
}

type SchoolRepository added in v0.2.1

type SchoolRepository interface {
	SchoolRules(context.Context, string) (Configuration, error)
}

type Service

type Service struct {
	Repo Repository
	Now  func() time.Time
}

func (Service) Get

func (s Service) Get(ctx context.Context, school, action string) (Rule, error)

func (Service) GetSchool added in v0.2.1

func (s Service) GetSchool(ctx context.Context, school string) (Configuration, error)

func (Service) Reset added in v0.2.1

func (s Service) Reset(ctx context.Context, actor, key, school, action string, in Reset) (Rule, error)

func (Service) Set

func (s Service) Set(ctx context.Context, actor, key, school, action string, in Change) (Rule, error)

type Update

type Update struct {
	Actor, Key, School, Action string
	Change                     Change
	At                         time.Time
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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