feat(perms): consistently throw correct permissions
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use revolt_quark::{
|
||||
models::{Invite, User},
|
||||
perms, Db, Error, Permission, Ref, Result,
|
||||
perms, Db, Permission, Ref, Result,
|
||||
};
|
||||
|
||||
use rocket::serde::json::Json;
|
||||
@@ -8,15 +8,10 @@ use rocket::serde::json::Json;
|
||||
#[post("/<target>/invites")]
|
||||
pub async fn req(db: &Db, user: User, target: Ref) -> Result<Json<Invite>> {
|
||||
let channel = target.as_channel(db).await?;
|
||||
|
||||
if !perms(&user)
|
||||
perms(&user)
|
||||
.channel(&channel)
|
||||
.calc(db)
|
||||
.await
|
||||
.can_invite_others()
|
||||
{
|
||||
return Error::from_permission(Permission::InviteOthers);
|
||||
}
|
||||
.throw_permission_and_view_channel(db, Permission::InviteOthers)
|
||||
.await?;
|
||||
|
||||
Invite::create(db, &user, &channel).await.map(Json)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user