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

Commit

Permalink
admin: rename the can_request_admin field to admin
Browse files Browse the repository at this point in the history
  • Loading branch information
sandhose committed Aug 7, 2024
1 parent 6189abe commit 29d6383
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 36 deletions.
10 changes: 5 additions & 5 deletions crates/handlers/src/admin/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub struct User {
locked_at: Option<DateTime<Utc>>,

/// Whether the user can request admin privileges.
can_request_admin: bool,
admin: bool,
}

impl User {
Expand All @@ -66,21 +66,21 @@ impl User {
username: "alice".to_owned(),
created_at: DateTime::default(),
locked_at: None,
can_request_admin: false,
admin: false,
},
Self {
id: Ulid::from_bytes([0x02; 16]),
username: "bob".to_owned(),
created_at: DateTime::default(),
locked_at: None,
can_request_admin: true,
admin: true,
},
Self {
id: Ulid::from_bytes([0x03; 16]),
username: "charlie".to_owned(),
created_at: DateTime::default(),
locked_at: Some(DateTime::default()),
can_request_admin: false,
admin: false,
},
]
}
Expand All @@ -93,7 +93,7 @@ impl From<mas_data_model::User> for User {
username: user.username,
created_at: user.created_at,
locked_at: user.locked_at,
can_request_admin: user.can_request_admin,
admin: user.can_request_admin,
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions crates/handlers/src/admin/v1/users/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ impl std::fmt::Display for UserStatus {
#[aide(input_with = "Query<FilterParams>")]
#[from_request(via(Query), rejection(RouteError))]
pub struct FilterParams {
/// Retrieve users with (or without) the `can_request_admin` flag set
#[serde(rename = "filter[can_request_admin]")]
can_request_admin: Option<bool>,
/// Retrieve users with (or without) the `admin` flag set
#[serde(rename = "filter[admin]")]
admin: Option<bool>,

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

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

let filter = match params.can_request_admin {
let filter = match params.admin {
Some(true) => filter.can_request_admin_only(),
Some(false) => filter.cannot_request_admin_only(),
None => filter,
Expand Down
12 changes: 6 additions & 6 deletions crates/handlers/src/admin/v1/users/set_admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl IntoResponse for RouteError {
#[serde(rename = "UserSetAdminRequest")]
pub struct Request {
/// Whether the user can request admin privileges.
can_request_admin: bool,
admin: bool,
}

pub fn doc(operation: TransformOperation) -> TransformOperation {
Expand Down Expand Up @@ -94,7 +94,7 @@ pub async fn handler(

let user = repo
.user()
.set_can_request_admin(user, params.can_request_admin)
.set_can_request_admin(user, params.admin)
.await?;

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

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

assert_eq!(body["data"]["attributes"]["can_request_admin"], true);
assert_eq!(body["data"]["attributes"]["admin"], true);

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

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

assert_eq!(body["data"]["attributes"]["can_request_admin"], false);
assert_eq!(body["data"]["attributes"]["admin"], false);

// Look at the state from the repository
let mut repo = state.repository().await.unwrap();
Expand Down
38 changes: 19 additions & 19 deletions docs/api/spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -378,10 +378,10 @@
},
{
"in": "query",
"name": "filter[can_request_admin]",
"description": "Retrieve users with (or without) the `can_request_admin` flag set",
"name": "filter[admin]",
"description": "Retrieve users with (or without) the `admin` flag set",
"schema": {
"description": "Retrieve users with (or without) the `can_request_admin` flag set",
"description": "Retrieve users with (or without) the `admin` flag set",
"type": "boolean",
"nullable": true
},
Expand Down Expand Up @@ -419,7 +419,7 @@
"username": "alice",
"created_at": "1970-01-01T00:00:00Z",
"locked_at": null,
"can_request_admin": false
"admin": false
},
"links": {
"self": "/api/admin/v1/users/01040G2081040G2081040G2081"
Expand All @@ -432,7 +432,7 @@
"username": "bob",
"created_at": "1970-01-01T00:00:00Z",
"locked_at": null,
"can_request_admin": true
"admin": true
},
"links": {
"self": "/api/admin/v1/users/02081040G2081040G2081040G2"
Expand All @@ -445,7 +445,7 @@
"username": "charlie",
"created_at": "1970-01-01T00:00:00Z",
"locked_at": "1970-01-01T00:00:00Z",
"can_request_admin": false
"admin": false
},
"links": {
"self": "/api/admin/v1/users/030C1G60R30C1G60R30C1G60R3"
Expand Down Expand Up @@ -496,7 +496,7 @@
"username": "alice",
"created_at": "1970-01-01T00:00:00Z",
"locked_at": null,
"can_request_admin": false
"admin": false
},
"links": {
"self": "/api/admin/v1/users/01040G2081040G2081040G2081"
Expand Down Expand Up @@ -581,7 +581,7 @@
"username": "alice",
"created_at": "1970-01-01T00:00:00Z",
"locked_at": null,
"can_request_admin": false
"admin": false
},
"links": {
"self": "/api/admin/v1/users/01040G2081040G2081040G2081"
Expand Down Expand Up @@ -744,7 +744,7 @@
"username": "alice",
"created_at": "1970-01-01T00:00:00Z",
"locked_at": null,
"can_request_admin": false
"admin": false
},
"links": {
"self": "/api/admin/v1/users/01040G2081040G2081040G2081"
Expand Down Expand Up @@ -823,7 +823,7 @@
"username": "bob",
"created_at": "1970-01-01T00:00:00Z",
"locked_at": null,
"can_request_admin": true
"admin": true
},
"links": {
"self": "/api/admin/v1/users/02081040G2081040G2081040G2"
Expand Down Expand Up @@ -892,7 +892,7 @@
"username": "charlie",
"created_at": "1970-01-01T00:00:00Z",
"locked_at": "1970-01-01T00:00:00Z",
"can_request_admin": false
"admin": false
},
"links": {
"self": "/api/admin/v1/users/030C1G60R30C1G60R30C1G60R3"
Expand Down Expand Up @@ -961,7 +961,7 @@
"username": "charlie",
"created_at": "1970-01-01T00:00:00Z",
"locked_at": "1970-01-01T00:00:00Z",
"can_request_admin": false
"admin": false
},
"links": {
"self": "/api/admin/v1/users/030C1G60R30C1G60R30C1G60R3"
Expand Down Expand Up @@ -1029,7 +1029,7 @@
"username": "alice",
"created_at": "1970-01-01T00:00:00Z",
"locked_at": null,
"can_request_admin": false
"admin": false
},
"links": {
"self": "/api/admin/v1/users/01040G2081040G2081040G2081"
Expand Down Expand Up @@ -1397,8 +1397,8 @@
"UserFilter": {
"type": "object",
"properties": {
"filter[can_request_admin]": {
"description": "Retrieve users with (or without) the `can_request_admin` flag set",
"filter[admin]": {
"description": "Retrieve users with (or without) the `admin` flag set",
"type": "boolean",
"nullable": true
},
Expand Down Expand Up @@ -1474,7 +1474,7 @@
"description": "A user",
"type": "object",
"required": [
"can_request_admin",
"admin",
"created_at",
"username"
],
Expand All @@ -1494,7 +1494,7 @@
"format": "date-time",
"nullable": true
},
"can_request_admin": {
"admin": {
"description": "Whether the user can request admin privileges.",
"type": "boolean"
}
Expand Down Expand Up @@ -1571,10 +1571,10 @@
"title": "JSON payload for the `POST /api/admin/v1/users/:id/set-admin` endpoint",
"type": "object",
"required": [
"can_request_admin"
"admin"
],
"properties": {
"can_request_admin": {
"admin": {
"description": "Whether the user can request admin privileges.",
"type": "boolean"
}
Expand Down

0 comments on commit 29d6383

Please sign in to comment.