forked from jmug/stoatchat
Servers: Add edit route. Ability to set icon / banner.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
use futures::StreamExt;
|
||||
use mongodb::bson::Document;
|
||||
use mongodb::options::{Collation, FindOneOptions};
|
||||
use mongodb::{
|
||||
bson::{doc, from_document},
|
||||
@@ -223,4 +224,31 @@ impl User {
|
||||
|
||||
Ok(users)
|
||||
}
|
||||
|
||||
/// Utility function to get all the server IDs the user is in.
|
||||
pub async fn fetch_server_ids(&self) -> Result<Vec<String>> {
|
||||
Ok(get_collection("server_members")
|
||||
.find(
|
||||
doc! {
|
||||
"_id.user": &self.id
|
||||
},
|
||||
None,
|
||||
)
|
||||
.await
|
||||
.map_err(|_| Error::DatabaseError {
|
||||
operation: "find",
|
||||
with: "server_members",
|
||||
})?
|
||||
.filter_map(async move |s| s.ok())
|
||||
.collect::<Vec<Document>>()
|
||||
.await
|
||||
.into_iter()
|
||||
.filter_map(|x| {
|
||||
x.get_document("_id")
|
||||
.ok()
|
||||
.map(|i| i.get_str("server").ok().map(|x| x.to_string()))
|
||||
})
|
||||
.flatten()
|
||||
.collect::<Vec<String>>())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
pub use crate::database::*;
|
||||
|
||||
pub mod channel;
|
||||
pub mod server;
|
||||
pub mod user;
|
||||
|
||||
pub use user::get_relationship;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use crate::database::*;
|
||||
use crate::util::result::Result;
|
||||
|
||||
use super::PermissionCalculator;
|
||||
@@ -10,6 +9,7 @@ use std::ops;
|
||||
#[repr(u32)]
|
||||
pub enum ServerPermission {
|
||||
View = 1,
|
||||
ManageServer = 8,
|
||||
}
|
||||
|
||||
impl_op_ex!(+ |a: &ServerPermission, b: &ServerPermission| -> u32 { *a as u32 | *b as u32 });
|
||||
@@ -19,6 +19,7 @@ bitfield! {
|
||||
pub struct ServerPermissions(MSB0 [u32]);
|
||||
u32;
|
||||
pub get_view, _: 31;
|
||||
pub get_manage_server, _: 28;
|
||||
}
|
||||
|
||||
impl<'a> PermissionCalculator<'a> {
|
||||
@@ -29,14 +30,14 @@ impl<'a> PermissionCalculator<'a> {
|
||||
unreachable!()
|
||||
};
|
||||
|
||||
if &self.perspective.id == server.owner {
|
||||
if self.perspective.id == server.owner {
|
||||
Ok(u32::MAX)
|
||||
} else {
|
||||
Ok(ServerPermission::View as u32)
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn for_server(self) -> Result<ChannelPermissions<[u32; 1]>> {
|
||||
pub async fn for_server(self) -> Result<ServerPermissions<[u32; 1]>> {
|
||||
Ok(ServerPermissions([self.calculate_server().await?]))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user