helpers
ModuleIdentifiers (id), roles (role) and permissions (permission).
Contents
3 submodules.
use utopia_database::helpers::id::custom;pub fn custom(id: impl Into<String>) -> StringAn ID given by the caller, as it is.
use utopia_database::helpers::id::unique;pub fn unique() -> Result<String>A new unique ID: 13 hex characters of the current time (uniqid()),
then PADDING random hex characters (20 characters in all).
use utopia_database::helpers::id;
let id = id::unique().unwrap();
assert_eq!(id.len(), 20);
assert!(id.bytes().all(|c| c.is_ascii_hexdigit()));use utopia_database::helpers::id::unique_padded;pub fn unique_padded(padding: i64) -> Result<String>A new unique ID with padding random hex characters after the 13 of
uniqid() (none when padding is 0 or less).
pub const PADDING: i64 = 7The random hex characters unique appends to the time-based part.
helpers::permission
Own page[Permission]: an action granted to a Role, written
action("role") (read("any"), update("team:123/owner")).
use utopia_database::helpers::permission::Permission;pub struct PermissionA permission: an action and the role it is granted to.
use utopia_database::helpers::permission::{Permission, PermissionType};
use utopia_database::helpers::role::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\")"]
);Display.use utopia_database::helpers::permission::PermissionType;pub enum PermissionTypeThe action a permission grants.
helpers::role
Own page[Role]: who a permission is granted to (any, users, user:<id>,
team:<id>/<dimension>, ...).
use utopia_database::helpers::role::Role;pub struct RoleA role: a name, an optional identifier and an optional dimension,
written name:identifier/dimension.
use utopia_database::helpers::role::Role;
let role = Role::parse("team:123/owner").unwrap();
assert_eq!(role.name().as_str(), "team");
assert_eq!(role.identifier(), "123");
assert_eq!(role.dimension(), "owner");
assert_eq!(Role::user("123", "verified").to_string(), "user:123/verified");
assert_eq!(Role::parse("users/a/b").unwrap_err().message(), "Only one dimension can be provided");Display.use utopia_database::helpers::role::RoleName;pub enum RoleNameUndocumented.