Documentation
¶
Overview ¶
Package eligibility evaluates explicit action rules using supplied current facts. It has no identity, verification, catalog or network dependency.
Index ¶
- Variables
- func Actions() []string
- func ValidAction(action string) bool
- func ValidSchool(school string) bool
- func Validate(rule Rule) error
- func ValidateAction(action string, rule Rule) error
- type Admission
- type CachedRules
- func (c *CachedRules) Apply(ctx context.Context, in Update) (Rule, error)
- func (c *CachedRules) Effective(ctx context.Context, action, school string) (Rule, error)
- func (c *CachedRules) Invalidate()
- func (c *CachedRules) Reset(ctx context.Context, in ResetUpdate) (Rule, error)
- func (c *CachedRules) SchoolRules(ctx context.Context, school string) (Configuration, error)
- type Change
- type Condition
- type Configuration
- type Defaults
- type Evaluation
- type EvaluationBatch
- type Fact
- type Facts
- type Repository
- type Reset
- type ResetRepository
- type ResetUpdate
- type Result
- type Rule
- type RuleSource
- type Rules
- type SchoolRepository
- type Service
- func (s Service) Get(ctx context.Context, school, action string) (Rule, error)
- func (s Service) GetSchool(ctx context.Context, school string) (Configuration, error)
- func (s Service) Reset(ctx context.Context, actor, key, school, action string, in Reset) (Rule, error)
- func (s Service) Set(ctx context.Context, actor, key, school, action string, in Change) (Rule, error)
- type Update
Constants ¶
This section is empty.
Variables ¶
var ErrConflict = errors.New("eligibility_conflict")
var ErrForbidden = errors.New("eligibility_forbidden")
var ErrRule = errors.New("invalid_eligibility_rule")
Functions ¶
func ValidAction ¶ added in v0.2.1
func ValidSchool ¶ added in v0.2.1
ValidSchool checks that school is "*" or a non-blank, control-free UTF-8 identifier up to 128 bytes.
func ValidateAction ¶ added in v0.2.1
ValidateAction verifies both structural rule invariants and that every configured condition is supported by the target action's fact providers.
Types ¶
type Admission ¶
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) 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) 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 Condition ¶
type Condition string
func SupportedConditions ¶ added in v0.2.1
SupportedConditions returns the explicit condition whitelist for an action. Only publish_course has a course enrollment context; other actions reject course_enrollment so misconfiguration cannot trigger runtime 503 failures.
type Configuration ¶
type Evaluation ¶ added in v0.2.1
type EvaluationBatch ¶ added in v0.2.1
type EvaluationBatch struct {
School string `json:"school"`
Items []Evaluation `json:"items"`
}
type ResetRepository ¶ added in v0.2.1
type ResetRepository interface {
Reset(context.Context, ResetUpdate) (Rule, error)
}
type ResetUpdate ¶ added in v0.2.1
type Result ¶
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 SchoolRepository ¶ added in v0.2.1
type SchoolRepository interface {
SchoolRules(context.Context, string) (Configuration, error)
}