Model workspaces, users, and organizations
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
use super::{
|
||||
id::{IdError, validate_id},
|
||||
user::UserId,
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
|
||||
pub struct OrganizationId(String);
|
||||
|
||||
impl OrganizationId {
|
||||
pub const MAX_BYTES: usize = 128;
|
||||
|
||||
pub fn new(value: impl Into<String>) -> Result<Self, IdError> {
|
||||
let value = value.into();
|
||||
validate_id(&value, Self::MAX_BYTES, IdError::Organization)?;
|
||||
Ok(Self(value))
|
||||
}
|
||||
|
||||
pub fn as_str(&self) -> &str {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub struct Organization {
|
||||
pub id: OrganizationId,
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub enum OrganizationRole {
|
||||
Owner,
|
||||
Admin,
|
||||
Member,
|
||||
}
|
||||
|
||||
/// Links a user to an organization with a role in that organization.
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub struct OrganizationMembership {
|
||||
pub organization_id: OrganizationId,
|
||||
pub user_id: UserId,
|
||||
pub role: OrganizationRole,
|
||||
}
|
||||
Reference in New Issue
Block a user