feat(perms): consistently throw correct permissions

This commit is contained in:
Paul Makles
2022-02-22 21:41:12 +00:00
parent 7befd77c5b
commit 4c40c6c2cc
33 changed files with 134 additions and 264 deletions

View File

@@ -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))
}