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

Commit cae5330

Browse files
committed
fixup! admin: set can_request_admin API
1 parent b592618 commit cae5330

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
@@ -61,11 +61,8 @@ where
6161
get_with(self::users::by_username, self::users::by_username_doc),
6262
)
6363
.api_route(
64-
"/users/:id/set-can-request-admin",
65-
post_with(
66-
self::users::set_can_request_admin,
67-
self::users::set_can_request_admin_doc,
68-
),
64+
"/users/:id/set-admin",
65+
post_with(self::users::set_admin, self::users::set_admin_doc),
6966
)
7067
.api_route(
7168
"/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 set_password;
2323
mod unlock;
2424

@@ -29,7 +29,7 @@ pub use self::{
2929
get::{doc as get_doc, handler as get},
3030
list::{doc as list_doc, handler as list},
3131
lock::{doc as lock_doc, handler as lock},
32-
set_can_request_admin::{doc as set_can_request_admin_doc, handler as set_can_request_admin},
32+
set_admin::{doc as set_admin_doc, handler as set_admin},
3333
set_password::{doc as set_password_doc, handler as set_password},
3434
unlock::{doc as unlock_doc, handler as unlock},
3535
};

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
@@ -777,14 +777,14 @@
777777
}
778778
}
779779
},
780-
"/api/admin/v1/users/{id}/set-can-request-admin": {
780+
"/api/admin/v1/users/{id}/set-admin": {
781781
"post": {
782782
"tags": [
783783
"user"
784784
],
785785
"summary": "Set whether a user can request admin",
786786
"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.",
787-
"operationId": "setCanRequestAdmin",
787+
"operationId": "userSetAdmin",
788788
"parameters": [
789789
{
790790
"in": "path",
@@ -801,7 +801,7 @@
801801
"content": {
802802
"application/json": {
803803
"schema": {
804-
"$ref": "#/components/schemas/SetCanRequestAdminRequest"
804+
"$ref": "#/components/schemas/UserSetAdminRequest"
805805
}
806806
}
807807
},
@@ -830,7 +830,7 @@
830830
}
831831
},
832832
"links": {
833-
"self": "/api/admin/v1/users/02081040G2081040G2081040G2/set-can-request-admin"
833+
"self": "/api/admin/v1/users/02081040G2081040G2081040G2/set-admin"
834834
}
835835
}
836836
}
@@ -1567,8 +1567,8 @@
15671567
}
15681568
}
15691569
},
1570-
"SetCanRequestAdminRequest": {
1571-
"title": "JSON payload for the `POST /api/admin/v1/users/:id/set-can-request-admin` endpoint",
1570+
"UserSetAdminRequest": {
1571+
"title": "JSON payload for the `POST /api/admin/v1/users/:id/set-admin` endpoint",
15721572
"type": "object",
15731573
"required": [
15741574
"can_request_admin"

0 commit comments

Comments
 (0)