Skip to content

Commit ddfaa05

Browse files
committed
feat(admin)!: remove request body for user deletion
1 parent 82763f6 commit ddfaa05

File tree

5 files changed

+8
-24
lines changed

5 files changed

+8
-24
lines changed

netmito/src/api/admin.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ use crate::{
2222

2323
pub fn admin_router(st: InfraPool, cancel_token: CancellationToken) -> Router<InfraPool> {
2424
Router::new()
25-
.route("/users", post(admin_create_user).delete(admin_delete_user))
25+
.route("/users", post(admin_create_user))
26+
.route("/users/{username}", delete(admin_delete_user))
2627
.route(
2728
"/users/{username}/password",
2829
post(admin_change_user_password),
@@ -83,16 +84,15 @@ pub async fn admin_create_user(
8384
pub async fn admin_delete_user(
8485
Extension(_): Extension<AuthAdminUser>,
8586
State(pool): State<InfraPool>,
86-
Json(req): Json<DeleteUserReq>,
87+
Path(username): Path<String>,
8788
) -> ApiResult<Json<UserStateResp>> {
88-
match service::user::change_user_state(&pool.db, req.username.clone(), UserState::Deleted).await
89-
{
89+
match service::user::change_user_state(&pool.db, username.clone(), UserState::Deleted).await {
9090
Ok(UserState::Deleted) => Ok(Json(UserStateResp {
9191
state: UserState::Deleted,
9292
})),
9393
Err(Error::DbError(DbErr::RecordNotUpdated)) => Err(ApiError::NotFound(format!(
9494
"User or group with name {}",
95-
req.username
95+
username
9696
))),
9797
Err(e) => {
9898
tracing::error!("{}", e);

netmito/src/client/http.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,13 +218,12 @@ impl MitoHttpClient {
218218
}
219219
}
220220

221-
pub async fn admin_delete_user(&mut self, req: DeleteUserReq) -> crate::error::Result<()> {
222-
self.url.set_path("admin/users");
221+
pub async fn admin_delete_user(&mut self, username: String) -> crate::error::Result<()> {
222+
self.url.set_path(&format!("admin/users/{username}"));
223223
let resp = self
224224
.http_client
225225
.delete(self.url.as_str())
226226
.bearer_auth(&self.credential)
227-
.json(&req)
228227
.send()
229228
.await
230229
.map_err(map_reqwest_err)?;

netmito/src/client/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ impl MitoClient {
329329
&mut self,
330330
args: AdminDeleteUserArgs,
331331
) -> crate::error::Result<()> {
332-
self.http_client.admin_delete_user(args.into()).await
332+
self.http_client.admin_delete_user(args.username).await
333333
}
334334

335335
pub async fn create_group(&mut self, args: CreateGroupArgs) -> crate::error::Result<()> {

netmito/src/config/client/admin.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use clap::{Args, Subcommand};
22
use serde::{Deserialize, Serialize};
33

4-
use crate::schema::DeleteUserReq;
5-
64
use super::{CancelWorkerArgs, DeleteArtifactArgs, DeleteAttachmentArgs};
75

86
#[derive(Serialize, Debug, Deserialize, Args, derive_more::From, Clone)]
@@ -135,11 +133,3 @@ pub enum AdminWorkersCommands {
135133
/// Cancel a worker
136134
Cancel(CancelWorkerArgs),
137135
}
138-
139-
impl From<AdminDeleteUserArgs> for DeleteUserReq {
140-
fn from(args: AdminDeleteUserArgs) -> Self {
141-
DeleteUserReq {
142-
username: args.username,
143-
}
144-
}
145-
}

netmito/src/schema.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,6 @@ pub struct AdminChangePasswordReq {
5050
pub new_md5_password: [u8; 16],
5151
}
5252

53-
#[derive(Debug, Serialize, Deserialize, Clone)]
54-
pub struct DeleteUserReq {
55-
pub username: String,
56-
}
57-
5853
#[derive(Debug, Serialize, Deserialize, Clone)]
5954
pub struct ChangeUserStateReq {
6055
pub state: UserState,

0 commit comments

Comments
 (0)