Skip to content
This repository was archived by the owner on Sep 10, 2024. It is now read-only.

Commit 055014e

Browse files
committed
fixup! admin: set can_request_admin API
1 parent d6af0b9 commit 055014e

File tree

4 files changed

+26
-35
lines changed

4 files changed

+26
-35
lines changed

crates/handlers/src/admin/v1/mod.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,8 @@ where
4646
get_with(self::users::by_username, self::users::by_username_doc),
4747
)
4848
.api_route(
49-
"/users/:id/set-can-request-admin",
50-
post_with(
51-
self::users::set_can_request_admin,
52-
self::users::set_can_request_admin_doc,
53-
),
49+
"/users/:id/set-admin",
50+
post_with(self::users::set_admin, self::users::set_admin_doc),
5451
)
5552
.api_route(
5653
"/users/:id/deactivate",

crates/handlers/src/admin/v1/users/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ mod deactivate;
1818
mod get;
1919
mod list;
2020
mod lock;
21-
mod set_can_request_admin;
21+
mod set_admin;
2222
mod unlock;
2323

2424
pub use self::{
@@ -28,6 +28,6 @@ pub use self::{
2828
get::{doc as get_doc, handler as get},
2929
list::{doc as list_doc, handler as list},
3030
lock::{doc as lock_doc, handler as lock},
31-
set_can_request_admin::{doc as set_can_request_admin_doc, handler as set_can_request_admin},
31+
set_admin::{doc as set_admin_doc, handler as set_admin},
3232
unlock::{doc as unlock_doc, handler as unlock},
3333
};

crates/handlers/src/admin/v1/users/set_can_request_admin.rs renamed to crates/handlers/src/admin/v1/users/set_admin.rs

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -52,25 +52,25 @@ impl IntoResponse for RouteError {
5252
}
5353
}
5454

55-
/// # JSON payload for the `POST /api/admin/v1/users/:id/set-can-request-admin` endpoint
55+
/// # JSON payload for the `POST /api/admin/v1/users/:id/set-admin` endpoint
5656
#[derive(Deserialize, JsonSchema)]
57-
#[serde(rename = "SetCanRequestAdminRequest")]
57+
#[serde(rename = "UserSetAdminRequest")]
5858
pub struct Request {
5959
/// Whether the user can request admin privileges.
6060
can_request_admin: bool,
6161
}
6262

6363
pub fn doc(operation: TransformOperation) -> TransformOperation {
6464
operation
65-
.id("setCanRequestAdmin")
65+
.id("userSetAdmin")
6666
.summary("Set whether a user can request admin")
6767
.description("Calling this endpoint will not have any effect on existing sessions, meaning that their existing sessions will keep admin access if they were granted it.")
6868
.tag("user")
6969
.response_with::<200, Json<SingleResponse<User>>, _>(|t| {
7070
// In the samples, the second user is the one which can request admin
7171
let [_alice, bob, ..] = User::samples();
7272
let id = bob.id();
73-
let response = SingleResponse::new(bob, format!("/api/admin/v1/users/{id}/set-can-request-admin"));
73+
let response = SingleResponse::new(bob, format!("/api/admin/v1/users/{id}/set-admin"));
7474
t.description("User had admin privileges set").example(response)
7575
})
7676
.response_with::<404, RouteError, _>(|t| {
@@ -79,7 +79,7 @@ pub fn doc(operation: TransformOperation) -> TransformOperation {
7979
})
8080
}
8181

82-
#[tracing::instrument(name = "handler.admin.v1.users.set_can_request_admin", skip_all, err)]
82+
#[tracing::instrument(name = "handler.admin.v1.users.set_admin", skip_all, err)]
8383
pub async fn handler(
8484
CallContext { mut repo, .. }: CallContext,
8585
id: UlidPathParam,
@@ -101,7 +101,7 @@ pub async fn handler(
101101

102102
Ok(Json(SingleResponse::new(
103103
User::from(user),
104-
format!("/api/admin/v1/users/{id}/set-can-request-admin"),
104+
format!("/api/admin/v1/users/{id}/set-admin"),
105105
)))
106106
}
107107

@@ -127,14 +127,11 @@ mod tests {
127127
.unwrap();
128128
repo.save().await.unwrap();
129129

130-
let request = Request::post(format!(
131-
"/api/admin/v1/users/{}/set-can-request-admin",
132-
user.id
133-
))
134-
.bearer(&token)
135-
.json(serde_json::json!({
136-
"can_request_admin": true,
137-
}));
130+
let request = Request::post(format!("/api/admin/v1/users/{}/set-admin", user.id))
131+
.bearer(&token)
132+
.json(serde_json::json!({
133+
"can_request_admin": true,
134+
}));
138135

139136
let response = state.request(request).await;
140137
response.assert_status(StatusCode::OK);
@@ -149,14 +146,11 @@ mod tests {
149146
repo.save().await.unwrap();
150147

151148
// Flip it back
152-
let request = Request::post(format!(
153-
"/api/admin/v1/users/{}/set-can-request-admin",
154-
user.id
155-
))
156-
.bearer(&token)
157-
.json(serde_json::json!({
158-
"can_request_admin": false,
159-
}));
149+
let request = Request::post(format!("/api/admin/v1/users/{}/set-admin", user.id))
150+
.bearer(&token)
151+
.json(serde_json::json!({
152+
"can_request_admin": false,
153+
}));
160154

161155
let response = state.request(request).await;
162156
response.assert_status(StatusCode::OK);

docs/api/spec.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -379,14 +379,14 @@
379379
}
380380
}
381381
},
382-
"/api/admin/v1/users/{id}/set-can-request-admin": {
382+
"/api/admin/v1/users/{id}/set-admin": {
383383
"post": {
384384
"tags": [
385385
"user"
386386
],
387387
"summary": "Set whether a user can request admin",
388388
"description": "Calling this endpoint will not have any effect on existing sessions, meaning that their existing sessions will keep admin access if they were granted it.",
389-
"operationId": "setCanRequestAdmin",
389+
"operationId": "userSetAdmin",
390390
"parameters": [
391391
{
392392
"in": "path",
@@ -403,7 +403,7 @@
403403
"content": {
404404
"application/json": {
405405
"schema": {
406-
"$ref": "#/components/schemas/SetCanRequestAdminRequest"
406+
"$ref": "#/components/schemas/UserSetAdminRequest"
407407
}
408408
}
409409
},
@@ -432,7 +432,7 @@
432432
}
433433
},
434434
"links": {
435-
"self": "/api/admin/v1/users/02081040G2081040G2081040G2/set-can-request-admin"
435+
"self": "/api/admin/v1/users/02081040G2081040G2081040G2/set-admin"
436436
}
437437
}
438438
}
@@ -981,8 +981,8 @@
981981
}
982982
}
983983
},
984-
"SetCanRequestAdminRequest": {
985-
"title": "JSON payload for the `POST /api/admin/v1/users/:id/set-can-request-admin` endpoint",
984+
"UserSetAdminRequest": {
985+
"title": "JSON payload for the `POST /api/admin/v1/users/:id/set-admin` endpoint",
986986
"type": "object",
987987
"required": [
988988
"can_request_admin"

0 commit comments

Comments
 (0)