forked from revoltchat/backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
147 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,25 @@ | ||
use revolt_quark::{ | ||
models::{Member, User}, | ||
perms, Db, Ref, Result, | ||
}; | ||
use revolt_quark::models::server_member::MemberResponse; | ||
use revolt_quark::{models::User, perms, Db, Ref, Result}; | ||
use rocket::serde::json::Json; | ||
|
||
/// # Fetch Member | ||
/// | ||
/// Retrieve a member. | ||
#[openapi(tag = "Server Members")] | ||
#[get("/<target>/members/<member>")] | ||
pub async fn req(db: &Db, user: User, target: Ref, member: Ref) -> Result<Json<Member>> { | ||
#[get("/<target>/members/<member>?<roles>")] | ||
pub async fn req( | ||
db: &Db, | ||
user: User, | ||
target: Ref, | ||
member: Ref, | ||
roles: Option<bool>, | ||
) -> Result<Json<MemberResponse>> { | ||
let server = target.as_server(db).await?; | ||
perms(&user).server(&server).calc(db).await?; | ||
|
||
member.as_member(db, &server.id).await.map(Json) | ||
let member_response: MemberResponse = match roles { | ||
Some(true) => member.as_member_with_roles(db, &server.id).await?.into(), | ||
_ => member.as_member(db, &server.id).await?.into(), | ||
}; | ||
|
||
Ok(Json(member_response)) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use revolt_quark::{models::server::Role, Db, Error, Ref, Result}; | ||
use rocket::serde::json::Json; | ||
|
||
/// # Fetch Role | ||
/// | ||
/// Fetch a role by its id. | ||
#[openapi(tag = "Server Permissions")] | ||
#[get("/<target>/roles/<role_id>")] | ||
pub async fn req(db: &Db, target: Ref, role_id: String) -> Result<Json<Role>> { | ||
let server = target.as_server(db).await?; | ||
|
||
let role = server.roles.get(&role_id); | ||
|
||
if let Some(role) = role { | ||
Ok(Json(role.clone())) | ||
} else { | ||
Err(Error::NotFound) | ||
} | ||
} |
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
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