Simplify delete user call syntax
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Pierre HUBERT 2022-11-19 16:46:40 +01:00
parent 0c35400e64
commit 75d894d648
2 changed files with 6 additions and 9 deletions

View File

@ -60,11 +60,8 @@ pub struct Clear2FALoginHistory(pub UserID);
#[rtype(result = "bool")]
pub struct UpdateUserRequest(pub User);
#[derive(Debug)]
pub struct DeleteUserResult(pub bool);
#[derive(Message)]
#[rtype(DeleteUserResult)]
#[rtype(result = "bool")]
pub struct DeleteUserRequest(pub UserID);
pub struct UsersActor {
@ -168,7 +165,7 @@ impl Handler<UpdateUserRequest> for UsersActor {
}
impl Handler<DeleteUserRequest> for UsersActor {
type Result = MessageResult<DeleteUserRequest>;
type Result = <DeleteUserRequest as actix::Message>::Result;
fn handle(&mut self, msg: DeleteUserRequest, _ctx: &mut Self::Context) -> Self::Result {
let user = match self.manager.find_by_user_id(&msg.0) {
@ -177,17 +174,17 @@ impl Handler<DeleteUserRequest> for UsersActor {
"Could not delete account {:?} because it was not found!",
msg.0
);
return MessageResult(DeleteUserResult(false));
return false;
}
Some(s) => s,
};
MessageResult(DeleteUserResult(match self.manager.remove(&user) {
match self.manager.remove(&user) {
Ok(_) => true,
Err(e) => {
log::error!("Failed to update delete account! {:?}", e);
false
}
}))
}
}
}

View File

@ -56,7 +56,7 @@ pub async fn delete_user(
};
let res = users.send(DeleteUserRequest(req.0.user_id)).await.unwrap();
if res.0 {
if res {
action_logger.log(Action::AdminDeleteUser(&user));
HttpResponse::Ok().finish()
} else {