pub struct OrgService<S> { /* private fields */ }Expand description
High-level org management service.
Wraps OrgRepository + InviteRepository + AuditLogRepository with
business logic for creating orgs, managing members, and the invite flow.
Implementations§
Source§impl<S> OrgService<S>where
S: OrgRepository + InviteRepository + SessionRepository + AuditLogRepository + Clone + Send + Sync + 'static,
impl<S> OrgService<S>where
S: OrgRepository + InviteRepository + SessionRepository + AuditLogRepository + Clone + Send + Sync + 'static,
pub fn new(storage: S, events: EventBus) -> Self
Sourcepub async fn create(
&self,
owner_id: Uuid,
name: String,
slug: String,
metadata: Option<Value>,
) -> Result<(Organization, Membership)>
pub async fn create( &self, owner_id: Uuid, name: String, slug: String, metadata: Option<Value>, ) -> Result<(Organization, Membership)>
Create a new org with an initial “owner” role.
The owner_id is added as a member with that role.
pub async fn get(&self, org_id: Uuid) -> Result<Organization>
pub async fn list_members(&self, org_id: Uuid) -> Result<Vec<Membership>>
pub async fn create_role( &self, org_id: Uuid, name: String, permissions: Vec<String>, ) -> Result<Role>
pub async fn set_member_role( &self, org_id: Uuid, user_id: Uuid, role_id: Uuid, ) -> Result<Membership>
pub async fn remove_member( &self, org_id: Uuid, user_id: Uuid, actor_id: Uuid, ) -> Result<()>
Sourcepub async fn invite_member(
&self,
org_id: Uuid,
email: String,
role_id: Uuid,
_actor_id: Uuid,
) -> Result<InviteDetails>
pub async fn invite_member( &self, org_id: Uuid, email: String, role_id: Uuid, _actor_id: Uuid, ) -> Result<InviteDetails>
Create an org invite. Returns the Invite row and the raw token.
The caller is responsible for emailing the raw token to the invitee.
Sourcepub async fn accept_invite(
&self,
raw_token: &str,
user_id: Uuid,
) -> Result<Membership>
pub async fn accept_invite( &self, raw_token: &str, user_id: Uuid, ) -> Result<Membership>
Accept an invite. Looks up the invite by raw token, verifies it hasn’t expired or been accepted, marks it accepted, then adds the user as a member.
Auto Trait Implementations§
impl<S> Freeze for OrgService<S>where
S: Freeze,
impl<S> !RefUnwindSafe for OrgService<S>
impl<S> Send for OrgService<S>where
S: Send,
impl<S> Sync for OrgService<S>where
S: Sync,
impl<S> Unpin for OrgService<S>where
S: Unpin,
impl<S> UnsafeUnpin for OrgService<S>where
S: UnsafeUnpin,
impl<S> !UnwindSafe for OrgService<S>
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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