Model workspaces, users, and organizations

This commit is contained in:
2026-11-30 18:19:05 +08:00
parent deb535c256
commit 365be3870e
6 changed files with 162 additions and 64 deletions
+42
View File
@@ -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,
}