mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-26 19:31:05 +00:00
* Adding site to GetPersonDetails. Fixes #4373 * Removing the conditioned site return.
This commit is contained in:
parent
4b4b99aa78
commit
eb56d9253c
4 changed files with 21 additions and 12 deletions
|
@ -1,6 +1,7 @@
|
||||||
use crate::sensitive::Sensitive;
|
use crate::sensitive::Sensitive;
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
newtypes::{CommentReplyId, CommunityId, LanguageId, PersonId, PersonMentionId},
|
newtypes::{CommentReplyId, CommunityId, LanguageId, PersonId, PersonMentionId},
|
||||||
|
source::site::Site,
|
||||||
CommentSortType,
|
CommentSortType,
|
||||||
ListingType,
|
ListingType,
|
||||||
PostListingMode,
|
PostListingMode,
|
||||||
|
@ -178,6 +179,7 @@ pub struct GetPersonDetails {
|
||||||
/// A person's details response.
|
/// A person's details response.
|
||||||
pub struct GetPersonDetailsResponse {
|
pub struct GetPersonDetailsResponse {
|
||||||
pub person_view: PersonView,
|
pub person_view: PersonView,
|
||||||
|
pub site: Option<Site>,
|
||||||
pub comments: Vec<CommentView>,
|
pub comments: Vec<CommentView>,
|
||||||
pub posts: Vec<PostView>,
|
pub posts: Vec<PostView>,
|
||||||
pub moderates: Vec<CommunityModeratorView>,
|
pub moderates: Vec<CommunityModeratorView>,
|
||||||
|
|
|
@ -20,6 +20,7 @@ use lemmy_db_schema::{
|
||||||
person::{Person, PersonUpdateForm},
|
person::{Person, PersonUpdateForm},
|
||||||
person_block::PersonBlock,
|
person_block::PersonBlock,
|
||||||
post::{Post, PostRead},
|
post::{Post, PostRead},
|
||||||
|
site::Site,
|
||||||
},
|
},
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
utils::DbPool,
|
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(
|
pub async fn purge_image_posts_for_person(
|
||||||
banned_person_id: PersonId,
|
banned_person_id: PersonId,
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
|
|
|
@ -4,13 +4,12 @@ use actix_web::web::{Json, Query};
|
||||||
use lemmy_api_common::{
|
use lemmy_api_common::{
|
||||||
community::{GetCommunity, GetCommunityResponse},
|
community::{GetCommunity, GetCommunityResponse},
|
||||||
context::LemmyContext,
|
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::{
|
use lemmy_db_schema::source::{
|
||||||
actor_language::CommunityLanguage,
|
actor_language::CommunityLanguage,
|
||||||
community::Community,
|
community::Community,
|
||||||
local_site::LocalSite,
|
local_site::LocalSite,
|
||||||
site::Site,
|
|
||||||
};
|
};
|
||||||
use lemmy_db_views::structs::LocalUserView;
|
use lemmy_db_views::structs::LocalUserView;
|
||||||
use lemmy_db_views_actor::structs::{CommunityModeratorView, CommunityView};
|
use lemmy_db_views_actor::structs::{CommunityModeratorView, CommunityView};
|
||||||
|
@ -64,15 +63,7 @@ pub async fn get_community(
|
||||||
.await
|
.await
|
||||||
.with_lemmy_type(LemmyErrorType::CouldntFindCommunity)?;
|
.with_lemmy_type(LemmyErrorType::CouldntFindCommunity)?;
|
||||||
|
|
||||||
let site_id = Site::instance_actor_id_from_url(community_view.community.actor_id.clone().into());
|
let site = read_site_for_actor(community_view.community.actor_id.clone(), &context).await?;
|
||||||
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 community_id = community_view.community.id;
|
let community_id = community_view.community.id;
|
||||||
let discussion_languages = CommunityLanguage::read(&mut context.pool(), community_id).await?;
|
let discussion_languages = CommunityLanguage::read(&mut context.pool(), community_id).await?;
|
||||||
|
|
|
@ -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,
|
utils::{check_private_instance, read_site_for_actor},
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::{local_site::LocalSite, person::Person},
|
source::{local_site::LocalSite, person::Person},
|
||||||
|
@ -89,9 +89,12 @@ pub async fn read_person(
|
||||||
let moderates =
|
let moderates =
|
||||||
CommunityModeratorView::for_person(&mut context.pool(), person_details_id).await?;
|
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
|
// Return the jwt
|
||||||
Ok(Json(GetPersonDetailsResponse {
|
Ok(Json(GetPersonDetailsResponse {
|
||||||
person_view,
|
person_view,
|
||||||
|
site,
|
||||||
moderates,
|
moderates,
|
||||||
comments,
|
comments,
|
||||||
posts,
|
posts,
|
||||||
|
|
Loading…
Reference in a new issue