Adding site to GetPersonDetails. Fixes #4373 (#4394)

* Adding site to GetPersonDetails. Fixes #4373

* Removing the conditioned site return.
This commit is contained in:
Dessalines 2024-01-24 04:32:14 -05:00 committed by GitHub
parent 4b4b99aa78
commit eb56d9253c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 21 additions and 12 deletions

View file

@ -1,6 +1,7 @@
use crate::sensitive::Sensitive;
use lemmy_db_schema::{
newtypes::{CommentReplyId, CommunityId, LanguageId, PersonId, PersonMentionId},
source::site::Site,
CommentSortType,
ListingType,
PostListingMode,
@ -178,6 +179,7 @@ pub struct GetPersonDetails {
/// A person's details response.
pub struct GetPersonDetailsResponse {
pub person_view: PersonView,
pub site: Option<Site>,
pub comments: Vec<CommentView>,
pub posts: Vec<PostView>,
pub moderates: Vec<CommunityModeratorView>,

View file

@ -20,6 +20,7 @@ use lemmy_db_schema::{
person::{Person, PersonUpdateForm},
person_block::PersonBlock,
post::{Post, PostRead},
site::Site,
},
traits::Crud,
utils::DbPool,
@ -566,6 +567,18 @@ pub fn check_private_instance_and_federation_enabled(
}
}
/// Read the site for an actor_id.
///
/// Used for GetCommunityResponse and GetPersonDetails
pub async fn read_site_for_actor(
actor_id: DbUrl,
context: &LemmyContext,
) -> Result<Option<Site>, LemmyError> {
let site_id = Site::instance_actor_id_from_url(actor_id.clone().into());
let site = Site::read_from_apub_id(&mut context.pool(), &site_id.into()).await?;
Ok(site)
}
pub async fn purge_image_posts_for_person(
banned_person_id: PersonId,
context: &LemmyContext,

View file

@ -4,13 +4,12 @@ use actix_web::web::{Json, Query};
use lemmy_api_common::{
community::{GetCommunity, GetCommunityResponse},
context::LemmyContext,
utils::{check_private_instance, is_mod_or_admin_opt},
utils::{check_private_instance, is_mod_or_admin_opt, read_site_for_actor},
};
use lemmy_db_schema::source::{
actor_language::CommunityLanguage,
community::Community,
local_site::LocalSite,
site::Site,
};
use lemmy_db_views::structs::LocalUserView;
use lemmy_db_views_actor::structs::{CommunityModeratorView, CommunityView};
@ -64,15 +63,7 @@ pub async fn get_community(
.await
.with_lemmy_type(LemmyErrorType::CouldntFindCommunity)?;
let site_id = Site::instance_actor_id_from_url(community_view.community.actor_id.clone().into());
let mut site = Site::read_from_apub_id(&mut context.pool(), &site_id.into()).await?;
// no need to include metadata for local site (its already available through other endpoints).
// this also prevents us from leaking the federation private key.
if let Some(s) = &site {
if s.actor_id.domain() == Some(context.settings().hostname.as_ref()) {
site = None;
}
}
let site = read_site_for_actor(community_view.community.actor_id.clone(), &context).await?;
let community_id = community_view.community.id;
let discussion_languages = CommunityLanguage::read(&mut context.pool(), community_id).await?;

View file

@ -4,7 +4,7 @@ use actix_web::web::{Json, Query};
use lemmy_api_common::{
context::LemmyContext,
person::{GetPersonDetails, GetPersonDetailsResponse},
utils::check_private_instance,
utils::{check_private_instance, read_site_for_actor},
};
use lemmy_db_schema::{
source::{local_site::LocalSite, person::Person},
@ -89,9 +89,12 @@ pub async fn read_person(
let moderates =
CommunityModeratorView::for_person(&mut context.pool(), person_details_id).await?;
let site = read_site_for_actor(person_view.person.actor_id.clone(), &context).await?;
// Return the jwt
Ok(Json(GetPersonDetailsResponse {
person_view,
site,
moderates,
comments,
posts,