Rust

permission

Module

[Permission]: an action granted to a Role, written action("role") (read("any"), update("team:123/owner")).

PHP: Utopia\Database\Permission.

Contents

use utopia_database::Permission;
Rust
pub struct Permission {
    // private fields
}

A permission: an action and the role it is granted to.

PHP: Utopia\Database\Permission; getRole(), getIdentifier() and getDimension() are read through Permission::role.

Rust
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\")"]
);
Also implements Display.
use utopia_database::PermissionType;
Rust
pub enum PermissionType {
    Create,
    Read,
    Update,
    Delete,
    Write,
}

The action a permission grants.

PHP: the $permission string of Permission (Database::PERMISSION_*). PHP's constructor also stores other strings, which Permission::parse never produces; Rust cannot hold them (a recorded deviation).

Also implements AsRef<str>.