feat: implement channel invites, perms, group create, members fetch

chore: when you accidentally run fmt
This commit is contained in:
Paul Makles
2022-02-04 21:50:30 +00:00
parent b58755dbeb
commit 88f811761b
59 changed files with 536 additions and 195 deletions

View File

@@ -1,16 +1,44 @@
use mongodb::bson::doc;
use rocket::serde::json::Json;
use serde::{Serialize, Deserialize};
use validator::Contains;
use serde::{Deserialize, Serialize};
use revolt_quark::{EmptyResponse, Result};
use revolt_quark::{
models::{Channel, User},
perms, ChannelPermission, Db, EmptyResponse, Error, Ref, Result,
};
#[derive(Serialize, Deserialize)]
pub struct Data {
permissions: u32
permissions: u32,
}
#[put("/<target>/permissions/<role>", data = "<data>", rank = 2)]
pub async fn req(/*user: UserRef, target: Ref,*/ target: String, role: String, data: Json<Data>) -> Result<EmptyResponse> {
todo!()
pub async fn req(
db: &Db,
user: User,
target: Ref,
role: String,
data: Json<Data>,
) -> Result<EmptyResponse> {
let channel = target.as_channel(db).await?;
if !perms(&user)
.channel(&channel)
.calc_channel(db)
.await
.get_manage_channel()
{
return Err(Error::MissingPermission {
permission: ChannelPermission::ManageChannel as i32,
});
}
match channel {
Channel::TextChannel { id, .. } | Channel::VoiceChannel { id, .. } => {
db.set_channel_role_permission(&id, &role, data.permissions)
.await?;
}
_ => return Err(Error::InvalidOperation),
}
Ok(EmptyResponse)
}