Skip to main content

UserUseCases

Struct UserUseCases 

Source
pub struct UserUseCases { /* private fields */ }

Implementations§

Source§

impl UserUseCases

Source

pub fn new( user_repo: Arc<dyn UserRepository>, role_repo: Arc<dyn UserRoleRepository>, ) -> Self

Source

pub async fn find_display_name( &self, id: Uuid, ) -> Result<Option<String>, String>

Look up a user’s display name by id (first_name + last_name). Returns None if the user does not exist.

Source

pub async fn list_all(&self) -> Result<Vec<UserResponse>, String>

List all users with their roles.

Source

pub async fn list_page( &self, recherche: Option<String>, role: Option<String>, limit: i64, offset: i64, ) -> Result<(Vec<UserResponse>, i64), String>

Une page d’utilisateurs avec leurs rôles, et le total qui va avec.

Le total n’est pas un ornement : sans lui, l’appelant reçoit un fragment sans savoir la taille du tout, et c’est exactement ainsi qu’une liste tronquée passe pour complète.

list_all reste pour les appelants internes qui ont réellement besoin de tout le monde. Ce qui n’en avait pas besoin, c’est l’écran d’administration : il recevait 4 120 lignes pour en afficher vingt.

Source

pub async fn list_by_organization( &self, organization_id: Uuid, ) -> Result<Vec<UserResponse>, String>

List users belonging to a given organization, with their roles.

Authorization (syndic/accountant own org, superadmin any org) is enforced upstream by the handler via AuthenticatedUser::verify_org_access.

Source

pub async fn create( &self, email: String, password_hash: String, first_name: String, last_name: String, primary_role: UserRole, primary_org: Option<Uuid>, role_assignments: Vec<UserRoleAssignment>, ) -> Result<UserResponse, String>

Create a new user with role assignments. Returns Err("email_exists") on duplicate email.

Source

pub async fn update( &self, id: Uuid, email: String, first_name: String, last_name: String, primary_role: UserRole, primary_org: Option<Uuid>, password_hash: Option<String>, role_assignments: Vec<UserRoleAssignment>, ) -> Result<Option<UserResponse>, String>

Update an existing user. Returns None if not found. Returns Err("email_exists") on duplicate email.

Source

pub async fn activate(&self, id: Uuid) -> Result<Option<UserResponse>, String>

Activate a user. Returns None if not found.

Source

pub async fn deactivate(&self, id: Uuid) -> Result<Option<UserResponse>, String>

Deactivate a user. Returns None if not found.

Source

pub async fn delete(&self, id: Uuid) -> Result<bool, String>

Delete a user. Returns false if not found.

Source

pub async fn validate_user_has_role( &self, user_id: Uuid, role: &str, ) -> Result<(), String>

Verify a user exists and holds the given role. Returns Err("User not found") or Err("User must have role '...' ...").

Source

pub async fn assign_role( &self, target_user_id: Uuid, role: UserRole, organization_id: Option<Uuid>, valid_until: Option<DateTime<Utc>>, granted_by_user_id: Uuid, ) -> Result<UserRoleAssignment, AppError>

Assigne un sous-rôle à un user existant.

L’autorisation (superadmin / syndic-sur-son-org) est vérifiée AMONT par le handler — ici on applique uniquement les invariants métier.

§Errors
  • AppError::NotFound si target_user_id n’existe pas.
  • AppError::Validation si valid_until n’est pas dans le futur, ou si un user tente de s’auto-attribuer un rôle à privilèges élevés (cohérent invariants MagicLink / Mandate §3.2 §3.4).
  • AppError::RoleAlreadyAssigned si une assignment active existe déjà pour le tuple (user_id, role, organization_id).
Source

pub async fn list_assignments_for_user( &self, user_id: Uuid, ) -> Result<Vec<UserRoleAssignment>, AppError>

Liste toutes les assignments d’un user (actives + expirées) afin que le FE puisse afficher l’historique.

L’autorisation (superadmin / syndic-sur-son-org / self) est vérifiée AMONT par le handler.

Source

pub async fn revoke_assignment( &self, assignment_id: Uuid, ) -> Result<(), AppError>

Révoque (= supprime) une assignment.

L’autorisation est vérifiée AMONT par le handler. Renvoie AppError::NotFound si l’assignment n’existe pas.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Fake for T

§

fn fake<U>(&self) -> U
where Self: FakeBase<U>,

§

fn fake_with_rng<U, R>(&self, rng: &mut R) -> U
where R: RngExt + ?Sized, Self: FakeBase<U>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more