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

Commit 29d6383

Browse files
committed
admin: rename the can_request_admin field to admin
1 parent 6189abe commit 29d6383

File tree

4 files changed

+36
-36
lines changed

4 files changed

+36
-36
lines changed

crates/handlers/src/admin/model.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub struct User {
5454
locked_at: Option<DateTime<Utc>>,
5555

5656
/// Whether the user can request admin privileges.
57-
can_request_admin: bool,
57+
admin: bool,
5858
}
5959

6060
impl User {
@@ -66,21 +66,21 @@ impl User {
6666
username: "alice".to_owned(),
6767
created_at: DateTime::default(),
6868
locked_at: None,
69-
can_request_admin: false,
69+
admin: false,
7070
},
7171
Self {
7272
id: Ulid::from_bytes([0x02; 16]),
7373
username: "bob".to_owned(),
7474
created_at: DateTime::default(),
7575
locked_at: None,
76-
can_request_admin: true,
76+
admin: true,
7777
},
7878
Self {
7979
id: Ulid::from_bytes([0x03; 16]),
8080
username: "charlie".to_owned(),
8181
created_at: DateTime::default(),
8282
locked_at: Some(DateTime::default()),
83-
can_request_admin: false,
83+
admin: false,
8484
},
8585
]
8686
}
@@ -93,7 +93,7 @@ impl From<mas_data_model::User> for User {
9393
username: user.username,
9494
created_at: user.created_at,
9595
locked_at: user.locked_at,
96-
can_request_admin: user.can_request_admin,
96+
admin: user.can_request_admin,
9797
}
9898
}
9999
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ impl std::fmt::Display for UserStatus {
5555
#[aide(input_with = "Query<FilterParams>")]
5656
#[from_request(via(Query), rejection(RouteError))]
5757
pub struct FilterParams {
58-
/// Retrieve users with (or without) the `can_request_admin` flag set
59-
#[serde(rename = "filter[can_request_admin]")]
60-
can_request_admin: Option<bool>,
58+
/// Retrieve users with (or without) the `admin` flag set
59+
#[serde(rename = "filter[admin]")]
60+
admin: Option<bool>,
6161

6262
/// Retrieve the items with the given status
6363
///
@@ -74,8 +74,8 @@ impl std::fmt::Display for FilterParams {
7474
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
7575
let mut sep = '?';
7676

77-
if let Some(can_request_admin) = self.can_request_admin {
78-
write!(f, "{sep}filter[can_request_admin]={can_request_admin}")?;
77+
if let Some(admin) = self.admin {
78+
write!(f, "{sep}filter[admin]={admin}")?;
7979
sep = '&';
8080
}
8181
if let Some(status) = self.status {
@@ -139,7 +139,7 @@ pub async fn handler(
139139
let base = format!("{path}{params}", path = User::PATH);
140140
let filter = UserFilter::default();
141141

142-
let filter = match params.can_request_admin {
142+
let filter = match params.admin {
143143
Some(true) => filter.can_request_admin_only(),
144144
Some(false) => filter.cannot_request_admin_only(),
145145
None => filter,

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl IntoResponse for RouteError {
5757
#[serde(rename = "UserSetAdminRequest")]
5858
pub struct Request {
5959
/// Whether the user can request admin privileges.
60-
can_request_admin: bool,
60+
admin: bool,
6161
}
6262

6363
pub fn doc(operation: TransformOperation) -> TransformOperation {
@@ -94,7 +94,7 @@ pub async fn handler(
9494

9595
let user = repo
9696
.user()
97-
.set_can_request_admin(user, params.can_request_admin)
97+
.set_can_request_admin(user, params.admin)
9898
.await?;
9999

100100
repo.save().await?;
@@ -130,14 +130,14 @@ mod tests {
130130
let request = Request::post(format!("/api/admin/v1/users/{}/set-admin", user.id))
131131
.bearer(&token)
132132
.json(serde_json::json!({
133-
"can_request_admin": true,
133+
"admin": true,
134134
}));
135135

136136
let response = state.request(request).await;
137137
response.assert_status(StatusCode::OK);
138138
let body: serde_json::Value = response.json();
139139

140-
assert_eq!(body["data"]["attributes"]["can_request_admin"], true);
140+
assert_eq!(body["data"]["attributes"]["admin"], true);
141141

142142
// Look at the state from the repository
143143
let mut repo = state.repository().await.unwrap();
@@ -149,14 +149,14 @@ mod tests {
149149
let request = Request::post(format!("/api/admin/v1/users/{}/set-admin", user.id))
150150
.bearer(&token)
151151
.json(serde_json::json!({
152-
"can_request_admin": false,
152+
"admin": false,
153153
}));
154154

155155
let response = state.request(request).await;
156156
response.assert_status(StatusCode::OK);
157157
let body: serde_json::Value = response.json();
158158

159-
assert_eq!(body["data"]["attributes"]["can_request_admin"], false);
159+
assert_eq!(body["data"]["attributes"]["admin"], false);
160160

161161
// Look at the state from the repository
162162
let mut repo = state.repository().await.unwrap();

docs/api/spec.json

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -378,10 +378,10 @@
378378
},
379379
{
380380
"in": "query",
381-
"name": "filter[can_request_admin]",
382-
"description": "Retrieve users with (or without) the `can_request_admin` flag set",
381+
"name": "filter[admin]",
382+
"description": "Retrieve users with (or without) the `admin` flag set",
383383
"schema": {
384-
"description": "Retrieve users with (or without) the `can_request_admin` flag set",
384+
"description": "Retrieve users with (or without) the `admin` flag set",
385385
"type": "boolean",
386386
"nullable": true
387387
},
@@ -419,7 +419,7 @@
419419
"username": "alice",
420420
"created_at": "1970-01-01T00:00:00Z",
421421
"locked_at": null,
422-
"can_request_admin": false
422+
"admin": false
423423
},
424424
"links": {
425425
"self": "/api/admin/v1/users/01040G2081040G2081040G2081"
@@ -432,7 +432,7 @@
432432
"username": "bob",
433433
"created_at": "1970-01-01T00:00:00Z",
434434
"locked_at": null,
435-
"can_request_admin": true
435+
"admin": true
436436
},
437437
"links": {
438438
"self": "/api/admin/v1/users/02081040G2081040G2081040G2"
@@ -445,7 +445,7 @@
445445
"username": "charlie",
446446
"created_at": "1970-01-01T00:00:00Z",
447447
"locked_at": "1970-01-01T00:00:00Z",
448-
"can_request_admin": false
448+
"admin": false
449449
},
450450
"links": {
451451
"self": "/api/admin/v1/users/030C1G60R30C1G60R30C1G60R3"
@@ -496,7 +496,7 @@
496496
"username": "alice",
497497
"created_at": "1970-01-01T00:00:00Z",
498498
"locked_at": null,
499-
"can_request_admin": false
499+
"admin": false
500500
},
501501
"links": {
502502
"self": "/api/admin/v1/users/01040G2081040G2081040G2081"
@@ -581,7 +581,7 @@
581581
"username": "alice",
582582
"created_at": "1970-01-01T00:00:00Z",
583583
"locked_at": null,
584-
"can_request_admin": false
584+
"admin": false
585585
},
586586
"links": {
587587
"self": "/api/admin/v1/users/01040G2081040G2081040G2081"
@@ -744,7 +744,7 @@
744744
"username": "alice",
745745
"created_at": "1970-01-01T00:00:00Z",
746746
"locked_at": null,
747-
"can_request_admin": false
747+
"admin": false
748748
},
749749
"links": {
750750
"self": "/api/admin/v1/users/01040G2081040G2081040G2081"
@@ -823,7 +823,7 @@
823823
"username": "bob",
824824
"created_at": "1970-01-01T00:00:00Z",
825825
"locked_at": null,
826-
"can_request_admin": true
826+
"admin": true
827827
},
828828
"links": {
829829
"self": "/api/admin/v1/users/02081040G2081040G2081040G2"
@@ -892,7 +892,7 @@
892892
"username": "charlie",
893893
"created_at": "1970-01-01T00:00:00Z",
894894
"locked_at": "1970-01-01T00:00:00Z",
895-
"can_request_admin": false
895+
"admin": false
896896
},
897897
"links": {
898898
"self": "/api/admin/v1/users/030C1G60R30C1G60R30C1G60R3"
@@ -961,7 +961,7 @@
961961
"username": "charlie",
962962
"created_at": "1970-01-01T00:00:00Z",
963963
"locked_at": "1970-01-01T00:00:00Z",
964-
"can_request_admin": false
964+
"admin": false
965965
},
966966
"links": {
967967
"self": "/api/admin/v1/users/030C1G60R30C1G60R30C1G60R3"
@@ -1029,7 +1029,7 @@
10291029
"username": "alice",
10301030
"created_at": "1970-01-01T00:00:00Z",
10311031
"locked_at": null,
1032-
"can_request_admin": false
1032+
"admin": false
10331033
},
10341034
"links": {
10351035
"self": "/api/admin/v1/users/01040G2081040G2081040G2081"
@@ -1397,8 +1397,8 @@
13971397
"UserFilter": {
13981398
"type": "object",
13991399
"properties": {
1400-
"filter[can_request_admin]": {
1401-
"description": "Retrieve users with (or without) the `can_request_admin` flag set",
1400+
"filter[admin]": {
1401+
"description": "Retrieve users with (or without) the `admin` flag set",
14021402
"type": "boolean",
14031403
"nullable": true
14041404
},
@@ -1474,7 +1474,7 @@
14741474
"description": "A user",
14751475
"type": "object",
14761476
"required": [
1477-
"can_request_admin",
1477+
"admin",
14781478
"created_at",
14791479
"username"
14801480
],
@@ -1494,7 +1494,7 @@
14941494
"format": "date-time",
14951495
"nullable": true
14961496
},
1497-
"can_request_admin": {
1497+
"admin": {
14981498
"description": "Whether the user can request admin privileges.",
14991499
"type": "boolean"
15001500
}
@@ -1571,10 +1571,10 @@
15711571
"title": "JSON payload for the `POST /api/admin/v1/users/:id/set-admin` endpoint",
15721572
"type": "object",
15731573
"required": [
1574-
"can_request_admin"
1574+
"admin"
15751575
],
15761576
"properties": {
1577-
"can_request_admin": {
1577+
"admin": {
15781578
"description": "Whether the user can request admin privileges.",
15791579
"type": "boolean"
15801580
}

0 commit comments

Comments
 (0)