-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #173 from ZeusWPI/feature/admin-state-change
Allow admins to change the state of users
- Loading branch information
Showing
5 changed files
with
135 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -879,3 +879,52 @@ async fn validate_on_admin_create() { | |
}) | ||
.await; | ||
} | ||
|
||
#[rocket::async_test] | ||
async fn disable_user() { | ||
common::as_admin(async move |http_client, db, _admin| { | ||
let user = User::create( | ||
NewUser { | ||
username: String::from("somebody"), | ||
password: String::from("once told me"), | ||
full_name: String::from("zeus"), | ||
email: String::from("[email protected]"), | ||
ssh_key: Some(String::from("ssh-rsa nananananananaaa")), | ||
not_a_robot: true, | ||
}, | ||
common::BCRYPT_COST, | ||
&db, | ||
) | ||
.await | ||
.unwrap(); | ||
|
||
assert_eq!( | ||
user.state, | ||
UserState::Active, | ||
"user should be active before state change" | ||
); | ||
|
||
let response = http_client | ||
.post(format!("/users/{}/change_state", user.username)) | ||
.header(ContentType::Form) | ||
.header(Accept::JSON) | ||
.body("state=Disabled") | ||
.dispatch() | ||
.await; | ||
|
||
assert_eq!( | ||
response.status(), | ||
Status::NoContent, | ||
"admin should be able to disable user" | ||
); | ||
|
||
let user = user.reload(&db).await.expect("reload user"); | ||
|
||
assert_eq!( | ||
user.state, | ||
UserState::Disabled, | ||
"user should be disabled after state change" | ||
); | ||
}) | ||
.await; | ||
} |