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

Commit b8884c2

Browse files
committed
admin: rename the can_request_admin field to admin
1 parent 055014e commit b8884c2

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
@@ -52,7 +52,7 @@ pub struct User {
5252
locked_at: Option<DateTime<Utc>>,
5353

5454
/// Whether the user can request admin privileges.
55-
can_request_admin: bool,
55+
admin: bool,
5656
}
5757

5858
impl User {
@@ -64,21 +64,21 @@ impl User {
6464
username: "alice".to_owned(),
6565
created_at: DateTime::default(),
6666
locked_at: None,
67-
can_request_admin: false,
67+
admin: false,
6868
},
6969
Self {
7070
id: Ulid::from_bytes([0x02; 16]),
7171
username: "bob".to_owned(),
7272
created_at: DateTime::default(),
7373
locked_at: None,
74-
can_request_admin: true,
74+
admin: true,
7575
},
7676
Self {
7777
id: Ulid::from_bytes([0x03; 16]),
7878
username: "charlie".to_owned(),
7979
created_at: DateTime::default(),
8080
locked_at: Some(DateTime::default()),
81-
can_request_admin: false,
81+
admin: false,
8282
},
8383
]
8484
}
@@ -91,7 +91,7 @@ impl From<mas_data_model::User> for User {
9191
username: user.username,
9292
created_at: user.created_at,
9393
locked_at: user.locked_at,
94-
can_request_admin: user.can_request_admin,
94+
admin: user.can_request_admin,
9595
}
9696
}
9797
}

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
@@ -74,10 +74,10 @@
7474
},
7575
{
7676
"in": "query",
77-
"name": "filter[can_request_admin]",
78-
"description": "Retrieve users with (or without) the `can_request_admin` flag set",
77+
"name": "filter[admin]",
78+
"description": "Retrieve users with (or without) the `admin` flag set",
7979
"schema": {
80-
"description": "Retrieve users with (or without) the `can_request_admin` flag set",
80+
"description": "Retrieve users with (or without) the `admin` flag set",
8181
"type": "boolean",
8282
"nullable": true
8383
},
@@ -115,7 +115,7 @@
115115
"username": "alice",
116116
"created_at": "1970-01-01T00:00:00Z",
117117
"locked_at": null,
118-
"can_request_admin": false
118+
"admin": false
119119
},
120120
"links": {
121121
"self": "/api/admin/v1/users/01040G2081040G2081040G2081"
@@ -128,7 +128,7 @@
128128
"username": "bob",
129129
"created_at": "1970-01-01T00:00:00Z",
130130
"locked_at": null,
131-
"can_request_admin": true
131+
"admin": true
132132
},
133133
"links": {
134134
"self": "/api/admin/v1/users/02081040G2081040G2081040G2"
@@ -141,7 +141,7 @@
141141
"username": "charlie",
142142
"created_at": "1970-01-01T00:00:00Z",
143143
"locked_at": "1970-01-01T00:00:00Z",
144-
"can_request_admin": false
144+
"admin": false
145145
},
146146
"links": {
147147
"self": "/api/admin/v1/users/030C1G60R30C1G60R30C1G60R3"
@@ -192,7 +192,7 @@
192192
"username": "alice",
193193
"created_at": "1970-01-01T00:00:00Z",
194194
"locked_at": null,
195-
"can_request_admin": false
195+
"admin": false
196196
},
197197
"links": {
198198
"self": "/api/admin/v1/users/01040G2081040G2081040G2081"
@@ -277,7 +277,7 @@
277277
"username": "alice",
278278
"created_at": "1970-01-01T00:00:00Z",
279279
"locked_at": null,
280-
"can_request_admin": false
280+
"admin": false
281281
},
282282
"links": {
283283
"self": "/api/admin/v1/users/01040G2081040G2081040G2081"
@@ -346,7 +346,7 @@
346346
"username": "alice",
347347
"created_at": "1970-01-01T00:00:00Z",
348348
"locked_at": null,
349-
"can_request_admin": false
349+
"admin": false
350350
},
351351
"links": {
352352
"self": "/api/admin/v1/users/01040G2081040G2081040G2081"
@@ -425,7 +425,7 @@
425425
"username": "bob",
426426
"created_at": "1970-01-01T00:00:00Z",
427427
"locked_at": null,
428-
"can_request_admin": true
428+
"admin": true
429429
},
430430
"links": {
431431
"self": "/api/admin/v1/users/02081040G2081040G2081040G2"
@@ -494,7 +494,7 @@
494494
"username": "charlie",
495495
"created_at": "1970-01-01T00:00:00Z",
496496
"locked_at": "1970-01-01T00:00:00Z",
497-
"can_request_admin": false
497+
"admin": false
498498
},
499499
"links": {
500500
"self": "/api/admin/v1/users/030C1G60R30C1G60R30C1G60R3"
@@ -563,7 +563,7 @@
563563
"username": "charlie",
564564
"created_at": "1970-01-01T00:00:00Z",
565565
"locked_at": "1970-01-01T00:00:00Z",
566-
"can_request_admin": false
566+
"admin": false
567567
},
568568
"links": {
569569
"self": "/api/admin/v1/users/030C1G60R30C1G60R30C1G60R3"
@@ -631,7 +631,7 @@
631631
"username": "alice",
632632
"created_at": "1970-01-01T00:00:00Z",
633633
"locked_at": null,
634-
"can_request_admin": false
634+
"admin": false
635635
},
636636
"links": {
637637
"self": "/api/admin/v1/users/01040G2081040G2081040G2081"
@@ -731,8 +731,8 @@
731731
"UserFilter": {
732732
"type": "object",
733733
"properties": {
734-
"filter[can_request_admin]": {
735-
"description": "Retrieve users with (or without) the `can_request_admin` flag set",
734+
"filter[admin]": {
735+
"description": "Retrieve users with (or without) the `admin` flag set",
736736
"type": "boolean",
737737
"nullable": true
738738
},
@@ -822,7 +822,7 @@
822822
"description": "A user",
823823
"type": "object",
824824
"required": [
825-
"can_request_admin",
825+
"admin",
826826
"created_at",
827827
"username"
828828
],
@@ -842,7 +842,7 @@
842842
"format": "date-time",
843843
"nullable": true
844844
},
845-
"can_request_admin": {
845+
"admin": {
846846
"description": "Whether the user can request admin privileges.",
847847
"type": "boolean"
848848
}
@@ -985,10 +985,10 @@
985985
"title": "JSON payload for the `POST /api/admin/v1/users/:id/set-admin` endpoint",
986986
"type": "object",
987987
"required": [
988-
"can_request_admin"
988+
"admin"
989989
],
990990
"properties": {
991-
"can_request_admin": {
991+
"admin": {
992992
"description": "Whether the user can request admin privileges.",
993993
"type": "boolean"
994994
}

0 commit comments

Comments
 (0)