pub struct UserUseCases { /* private fields */ }Implementations§
Source§impl UserUseCases
impl UserUseCases
pub fn new( user_repo: Arc<dyn UserRepository>, role_repo: Arc<dyn UserRoleRepository>, ) -> Self
Sourcepub async fn find_display_name(
&self,
id: Uuid,
) -> Result<Option<String>, String>
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.
Sourcepub async fn list_all(&self) -> Result<Vec<UserResponse>, String>
pub async fn list_all(&self) -> Result<Vec<UserResponse>, String>
List all users with their roles.
Sourcepub async fn list_page(
&self,
recherche: Option<String>,
role: Option<String>,
limit: i64,
offset: i64,
) -> Result<(Vec<UserResponse>, i64), String>
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.
Sourcepub async fn list_by_organization(
&self,
organization_id: Uuid,
) -> Result<Vec<UserResponse>, String>
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.
Sourcepub 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>
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.
Sourcepub 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>
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.
Sourcepub async fn activate(&self, id: Uuid) -> Result<Option<UserResponse>, String>
pub async fn activate(&self, id: Uuid) -> Result<Option<UserResponse>, String>
Activate a user. Returns None if not found.
Sourcepub async fn deactivate(&self, id: Uuid) -> Result<Option<UserResponse>, String>
pub async fn deactivate(&self, id: Uuid) -> Result<Option<UserResponse>, String>
Deactivate a user. Returns None if not found.
Sourcepub async fn delete(&self, id: Uuid) -> Result<bool, String>
pub async fn delete(&self, id: Uuid) -> Result<bool, String>
Delete a user. Returns false if not found.
Sourcepub async fn validate_user_has_role(
&self,
user_id: Uuid,
role: &str,
) -> Result<(), String>
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 '...' ...").
Sourcepub 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>
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::NotFoundsitarget_user_idn’existe pas.AppError::Validationsivalid_untiln’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::RoleAlreadyAssignedsi une assignment active existe déjà pour le tuple(user_id, role, organization_id).
Sourcepub async fn list_assignments_for_user(
&self,
user_id: Uuid,
) -> Result<Vec<UserRoleAssignment>, AppError>
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.
Auto Trait Implementations§
impl !RefUnwindSafe for UserUseCases
impl !UnwindSafe for UserUseCases
impl Freeze for UserUseCases
impl Send for UserUseCases
impl Sync for UserUseCases
impl Unpin for UserUseCases
impl UnsafeUnpin for UserUseCases
Blanket Implementations§
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> Fake for T
impl<T> Fake for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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