mirror of
https://github.com/LemmyNet/lemmy.git
synced 2025-01-05 17:53:48 +00:00
Allow admins to view deleted users (fixes #5249)
This commit is contained in:
parent
8a5daeec97
commit
284569e4de
7 changed files with 34 additions and 20 deletions
|
@ -110,7 +110,7 @@ pub async fn ban_from_community(
|
||||||
|
|
||||||
ModBanFromCommunity::create(&mut context.pool(), &form).await?;
|
ModBanFromCommunity::create(&mut context.pool(), &form).await?;
|
||||||
|
|
||||||
let person_view = PersonView::read(&mut context.pool(), data.person_id).await?;
|
let person_view = PersonView::read(&mut context.pool(), data.person_id, false).await?;
|
||||||
|
|
||||||
ActivityChannel::submit_activity(
|
ActivityChannel::submit_activity(
|
||||||
SendActivityData::BanFromCommunity {
|
SendActivityData::BanFromCommunity {
|
||||||
|
|
|
@ -88,7 +88,7 @@ pub async fn ban_from_site(
|
||||||
|
|
||||||
ModBan::create(&mut context.pool(), &form).await?;
|
ModBan::create(&mut context.pool(), &form).await?;
|
||||||
|
|
||||||
let person_view = PersonView::read(&mut context.pool(), person.id).await?;
|
let person_view = PersonView::read(&mut context.pool(), person.id, false).await?;
|
||||||
|
|
||||||
ban_nonlocal_user_from_local_communities(
|
ban_nonlocal_user_from_local_communities(
|
||||||
&local_user_view,
|
&local_user_view,
|
||||||
|
|
|
@ -48,7 +48,7 @@ pub async fn user_block_person(
|
||||||
.with_lemmy_type(LemmyErrorType::PersonBlockAlreadyExists)?;
|
.with_lemmy_type(LemmyErrorType::PersonBlockAlreadyExists)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let person_view = PersonView::read(&mut context.pool(), target_id).await?;
|
let person_view = PersonView::read(&mut context.pool(), target_id, false).await?;
|
||||||
Ok(Json(BlockPersonResponse {
|
Ok(Json(BlockPersonResponse {
|
||||||
person_view,
|
person_view,
|
||||||
blocked: data.block,
|
blocked: data.block,
|
||||||
|
|
|
@ -4,7 +4,7 @@ use actix_web::web::{Json, Query};
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
person::{GetPersonDetails, GetPersonDetailsResponse},
|
person::{GetPersonDetails, GetPersonDetailsResponse},
|
||||||
utils::{check_private_instance, read_site_for_actor},
|
utils::{check_private_instance, is_admin, read_site_for_actor},
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{source::person::Person, utils::post_to_comment_sort_type};
|
use lemmy_db_schema::{source::person::Person, utils::post_to_comment_sort_type};
|
||||||
use lemmy_db_views::{
|
use lemmy_db_views::{
|
||||||
|
@ -45,7 +45,11 @@ pub async fn read_person(
|
||||||
|
|
||||||
// You don't need to return settings for the user, since this comes back with GetSite
|
// You don't need to return settings for the user, since this comes back with GetSite
|
||||||
// `my_user`
|
// `my_user`
|
||||||
let person_view = PersonView::read(&mut context.pool(), person_details_id).await?;
|
let is_admin = local_user_view
|
||||||
|
.as_ref()
|
||||||
|
.map(|l| is_admin(l).is_ok())
|
||||||
|
.unwrap_or_default();
|
||||||
|
let person_view = PersonView::read(&mut context.pool(), person_details_id, is_admin).await?;
|
||||||
|
|
||||||
let sort = data.sort;
|
let sort = data.sort;
|
||||||
let page = data.page;
|
let page = data.page;
|
||||||
|
|
|
@ -60,7 +60,7 @@ async fn convert_response(
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
SearchableObjects::PersonOrCommunity(pc) => match *pc {
|
SearchableObjects::PersonOrCommunity(pc) => match *pc {
|
||||||
UserOrCommunity::User(u) => res.person = Some(PersonView::read(pool, u.id).await?),
|
UserOrCommunity::User(u) => res.person = Some(PersonView::read(pool, u.id, is_admin).await?),
|
||||||
UserOrCommunity::Community(c) => {
|
UserOrCommunity::Community(c) => {
|
||||||
res.community = Some(CommunityView::read(pool, c.id, local_user.as_ref(), is_admin).await?)
|
res.community = Some(CommunityView::read(pool, c.id, local_user.as_ref(), is_admin).await?)
|
||||||
}
|
}
|
||||||
|
|
|
@ -188,7 +188,7 @@ impl CommunityView {
|
||||||
let is_mod =
|
let is_mod =
|
||||||
CommunityModeratorView::check_is_community_moderator(pool, community_id, person_id).await;
|
CommunityModeratorView::check_is_community_moderator(pool, community_id, person_id).await;
|
||||||
if is_mod.is_ok()
|
if is_mod.is_ok()
|
||||||
|| PersonView::read(pool, person_id)
|
|| PersonView::read(pool, person_id, false)
|
||||||
.await
|
.await
|
||||||
.is_ok_and(|t| t.is_admin)
|
.is_ok_and(|t| t.is_admin)
|
||||||
{
|
{
|
||||||
|
@ -206,7 +206,7 @@ impl CommunityView {
|
||||||
let is_mod_of_any =
|
let is_mod_of_any =
|
||||||
CommunityModeratorView::is_community_moderator_of_any(pool, person_id).await;
|
CommunityModeratorView::is_community_moderator_of_any(pool, person_id).await;
|
||||||
if is_mod_of_any.is_ok()
|
if is_mod_of_any.is_ok()
|
||||||
|| PersonView::read(pool, person_id)
|
|| PersonView::read(pool, person_id, false)
|
||||||
.await
|
.await
|
||||||
.is_ok_and(|t| t.is_admin)
|
.is_ok_and(|t| t.is_admin)
|
||||||
{
|
{
|
||||||
|
|
|
@ -58,12 +58,11 @@ fn post_to_person_sort_type(sort: PostSortType) -> PersonSortType {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn queries<'a>(
|
fn queries<'a>(
|
||||||
) -> Queries<impl ReadFn<'a, PersonView, PersonId>, impl ListFn<'a, PersonView, ListMode>> {
|
) -> Queries<impl ReadFn<'a, PersonView, (PersonId, bool)>, impl ListFn<'a, PersonView, ListMode>> {
|
||||||
let all_joins = move |query: person::BoxedQuery<'a, Pg>| {
|
let all_joins = move |query: person::BoxedQuery<'a, Pg>| {
|
||||||
query
|
query
|
||||||
.inner_join(person_aggregates::table)
|
.inner_join(person_aggregates::table)
|
||||||
.left_join(local_user::table)
|
.left_join(local_user::table)
|
||||||
.filter(person::deleted.eq(false))
|
|
||||||
.select((
|
.select((
|
||||||
person::all_columns,
|
person::all_columns,
|
||||||
person_aggregates::all_columns,
|
person_aggregates::all_columns,
|
||||||
|
@ -71,14 +70,17 @@ fn queries<'a>(
|
||||||
))
|
))
|
||||||
};
|
};
|
||||||
|
|
||||||
let read = move |mut conn: DbConn<'a>, person_id: PersonId| async move {
|
let read = move |mut conn: DbConn<'a>, params: (PersonId, bool)| async move {
|
||||||
all_joins(person::table.find(person_id).into_boxed())
|
let (person_id, is_admin) = params;
|
||||||
.first(&mut conn)
|
let mut query = all_joins(person::table.find(person_id).into_boxed());
|
||||||
.await
|
if !is_admin {
|
||||||
|
query = query.filter(person::deleted.eq(false));
|
||||||
|
}
|
||||||
|
query.first(&mut conn).await
|
||||||
};
|
};
|
||||||
|
|
||||||
let list = move |mut conn: DbConn<'a>, mode: ListMode| async move {
|
let list = move |mut conn: DbConn<'a>, mode: ListMode| async move {
|
||||||
let mut query = all_joins(person::table.into_boxed());
|
let mut query = all_joins(person::table.into_boxed()).filter(person::deleted.eq(false));
|
||||||
match mode {
|
match mode {
|
||||||
ListMode::Admins => {
|
ListMode::Admins => {
|
||||||
query = query
|
query = query
|
||||||
|
@ -135,8 +137,12 @@ fn queries<'a>(
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PersonView {
|
impl PersonView {
|
||||||
pub async fn read(pool: &mut DbPool<'_>, person_id: PersonId) -> Result<Self, Error> {
|
pub async fn read(
|
||||||
queries().read(pool, person_id).await
|
pool: &mut DbPool<'_>,
|
||||||
|
person_id: PersonId,
|
||||||
|
is_admin: bool,
|
||||||
|
) -> Result<Self, Error> {
|
||||||
|
queries().read(pool, (person_id, is_admin)).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn admins(pool: &mut DbPool<'_>) -> Result<Vec<Self>, Error> {
|
pub async fn admins(pool: &mut DbPool<'_>) -> Result<Vec<Self>, Error> {
|
||||||
|
@ -243,9 +249,13 @@ mod tests {
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let read = PersonView::read(pool, data.alice.id).await;
|
let read = PersonView::read(pool, data.alice.id, false).await;
|
||||||
assert!(read.is_err());
|
assert!(read.is_err());
|
||||||
|
|
||||||
|
// only admin can view deleted users
|
||||||
|
let read = PersonView::read(pool, data.alice.id, true).await;
|
||||||
|
assert!(read.is_ok());
|
||||||
|
|
||||||
let list = PersonQuery {
|
let list = PersonQuery {
|
||||||
sort: Some(PostSortType::New),
|
sort: Some(PostSortType::New),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
|
@ -303,10 +313,10 @@ mod tests {
|
||||||
assert_length!(1, list);
|
assert_length!(1, list);
|
||||||
assert_eq!(list[0].person.id, data.alice.id);
|
assert_eq!(list[0].person.id, data.alice.id);
|
||||||
|
|
||||||
let is_admin = PersonView::read(pool, data.alice.id).await?.is_admin;
|
let is_admin = PersonView::read(pool, data.alice.id, false).await?.is_admin;
|
||||||
assert!(is_admin);
|
assert!(is_admin);
|
||||||
|
|
||||||
let is_admin = PersonView::read(pool, data.bob.id).await?.is_admin;
|
let is_admin = PersonView::read(pool, data.bob.id, false).await?.is_admin;
|
||||||
assert!(!is_admin);
|
assert!(!is_admin);
|
||||||
|
|
||||||
cleanup(data, pool).await
|
cleanup(data, pool).await
|
||||||
|
|
Loading…
Reference in a new issue