pub struct Permission { /* private fields */ }Expand description
A permission: an action and the role it is granted to.
use utopia_database::{Permission, PermissionType};
use utopia_database::Role;
let p = Permission::parse("read(\"user:123\")").unwrap();
assert_eq!(p.permission(), PermissionType::Read);
assert_eq!(p.role().identifier(), "123");
assert_eq!(Permission::read(&Role::any()), "read(\"any\")");
assert_eq!(
Permission::aggregate(&["write(\"any\")"], &PermissionType::ALL).unwrap(),
["create(\"any\")", "update(\"any\")", "delete(\"any\")"]
);PHP: Utopia\Database\Permission; getRole(),
getIdentifier() and getDimension() are read through Permission::role.
Implementations§
Source§impl Permission
impl Permission
Sourcepub fn new(permission: PermissionType, role: Role) -> Self
pub fn new(permission: PermissionType, role: Role) -> Self
new Permission($permission, $role, $identifier, $dimension).
Sourcepub fn permission(&self) -> PermissionType
pub fn permission(&self) -> PermissionType
The action (getPermission()).
Sourcepub fn parse(permission: &str) -> Result<Self>
pub fn parse(permission: &str) -> Result<Self>
Permission::parse($permission).
Fails (crate::Kind::Database) with Invalid permission string format: "...", Invalid permission type: "...", Only one dimension can be provided or Dimension must not be empty.
Sourcepub fn aggregate<S: AsRef<str>>(
permissions: &[S],
allowed: &[PermissionType],
) -> Result<Vec<String>>
pub fn aggregate<S: AsRef<str>>( permissions: &[S], allowed: &[PermissionType], ) -> Result<Vec<String>>
Permission::aggregate($permissions, $allowed): each permission
string parsed and written back, aggregates (write) expanded into
the individual actions in allowed, without duplicates, in order.
PHP: null permissions give null; a Rust caller without
permissions has nothing to call.
Trait Implementations§
Source§impl Clone for Permission
impl Clone for Permission
Source§impl Debug for Permission
impl Debug for Permission
Source§impl Display for Permission
impl Display for Permission
impl Eq for Permission
Source§impl Hash for Permission
impl Hash for Permission
Source§impl PartialEq for Permission
impl PartialEq for Permission
impl StructuralPartialEq for Permission
Auto Trait Implementations§
impl Forget for Permission
impl Freeze for Permission
impl Move for Permission
impl RefUnwindSafe for Permission
impl Send for Permission
impl Sync for Permission
impl Unpin for Permission
impl UnsafeUnpin for Permission
impl UnwindSafe for Permission
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.