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:
Dessalines 2024-07-23 12:38:54 -04:00 committed by GitHub
parent db390a2f3a
commit 32b73193df
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 17 additions and 8 deletions

View File

@ -84,7 +84,7 @@ pub async fn get_site(
|pool| CommunityBlockView::for_person(pool, person_id),
|pool| InstanceBlockView::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)
))
.with_lemmy_type(LemmyErrorType::SystemErrLogin)?;

View File

@ -96,7 +96,7 @@ pub async fn read_person(
let moderates = CommunityModeratorView::for_person(
&mut context.pool(),
person_details_id,
local_user_view.is_some(),
local_user_view.map(|l| l.local_user).as_ref(),
)
.await?;

View File

@ -2,10 +2,11 @@ use crate::structs::CommunityModeratorView;
use diesel::{dsl::exists, result::Error, select, ExpressionMethods, QueryDsl};
use diesel_async::RunQueryDsl;
use lemmy_db_schema::{
impls::local_user::LocalUserOptionHelper,
newtypes::{CommunityId, PersonId},
schema::{community, community_moderator, person},
source::local_user::LocalUser,
utils::{get_conn, DbPool},
CommunityVisibility,
};
impl CommunityModeratorView {
@ -60,20 +61,28 @@ impl CommunityModeratorView {
pub async fn for_person(
pool: &mut DbPool<'_>,
person_id: PersonId,
is_authenticated: bool,
local_user: Option<&LocalUser>,
) -> Result<Vec<Self>, Error> {
let conn = &mut get_conn(pool).await?;
let mut query = community_moderator::table
.inner_join(community::table)
.inner_join(person::table)
.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))
.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
}