Joinable,
};
use diesel::{dsl::*, result::Error, *};
+use serde::Serialize;
-#[derive(Clone, Queryable, Identifiable, PartialEq, Debug)]
+#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
#[table_name = "community"]
pub struct Community {
pub id: i32,
pub banner: Option<String>,
}
+/// A safe representation of community, without the sensitive info
+#[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)]
+#[table_name = "community"]
+pub struct CommunitySafe {
+ pub id: i32,
+ pub name: String,
+ pub title: String,
+ pub description: Option<String>,
+ pub category_id: i32,
+ pub creator_id: i32,
+ pub removed: bool,
+ pub published: chrono::NaiveDateTime,
+ pub updated: Option<chrono::NaiveDateTime>,
+ pub deleted: bool,
+ pub nsfw: bool,
+ pub actor_id: String,
+ pub local: bool,
+ pub icon: Option<String>,
+ pub banner: Option<String>,
+}
+
+mod safe_type {
+ use crate::{community::Community, schema::community::columns::*, ToSafe};
+ type Columns = (
+ id,
+ name,
+ title,
+ description,
+ category_id,
+ creator_id,
+ removed,
+ published,
+ updated,
+ deleted,
+ nsfw,
+ actor_id,
+ local,
+ icon,
+ banner,
+ );
+
+ impl ToSafe for Community {
+ type SafeColumns = Columns;
+ fn safe_columns_tuple() -> Self::SafeColumns {
+ (
+ id,
+ name,
+ title,
+ description,
+ category_id,
+ creator_id,
+ removed,
+ published,
+ updated,
+ deleted,
+ nsfw,
+ actor_id,
+ local,
+ icon,
+ banner,
+ )
+ }
+ }
+}
+
#[derive(Insertable, AsChangeset, Debug)]
#[table_name = "community"]
pub struct CommunityForm {
}
fn community_mods_and_admins(conn: &PgConnection, community_id: i32) -> Result<Vec<i32>, Error> {
- use crate::{community_view::CommunityModeratorView, user_view::UserView};
+ use crate::views::{community_moderator_view::CommunityModeratorView, user_view::UserViewSafe};
let mut mods_and_admins: Vec<i32> = Vec::new();
mods_and_admins.append(
&mut CommunityModeratorView::for_community(conn, community_id)
- .map(|v| v.into_iter().map(|m| m.user_id).collect())?,
+ .map(|v| v.into_iter().map(|m| m.moderator.id).collect())?,
);
mods_and_admins
- .append(&mut UserView::admins(conn).map(|v| v.into_iter().map(|a| a.id).collect())?);
+ .append(&mut UserViewSafe::admins(conn).map(|v| v.into_iter().map(|a| a.user.id).collect())?);
Ok(mods_and_admins)
}