mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-21 22:27:08 +00:00
Make sure you can view your moderated deleted and removed communities. (#4912)
* Make sure you can view your moderated deleted and removed communities. - The front end checks to see whether you are a mod, in order to be able to restore deleted / removed communities. This removes a filter which prevents that. - Fixes #4911 * Only show deleted communities to creator, and removed to admins. * Addressing PR comments.
This commit is contained in:
parent
db390a2f3a
commit
32b73193df
|
@ -84,7 +84,7 @@ pub async fn get_site(
|
||||||
|pool| CommunityBlockView::for_person(pool, person_id),
|
|pool| CommunityBlockView::for_person(pool, person_id),
|
||||||
|pool| InstanceBlockView::for_person(pool, person_id),
|
|pool| InstanceBlockView::for_person(pool, person_id),
|
||||||
|pool| PersonBlockView::for_person(pool, person_id),
|
|pool| PersonBlockView::for_person(pool, person_id),
|
||||||
|pool| CommunityModeratorView::for_person(pool, person_id, true),
|
|pool| CommunityModeratorView::for_person(pool, person_id, Some(&local_user_view.local_user)),
|
||||||
|pool| LocalUserLanguage::read(pool, local_user_id)
|
|pool| LocalUserLanguage::read(pool, local_user_id)
|
||||||
))
|
))
|
||||||
.with_lemmy_type(LemmyErrorType::SystemErrLogin)?;
|
.with_lemmy_type(LemmyErrorType::SystemErrLogin)?;
|
||||||
|
|
|
@ -96,7 +96,7 @@ pub async fn read_person(
|
||||||
let moderates = CommunityModeratorView::for_person(
|
let moderates = CommunityModeratorView::for_person(
|
||||||
&mut context.pool(),
|
&mut context.pool(),
|
||||||
person_details_id,
|
person_details_id,
|
||||||
local_user_view.is_some(),
|
local_user_view.map(|l| l.local_user).as_ref(),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
|
|
@ -2,10 +2,11 @@ use crate::structs::CommunityModeratorView;
|
||||||
use diesel::{dsl::exists, result::Error, select, ExpressionMethods, QueryDsl};
|
use diesel::{dsl::exists, result::Error, select, ExpressionMethods, QueryDsl};
|
||||||
use diesel_async::RunQueryDsl;
|
use diesel_async::RunQueryDsl;
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
|
impls::local_user::LocalUserOptionHelper,
|
||||||
newtypes::{CommunityId, PersonId},
|
newtypes::{CommunityId, PersonId},
|
||||||
schema::{community, community_moderator, person},
|
schema::{community, community_moderator, person},
|
||||||
|
source::local_user::LocalUser,
|
||||||
utils::{get_conn, DbPool},
|
utils::{get_conn, DbPool},
|
||||||
CommunityVisibility,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
impl CommunityModeratorView {
|
impl CommunityModeratorView {
|
||||||
|
@ -60,20 +61,28 @@ impl CommunityModeratorView {
|
||||||
pub async fn for_person(
|
pub async fn for_person(
|
||||||
pool: &mut DbPool<'_>,
|
pool: &mut DbPool<'_>,
|
||||||
person_id: PersonId,
|
person_id: PersonId,
|
||||||
is_authenticated: bool,
|
local_user: Option<&LocalUser>,
|
||||||
) -> Result<Vec<Self>, Error> {
|
) -> Result<Vec<Self>, Error> {
|
||||||
let conn = &mut get_conn(pool).await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
let mut query = community_moderator::table
|
let mut query = community_moderator::table
|
||||||
.inner_join(community::table)
|
.inner_join(community::table)
|
||||||
.inner_join(person::table)
|
.inner_join(person::table)
|
||||||
.filter(community_moderator::person_id.eq(person_id))
|
.filter(community_moderator::person_id.eq(person_id))
|
||||||
.filter(community::deleted.eq(false))
|
|
||||||
.filter(community::removed.eq(false))
|
|
||||||
.select((community::all_columns, person::all_columns))
|
.select((community::all_columns, person::all_columns))
|
||||||
.into_boxed();
|
.into_boxed();
|
||||||
if !is_authenticated {
|
|
||||||
query = query.filter(community::visibility.eq(CommunityVisibility::Public));
|
query = local_user.visible_communities_only(query);
|
||||||
|
|
||||||
|
// only show deleted communities to creator
|
||||||
|
if Some(person_id) != local_user.person_id() {
|
||||||
|
query = query.filter(community::deleted.eq(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Show removed communities to admins only
|
||||||
|
if !local_user.is_admin() {
|
||||||
|
query = query.filter(community::removed.eq(false))
|
||||||
|
}
|
||||||
|
|
||||||
query.load::<CommunityModeratorView>(conn).await
|
query.load::<CommunityModeratorView>(conn).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue