forked from jmug/stoatchat
feat(perms): consistently throw correct permissions
This commit is contained in:
@@ -1,22 +1,17 @@
|
||||
use revolt_quark::{
|
||||
models::{Channel, User},
|
||||
perms, Database, Error, Permission, Ref, Result,
|
||||
perms, Database, Permission, Ref, Result,
|
||||
};
|
||||
|
||||
use rocket::{serde::json::Json, State};
|
||||
|
||||
#[get("/<target>")]
|
||||
pub async fn req(db: &State<Database>, user: User, target: Ref) -> Result<Json<Channel>> {
|
||||
let target = target.as_channel(db).await?;
|
||||
let channel = target.as_channel(db).await?;
|
||||
perms(&user)
|
||||
.channel(&channel)
|
||||
.throw_permission(db, Permission::ViewChannel)
|
||||
.await?;
|
||||
|
||||
if perms(&user)
|
||||
.channel(&target)
|
||||
.calc(db)
|
||||
.await
|
||||
.can_view_channel()
|
||||
{
|
||||
Ok(Json(target))
|
||||
} else {
|
||||
Error::from_permission(Permission::ViewChannel)
|
||||
}
|
||||
Ok(Json(channel))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user