Intro
It's designed to be used in ACL (Access Control List) systems, where you need to check if a user has access to a resource.
Example
(
@req.user.role == 'admin'
||
@req.user.id in @record.granted
)
&&
(
@record.published
||
@record.owner == @req.user.id
)
Let's break it down:
@req.user.role == 'admin': Check if the user has the role ofadmin.@req.user.id in @record.granted: Check if the user's id is in thegrantedlist of the record.@record.published: Check if the record is published.@record.owner == @req.user.id: Check if the record's owner is the user.
The above example is a simple ACL system that checks if the user has access to a record.
More language details can be found in LANG.md.
Usage
Integration
// Parse expr
let expr = "@req.user.name in 'foobar' && @files.0.published == true";
let expr = try_from?;
// Construct context
let ctx_names = expr.requested_ctx; // ["req", "files"]
// You can construct the context indeed, but we use json! for simplicity
let ctx = json!;
// Eval
let result = expr.eval?; // Val::Bool(true)
match result
CLI
License
Apache-2.0
2024 @lollipopkit