2021-10-06 20:20:05 +00:00
|
|
|
use crate::{Bannable, Crud, DeleteableOrRemoveable, Followable, Joinable};
|
2020-05-16 14:04:08 +00:00
|
|
|
use diesel::{dsl::*, result::Error, *};
|
2020-12-18 17:27:25 +00:00
|
|
|
use lemmy_db_schema::{
|
|
|
|
naive_now,
|
2020-12-21 12:28:12 +00:00
|
|
|
source::community::{
|
|
|
|
Community,
|
|
|
|
CommunityFollower,
|
|
|
|
CommunityFollowerForm,
|
|
|
|
CommunityForm,
|
|
|
|
CommunityModerator,
|
|
|
|
CommunityModeratorForm,
|
2021-02-26 13:49:58 +00:00
|
|
|
CommunityPersonBan,
|
|
|
|
CommunityPersonBanForm,
|
2021-07-30 18:44:15 +00:00
|
|
|
CommunitySafe,
|
2020-12-21 12:28:12 +00:00
|
|
|
},
|
2021-03-18 20:25:21 +00:00
|
|
|
CommunityId,
|
2021-03-02 12:41:48 +00:00
|
|
|
DbUrl,
|
2021-03-18 20:25:21 +00:00
|
|
|
PersonId,
|
2020-12-18 16:17:21 +00:00
|
|
|
};
|
2020-12-06 03:49:15 +00:00
|
|
|
|
|
|
|
mod safe_type {
|
2020-12-18 16:17:21 +00:00
|
|
|
use crate::{source::community::Community, ToSafe};
|
2020-12-21 12:28:12 +00:00
|
|
|
use lemmy_db_schema::schema::community::*;
|
|
|
|
|
2020-12-06 03:49:15 +00:00
|
|
|
type Columns = (
|
|
|
|
id,
|
|
|
|
name,
|
|
|
|
title,
|
|
|
|
description,
|
|
|
|
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,
|
|
|
|
removed,
|
|
|
|
published,
|
|
|
|
updated,
|
|
|
|
deleted,
|
|
|
|
nsfw,
|
|
|
|
actor_id,
|
|
|
|
local,
|
|
|
|
icon,
|
|
|
|
banner,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-17 18:04:58 +00:00
|
|
|
impl Crud for Community {
|
|
|
|
type Form = CommunityForm;
|
|
|
|
type IdType = CommunityId;
|
2021-03-18 20:25:21 +00:00
|
|
|
fn read(conn: &PgConnection, community_id: CommunityId) -> Result<Self, Error> {
|
2020-12-18 16:17:21 +00:00
|
|
|
use lemmy_db_schema::schema::community::dsl::*;
|
2019-09-07 15:35:05 +00:00
|
|
|
community.find(community_id).first::<Self>(conn)
|
2019-04-16 23:04:23 +00:00
|
|
|
}
|
|
|
|
|
2021-03-18 20:25:21 +00:00
|
|
|
fn delete(conn: &PgConnection, community_id: CommunityId) -> Result<usize, Error> {
|
2020-12-18 16:17:21 +00:00
|
|
|
use lemmy_db_schema::schema::community::dsl::*;
|
2019-09-07 15:35:05 +00:00
|
|
|
diesel::delete(community.find(community_id)).execute(conn)
|
2019-04-16 23:04:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn create(conn: &PgConnection, new_community: &CommunityForm) -> Result<Self, Error> {
|
2020-12-18 16:17:21 +00:00
|
|
|
use lemmy_db_schema::schema::community::dsl::*;
|
2019-09-07 15:35:05 +00:00
|
|
|
insert_into(community)
|
|
|
|
.values(new_community)
|
|
|
|
.get_result::<Self>(conn)
|
2019-04-16 23:04:23 +00:00
|
|
|
}
|
|
|
|
|
2019-09-07 15:35:05 +00:00
|
|
|
fn update(
|
|
|
|
conn: &PgConnection,
|
2021-03-18 20:25:21 +00:00
|
|
|
community_id: CommunityId,
|
2019-09-07 15:35:05 +00:00
|
|
|
new_community: &CommunityForm,
|
|
|
|
) -> Result<Self, Error> {
|
2020-12-18 16:17:21 +00:00
|
|
|
use lemmy_db_schema::schema::community::dsl::*;
|
2019-04-16 23:04:23 +00:00
|
|
|
diesel::update(community.find(community_id))
|
|
|
|
.set(new_community)
|
|
|
|
.get_result::<Self>(conn)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-21 12:28:12 +00:00
|
|
|
pub trait Community_ {
|
|
|
|
fn read_from_name(conn: &PgConnection, community_name: &str) -> Result<Community, Error>;
|
|
|
|
fn update_deleted(
|
|
|
|
conn: &PgConnection,
|
2021-03-18 20:25:21 +00:00
|
|
|
community_id: CommunityId,
|
2020-12-21 12:28:12 +00:00
|
|
|
new_deleted: bool,
|
|
|
|
) -> Result<Community, Error>;
|
|
|
|
fn update_removed(
|
|
|
|
conn: &PgConnection,
|
2021-03-18 20:25:21 +00:00
|
|
|
community_id: CommunityId,
|
2020-12-21 12:28:12 +00:00
|
|
|
new_removed: bool,
|
|
|
|
) -> Result<Community, Error>;
|
|
|
|
fn distinct_federated_communities(conn: &PgConnection) -> Result<Vec<String>, Error>;
|
2021-03-02 12:41:48 +00:00
|
|
|
fn read_from_followers_url(
|
|
|
|
conn: &PgConnection,
|
|
|
|
followers_url: &DbUrl,
|
|
|
|
) -> Result<Community, Error>;
|
2021-09-25 15:44:52 +00:00
|
|
|
fn upsert(conn: &PgConnection, community_form: &CommunityForm) -> Result<Community, Error>;
|
2020-12-21 12:28:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Community_ for Community {
|
|
|
|
fn read_from_name(conn: &PgConnection, community_name: &str) -> Result<Community, Error> {
|
2020-12-18 16:17:21 +00:00
|
|
|
use lemmy_db_schema::schema::community::dsl::*;
|
2020-04-07 16:47:19 +00:00
|
|
|
community
|
2020-12-08 17:38:48 +00:00
|
|
|
.filter(local.eq(true))
|
|
|
|
.filter(name.eq(community_name))
|
2020-04-07 16:47:19 +00:00
|
|
|
.first::<Self>(conn)
|
|
|
|
}
|
|
|
|
|
2020-12-21 12:28:12 +00:00
|
|
|
fn update_deleted(
|
2020-07-20 17:37:39 +00:00
|
|
|
conn: &PgConnection,
|
2021-03-18 20:25:21 +00:00
|
|
|
community_id: CommunityId,
|
2020-07-20 17:37:39 +00:00
|
|
|
new_deleted: bool,
|
2020-12-21 12:28:12 +00:00
|
|
|
) -> Result<Community, Error> {
|
2020-12-18 16:17:21 +00:00
|
|
|
use lemmy_db_schema::schema::community::dsl::*;
|
2020-07-20 17:37:39 +00:00
|
|
|
diesel::update(community.find(community_id))
|
2020-08-05 16:03:46 +00:00
|
|
|
.set((deleted.eq(new_deleted), updated.eq(naive_now())))
|
2020-07-20 17:37:39 +00:00
|
|
|
.get_result::<Self>(conn)
|
|
|
|
}
|
|
|
|
|
2020-12-21 12:28:12 +00:00
|
|
|
fn update_removed(
|
2020-07-20 17:37:39 +00:00
|
|
|
conn: &PgConnection,
|
2021-03-18 20:25:21 +00:00
|
|
|
community_id: CommunityId,
|
2020-07-20 17:37:39 +00:00
|
|
|
new_removed: bool,
|
2020-12-21 12:28:12 +00:00
|
|
|
) -> Result<Community, Error> {
|
2020-12-18 16:17:21 +00:00
|
|
|
use lemmy_db_schema::schema::community::dsl::*;
|
2020-07-20 17:37:39 +00:00
|
|
|
diesel::update(community.find(community_id))
|
2020-08-05 16:03:46 +00:00
|
|
|
.set((removed.eq(new_removed), updated.eq(naive_now())))
|
2020-07-20 17:37:39 +00:00
|
|
|
.get_result::<Self>(conn)
|
|
|
|
}
|
|
|
|
|
2020-12-21 12:28:12 +00:00
|
|
|
fn distinct_federated_communities(conn: &PgConnection) -> Result<Vec<String>, Error> {
|
2020-12-18 16:17:21 +00:00
|
|
|
use lemmy_db_schema::schema::community::dsl::*;
|
2020-09-24 13:46:57 +00:00
|
|
|
community.select(actor_id).distinct().load::<String>(conn)
|
|
|
|
}
|
2021-02-04 16:34:58 +00:00
|
|
|
|
|
|
|
fn read_from_followers_url(
|
|
|
|
conn: &PgConnection,
|
2021-03-02 12:41:48 +00:00
|
|
|
followers_url_: &DbUrl,
|
2021-02-04 16:34:58 +00:00
|
|
|
) -> Result<Community, Error> {
|
|
|
|
use lemmy_db_schema::schema::community::dsl::*;
|
|
|
|
community
|
|
|
|
.filter(followers_url.eq(followers_url_))
|
|
|
|
.first::<Self>(conn)
|
|
|
|
}
|
2021-09-25 15:44:52 +00:00
|
|
|
|
|
|
|
fn upsert(conn: &PgConnection, community_form: &CommunityForm) -> Result<Community, Error> {
|
|
|
|
use lemmy_db_schema::schema::community::dsl::*;
|
|
|
|
insert_into(community)
|
|
|
|
.values(community_form)
|
|
|
|
.on_conflict(actor_id)
|
|
|
|
.do_update()
|
|
|
|
.set(community_form)
|
|
|
|
.get_result::<Self>(conn)
|
|
|
|
}
|
2019-04-25 21:52:18 +00:00
|
|
|
}
|
|
|
|
|
2021-08-17 18:04:58 +00:00
|
|
|
impl Joinable for CommunityModerator {
|
|
|
|
type Form = CommunityModeratorForm;
|
2019-09-07 15:35:05 +00:00
|
|
|
fn join(
|
|
|
|
conn: &PgConnection,
|
2021-02-26 13:49:58 +00:00
|
|
|
community_moderator_form: &CommunityModeratorForm,
|
2019-09-07 15:35:05 +00:00
|
|
|
) -> Result<Self, Error> {
|
2020-12-18 16:17:21 +00:00
|
|
|
use lemmy_db_schema::schema::community_moderator::dsl::*;
|
2019-04-16 23:04:23 +00:00
|
|
|
insert_into(community_moderator)
|
2021-02-26 13:49:58 +00:00
|
|
|
.values(community_moderator_form)
|
2019-04-16 23:04:23 +00:00
|
|
|
.get_result::<Self>(conn)
|
|
|
|
}
|
|
|
|
|
2019-09-07 15:35:05 +00:00
|
|
|
fn leave(
|
|
|
|
conn: &PgConnection,
|
2021-02-26 13:49:58 +00:00
|
|
|
community_moderator_form: &CommunityModeratorForm,
|
2019-09-07 15:35:05 +00:00
|
|
|
) -> Result<usize, Error> {
|
2020-12-18 16:17:21 +00:00
|
|
|
use lemmy_db_schema::schema::community_moderator::dsl::*;
|
2019-09-07 15:35:05 +00:00
|
|
|
diesel::delete(
|
|
|
|
community_moderator
|
2021-02-26 13:49:58 +00:00
|
|
|
.filter(community_id.eq(community_moderator_form.community_id))
|
|
|
|
.filter(person_id.eq(community_moderator_form.person_id)),
|
2019-09-07 15:35:05 +00:00
|
|
|
)
|
|
|
|
.execute(conn)
|
2019-04-16 23:04:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-30 18:44:15 +00:00
|
|
|
impl DeleteableOrRemoveable for CommunitySafe {
|
|
|
|
fn blank_out_deleted_or_removed_info(mut self) -> Self {
|
|
|
|
self.title = "".into();
|
|
|
|
self.description = None;
|
|
|
|
self.icon = None;
|
|
|
|
self.banner = None;
|
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl DeleteableOrRemoveable for Community {
|
|
|
|
fn blank_out_deleted_or_removed_info(mut self) -> Self {
|
|
|
|
self.title = "".into();
|
|
|
|
self.description = None;
|
|
|
|
self.icon = None;
|
|
|
|
self.banner = None;
|
|
|
|
self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-21 12:28:12 +00:00
|
|
|
pub trait CommunityModerator_ {
|
2021-03-18 20:25:21 +00:00
|
|
|
fn delete_for_community(
|
|
|
|
conn: &PgConnection,
|
|
|
|
for_community_id: CommunityId,
|
|
|
|
) -> Result<usize, Error>;
|
2021-02-26 13:49:58 +00:00
|
|
|
fn get_person_moderated_communities(
|
2020-12-21 12:28:12 +00:00
|
|
|
conn: &PgConnection,
|
2021-03-18 20:25:21 +00:00
|
|
|
for_person_id: PersonId,
|
|
|
|
) -> Result<Vec<CommunityId>, Error>;
|
2020-12-21 12:28:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl CommunityModerator_ for CommunityModerator {
|
2021-03-18 20:25:21 +00:00
|
|
|
fn delete_for_community(
|
|
|
|
conn: &PgConnection,
|
|
|
|
for_community_id: CommunityId,
|
|
|
|
) -> Result<usize, Error> {
|
2020-12-18 16:17:21 +00:00
|
|
|
use lemmy_db_schema::schema::community_moderator::dsl::*;
|
2019-09-07 15:35:05 +00:00
|
|
|
diesel::delete(community_moderator.filter(community_id.eq(for_community_id))).execute(conn)
|
2019-08-24 02:40:41 +00:00
|
|
|
}
|
2020-10-25 02:59:13 +00:00
|
|
|
|
2021-02-26 13:49:58 +00:00
|
|
|
fn get_person_moderated_communities(
|
2020-11-04 02:15:11 +00:00
|
|
|
conn: &PgConnection,
|
2021-03-18 20:25:21 +00:00
|
|
|
for_person_id: PersonId,
|
|
|
|
) -> Result<Vec<CommunityId>, Error> {
|
2020-12-18 16:17:21 +00:00
|
|
|
use lemmy_db_schema::schema::community_moderator::dsl::*;
|
2020-10-25 02:59:13 +00:00
|
|
|
community_moderator
|
2021-02-26 13:49:58 +00:00
|
|
|
.filter(person_id.eq(for_person_id))
|
2020-11-04 02:15:11 +00:00
|
|
|
.select(community_id)
|
2021-03-18 20:25:21 +00:00
|
|
|
.load::<CommunityId>(conn)
|
2020-10-25 02:59:13 +00:00
|
|
|
}
|
2019-08-24 02:40:41 +00:00
|
|
|
}
|
|
|
|
|
2021-08-17 18:04:58 +00:00
|
|
|
impl Bannable for CommunityPersonBan {
|
|
|
|
type Form = CommunityPersonBanForm;
|
2019-09-07 15:35:05 +00:00
|
|
|
fn ban(
|
|
|
|
conn: &PgConnection,
|
2021-02-26 13:49:58 +00:00
|
|
|
community_person_ban_form: &CommunityPersonBanForm,
|
2019-09-07 15:35:05 +00:00
|
|
|
) -> Result<Self, Error> {
|
2021-02-26 13:49:58 +00:00
|
|
|
use lemmy_db_schema::schema::community_person_ban::dsl::*;
|
|
|
|
insert_into(community_person_ban)
|
|
|
|
.values(community_person_ban_form)
|
2019-04-16 23:04:23 +00:00
|
|
|
.get_result::<Self>(conn)
|
|
|
|
}
|
|
|
|
|
2019-09-07 15:35:05 +00:00
|
|
|
fn unban(
|
|
|
|
conn: &PgConnection,
|
2021-02-26 13:49:58 +00:00
|
|
|
community_person_ban_form: &CommunityPersonBanForm,
|
2019-09-07 15:35:05 +00:00
|
|
|
) -> Result<usize, Error> {
|
2021-02-26 13:49:58 +00:00
|
|
|
use lemmy_db_schema::schema::community_person_ban::dsl::*;
|
2019-09-07 15:35:05 +00:00
|
|
|
diesel::delete(
|
2021-02-26 13:49:58 +00:00
|
|
|
community_person_ban
|
|
|
|
.filter(community_id.eq(community_person_ban_form.community_id))
|
|
|
|
.filter(person_id.eq(community_person_ban_form.person_id)),
|
2019-09-07 15:35:05 +00:00
|
|
|
)
|
|
|
|
.execute(conn)
|
2019-04-16 23:04:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-17 18:04:58 +00:00
|
|
|
impl Followable for CommunityFollower {
|
|
|
|
type Form = CommunityFollowerForm;
|
2019-09-07 15:35:05 +00:00
|
|
|
fn follow(
|
|
|
|
conn: &PgConnection,
|
|
|
|
community_follower_form: &CommunityFollowerForm,
|
|
|
|
) -> Result<Self, Error> {
|
2020-12-18 16:17:21 +00:00
|
|
|
use lemmy_db_schema::schema::community_follower::dsl::*;
|
2019-03-04 16:39:07 +00:00
|
|
|
insert_into(community_follower)
|
|
|
|
.values(community_follower_form)
|
2021-03-10 22:33:55 +00:00
|
|
|
.on_conflict((community_id, person_id))
|
2020-12-16 14:42:57 +00:00
|
|
|
.do_update()
|
|
|
|
.set(community_follower_form)
|
2019-03-23 01:42:57 +00:00
|
|
|
.get_result::<Self>(conn)
|
2019-03-04 16:39:07 +00:00
|
|
|
}
|
2021-03-11 04:43:11 +00:00
|
|
|
fn follow_accepted(
|
|
|
|
conn: &PgConnection,
|
2021-03-18 20:25:21 +00:00
|
|
|
community_id_: CommunityId,
|
|
|
|
person_id_: PersonId,
|
2021-03-11 04:43:11 +00:00
|
|
|
) -> Result<Self, Error>
|
2020-11-10 15:45:10 +00:00
|
|
|
where
|
|
|
|
Self: Sized,
|
|
|
|
{
|
2020-12-18 16:17:21 +00:00
|
|
|
use lemmy_db_schema::schema::community_follower::dsl::*;
|
2020-11-10 15:45:10 +00:00
|
|
|
diesel::update(
|
|
|
|
community_follower
|
|
|
|
.filter(community_id.eq(community_id_))
|
2021-03-10 22:33:55 +00:00
|
|
|
.filter(person_id.eq(person_id_)),
|
2020-11-10 15:45:10 +00:00
|
|
|
)
|
|
|
|
.set(pending.eq(true))
|
|
|
|
.get_result::<Self>(conn)
|
|
|
|
}
|
2020-05-04 18:26:16 +00:00
|
|
|
fn unfollow(
|
2019-09-07 15:35:05 +00:00
|
|
|
conn: &PgConnection,
|
|
|
|
community_follower_form: &CommunityFollowerForm,
|
|
|
|
) -> Result<usize, Error> {
|
2020-12-18 16:17:21 +00:00
|
|
|
use lemmy_db_schema::schema::community_follower::dsl::*;
|
2019-09-07 15:35:05 +00:00
|
|
|
diesel::delete(
|
|
|
|
community_follower
|
|
|
|
.filter(community_id.eq(&community_follower_form.community_id))
|
2021-03-10 22:33:55 +00:00
|
|
|
.filter(person_id.eq(&community_follower_form.person_id)),
|
2019-09-07 15:35:05 +00:00
|
|
|
)
|
|
|
|
.execute(conn)
|
2019-03-04 16:39:07 +00:00
|
|
|
}
|
2020-11-11 16:40:45 +00:00
|
|
|
// TODO: this function name only makes sense if you call it with a remote community. for a local
|
|
|
|
// community, it will also return true if only remote followers exist
|
2021-03-18 20:25:21 +00:00
|
|
|
fn has_local_followers(conn: &PgConnection, community_id_: CommunityId) -> Result<bool, Error> {
|
2020-12-18 16:17:21 +00:00
|
|
|
use lemmy_db_schema::schema::community_follower::dsl::*;
|
2020-11-11 16:40:45 +00:00
|
|
|
diesel::select(exists(
|
|
|
|
community_follower.filter(community_id.eq(community_id_)),
|
|
|
|
))
|
|
|
|
.get_result(conn)
|
|
|
|
}
|
2019-03-04 16:39:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
2021-03-11 04:43:11 +00:00
|
|
|
use crate::{establish_unpooled_connection, Bannable, Crud, Followable, Joinable};
|
2021-02-26 13:49:58 +00:00
|
|
|
use lemmy_db_schema::source::{community::*, person::*};
|
2021-02-25 19:43:39 +00:00
|
|
|
use serial_test::serial;
|
2020-05-16 14:04:08 +00:00
|
|
|
|
2019-09-07 15:35:05 +00:00
|
|
|
#[test]
|
2021-02-25 19:43:39 +00:00
|
|
|
#[serial]
|
2019-03-04 16:39:07 +00:00
|
|
|
fn test_crud() {
|
2020-01-12 15:31:51 +00:00
|
|
|
let conn = establish_unpooled_connection();
|
2019-04-03 06:49:32 +00:00
|
|
|
|
2021-02-26 13:49:58 +00:00
|
|
|
let new_person = PersonForm {
|
2019-04-15 23:12:06 +00:00
|
|
|
name: "bobbee".into(),
|
2021-03-20 20:59:07 +00:00
|
|
|
..PersonForm::default()
|
2019-04-03 06:49:32 +00:00
|
|
|
};
|
|
|
|
|
2021-02-26 13:49:58 +00:00
|
|
|
let inserted_person = Person::create(&conn, &new_person).unwrap();
|
2019-04-03 06:49:32 +00:00
|
|
|
|
2019-03-04 16:39:07 +00:00
|
|
|
let new_community = CommunityForm {
|
|
|
|
name: "TIL".into(),
|
2019-04-03 20:59:37 +00:00
|
|
|
title: "nada".to_owned(),
|
2021-03-20 20:59:07 +00:00
|
|
|
..CommunityForm::default()
|
2019-03-04 16:39:07 +00:00
|
|
|
};
|
|
|
|
|
2019-03-23 01:42:57 +00:00
|
|
|
let inserted_community = Community::create(&conn, &new_community).unwrap();
|
2019-03-04 16:39:07 +00:00
|
|
|
|
|
|
|
let expected_community = Community {
|
|
|
|
id: inserted_community.id,
|
|
|
|
name: "TIL".into(),
|
2019-04-03 20:59:37 +00:00
|
|
|
title: "nada".to_owned(),
|
|
|
|
description: None,
|
2019-08-14 02:52:43 +00:00
|
|
|
nsfw: false,
|
2019-04-20 04:06:25 +00:00
|
|
|
removed: false,
|
2019-04-29 19:14:54 +00:00
|
|
|
deleted: false,
|
2019-03-05 03:52:09 +00:00
|
|
|
published: inserted_community.published,
|
2019-09-07 15:35:05 +00:00
|
|
|
updated: None,
|
2020-07-19 17:12:42 +00:00
|
|
|
actor_id: inserted_community.actor_id.to_owned(),
|
2020-04-03 04:12:05 +00:00
|
|
|
local: true,
|
|
|
|
private_key: None,
|
|
|
|
public_key: None,
|
|
|
|
last_refreshed_at: inserted_community.published,
|
2020-08-05 16:03:46 +00:00
|
|
|
icon: None,
|
|
|
|
banner: None,
|
2021-02-04 16:34:58 +00:00
|
|
|
followers_url: inserted_community.followers_url.to_owned(),
|
|
|
|
inbox_url: inserted_community.inbox_url.to_owned(),
|
|
|
|
shared_inbox_url: None,
|
2019-03-04 16:39:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
let community_follower_form = CommunityFollowerForm {
|
2019-03-23 01:42:57 +00:00
|
|
|
community_id: inserted_community.id,
|
2021-02-26 13:49:58 +00:00
|
|
|
person_id: inserted_person.id,
|
2020-11-10 16:11:08 +00:00
|
|
|
pending: false,
|
2019-03-04 16:39:07 +00:00
|
|
|
};
|
|
|
|
|
2019-09-07 15:35:05 +00:00
|
|
|
let inserted_community_follower =
|
|
|
|
CommunityFollower::follow(&conn, &community_follower_form).unwrap();
|
2019-04-15 23:12:06 +00:00
|
|
|
|
2019-03-04 16:39:07 +00:00
|
|
|
let expected_community_follower = CommunityFollower {
|
|
|
|
id: inserted_community_follower.id,
|
|
|
|
community_id: inserted_community.id,
|
2021-02-26 13:49:58 +00:00
|
|
|
person_id: inserted_person.id,
|
2020-11-10 16:11:08 +00:00
|
|
|
pending: Some(false),
|
2019-09-07 15:35:05 +00:00
|
|
|
published: inserted_community_follower.published,
|
2019-03-04 16:39:07 +00:00
|
|
|
};
|
2019-09-07 15:35:05 +00:00
|
|
|
|
2021-02-26 13:49:58 +00:00
|
|
|
let community_moderator_form = CommunityModeratorForm {
|
2019-03-23 01:42:57 +00:00
|
|
|
community_id: inserted_community.id,
|
2021-02-26 13:49:58 +00:00
|
|
|
person_id: inserted_person.id,
|
2019-03-04 16:39:07 +00:00
|
|
|
};
|
|
|
|
|
2021-03-11 04:43:11 +00:00
|
|
|
let inserted_community_moderator =
|
|
|
|
CommunityModerator::join(&conn, &community_moderator_form).unwrap();
|
2019-03-04 16:39:07 +00:00
|
|
|
|
2021-02-26 13:49:58 +00:00
|
|
|
let expected_community_moderator = CommunityModerator {
|
|
|
|
id: inserted_community_moderator.id,
|
2019-03-04 16:39:07 +00:00
|
|
|
community_id: inserted_community.id,
|
2021-02-26 13:49:58 +00:00
|
|
|
person_id: inserted_person.id,
|
|
|
|
published: inserted_community_moderator.published,
|
2019-03-04 16:39:07 +00:00
|
|
|
};
|
|
|
|
|
2021-02-26 13:49:58 +00:00
|
|
|
let community_person_ban_form = CommunityPersonBanForm {
|
2019-04-15 23:12:06 +00:00
|
|
|
community_id: inserted_community.id,
|
2021-02-26 13:49:58 +00:00
|
|
|
person_id: inserted_person.id,
|
2019-04-15 23:12:06 +00:00
|
|
|
};
|
|
|
|
|
2021-02-26 13:49:58 +00:00
|
|
|
let inserted_community_person_ban =
|
|
|
|
CommunityPersonBan::ban(&conn, &community_person_ban_form).unwrap();
|
2019-04-15 23:12:06 +00:00
|
|
|
|
2021-02-26 13:49:58 +00:00
|
|
|
let expected_community_person_ban = CommunityPersonBan {
|
|
|
|
id: inserted_community_person_ban.id,
|
2019-04-15 23:12:06 +00:00
|
|
|
community_id: inserted_community.id,
|
2021-02-26 13:49:58 +00:00
|
|
|
person_id: inserted_person.id,
|
|
|
|
published: inserted_community_person_ban.published,
|
2019-04-15 23:12:06 +00:00
|
|
|
};
|
|
|
|
|
2019-03-23 01:42:57 +00:00
|
|
|
let read_community = Community::read(&conn, inserted_community.id).unwrap();
|
2019-09-07 15:35:05 +00:00
|
|
|
let updated_community =
|
|
|
|
Community::update(&conn, inserted_community.id, &new_community).unwrap();
|
2020-05-04 18:26:16 +00:00
|
|
|
let ignored_community = CommunityFollower::unfollow(&conn, &community_follower_form).unwrap();
|
2021-02-26 13:49:58 +00:00
|
|
|
let left_community = CommunityModerator::leave(&conn, &community_moderator_form).unwrap();
|
|
|
|
let unban = CommunityPersonBan::unban(&conn, &community_person_ban_form).unwrap();
|
2019-03-23 01:42:57 +00:00
|
|
|
let num_deleted = Community::delete(&conn, inserted_community.id).unwrap();
|
2021-02-26 13:49:58 +00:00
|
|
|
Person::delete(&conn, inserted_person.id).unwrap();
|
2019-03-04 16:39:07 +00:00
|
|
|
|
|
|
|
assert_eq!(expected_community, read_community);
|
|
|
|
assert_eq!(expected_community, inserted_community);
|
|
|
|
assert_eq!(expected_community, updated_community);
|
|
|
|
assert_eq!(expected_community_follower, inserted_community_follower);
|
2021-02-26 13:49:58 +00:00
|
|
|
assert_eq!(expected_community_moderator, inserted_community_moderator);
|
|
|
|
assert_eq!(expected_community_person_ban, inserted_community_person_ban);
|
2019-03-04 16:39:07 +00:00
|
|
|
assert_eq!(1, ignored_community);
|
|
|
|
assert_eq!(1, left_community);
|
2019-04-15 23:12:06 +00:00
|
|
|
assert_eq!(1, unban);
|
2019-04-03 06:49:32 +00:00
|
|
|
// assert_eq!(2, loaded_count);
|
2019-03-04 16:39:07 +00:00
|
|
|
assert_eq!(1, num_deleted);
|
|
|
|
}
|
|
|
|
}
|