pub enum Access {
None,
User(Arc<User>),
}Expand description
Authorization decision attached to a request Context.
Closed enum (no dyn): the dispatch layer reads
ctx.access.can_read_table(db, t) and the compiler devirtualizes
to a stack-resident match. Customer authentication plugins extend
via AuthProvider — they produce an AuthIdentity which the
framework resolves into a User; they do not implement Access
directly.
Variants§
None
Unauthenticated request. Every permission check returns
false; the only way through is a resource that explicitly
opts into public access (e.g. via @access(public: [read])).
User(Arc<User>)
Authenticated user — RBAC decisions delegate to the inner
User. Wrapped in Arc so cloning Access across the
request pipeline is one atomic bump, not a deep Role copy.
Implementations§
Source§impl Access
impl Access
Sourcepub const fn is_authenticated(&self) -> bool
pub const fn is_authenticated(&self) -> bool
true if the request authenticated as a user (any user).
Sourcepub fn is_super_user(&self) -> bool
pub fn is_super_user(&self) -> bool
true if the request authenticated as a super-user role.
Sourcepub fn role(&self) -> &str
pub fn role(&self) -> &str
Role identifier of the authenticated user, or empty string if unauthenticated.
Sourcepub fn username(&self) -> &str
pub fn username(&self) -> &str
Username of the authenticated user, or empty string if unauthenticated.
Sourcepub fn user(&self) -> Option<&User>
pub fn user(&self) -> Option<&User>
Some(user) if authenticated, None otherwise. Useful when
the caller needs to reach into User-specific fields beyond
the helper methods on Access.
Sourcepub fn can_read_table(&self, database: &str, table: &str) -> bool
pub fn can_read_table(&self, database: &str, table: &str) -> bool
May the requester read records from database.table?
Sourcepub fn can_insert_table(&self, database: &str, table: &str) -> bool
pub fn can_insert_table(&self, database: &str, table: &str) -> bool
May the requester insert records into database.table?
Sourcepub fn can_update_table(&self, database: &str, table: &str) -> bool
pub fn can_update_table(&self, database: &str, table: &str) -> bool
May the requester update records in database.table?
Sourcepub fn can_delete_table(&self, database: &str, table: &str) -> bool
pub fn can_delete_table(&self, database: &str, table: &str) -> bool
May the requester delete records from database.table?
Sourcepub fn can_read_attribute(
&self,
database: &str,
table: &str,
attr: &str,
) -> bool
pub fn can_read_attribute( &self, database: &str, table: &str, attr: &str, ) -> bool
May the requester read field attr on database.table?
Sourcepub fn can_write_attribute(
&self,
database: &str,
table: &str,
attr: &str,
) -> bool
pub fn can_write_attribute( &self, database: &str, table: &str, attr: &str, ) -> bool
May the requester write field attr on database.table?
Sourcepub fn has_unrestricted_attributes(&self, database: &str, table: &str) -> bool
pub fn has_unrestricted_attributes(&self, database: &str, table: &str) -> bool
true if no per-attribute restrictions apply for database.table.
Access::None returns true here because there is no user
whose attribute grants need consulting — callers gate on
is_authenticated separately if they
need to distinguish “no user” from “user with full attributes”.
Sourcepub fn filter_readable_attributes<'a>(
&self,
database: &str,
table: &str,
attrs: &[&'a str],
) -> Vec<&'a str>
pub fn filter_readable_attributes<'a>( &self, database: &str, table: &str, attrs: &[&'a str], ) -> Vec<&'a str>
Filter attrs to only those the requester may read on
database.table. Super-users keep the full list; unauthenticated
requests get an empty list.
Sourcepub fn validate_writable_attributes(
&self,
database: &str,
table: &str,
attrs: &[&str],
) -> Result<(), Vec<String>>
pub fn validate_writable_attributes( &self, database: &str, table: &str, attrs: &[&str], ) -> Result<(), Vec<String>>
Verify every attribute in attrs is writable. Super-users
always succeed; unauthenticated requests fail listing every
attribute as unauthorized.
§Errors
Returns Err(unauthorized) with the list of attribute names
the requester may not write.
Sourcepub fn filter_record(&self, database: &str, table: &str, record: &mut Value)
pub fn filter_record(&self, database: &str, table: &str, record: &mut Value)
Filter a JSON object in-place, retaining only attributes the requester may read. Super-users pass-through. Unauthenticated requests reduce the object to empty.
Sourcepub fn filter_records(&self, database: &str, table: &str, records: &mut [Value])
pub fn filter_records(&self, database: &str, table: &str, records: &mut [Value])
Filter every record in records via filter_record.