Framework.MessageSecurity (Framework v0.5.0)
View SourceMessageSecurity provides pure predicate functions compiled from AppSpec
visible_if clauses. These predicates run during Accept/Plan phase and
enforce the same authorization logic used for UI visibility.
Core Principle
Visibility and enforcement are the same predicate evaluated in different places.
AuthContext Structure
The context passed to visibility predicates includes:
actor: Current user/actor informationorg: Organization contextroles: List of roles for current contextfeature_flags: Available feature flagsacl_bitsets: Access control lists as bitsetstenant_id: Multi-tenant identifierauthenticated?: Boolean authentication status
Summary
Functions
Compiles a visibility predicate from AppSpec page AST.
Creates an executable function from AST that supports param/1 calls.
Extracts the visible_if clause from page AST.
Generates verified route helpers from AppSpec definitions.
Gets the visibility predicate for a specific page from an AppSpec module.
Gets all registered AppSpec modules.
Gets the compiled visibility predicate for a given page.
Transforms predicate AST to handle param/1 calls and context access safely.
Validates route parameters against their schema.
Evaluates visibility predicate for a given page and context.
Functions
Compiles a visibility predicate from AppSpec page AST.
Creates an executable function from AST that supports param/1 calls.
Extracts the visible_if clause from page AST.
Generates verified route helpers from AppSpec definitions.
This will be called at compile time to generate the routes() helpers.
Gets the visibility predicate for a specific page from an AppSpec module.
Gets all registered AppSpec modules.
Gets the compiled visibility predicate for a given page.
This loads the predicate from the registered AppSpec modules.
Transforms predicate AST to handle param/1 calls and context access safely.
Validates route parameters against their schema.
Returns {:ok, coerced_params} for valid params,
{:error, :url_invalid} for invalid params.
Evaluates visibility predicate for a given page and context.
Returns true if the page should be visible/accessible, false otherwise.
Examples
ctx = %{authenticated?: true, roles: [:member, :admin]}
MessageSecurity.visible?(:dashboard, ctx, %{})
#=> true or false