-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(webserver): Add GraphQL endpoint updateUserRole (#1449)
* feat(webserver): Add GraphQL endpoint updateUserRole * Add unit test
- Loading branch information
Showing
4 changed files
with
59 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -300,6 +300,14 @@ impl AuthenticationService for AuthenticationServiceImpl { | |
Ok(!admin.is_empty()) | ||
} | ||
|
||
async fn update_user_role(&self, id: &ID, is_admin: bool) -> Result<()> { | ||
let id = id.as_rowid()?; | ||
if id == 1 { | ||
return Err(anyhow!("The owner's admin status may not be changed")); | ||
} | ||
self.db.update_user_role(id, is_admin).await | ||
} | ||
|
||
async fn get_user_by_email(&self, email: &str) -> Result<User> { | ||
let user = self.db.get_user_by_email(email).await?; | ||
if let Some(user) = user { | ||
|
@@ -803,6 +811,32 @@ mod tests { | |
.is_err()); | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_update_role() { | ||
let service = test_authentication_service().await; | ||
let admin_id = service | ||
.db | ||
.create_user("[email protected]".into(), "".into(), true) | ||
.await | ||
.unwrap(); | ||
|
||
let user_id = service | ||
.db | ||
.create_user("[email protected]".into(), "".into(), false) | ||
.await | ||
.unwrap(); | ||
|
||
assert!(service | ||
.update_user_role(&user_id.as_id(), true) | ||
.await | ||
.is_ok()); | ||
|
||
assert!(service | ||
.update_user_role(&admin_id.as_id(), false) | ||
.await | ||
.is_err()); | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_pagination() { | ||
let service = test_authentication_service().await; | ||
|