mirror of
https://github.com/stoatchat/stoatchat.git
synced 2026-07-14 13:36:59 +00:00
Return banned user objects.
Fix category edit.
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
#!/bin/bash
|
||||
export version=0.5.1-alpha.9
|
||||
export version=0.5.1-alpha.10
|
||||
echo "pub const VERSION: &str = \"${version}\";" > src/version.rs
|
||||
|
||||
@@ -2,8 +2,17 @@ use crate::database::*;
|
||||
use crate::util::result::{Error, Result};
|
||||
|
||||
use futures::StreamExt;
|
||||
use mongodb::bson::{doc, from_document};
|
||||
use mongodb::options::FindOptions;
|
||||
use serde::{Serialize, Deserialize};
|
||||
use rocket_contrib::json::JsonValue;
|
||||
use mongodb::bson::{doc, from_document};
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct BannedUser {
|
||||
_id: String,
|
||||
username: String,
|
||||
avatar: Option<File>
|
||||
}
|
||||
|
||||
#[get("/<target>/bans")]
|
||||
pub async fn req(user: User, target: Ref) -> Result<JsonValue> {
|
||||
@@ -32,13 +41,47 @@ pub async fn req(user: User, target: Ref) -> Result<JsonValue> {
|
||||
})?;
|
||||
|
||||
let mut bans = vec![];
|
||||
let mut user_ids = vec![];
|
||||
while let Some(result) = cursor.next().await {
|
||||
if let Ok(doc) = result {
|
||||
if let Ok(ban) = from_document::<Ban>(doc) {
|
||||
user_ids.push(ban.id.user.clone());
|
||||
bans.push(ban);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(json!(bans))
|
||||
let mut cursor = get_collection("users")
|
||||
.find(
|
||||
doc! {
|
||||
"_id": {
|
||||
"$in": user_ids
|
||||
}
|
||||
},
|
||||
FindOptions::builder()
|
||||
.projection(doc! {
|
||||
"username": 1,
|
||||
"avatar": 1
|
||||
})
|
||||
.build(),
|
||||
)
|
||||
.await
|
||||
.map_err(|_| Error::DatabaseError {
|
||||
operation: "find",
|
||||
with: "users",
|
||||
})?;
|
||||
|
||||
let mut users = vec![];
|
||||
while let Some(result) = cursor.next().await {
|
||||
if let Ok(doc) = result {
|
||||
if let Ok(user) = from_document::<BannedUser>(doc) {
|
||||
users.push(user);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(json!({
|
||||
"users": users,
|
||||
"bans": bans
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ use crate::notifications::events::ClientboundNotification;
|
||||
use crate::util::result::{Error, Result};
|
||||
use crate::{database::*, notifications::events::RemoveServerField};
|
||||
|
||||
use mongodb::bson::{doc, to_document};
|
||||
use mongodb::bson::{doc, to_bson, to_document};
|
||||
use rocket_contrib::json::Json;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use validator::Validate;
|
||||
@@ -98,11 +98,11 @@ pub async fn req(user: User, target: Ref, data: Json<Data>) -> Result<()> {
|
||||
}
|
||||
|
||||
if let Some(categories) = &data.categories {
|
||||
set.insert("categories", to_document(&categories).map_err(|_| Error::DatabaseError { operation: "to_document", with: "categories" })?);
|
||||
set.insert("categories", to_bson(&categories).map_err(|_| Error::DatabaseError { operation: "to_document", with: "categories" })?);
|
||||
}
|
||||
|
||||
if let Some(system_messages) = &data.system_messages {
|
||||
set.insert("system_messages", to_document(&system_messages).map_err(|_| Error::DatabaseError { operation: "to_document", with: "system_messages" })?);
|
||||
set.insert("system_messages", to_bson(&system_messages).map_err(|_| Error::DatabaseError { operation: "to_document", with: "system_messages" })?);
|
||||
}
|
||||
|
||||
let mut operations = doc! {};
|
||||
|
||||
@@ -1 +1 @@
|
||||
pub const VERSION: &str = "0.5.1-alpha.9";
|
||||
pub const VERSION: &str = "0.5.1-alpha.10";
|
||||
|
||||
Reference in New Issue
Block a user