mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-29 15:51:20 +00:00
Removing community.creator column. Fixes #1504
This commit is contained in:
parent
fac024b90c
commit
bc8eb2dd17
25 changed files with 64 additions and 136 deletions
|
@ -10,11 +10,7 @@ use lemmy_api_common::{
|
||||||
};
|
};
|
||||||
use lemmy_apub::{ActorType, CommunityType, UserType};
|
use lemmy_apub::{ActorType, CommunityType, UserType};
|
||||||
use lemmy_db_queries::{
|
use lemmy_db_queries::{
|
||||||
source::{
|
source::{comment::Comment_, community::CommunityModerator_, post::Post_},
|
||||||
comment::Comment_,
|
|
||||||
community::{CommunityModerator_, Community_},
|
|
||||||
post::Post_,
|
|
||||||
},
|
|
||||||
Bannable,
|
Bannable,
|
||||||
Crud,
|
Crud,
|
||||||
Followable,
|
Followable,
|
||||||
|
@ -324,12 +320,6 @@ impl Perform for TransferCommunity {
|
||||||
let data: &TransferCommunity = &self;
|
let data: &TransferCommunity = &self;
|
||||||
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
|
||||||
let community_id = data.community_id;
|
|
||||||
let read_community = blocking(context.pool(), move |conn| {
|
|
||||||
Community::read(conn, community_id)
|
|
||||||
})
|
|
||||||
.await??;
|
|
||||||
|
|
||||||
let site_creator_id = blocking(context.pool(), move |conn| {
|
let site_creator_id = blocking(context.pool(), move |conn| {
|
||||||
Site::read(conn, 1).map(|s| s.creator_id)
|
Site::read(conn, 1).map(|s| s.creator_id)
|
||||||
})
|
})
|
||||||
|
@ -337,7 +327,7 @@ impl Perform for TransferCommunity {
|
||||||
|
|
||||||
let mut admins = blocking(context.pool(), move |conn| PersonViewSafe::admins(conn)).await??;
|
let mut admins = blocking(context.pool(), move |conn| PersonViewSafe::admins(conn)).await??;
|
||||||
|
|
||||||
// Making sure the creator, if an admin, is at the top
|
// Making sure the site creator, if an admin, is at the top
|
||||||
let creator_index = admins
|
let creator_index = admins
|
||||||
.iter()
|
.iter()
|
||||||
.position(|r| r.person.id == site_creator_id)
|
.position(|r| r.person.id == site_creator_id)
|
||||||
|
@ -345,8 +335,15 @@ impl Perform for TransferCommunity {
|
||||||
let creator_person = admins.remove(creator_index);
|
let creator_person = admins.remove(creator_index);
|
||||||
admins.insert(0, creator_person);
|
admins.insert(0, creator_person);
|
||||||
|
|
||||||
// Make sure user is the creator, or an admin
|
// Fetch the community mods
|
||||||
if local_user_view.person.id != read_community.creator_id
|
let community_id = data.community_id;
|
||||||
|
let mut community_mods = blocking(context.pool(), move |conn| {
|
||||||
|
CommunityModeratorView::for_community(conn, community_id)
|
||||||
|
})
|
||||||
|
.await??;
|
||||||
|
|
||||||
|
// Make sure transferrer is either the top community mod, or an admin
|
||||||
|
if local_user_view.person.id != community_mods[0].moderator.id
|
||||||
&& !admins
|
&& !admins
|
||||||
.iter()
|
.iter()
|
||||||
.map(|a| a.person.id)
|
.map(|a| a.person.id)
|
||||||
|
@ -355,19 +352,8 @@ impl Perform for TransferCommunity {
|
||||||
return Err(ApiError::err("not_an_admin").into());
|
return Err(ApiError::err("not_an_admin").into());
|
||||||
}
|
}
|
||||||
|
|
||||||
let community_id = data.community_id;
|
// You have to re-do the community_moderator table, reordering it.
|
||||||
let new_creator = data.person_id;
|
// Add the transferee to the top
|
||||||
let update = move |conn: &'_ _| Community::update_creator(conn, community_id, new_creator);
|
|
||||||
if blocking(context.pool(), update).await?.is_err() {
|
|
||||||
return Err(ApiError::err("couldnt_update_community").into());
|
|
||||||
};
|
|
||||||
|
|
||||||
// You also have to re-do the community_moderator table, reordering it.
|
|
||||||
let community_id = data.community_id;
|
|
||||||
let mut community_mods = blocking(context.pool(), move |conn| {
|
|
||||||
CommunityModeratorView::for_community(conn, community_id)
|
|
||||||
})
|
|
||||||
.await??;
|
|
||||||
let creator_index = community_mods
|
let creator_index = community_mods
|
||||||
.iter()
|
.iter()
|
||||||
.position(|r| r.moderator.id == data.person_id)
|
.position(|r| r.moderator.id == data.person_id)
|
||||||
|
@ -375,6 +361,7 @@ impl Perform for TransferCommunity {
|
||||||
let creator_person = community_mods.remove(creator_index);
|
let creator_person = community_mods.remove(creator_index);
|
||||||
community_mods.insert(0, creator_person);
|
community_mods.insert(0, creator_person);
|
||||||
|
|
||||||
|
// Delete all the mods
|
||||||
let community_id = data.community_id;
|
let community_id = data.community_id;
|
||||||
blocking(context.pool(), move |conn| {
|
blocking(context.pool(), move |conn| {
|
||||||
CommunityModerator::delete_for_community(conn, community_id)
|
CommunityModerator::delete_for_community(conn, community_id)
|
||||||
|
@ -382,6 +369,7 @@ impl Perform for TransferCommunity {
|
||||||
.await??;
|
.await??;
|
||||||
|
|
||||||
// TODO: this should probably be a bulk operation
|
// TODO: this should probably be a bulk operation
|
||||||
|
// Re-add the mods, in the new order
|
||||||
for cmod in &community_mods {
|
for cmod in &community_mods {
|
||||||
let community_moderator_form = CommunityModeratorForm {
|
let community_moderator_form = CommunityModeratorForm {
|
||||||
community_id: cmod.community.id,
|
community_id: cmod.community.id,
|
||||||
|
@ -395,6 +383,8 @@ impl Perform for TransferCommunity {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mod tables
|
// Mod tables
|
||||||
|
// TODO there should probably be another table for transfer community
|
||||||
|
// Right now, it will just look like it modded them twice
|
||||||
let form = ModAddCommunityForm {
|
let form = ModAddCommunityForm {
|
||||||
mod_person_id: local_user_view.person.id,
|
mod_person_id: local_user_view.person.id,
|
||||||
other_person_id: data.person_id,
|
other_person_id: data.person_id,
|
||||||
|
|
|
@ -18,7 +18,6 @@ use lemmy_db_queries::{
|
||||||
diesel_option_overwrite_to_url,
|
diesel_option_overwrite_to_url,
|
||||||
source::{
|
source::{
|
||||||
comment::Comment_,
|
comment::Comment_,
|
||||||
community::Community_,
|
|
||||||
local_user::LocalUser_,
|
local_user::LocalUser_,
|
||||||
password_reset_request::PasswordResetRequest_,
|
password_reset_request::PasswordResetRequest_,
|
||||||
person::Person_,
|
person::Person_,
|
||||||
|
@ -33,7 +32,6 @@ use lemmy_db_schema::{
|
||||||
naive_now,
|
naive_now,
|
||||||
source::{
|
source::{
|
||||||
comment::Comment,
|
comment::Comment,
|
||||||
community::*,
|
|
||||||
local_user::{LocalUser, LocalUserForm},
|
local_user::{LocalUser, LocalUserForm},
|
||||||
moderator::*,
|
moderator::*,
|
||||||
password_reset_request::*,
|
password_reset_request::*,
|
||||||
|
@ -394,10 +392,9 @@ impl Perform for BanPerson {
|
||||||
.await??;
|
.await??;
|
||||||
|
|
||||||
// Communities
|
// Communities
|
||||||
blocking(context.pool(), move |conn: &'_ _| {
|
// Remove all communities where they're the top mod
|
||||||
Community::update_removed_for_creator(conn, banned_person_id, true)
|
// TODO couldn't get group by's working in diesel,
|
||||||
})
|
// for now, remove the communities manually
|
||||||
.await??;
|
|
||||||
|
|
||||||
// Comments
|
// Comments
|
||||||
blocking(context.pool(), move |conn: &'_ _| {
|
blocking(context.pool(), move |conn: &'_ _| {
|
||||||
|
|
|
@ -75,7 +75,6 @@ impl PerformCrud for CreateCommunity {
|
||||||
description: data.description.to_owned(),
|
description: data.description.to_owned(),
|
||||||
icon,
|
icon,
|
||||||
banner,
|
banner,
|
||||||
creator_id: local_user_view.person.id,
|
|
||||||
nsfw: data.nsfw,
|
nsfw: data.nsfw,
|
||||||
actor_id: Some(community_actor_id.to_owned()),
|
actor_id: Some(community_actor_id.to_owned()),
|
||||||
private_key: Some(keypair.private_key),
|
private_key: Some(keypair.private_key),
|
||||||
|
|
|
@ -7,7 +7,10 @@ use lemmy_db_schema::source::{
|
||||||
community::*,
|
community::*,
|
||||||
moderator::{ModRemoveCommunity, ModRemoveCommunityForm},
|
moderator::{ModRemoveCommunity, ModRemoveCommunityForm},
|
||||||
};
|
};
|
||||||
use lemmy_db_views_actor::community_view::CommunityView;
|
use lemmy_db_views_actor::{
|
||||||
|
community_moderator_view::CommunityModeratorView,
|
||||||
|
community_view::CommunityView,
|
||||||
|
};
|
||||||
use lemmy_utils::{utils::naive_from_unix, ApiError, ConnectionId, LemmyError};
|
use lemmy_utils::{utils::naive_from_unix, ApiError, ConnectionId, LemmyError};
|
||||||
use lemmy_websocket::{LemmyContext, UserOperationCrud};
|
use lemmy_websocket::{LemmyContext, UserOperationCrud};
|
||||||
|
|
||||||
|
@ -23,13 +26,15 @@ impl PerformCrud for DeleteCommunity {
|
||||||
let data: &DeleteCommunity = &self;
|
let data: &DeleteCommunity = &self;
|
||||||
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
let local_user_view = get_local_user_view_from_jwt(&data.auth, context.pool()).await?;
|
||||||
|
|
||||||
// Verify its the creator (only a creator can delete the community)
|
// Fetch the community mods
|
||||||
let community_id = data.community_id;
|
let community_id = data.community_id;
|
||||||
let read_community = blocking(context.pool(), move |conn| {
|
let community_mods = blocking(context.pool(), move |conn| {
|
||||||
Community::read(conn, community_id)
|
CommunityModeratorView::for_community(conn, community_id)
|
||||||
})
|
})
|
||||||
.await??;
|
.await??;
|
||||||
if read_community.creator_id != local_user_view.person.id {
|
|
||||||
|
// Make sure deleter is the top mod
|
||||||
|
if local_user_view.person.id != community_mods[0].moderator.id {
|
||||||
return Err(ApiError::err("no_community_edit_allowed").into());
|
return Err(ApiError::err("no_community_edit_allowed").into());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -61,7 +61,6 @@ impl PerformCrud for EditCommunity {
|
||||||
let community_form = CommunityForm {
|
let community_form = CommunityForm {
|
||||||
name: read_community.name,
|
name: read_community.name,
|
||||||
title: data.title.to_owned(),
|
title: data.title.to_owned(),
|
||||||
creator_id: read_community.creator_id,
|
|
||||||
description: data.description.to_owned(),
|
description: data.description.to_owned(),
|
||||||
icon,
|
icon,
|
||||||
banner,
|
banner,
|
||||||
|
|
|
@ -177,7 +177,6 @@ impl PerformCrud for Register {
|
||||||
name: default_community_name.to_string(),
|
name: default_community_name.to_string(),
|
||||||
title: "The Default Community".to_string(),
|
title: "The Default Community".to_string(),
|
||||||
description: Some("The Default Community".to_string()),
|
description: Some("The Default Community".to_string()),
|
||||||
creator_id: inserted_person.id,
|
|
||||||
actor_id: Some(actor_id.to_owned()),
|
actor_id: Some(actor_id.to_owned()),
|
||||||
private_key: Some(main_community_keypair.private_key),
|
private_key: Some(main_community_keypair.private_key),
|
||||||
public_key: Some(main_community_keypair.public_key),
|
public_key: Some(main_community_keypair.public_key),
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
extensions::{context::lemmy_context, group_extension::GroupExtension},
|
extensions::{context::lemmy_context, group_extension::GroupExtension},
|
||||||
fetcher::{community::fetch_community_mods, person::get_or_fetch_and_upsert_person},
|
fetcher::community::fetch_community_mods,
|
||||||
generate_moderators_url,
|
generate_moderators_url,
|
||||||
objects::{
|
objects::{
|
||||||
check_object_domain,
|
check_object_domain,
|
||||||
|
@ -140,24 +140,7 @@ impl FromApubToForm<GroupExt> for CommunityForm {
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
_mod_action_allowed: bool,
|
_mod_action_allowed: bool,
|
||||||
) -> Result<Self, LemmyError> {
|
) -> Result<Self, LemmyError> {
|
||||||
let moderator_uris = fetch_community_mods(context, group, request_counter).await?;
|
fetch_community_mods(context, group, request_counter).await?;
|
||||||
let creator = if let Some(creator_uri) = moderator_uris.first() {
|
|
||||||
get_or_fetch_and_upsert_person(creator_uri, context, request_counter)
|
|
||||||
} else {
|
|
||||||
// NOTE: code for compatibility with lemmy v0.9.9
|
|
||||||
let creator_uri = group
|
|
||||||
.inner
|
|
||||||
.attributed_to()
|
|
||||||
.map(|a| a.as_many())
|
|
||||||
.flatten()
|
|
||||||
.map(|a| a.first())
|
|
||||||
.flatten()
|
|
||||||
.map(|a| a.as_xsd_any_uri())
|
|
||||||
.flatten()
|
|
||||||
.context(location_info!())?;
|
|
||||||
get_or_fetch_and_upsert_person(creator_uri, context, request_counter)
|
|
||||||
}
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
let name = group
|
let name = group
|
||||||
.inner
|
.inner
|
||||||
|
@ -215,7 +198,6 @@ impl FromApubToForm<GroupExt> for CommunityForm {
|
||||||
name,
|
name,
|
||||||
title,
|
title,
|
||||||
description,
|
description,
|
||||||
creator_id: creator.id,
|
|
||||||
removed: None,
|
removed: None,
|
||||||
published: group.inner.published().map(|u| u.to_owned().naive_local()),
|
published: group.inner.published().map(|u| u.to_owned().naive_local()),
|
||||||
updated: group.inner.updated().map(|u| u.to_owned().naive_local()),
|
updated: group.inner.updated().map(|u| u.to_owned().naive_local()),
|
||||||
|
|
|
@ -58,7 +58,6 @@ mod tests {
|
||||||
|
|
||||||
let new_community = CommunityForm {
|
let new_community = CommunityForm {
|
||||||
name: "TIL_comment_agg".into(),
|
name: "TIL_comment_agg".into(),
|
||||||
creator_id: inserted_person.id,
|
|
||||||
title: "nada".to_owned(),
|
title: "nada".to_owned(),
|
||||||
..CommunityForm::default()
|
..CommunityForm::default()
|
||||||
};
|
};
|
||||||
|
|
|
@ -62,7 +62,6 @@ mod tests {
|
||||||
|
|
||||||
let new_community = CommunityForm {
|
let new_community = CommunityForm {
|
||||||
name: "TIL_community_agg".into(),
|
name: "TIL_community_agg".into(),
|
||||||
creator_id: inserted_person.id,
|
|
||||||
title: "nada".to_owned(),
|
title: "nada".to_owned(),
|
||||||
..CommunityForm::default()
|
..CommunityForm::default()
|
||||||
};
|
};
|
||||||
|
@ -71,7 +70,6 @@ mod tests {
|
||||||
|
|
||||||
let another_community = CommunityForm {
|
let another_community = CommunityForm {
|
||||||
name: "TIL_community_agg_2".into(),
|
name: "TIL_community_agg_2".into(),
|
||||||
creator_id: inserted_person.id,
|
|
||||||
title: "nada".to_owned(),
|
title: "nada".to_owned(),
|
||||||
..CommunityForm::default()
|
..CommunityForm::default()
|
||||||
};
|
};
|
||||||
|
|
|
@ -58,7 +58,6 @@ mod tests {
|
||||||
|
|
||||||
let new_community = CommunityForm {
|
let new_community = CommunityForm {
|
||||||
name: "TIL_site_agg".into(),
|
name: "TIL_site_agg".into(),
|
||||||
creator_id: inserted_person.id,
|
|
||||||
title: "nada".to_owned(),
|
title: "nada".to_owned(),
|
||||||
..CommunityForm::default()
|
..CommunityForm::default()
|
||||||
};
|
};
|
||||||
|
|
|
@ -62,7 +62,6 @@ mod tests {
|
||||||
|
|
||||||
let new_community = CommunityForm {
|
let new_community = CommunityForm {
|
||||||
name: "TIL_community_agg".into(),
|
name: "TIL_community_agg".into(),
|
||||||
creator_id: inserted_person.id,
|
|
||||||
title: "nada".to_owned(),
|
title: "nada".to_owned(),
|
||||||
..CommunityForm::default()
|
..CommunityForm::default()
|
||||||
};
|
};
|
||||||
|
|
|
@ -63,7 +63,6 @@ mod tests {
|
||||||
|
|
||||||
let new_community = CommunityForm {
|
let new_community = CommunityForm {
|
||||||
name: "TIL_site_agg".into(),
|
name: "TIL_site_agg".into(),
|
||||||
creator_id: inserted_person.id,
|
|
||||||
title: "nada".to_owned(),
|
title: "nada".to_owned(),
|
||||||
..CommunityForm::default()
|
..CommunityForm::default()
|
||||||
};
|
};
|
||||||
|
|
|
@ -254,7 +254,6 @@ mod tests {
|
||||||
let new_community = CommunityForm {
|
let new_community = CommunityForm {
|
||||||
name: "test community".to_string(),
|
name: "test community".to_string(),
|
||||||
title: "nada".to_owned(),
|
title: "nada".to_owned(),
|
||||||
creator_id: inserted_person.id,
|
|
||||||
..CommunityForm::default()
|
..CommunityForm::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,6 @@ mod safe_type {
|
||||||
name,
|
name,
|
||||||
title,
|
title,
|
||||||
description,
|
description,
|
||||||
creator_id,
|
|
||||||
removed,
|
removed,
|
||||||
published,
|
published,
|
||||||
updated,
|
updated,
|
||||||
|
@ -46,7 +45,6 @@ mod safe_type {
|
||||||
name,
|
name,
|
||||||
title,
|
title,
|
||||||
description,
|
description,
|
||||||
creator_id,
|
|
||||||
removed,
|
removed,
|
||||||
published,
|
published,
|
||||||
updated,
|
updated,
|
||||||
|
@ -122,16 +120,6 @@ pub trait Community_ {
|
||||||
community_id: CommunityId,
|
community_id: CommunityId,
|
||||||
new_removed: bool,
|
new_removed: bool,
|
||||||
) -> Result<Community, Error>;
|
) -> Result<Community, Error>;
|
||||||
fn update_removed_for_creator(
|
|
||||||
conn: &PgConnection,
|
|
||||||
for_creator_id: PersonId,
|
|
||||||
new_removed: bool,
|
|
||||||
) -> Result<Vec<Community>, Error>;
|
|
||||||
fn update_creator(
|
|
||||||
conn: &PgConnection,
|
|
||||||
community_id: CommunityId,
|
|
||||||
new_creator_id: PersonId,
|
|
||||||
) -> Result<Community, Error>;
|
|
||||||
fn distinct_federated_communities(conn: &PgConnection) -> Result<Vec<String>, Error>;
|
fn distinct_federated_communities(conn: &PgConnection) -> Result<Vec<String>, Error>;
|
||||||
fn read_from_followers_url(
|
fn read_from_followers_url(
|
||||||
conn: &PgConnection,
|
conn: &PgConnection,
|
||||||
|
@ -170,28 +158,6 @@ impl Community_ for Community {
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_removed_for_creator(
|
|
||||||
conn: &PgConnection,
|
|
||||||
for_creator_id: PersonId,
|
|
||||||
new_removed: bool,
|
|
||||||
) -> Result<Vec<Community>, Error> {
|
|
||||||
use lemmy_db_schema::schema::community::dsl::*;
|
|
||||||
diesel::update(community.filter(creator_id.eq(for_creator_id)))
|
|
||||||
.set((removed.eq(new_removed), updated.eq(naive_now())))
|
|
||||||
.get_results::<Self>(conn)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn update_creator(
|
|
||||||
conn: &PgConnection,
|
|
||||||
community_id: CommunityId,
|
|
||||||
new_creator_id: PersonId,
|
|
||||||
) -> Result<Community, Error> {
|
|
||||||
use lemmy_db_schema::schema::community::dsl::*;
|
|
||||||
diesel::update(community.find(community_id))
|
|
||||||
.set((creator_id.eq(new_creator_id), updated.eq(naive_now())))
|
|
||||||
.get_result::<Self>(conn)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn distinct_federated_communities(conn: &PgConnection) -> Result<Vec<String>, Error> {
|
fn distinct_federated_communities(conn: &PgConnection) -> Result<Vec<String>, Error> {
|
||||||
use lemmy_db_schema::schema::community::dsl::*;
|
use lemmy_db_schema::schema::community::dsl::*;
|
||||||
community.select(actor_id).distinct().load::<String>(conn)
|
community.select(actor_id).distinct().load::<String>(conn)
|
||||||
|
@ -363,7 +329,6 @@ mod tests {
|
||||||
|
|
||||||
let new_community = CommunityForm {
|
let new_community = CommunityForm {
|
||||||
name: "TIL".into(),
|
name: "TIL".into(),
|
||||||
creator_id: inserted_person.id,
|
|
||||||
title: "nada".to_owned(),
|
title: "nada".to_owned(),
|
||||||
..CommunityForm::default()
|
..CommunityForm::default()
|
||||||
};
|
};
|
||||||
|
@ -372,7 +337,6 @@ mod tests {
|
||||||
|
|
||||||
let expected_community = Community {
|
let expected_community = Community {
|
||||||
id: inserted_community.id,
|
id: inserted_community.id,
|
||||||
creator_id: inserted_person.id,
|
|
||||||
name: "TIL".into(),
|
name: "TIL".into(),
|
||||||
title: "nada".to_owned(),
|
title: "nada".to_owned(),
|
||||||
description: None,
|
description: None,
|
||||||
|
|
|
@ -224,7 +224,6 @@ mod tests {
|
||||||
let new_community = CommunityForm {
|
let new_community = CommunityForm {
|
||||||
name: "mod_community".to_string(),
|
name: "mod_community".to_string(),
|
||||||
title: "nada".to_owned(),
|
title: "nada".to_owned(),
|
||||||
creator_id: inserted_person.id,
|
|
||||||
..CommunityForm::default()
|
..CommunityForm::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -232,7 +231,6 @@ mod tests {
|
||||||
|
|
||||||
let new_post = PostForm {
|
let new_post = PostForm {
|
||||||
name: "A test post thweep".into(),
|
name: "A test post thweep".into(),
|
||||||
creator_id: inserted_person.id,
|
|
||||||
community_id: inserted_community.id,
|
community_id: inserted_community.id,
|
||||||
..PostForm::default()
|
..PostForm::default()
|
||||||
};
|
};
|
||||||
|
|
|
@ -105,7 +105,6 @@ mod tests {
|
||||||
let new_community = CommunityForm {
|
let new_community = CommunityForm {
|
||||||
name: "test community lake".to_string(),
|
name: "test community lake".to_string(),
|
||||||
title: "nada".to_owned(),
|
title: "nada".to_owned(),
|
||||||
creator_id: inserted_person.id,
|
|
||||||
..CommunityForm::default()
|
..CommunityForm::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -113,7 +112,6 @@ mod tests {
|
||||||
|
|
||||||
let new_post = PostForm {
|
let new_post = PostForm {
|
||||||
name: "A test post".into(),
|
name: "A test post".into(),
|
||||||
creator_id: inserted_person.id,
|
|
||||||
community_id: inserted_community.id,
|
community_id: inserted_community.id,
|
||||||
..PostForm::default()
|
..PostForm::default()
|
||||||
};
|
};
|
||||||
|
|
|
@ -281,7 +281,6 @@ mod tests {
|
||||||
let new_community = CommunityForm {
|
let new_community = CommunityForm {
|
||||||
name: "test community_3".to_string(),
|
name: "test community_3".to_string(),
|
||||||
title: "nada".to_owned(),
|
title: "nada".to_owned(),
|
||||||
creator_id: inserted_person.id,
|
|
||||||
..CommunityForm::default()
|
..CommunityForm::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -78,7 +78,6 @@ table! {
|
||||||
name -> Varchar,
|
name -> Varchar,
|
||||||
title -> Varchar,
|
title -> Varchar,
|
||||||
description -> Nullable<Text>,
|
description -> Nullable<Text>,
|
||||||
creator_id -> Int4,
|
|
||||||
removed -> Bool,
|
removed -> Bool,
|
||||||
published -> Timestamp,
|
published -> Timestamp,
|
||||||
updated -> Nullable<Timestamp>,
|
updated -> Nullable<Timestamp>,
|
||||||
|
@ -532,7 +531,6 @@ joinable!(comment_like -> post (post_id));
|
||||||
joinable!(comment_report -> comment (comment_id));
|
joinable!(comment_report -> comment (comment_id));
|
||||||
joinable!(comment_saved -> comment (comment_id));
|
joinable!(comment_saved -> comment (comment_id));
|
||||||
joinable!(comment_saved -> person (person_id));
|
joinable!(comment_saved -> person (person_id));
|
||||||
joinable!(community -> person (creator_id));
|
|
||||||
joinable!(community_aggregates -> community (community_id));
|
joinable!(community_aggregates -> community (community_id));
|
||||||
joinable!(community_follower -> community (community_id));
|
joinable!(community_follower -> community (community_id));
|
||||||
joinable!(community_follower -> person (person_id));
|
joinable!(community_follower -> person (person_id));
|
||||||
|
|
|
@ -13,7 +13,6 @@ pub struct Community {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub title: String,
|
pub title: String,
|
||||||
pub description: Option<String>,
|
pub description: Option<String>,
|
||||||
pub creator_id: PersonId,
|
|
||||||
pub removed: bool,
|
pub removed: bool,
|
||||||
pub published: chrono::NaiveDateTime,
|
pub published: chrono::NaiveDateTime,
|
||||||
pub updated: Option<chrono::NaiveDateTime>,
|
pub updated: Option<chrono::NaiveDateTime>,
|
||||||
|
@ -39,7 +38,6 @@ pub struct CommunitySafe {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub title: String,
|
pub title: String,
|
||||||
pub description: Option<String>,
|
pub description: Option<String>,
|
||||||
pub creator_id: PersonId,
|
|
||||||
pub removed: bool,
|
pub removed: bool,
|
||||||
pub published: chrono::NaiveDateTime,
|
pub published: chrono::NaiveDateTime,
|
||||||
pub updated: Option<chrono::NaiveDateTime>,
|
pub updated: Option<chrono::NaiveDateTime>,
|
||||||
|
@ -57,7 +55,6 @@ pub struct CommunityForm {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub title: String,
|
pub title: String,
|
||||||
pub description: Option<String>,
|
pub description: Option<String>,
|
||||||
pub creator_id: PersonId,
|
|
||||||
pub removed: Option<bool>,
|
pub removed: Option<bool>,
|
||||||
pub published: Option<chrono::NaiveDateTime>,
|
pub published: Option<chrono::NaiveDateTime>,
|
||||||
pub updated: Option<chrono::NaiveDateTime>,
|
pub updated: Option<chrono::NaiveDateTime>,
|
||||||
|
|
|
@ -462,7 +462,6 @@ mod tests {
|
||||||
let new_community = CommunityForm {
|
let new_community = CommunityForm {
|
||||||
name: "test community 5".to_string(),
|
name: "test community 5".to_string(),
|
||||||
title: "nada".to_owned(),
|
title: "nada".to_owned(),
|
||||||
creator_id: inserted_person.id,
|
|
||||||
..CommunityForm::default()
|
..CommunityForm::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -567,7 +566,6 @@ mod tests {
|
||||||
local: true,
|
local: true,
|
||||||
title: "nada".to_owned(),
|
title: "nada".to_owned(),
|
||||||
description: None,
|
description: None,
|
||||||
creator_id: inserted_person.id,
|
|
||||||
updated: None,
|
updated: None,
|
||||||
banner: None,
|
banner: None,
|
||||||
published: inserted_community.published,
|
published: inserted_community.published,
|
||||||
|
|
|
@ -263,7 +263,7 @@ impl<'a> PostQueryBuilder<'a> {
|
||||||
community_person_ban::table.on(
|
community_person_ban::table.on(
|
||||||
post::community_id
|
post::community_id
|
||||||
.eq(community_person_ban::community_id)
|
.eq(community_person_ban::community_id)
|
||||||
.and(community_person_ban::person_id.eq(community::creator_id)),
|
.and(community_person_ban::person_id.eq(post::creator_id)),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.inner_join(post_aggregates::table)
|
.inner_join(post_aggregates::table)
|
||||||
|
@ -462,7 +462,6 @@ mod tests {
|
||||||
let new_community = CommunityForm {
|
let new_community = CommunityForm {
|
||||||
name: community_name.to_owned(),
|
name: community_name.to_owned(),
|
||||||
title: "nada".to_owned(),
|
title: "nada".to_owned(),
|
||||||
creator_id: inserted_person.id,
|
|
||||||
..CommunityForm::default()
|
..CommunityForm::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -568,7 +567,6 @@ mod tests {
|
||||||
local: true,
|
local: true,
|
||||||
title: "nada".to_owned(),
|
title: "nada".to_owned(),
|
||||||
description: None,
|
description: None,
|
||||||
creator_id: inserted_person.id,
|
|
||||||
updated: None,
|
updated: None,
|
||||||
banner: None,
|
banner: None,
|
||||||
published: inserted_community.published,
|
published: inserted_community.published,
|
||||||
|
|
|
@ -12,11 +12,8 @@ use lemmy_db_queries::{
|
||||||
ViewToVec,
|
ViewToVec,
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
schema::{community, community_aggregates, community_follower, person},
|
schema::{community, community_aggregates, community_follower},
|
||||||
source::{
|
source::community::{Community, CommunityFollower, CommunitySafe},
|
||||||
community::{Community, CommunityFollower, CommunitySafe},
|
|
||||||
person::{Person, PersonSafe},
|
|
||||||
},
|
|
||||||
CommunityId,
|
CommunityId,
|
||||||
PersonId,
|
PersonId,
|
||||||
};
|
};
|
||||||
|
@ -25,14 +22,12 @@ use serde::Serialize;
|
||||||
#[derive(Debug, Serialize, Clone)]
|
#[derive(Debug, Serialize, Clone)]
|
||||||
pub struct CommunityView {
|
pub struct CommunityView {
|
||||||
pub community: CommunitySafe,
|
pub community: CommunitySafe,
|
||||||
pub creator: PersonSafe,
|
|
||||||
pub subscribed: bool,
|
pub subscribed: bool,
|
||||||
pub counts: CommunityAggregates,
|
pub counts: CommunityAggregates,
|
||||||
}
|
}
|
||||||
|
|
||||||
type CommunityViewTuple = (
|
type CommunityViewTuple = (
|
||||||
CommunitySafe,
|
CommunitySafe,
|
||||||
PersonSafe,
|
|
||||||
CommunityAggregates,
|
CommunityAggregates,
|
||||||
Option<CommunityFollower>,
|
Option<CommunityFollower>,
|
||||||
);
|
);
|
||||||
|
@ -46,9 +41,8 @@ impl CommunityView {
|
||||||
// The left join below will return None in this case
|
// The left join below will return None in this case
|
||||||
let person_id_join = my_person_id.unwrap_or(PersonId(-1));
|
let person_id_join = my_person_id.unwrap_or(PersonId(-1));
|
||||||
|
|
||||||
let (community, creator, counts, follower) = community::table
|
let (community, counts, follower) = community::table
|
||||||
.find(community_id)
|
.find(community_id)
|
||||||
.inner_join(person::table)
|
|
||||||
.inner_join(community_aggregates::table)
|
.inner_join(community_aggregates::table)
|
||||||
.left_join(
|
.left_join(
|
||||||
community_follower::table.on(
|
community_follower::table.on(
|
||||||
|
@ -59,7 +53,6 @@ impl CommunityView {
|
||||||
)
|
)
|
||||||
.select((
|
.select((
|
||||||
Community::safe_columns_tuple(),
|
Community::safe_columns_tuple(),
|
||||||
Person::safe_columns_tuple(),
|
|
||||||
community_aggregates::all_columns,
|
community_aggregates::all_columns,
|
||||||
community_follower::all_columns.nullable(),
|
community_follower::all_columns.nullable(),
|
||||||
))
|
))
|
||||||
|
@ -67,7 +60,6 @@ impl CommunityView {
|
||||||
|
|
||||||
Ok(CommunityView {
|
Ok(CommunityView {
|
||||||
community,
|
community,
|
||||||
creator,
|
|
||||||
subscribed: follower.is_some(),
|
subscribed: follower.is_some(),
|
||||||
counts,
|
counts,
|
||||||
})
|
})
|
||||||
|
@ -165,7 +157,6 @@ impl<'a> CommunityQueryBuilder<'a> {
|
||||||
let person_id_join = self.my_person_id.unwrap_or(PersonId(-1));
|
let person_id_join = self.my_person_id.unwrap_or(PersonId(-1));
|
||||||
|
|
||||||
let mut query = community::table
|
let mut query = community::table
|
||||||
.inner_join(person::table)
|
|
||||||
.inner_join(community_aggregates::table)
|
.inner_join(community_aggregates::table)
|
||||||
.left_join(
|
.left_join(
|
||||||
community_follower::table.on(
|
community_follower::table.on(
|
||||||
|
@ -176,7 +167,6 @@ impl<'a> CommunityQueryBuilder<'a> {
|
||||||
)
|
)
|
||||||
.select((
|
.select((
|
||||||
Community::safe_columns_tuple(),
|
Community::safe_columns_tuple(),
|
||||||
Person::safe_columns_tuple(),
|
|
||||||
community_aggregates::all_columns,
|
community_aggregates::all_columns,
|
||||||
community_follower::all_columns.nullable(),
|
community_follower::all_columns.nullable(),
|
||||||
))
|
))
|
||||||
|
@ -236,9 +226,8 @@ impl ViewToVec for CommunityView {
|
||||||
.iter()
|
.iter()
|
||||||
.map(|a| Self {
|
.map(|a| Self {
|
||||||
community: a.0.to_owned(),
|
community: a.0.to_owned(),
|
||||||
creator: a.1.to_owned(),
|
counts: a.1.to_owned(),
|
||||||
counts: a.2.to_owned(),
|
subscribed: a.2.is_some(),
|
||||||
subscribed: a.3.is_some(),
|
|
||||||
})
|
})
|
||||||
.collect::<Vec<Self>>()
|
.collect::<Vec<Self>>()
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
|
||||||
|
-- Add the column back
|
||||||
|
alter table community add column creator_id int references person on update cascade on delete cascade;
|
||||||
|
|
||||||
|
-- Recreate the index
|
||||||
|
create index idx_community_creator on community (creator_id);
|
||||||
|
|
||||||
|
-- Add the data, selecting the highest mod
|
||||||
|
update community
|
||||||
|
set creator_id = sub.person_id
|
||||||
|
from (
|
||||||
|
select
|
||||||
|
cm.community_id,
|
||||||
|
cm.person_id
|
||||||
|
from
|
||||||
|
community_moderator cm
|
||||||
|
limit 1
|
||||||
|
) as sub
|
||||||
|
where id = sub.community_id;
|
||||||
|
|
||||||
|
-- Set to not null
|
||||||
|
alter table community alter column creator_id set not null;
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
-- Drop the column
|
||||||
|
alter table community drop column creator_id;
|
|
@ -89,7 +89,6 @@ fn community_updates_2020_04_02(conn: &PgConnection) -> Result<(), LemmyError> {
|
||||||
name: ccommunity.name.to_owned(),
|
name: ccommunity.name.to_owned(),
|
||||||
title: ccommunity.title.to_owned(),
|
title: ccommunity.title.to_owned(),
|
||||||
description: ccommunity.description.to_owned(),
|
description: ccommunity.description.to_owned(),
|
||||||
creator_id: ccommunity.creator_id,
|
|
||||||
removed: None,
|
removed: None,
|
||||||
deleted: None,
|
deleted: None,
|
||||||
nsfw: None,
|
nsfw: None,
|
||||||
|
|
Loading…
Reference in a new issue