mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-26 14:21:19 +00:00
compiling
This commit is contained in:
parent
c521a92914
commit
d106144ac6
116 changed files with 287 additions and 682 deletions
|
@ -22,8 +22,7 @@ pub async fn distinguish_comment(
|
||||||
data.comment_id,
|
data.comment_id,
|
||||||
Some(&local_user_view.local_user),
|
Some(&local_user_view.local_user),
|
||||||
)
|
)
|
||||||
.await?
|
.await?;
|
||||||
.ok_or(LemmyErrorType::CouldntFindComment)?;
|
|
||||||
|
|
||||||
check_community_user_action(
|
check_community_user_action(
|
||||||
&local_user_view.person,
|
&local_user_view.person,
|
||||||
|
@ -60,8 +59,7 @@ pub async fn distinguish_comment(
|
||||||
data.comment_id,
|
data.comment_id,
|
||||||
Some(&local_user_view.local_user),
|
Some(&local_user_view.local_user),
|
||||||
)
|
)
|
||||||
.await?
|
.await?;
|
||||||
.ok_or(LemmyErrorType::CouldntFindComment)?;
|
|
||||||
|
|
||||||
Ok(Json(CommentResponse {
|
Ok(Json(CommentResponse {
|
||||||
comment_view,
|
comment_view,
|
||||||
|
|
|
@ -40,8 +40,7 @@ pub async fn like_comment(
|
||||||
comment_id,
|
comment_id,
|
||||||
Some(&local_user_view.local_user),
|
Some(&local_user_view.local_user),
|
||||||
)
|
)
|
||||||
.await?
|
.await?;
|
||||||
.ok_or(LemmyErrorType::CouldntFindComment)?;
|
|
||||||
|
|
||||||
check_community_user_action(
|
check_community_user_action(
|
||||||
&local_user_view.person,
|
&local_user_view.person,
|
||||||
|
@ -54,8 +53,7 @@ pub async fn like_comment(
|
||||||
let comment_reply = CommentReply::read_by_comment(&mut context.pool(), comment_id).await;
|
let comment_reply = CommentReply::read_by_comment(&mut context.pool(), comment_id).await;
|
||||||
if let Ok(Some(reply)) = comment_reply {
|
if let Ok(Some(reply)) = comment_reply {
|
||||||
let recipient_id = reply.recipient_id;
|
let recipient_id = reply.recipient_id;
|
||||||
if let Ok(Some(local_recipient)) =
|
if let Ok(local_recipient) = LocalUserView::read_person(&mut context.pool(), recipient_id).await
|
||||||
LocalUserView::read_person(&mut context.pool(), recipient_id).await
|
|
||||||
{
|
{
|
||||||
recipient_ids.push(local_recipient.local_user.id);
|
recipient_ids.push(local_recipient.local_user.id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ use lemmy_api_common::{
|
||||||
utils::is_mod_or_admin,
|
utils::is_mod_or_admin,
|
||||||
};
|
};
|
||||||
use lemmy_db_views::structs::{CommentView, LocalUserView, VoteView};
|
use lemmy_db_views::structs::{CommentView, LocalUserView, VoteView};
|
||||||
use lemmy_utils::{error::LemmyResult, LemmyErrorType};
|
use lemmy_utils::error::LemmyResult;
|
||||||
|
|
||||||
/// Lists likes for a comment
|
/// Lists likes for a comment
|
||||||
#[tracing::instrument(skip(context))]
|
#[tracing::instrument(skip(context))]
|
||||||
|
@ -19,8 +19,7 @@ pub async fn list_comment_likes(
|
||||||
data.comment_id,
|
data.comment_id,
|
||||||
Some(&local_user_view.local_user),
|
Some(&local_user_view.local_user),
|
||||||
)
|
)
|
||||||
.await?
|
.await?;
|
||||||
.ok_or(LemmyErrorType::CouldntFindComment)?;
|
|
||||||
|
|
||||||
is_mod_or_admin(
|
is_mod_or_admin(
|
||||||
&mut context.pool(),
|
&mut context.pool(),
|
||||||
|
|
|
@ -37,8 +37,7 @@ pub async fn save_comment(
|
||||||
comment_id,
|
comment_id,
|
||||||
Some(&local_user_view.local_user),
|
Some(&local_user_view.local_user),
|
||||||
)
|
)
|
||||||
.await?
|
.await?;
|
||||||
.ok_or(LemmyErrorType::CouldntFindComment)?;
|
|
||||||
|
|
||||||
Ok(Json(CommentResponse {
|
Ok(Json(CommentResponse {
|
||||||
comment_view,
|
comment_view,
|
||||||
|
|
|
@ -40,8 +40,7 @@ pub async fn create_comment_report(
|
||||||
comment_id,
|
comment_id,
|
||||||
Some(&local_user_view.local_user),
|
Some(&local_user_view.local_user),
|
||||||
)
|
)
|
||||||
.await?
|
.await?;
|
||||||
.ok_or(LemmyErrorType::CouldntFindComment)?;
|
|
||||||
|
|
||||||
check_community_user_action(
|
check_community_user_action(
|
||||||
&local_user_view.person,
|
&local_user_view.person,
|
||||||
|
@ -64,9 +63,8 @@ pub async fn create_comment_report(
|
||||||
.await
|
.await
|
||||||
.with_lemmy_type(LemmyErrorType::CouldntCreateReport)?;
|
.with_lemmy_type(LemmyErrorType::CouldntCreateReport)?;
|
||||||
|
|
||||||
let comment_report_view = CommentReportView::read(&mut context.pool(), report.id, person_id)
|
let comment_report_view =
|
||||||
.await?
|
CommentReportView::read(&mut context.pool(), report.id, person_id).await?;
|
||||||
.ok_or(LemmyErrorType::CouldntFindCommentReport)?;
|
|
||||||
|
|
||||||
// Email the admins
|
// Email the admins
|
||||||
if local_site.reports_email_admins {
|
if local_site.reports_email_admins {
|
||||||
|
|
|
@ -17,9 +17,7 @@ pub async fn resolve_comment_report(
|
||||||
) -> LemmyResult<Json<CommentReportResponse>> {
|
) -> LemmyResult<Json<CommentReportResponse>> {
|
||||||
let report_id = data.report_id;
|
let report_id = data.report_id;
|
||||||
let person_id = local_user_view.person.id;
|
let person_id = local_user_view.person.id;
|
||||||
let report = CommentReportView::read(&mut context.pool(), report_id, person_id)
|
let report = CommentReportView::read(&mut context.pool(), report_id, person_id).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindCommentReport)?;
|
|
||||||
|
|
||||||
let person_id = local_user_view.person.id;
|
let person_id = local_user_view.person.id;
|
||||||
check_community_mod_action(
|
check_community_mod_action(
|
||||||
|
@ -41,9 +39,8 @@ pub async fn resolve_comment_report(
|
||||||
}
|
}
|
||||||
|
|
||||||
let report_id = data.report_id;
|
let report_id = data.report_id;
|
||||||
let comment_report_view = CommentReportView::read(&mut context.pool(), report_id, person_id)
|
let comment_report_view =
|
||||||
.await?
|
CommentReportView::read(&mut context.pool(), report_id, person_id).await?;
|
||||||
.ok_or(LemmyErrorType::CouldntFindCommentReport)?;
|
|
||||||
|
|
||||||
Ok(Json(CommentReportResponse {
|
Ok(Json(CommentReportResponse {
|
||||||
comment_report_view,
|
comment_report_view,
|
||||||
|
|
|
@ -46,9 +46,7 @@ pub async fn add_mod_to_community(
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let community = Community::read(&mut context.pool(), community_id)
|
let community = Community::read(&mut context.pool(), community_id).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindCommunity)?;
|
|
||||||
|
|
||||||
// If user is admin and community is remote, explicitly check that he is a
|
// If user is admin and community is remote, explicitly check that he is a
|
||||||
// moderator. This is necessary because otherwise the action would be rejected
|
// moderator. This is necessary because otherwise the action would be rejected
|
||||||
|
|
|
@ -111,9 +111,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)
|
let person_view = PersonView::read(&mut context.pool(), data.person_id).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindPerson)?;
|
|
||||||
|
|
||||||
ActivityChannel::submit_activity(
|
ActivityChannel::submit_activity(
|
||||||
SendActivityData::BanFromCommunity {
|
SendActivityData::BanFromCommunity {
|
||||||
|
|
|
@ -56,8 +56,7 @@ pub async fn block_community(
|
||||||
Some(&local_user_view.local_user),
|
Some(&local_user_view.local_user),
|
||||||
false,
|
false,
|
||||||
)
|
)
|
||||||
.await?
|
.await?;
|
||||||
.ok_or(LemmyErrorType::CouldntFindCommunity)?;
|
|
||||||
|
|
||||||
ActivityChannel::submit_activity(
|
ActivityChannel::submit_activity(
|
||||||
SendActivityData::FollowCommunity(
|
SendActivityData::FollowCommunity(
|
||||||
|
|
|
@ -23,9 +23,7 @@ pub async fn follow_community(
|
||||||
context: Data<LemmyContext>,
|
context: Data<LemmyContext>,
|
||||||
local_user_view: LocalUserView,
|
local_user_view: LocalUserView,
|
||||||
) -> LemmyResult<Json<CommunityResponse>> {
|
) -> LemmyResult<Json<CommunityResponse>> {
|
||||||
let community = Community::read(&mut context.pool(), data.community_id)
|
let community = Community::read(&mut context.pool(), data.community_id).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindCommunity)?;
|
|
||||||
let mut community_follower_form = CommunityFollowerForm {
|
let mut community_follower_form = CommunityFollowerForm {
|
||||||
community_id: community.id,
|
community_id: community.id,
|
||||||
person_id: local_user_view.person.id,
|
person_id: local_user_view.person.id,
|
||||||
|
@ -68,8 +66,7 @@ pub async fn follow_community(
|
||||||
Some(&local_user_view.local_user),
|
Some(&local_user_view.local_user),
|
||||||
false,
|
false,
|
||||||
)
|
)
|
||||||
.await?
|
.await?;
|
||||||
.ok_or(LemmyErrorType::CouldntFindCommunity)?;
|
|
||||||
|
|
||||||
let discussion_languages = CommunityLanguage::read(&mut context.pool(), community_id).await?;
|
let discussion_languages = CommunityLanguage::read(&mut context.pool(), community_id).await?;
|
||||||
|
|
||||||
|
|
|
@ -82,13 +82,10 @@ pub async fn transfer_community(
|
||||||
Some(&local_user_view.local_user),
|
Some(&local_user_view.local_user),
|
||||||
false,
|
false,
|
||||||
)
|
)
|
||||||
.await?
|
.await?;
|
||||||
.ok_or(LemmyErrorType::CouldntFindCommunity)?;
|
|
||||||
|
|
||||||
let community_id = data.community_id;
|
let community_id = data.community_id;
|
||||||
let moderators = CommunityModeratorView::for_community(&mut context.pool(), community_id)
|
let moderators = CommunityModeratorView::for_community(&mut context.pool(), community_id).await?;
|
||||||
.await
|
|
||||||
.with_lemmy_type(LemmyErrorType::CouldntFindCommunity)?;
|
|
||||||
|
|
||||||
// Return the jwt
|
// Return the jwt
|
||||||
Ok(Json(GetCommunityResponse {
|
Ok(Json(GetCommunityResponse {
|
||||||
|
|
|
@ -258,9 +258,7 @@ pub async fn local_user_view_from_jwt(
|
||||||
let local_user_id = Claims::validate(jwt, context)
|
let local_user_id = Claims::validate(jwt, context)
|
||||||
.await
|
.await
|
||||||
.with_lemmy_type(LemmyErrorType::NotLoggedIn)?;
|
.with_lemmy_type(LemmyErrorType::NotLoggedIn)?;
|
||||||
let local_user_view = LocalUserView::read(&mut context.pool(), local_user_id)
|
let local_user_view = LocalUserView::read(&mut context.pool(), local_user_id).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindLocalUser)?;
|
|
||||||
check_user_valid(&local_user_view.person)?;
|
check_user_valid(&local_user_view.person)?;
|
||||||
|
|
||||||
Ok(local_user_view)
|
Ok(local_user_view)
|
||||||
|
|
|
@ -36,8 +36,8 @@ pub async fn add_admin(
|
||||||
|
|
||||||
// Make sure that the person_id added is local
|
// Make sure that the person_id added is local
|
||||||
let added_local_user = LocalUserView::read_person(&mut context.pool(), data.person_id)
|
let added_local_user = LocalUserView::read_person(&mut context.pool(), data.person_id)
|
||||||
.await?
|
.await
|
||||||
.ok_or(LemmyErrorType::ObjectNotLocal)?;
|
.map_err(|_| LemmyErrorType::ObjectNotLocal)?;
|
||||||
|
|
||||||
LocalUser::update(
|
LocalUser::update(
|
||||||
&mut context.pool(),
|
&mut context.pool(),
|
||||||
|
|
|
@ -60,7 +60,7 @@ pub async fn ban_from_site(
|
||||||
|
|
||||||
// if its a local user, invalidate logins
|
// if its a local user, invalidate logins
|
||||||
let local_user = LocalUserView::read_person(&mut context.pool(), person.id).await;
|
let local_user = LocalUserView::read_person(&mut context.pool(), person.id).await;
|
||||||
if let Ok(Some(local_user)) = local_user {
|
if let Ok(local_user) = local_user {
|
||||||
LoginToken::invalidate_all(&mut context.pool(), local_user.local_user.id).await?;
|
LoginToken::invalidate_all(&mut context.pool(), local_user.local_user.id).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,9 +84,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)
|
let person_view = PersonView::read(&mut context.pool(), person.id).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindPerson)?;
|
|
||||||
|
|
||||||
ban_nonlocal_user_from_local_communities(
|
ban_nonlocal_user_from_local_communities(
|
||||||
&local_user_view,
|
&local_user_view,
|
||||||
|
|
|
@ -32,8 +32,7 @@ pub async fn block_person(
|
||||||
|
|
||||||
let target_user = LocalUserView::read_person(&mut context.pool(), target_id)
|
let target_user = LocalUserView::read_person(&mut context.pool(), target_id)
|
||||||
.await
|
.await
|
||||||
.ok()
|
.ok();
|
||||||
.flatten();
|
|
||||||
|
|
||||||
if target_user.is_some_and(|t| t.local_user.admin) {
|
if target_user.is_some_and(|t| t.local_user.admin) {
|
||||||
Err(LemmyErrorType::CantBlockAdmin)?
|
Err(LemmyErrorType::CantBlockAdmin)?
|
||||||
|
@ -49,9 +48,7 @@ pub async fn block_person(
|
||||||
.with_lemmy_type(LemmyErrorType::PersonBlockAlreadyExists)?;
|
.with_lemmy_type(LemmyErrorType::PersonBlockAlreadyExists)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let person_view = PersonView::read(&mut context.pool(), target_id)
|
let person_view = PersonView::read(&mut context.pool(), target_id).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindPerson)?;
|
|
||||||
Ok(Json(BlockPersonResponse {
|
Ok(Json(BlockPersonResponse {
|
||||||
person_view,
|
person_view,
|
||||||
blocked: data.block,
|
blocked: data.block,
|
||||||
|
|
|
@ -21,7 +21,6 @@ pub async fn change_password_after_reset(
|
||||||
let token = data.token.clone();
|
let token = data.token.clone();
|
||||||
let local_user_id = PasswordResetRequest::read_and_delete(&mut context.pool(), &token)
|
let local_user_id = PasswordResetRequest::read_and_delete(&mut context.pool(), &token)
|
||||||
.await?
|
.await?
|
||||||
.ok_or(LemmyErrorType::TokenNotFound)?
|
|
||||||
.local_user_id;
|
.local_user_id;
|
||||||
|
|
||||||
password_length_check(&data.password)?;
|
password_length_check(&data.password)?;
|
||||||
|
|
|
@ -24,9 +24,7 @@ pub async fn login(
|
||||||
// Fetch that username / email
|
// Fetch that username / email
|
||||||
let username_or_email = data.username_or_email.clone();
|
let username_or_email = data.username_or_email.clone();
|
||||||
let local_user_view =
|
let local_user_view =
|
||||||
LocalUserView::find_by_email_or_name(&mut context.pool(), &username_or_email)
|
LocalUserView::find_by_email_or_name(&mut context.pool(), &username_or_email).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::IncorrectLogin)?;
|
|
||||||
|
|
||||||
// Verify the password
|
// Verify the password
|
||||||
let valid: bool = local_user_view
|
let valid: bool = local_user_view
|
||||||
|
|
|
@ -18,9 +18,7 @@ pub async fn mark_person_mention_as_read(
|
||||||
local_user_view: LocalUserView,
|
local_user_view: LocalUserView,
|
||||||
) -> LemmyResult<Json<PersonMentionResponse>> {
|
) -> LemmyResult<Json<PersonMentionResponse>> {
|
||||||
let person_mention_id = data.person_mention_id;
|
let person_mention_id = data.person_mention_id;
|
||||||
let read_person_mention = PersonMention::read(&mut context.pool(), person_mention_id)
|
let read_person_mention = PersonMention::read(&mut context.pool(), person_mention_id).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindPersonMention)?;
|
|
||||||
|
|
||||||
if local_user_view.person.id != read_person_mention.recipient_id {
|
if local_user_view.person.id != read_person_mention.recipient_id {
|
||||||
Err(LemmyErrorType::CouldntUpdateComment)?
|
Err(LemmyErrorType::CouldntUpdateComment)?
|
||||||
|
@ -39,9 +37,7 @@ pub async fn mark_person_mention_as_read(
|
||||||
let person_mention_id = read_person_mention.id;
|
let person_mention_id = read_person_mention.id;
|
||||||
let person_id = local_user_view.person.id;
|
let person_id = local_user_view.person.id;
|
||||||
let person_mention_view =
|
let person_mention_view =
|
||||||
PersonMentionView::read(&mut context.pool(), person_mention_id, Some(person_id))
|
PersonMentionView::read(&mut context.pool(), person_mention_id, Some(person_id)).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindPersonMention)?;
|
|
||||||
|
|
||||||
Ok(Json(PersonMentionResponse {
|
Ok(Json(PersonMentionResponse {
|
||||||
person_mention_view,
|
person_mention_view,
|
||||||
|
|
|
@ -18,9 +18,7 @@ pub async fn mark_reply_as_read(
|
||||||
local_user_view: LocalUserView,
|
local_user_view: LocalUserView,
|
||||||
) -> LemmyResult<Json<CommentReplyResponse>> {
|
) -> LemmyResult<Json<CommentReplyResponse>> {
|
||||||
let comment_reply_id = data.comment_reply_id;
|
let comment_reply_id = data.comment_reply_id;
|
||||||
let read_comment_reply = CommentReply::read(&mut context.pool(), comment_reply_id)
|
let read_comment_reply = CommentReply::read(&mut context.pool(), comment_reply_id).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindCommentReply)?;
|
|
||||||
|
|
||||||
if local_user_view.person.id != read_comment_reply.recipient_id {
|
if local_user_view.person.id != read_comment_reply.recipient_id {
|
||||||
Err(LemmyErrorType::CouldntUpdateComment)?
|
Err(LemmyErrorType::CouldntUpdateComment)?
|
||||||
|
@ -40,9 +38,7 @@ pub async fn mark_reply_as_read(
|
||||||
let comment_reply_id = read_comment_reply.id;
|
let comment_reply_id = read_comment_reply.id;
|
||||||
let person_id = local_user_view.person.id;
|
let person_id = local_user_view.person.id;
|
||||||
let comment_reply_view =
|
let comment_reply_view =
|
||||||
CommentReplyView::read(&mut context.pool(), comment_reply_id, Some(person_id))
|
CommentReplyView::read(&mut context.pool(), comment_reply_id, Some(person_id)).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindCommentReply)?;
|
|
||||||
|
|
||||||
Ok(Json(CommentReplyResponse { comment_reply_view }))
|
Ok(Json(CommentReplyResponse { comment_reply_view }))
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,8 +16,8 @@ pub async fn reset_password(
|
||||||
// Fetch that email
|
// Fetch that email
|
||||||
let email = data.email.to_lowercase();
|
let email = data.email.to_lowercase();
|
||||||
let local_user_view = LocalUserView::find_by_email(&mut context.pool(), &email)
|
let local_user_view = LocalUserView::find_by_email(&mut context.pool(), &email)
|
||||||
.await?
|
.await
|
||||||
.ok_or(LemmyErrorType::IncorrectLogin)?;
|
.map_err(|_| LemmyErrorType::IncorrectLogin)?;
|
||||||
|
|
||||||
let site_view = SiteView::read_local(&mut context.pool()).await?;
|
let site_view = SiteView::read_local(&mut context.pool()).await?;
|
||||||
check_email_verified(&local_user_view, &site_view)?;
|
check_email_verified(&local_user_view, &site_view)?;
|
||||||
|
|
|
@ -10,7 +10,7 @@ use lemmy_db_schema::source::{
|
||||||
local_user::{LocalUser, LocalUserUpdateForm},
|
local_user::{LocalUser, LocalUserUpdateForm},
|
||||||
};
|
};
|
||||||
use lemmy_db_views::structs::{LocalUserView, SiteView};
|
use lemmy_db_views::structs::{LocalUserView, SiteView};
|
||||||
use lemmy_utils::error::{LemmyErrorType, LemmyResult};
|
use lemmy_utils::error::LemmyResult;
|
||||||
|
|
||||||
pub async fn verify_email(
|
pub async fn verify_email(
|
||||||
data: Json<VerifyEmail>,
|
data: Json<VerifyEmail>,
|
||||||
|
@ -18,9 +18,7 @@ pub async fn verify_email(
|
||||||
) -> LemmyResult<Json<SuccessResponse>> {
|
) -> LemmyResult<Json<SuccessResponse>> {
|
||||||
let site_view = SiteView::read_local(&mut context.pool()).await?;
|
let site_view = SiteView::read_local(&mut context.pool()).await?;
|
||||||
let token = data.token.clone();
|
let token = data.token.clone();
|
||||||
let verification = EmailVerification::read_for_token(&mut context.pool(), &token)
|
let verification = EmailVerification::read_for_token(&mut context.pool(), &token).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::TokenNotFound)?;
|
|
||||||
|
|
||||||
let form = LocalUserUpdateForm {
|
let form = LocalUserUpdateForm {
|
||||||
// necessary in case this is a new signup
|
// necessary in case this is a new signup
|
||||||
|
@ -37,9 +35,7 @@ pub async fn verify_email(
|
||||||
|
|
||||||
// send out notification about registration application to admins if enabled
|
// send out notification about registration application to admins if enabled
|
||||||
if site_view.local_site.application_email_admins {
|
if site_view.local_site.application_email_admins {
|
||||||
let local_user = LocalUserView::read(&mut context.pool(), local_user_id)
|
let local_user = LocalUserView::read(&mut context.pool(), local_user_id).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindPerson)?;
|
|
||||||
|
|
||||||
send_new_applicant_email_to_admins(
|
send_new_applicant_email_to_admins(
|
||||||
&local_user.person.name,
|
&local_user.person.name,
|
||||||
|
|
|
@ -16,7 +16,7 @@ use lemmy_db_schema::{
|
||||||
PostFeatureType,
|
PostFeatureType,
|
||||||
};
|
};
|
||||||
use lemmy_db_views::structs::LocalUserView;
|
use lemmy_db_views::structs::LocalUserView;
|
||||||
use lemmy_utils::{error::LemmyResult, LemmyErrorType};
|
use lemmy_utils::error::LemmyResult;
|
||||||
|
|
||||||
#[tracing::instrument(skip(context))]
|
#[tracing::instrument(skip(context))]
|
||||||
pub async fn feature_post(
|
pub async fn feature_post(
|
||||||
|
@ -25,9 +25,7 @@ pub async fn feature_post(
|
||||||
local_user_view: LocalUserView,
|
local_user_view: LocalUserView,
|
||||||
) -> LemmyResult<Json<PostResponse>> {
|
) -> LemmyResult<Json<PostResponse>> {
|
||||||
let post_id = data.post_id;
|
let post_id = data.post_id;
|
||||||
let orig_post = Post::read(&mut context.pool(), post_id)
|
let orig_post = Post::read(&mut context.pool(), post_id).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindPost)?;
|
|
||||||
|
|
||||||
check_community_mod_action(
|
check_community_mod_action(
|
||||||
&local_user_view.person,
|
&local_user_view.person,
|
||||||
|
|
|
@ -38,9 +38,7 @@ pub async fn like_post(
|
||||||
|
|
||||||
// Check for a community ban
|
// Check for a community ban
|
||||||
let post_id = data.post_id;
|
let post_id = data.post_id;
|
||||||
let post = Post::read(&mut context.pool(), post_id)
|
let post = Post::read(&mut context.pool(), post_id).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindPost)?;
|
|
||||||
|
|
||||||
check_community_user_action(
|
check_community_user_action(
|
||||||
&local_user_view.person,
|
&local_user_view.person,
|
||||||
|
@ -70,9 +68,7 @@ pub async fn like_post(
|
||||||
|
|
||||||
mark_post_as_read(person_id, post_id, &mut context.pool()).await?;
|
mark_post_as_read(person_id, post_id, &mut context.pool()).await?;
|
||||||
|
|
||||||
let community = Community::read(&mut context.pool(), post.community_id)
|
let community = Community::read(&mut context.pool(), post.community_id).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindCommunity)?;
|
|
||||||
|
|
||||||
ActivityChannel::submit_activity(
|
ActivityChannel::submit_activity(
|
||||||
SendActivityData::LikePostOrComment {
|
SendActivityData::LikePostOrComment {
|
||||||
|
|
|
@ -6,7 +6,7 @@ use lemmy_api_common::{
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{source::post::Post, traits::Crud};
|
use lemmy_db_schema::{source::post::Post, traits::Crud};
|
||||||
use lemmy_db_views::structs::{LocalUserView, VoteView};
|
use lemmy_db_views::structs::{LocalUserView, VoteView};
|
||||||
use lemmy_utils::{error::LemmyResult, LemmyErrorType};
|
use lemmy_utils::error::LemmyResult;
|
||||||
|
|
||||||
/// Lists likes for a post
|
/// Lists likes for a post
|
||||||
#[tracing::instrument(skip(context))]
|
#[tracing::instrument(skip(context))]
|
||||||
|
@ -15,9 +15,7 @@ pub async fn list_post_likes(
|
||||||
context: Data<LemmyContext>,
|
context: Data<LemmyContext>,
|
||||||
local_user_view: LocalUserView,
|
local_user_view: LocalUserView,
|
||||||
) -> LemmyResult<Json<ListPostLikesResponse>> {
|
) -> LemmyResult<Json<ListPostLikesResponse>> {
|
||||||
let post = Post::read(&mut context.pool(), data.post_id)
|
let post = Post::read(&mut context.pool(), data.post_id).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindPost)?;
|
|
||||||
is_mod_or_admin(
|
is_mod_or_admin(
|
||||||
&mut context.pool(),
|
&mut context.pool(),
|
||||||
&local_user_view.person,
|
&local_user_view.person,
|
||||||
|
|
|
@ -15,7 +15,7 @@ use lemmy_db_schema::{
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
};
|
};
|
||||||
use lemmy_db_views::structs::LocalUserView;
|
use lemmy_db_views::structs::LocalUserView;
|
||||||
use lemmy_utils::{error::LemmyResult, LemmyErrorType};
|
use lemmy_utils::error::LemmyResult;
|
||||||
|
|
||||||
#[tracing::instrument(skip(context))]
|
#[tracing::instrument(skip(context))]
|
||||||
pub async fn lock_post(
|
pub async fn lock_post(
|
||||||
|
@ -24,9 +24,7 @@ pub async fn lock_post(
|
||||||
local_user_view: LocalUserView,
|
local_user_view: LocalUserView,
|
||||||
) -> LemmyResult<Json<PostResponse>> {
|
) -> LemmyResult<Json<PostResponse>> {
|
||||||
let post_id = data.post_id;
|
let post_id = data.post_id;
|
||||||
let orig_post = Post::read(&mut context.pool(), post_id)
|
let orig_post = Post::read(&mut context.pool(), post_id).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindPost)?;
|
|
||||||
|
|
||||||
check_community_mod_action(
|
check_community_mod_action(
|
||||||
&local_user_view.person,
|
&local_user_view.person,
|
||||||
|
|
|
@ -40,8 +40,7 @@ pub async fn save_post(
|
||||||
Some(&local_user_view.local_user),
|
Some(&local_user_view.local_user),
|
||||||
false,
|
false,
|
||||||
)
|
)
|
||||||
.await?
|
.await?;
|
||||||
.ok_or(LemmyErrorType::CouldntFindPost)?;
|
|
||||||
|
|
||||||
mark_post_as_read(person_id, post_id, &mut context.pool()).await?;
|
mark_post_as_read(person_id, post_id, &mut context.pool()).await?;
|
||||||
|
|
||||||
|
|
|
@ -35,9 +35,7 @@ pub async fn create_post_report(
|
||||||
|
|
||||||
let person_id = local_user_view.person.id;
|
let person_id = local_user_view.person.id;
|
||||||
let post_id = data.post_id;
|
let post_id = data.post_id;
|
||||||
let post_view = PostView::read(&mut context.pool(), post_id, None, false)
|
let post_view = PostView::read(&mut context.pool(), post_id, None, false).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindPost)?;
|
|
||||||
|
|
||||||
check_community_user_action(
|
check_community_user_action(
|
||||||
&local_user_view.person,
|
&local_user_view.person,
|
||||||
|
@ -61,9 +59,7 @@ pub async fn create_post_report(
|
||||||
.await
|
.await
|
||||||
.with_lemmy_type(LemmyErrorType::CouldntCreateReport)?;
|
.with_lemmy_type(LemmyErrorType::CouldntCreateReport)?;
|
||||||
|
|
||||||
let post_report_view = PostReportView::read(&mut context.pool(), report.id, person_id)
|
let post_report_view = PostReportView::read(&mut context.pool(), report.id, person_id).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindPostReport)?;
|
|
||||||
|
|
||||||
// Email the admins
|
// Email the admins
|
||||||
if local_site.reports_email_admins {
|
if local_site.reports_email_admins {
|
||||||
|
|
|
@ -17,9 +17,7 @@ pub async fn resolve_post_report(
|
||||||
) -> LemmyResult<Json<PostReportResponse>> {
|
) -> LemmyResult<Json<PostReportResponse>> {
|
||||||
let report_id = data.report_id;
|
let report_id = data.report_id;
|
||||||
let person_id = local_user_view.person.id;
|
let person_id = local_user_view.person.id;
|
||||||
let report = PostReportView::read(&mut context.pool(), report_id, person_id)
|
let report = PostReportView::read(&mut context.pool(), report_id, person_id).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindPostReport)?;
|
|
||||||
|
|
||||||
let person_id = local_user_view.person.id;
|
let person_id = local_user_view.person.id;
|
||||||
check_community_mod_action(
|
check_community_mod_action(
|
||||||
|
@ -40,9 +38,7 @@ pub async fn resolve_post_report(
|
||||||
.with_lemmy_type(LemmyErrorType::CouldntResolveReport)?;
|
.with_lemmy_type(LemmyErrorType::CouldntResolveReport)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let post_report_view = PostReportView::read(&mut context.pool(), report_id, person_id)
|
let post_report_view = PostReportView::read(&mut context.pool(), report_id, person_id).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindPostReport)?;
|
|
||||||
|
|
||||||
Ok(Json(PostReportResponse { post_report_view }))
|
Ok(Json(PostReportResponse { post_report_view }))
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,9 +18,7 @@ pub async fn mark_pm_as_read(
|
||||||
) -> LemmyResult<Json<PrivateMessageResponse>> {
|
) -> LemmyResult<Json<PrivateMessageResponse>> {
|
||||||
// Checking permissions
|
// Checking permissions
|
||||||
let private_message_id = data.private_message_id;
|
let private_message_id = data.private_message_id;
|
||||||
let orig_private_message = PrivateMessage::read(&mut context.pool(), private_message_id)
|
let orig_private_message = PrivateMessage::read(&mut context.pool(), private_message_id).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindPrivateMessage)?;
|
|
||||||
if local_user_view.person.id != orig_private_message.recipient_id {
|
if local_user_view.person.id != orig_private_message.recipient_id {
|
||||||
Err(LemmyErrorType::CouldntUpdatePrivateMessage)?
|
Err(LemmyErrorType::CouldntUpdatePrivateMessage)?
|
||||||
}
|
}
|
||||||
|
@ -39,9 +37,7 @@ pub async fn mark_pm_as_read(
|
||||||
.await
|
.await
|
||||||
.with_lemmy_type(LemmyErrorType::CouldntUpdatePrivateMessage)?;
|
.with_lemmy_type(LemmyErrorType::CouldntUpdatePrivateMessage)?;
|
||||||
|
|
||||||
let view = PrivateMessageView::read(&mut context.pool(), private_message_id)
|
let view = PrivateMessageView::read(&mut context.pool(), private_message_id).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindPrivateMessage)?;
|
|
||||||
Ok(Json(PrivateMessageResponse {
|
Ok(Json(PrivateMessageResponse {
|
||||||
private_message_view: view,
|
private_message_view: view,
|
||||||
}))
|
}))
|
||||||
|
|
|
@ -29,9 +29,7 @@ pub async fn create_pm_report(
|
||||||
|
|
||||||
let person_id = local_user_view.person.id;
|
let person_id = local_user_view.person.id;
|
||||||
let private_message_id = data.private_message_id;
|
let private_message_id = data.private_message_id;
|
||||||
let private_message = PrivateMessage::read(&mut context.pool(), private_message_id)
|
let private_message = PrivateMessage::read(&mut context.pool(), private_message_id).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindPrivateMessage)?;
|
|
||||||
|
|
||||||
// Make sure that only the recipient of the private message can create a report
|
// Make sure that only the recipient of the private message can create a report
|
||||||
if person_id != private_message.recipient_id {
|
if person_id != private_message.recipient_id {
|
||||||
|
@ -49,9 +47,8 @@ pub async fn create_pm_report(
|
||||||
.await
|
.await
|
||||||
.with_lemmy_type(LemmyErrorType::CouldntCreateReport)?;
|
.with_lemmy_type(LemmyErrorType::CouldntCreateReport)?;
|
||||||
|
|
||||||
let private_message_report_view = PrivateMessageReportView::read(&mut context.pool(), report.id)
|
let private_message_report_view =
|
||||||
.await?
|
PrivateMessageReportView::read(&mut context.pool(), report.id).await?;
|
||||||
.ok_or(LemmyErrorType::CouldntFindPrivateMessageReport)?;
|
|
||||||
|
|
||||||
// Email the admins
|
// Email the admins
|
||||||
if local_site.reports_email_admins {
|
if local_site.reports_email_admins {
|
||||||
|
|
|
@ -28,9 +28,8 @@ pub async fn resolve_pm_report(
|
||||||
.with_lemmy_type(LemmyErrorType::CouldntResolveReport)?;
|
.with_lemmy_type(LemmyErrorType::CouldntResolveReport)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let private_message_report_view = PrivateMessageReportView::read(&mut context.pool(), report_id)
|
let private_message_report_view =
|
||||||
.await?
|
PrivateMessageReportView::read(&mut context.pool(), report_id).await?;
|
||||||
.ok_or(LemmyErrorType::CouldntFindPrivateMessageReport)?;
|
|
||||||
|
|
||||||
Ok(Json(PrivateMessageReportResponse {
|
Ok(Json(PrivateMessageReportResponse {
|
||||||
private_message_report_view,
|
private_message_report_view,
|
||||||
|
|
|
@ -16,7 +16,7 @@ use lemmy_db_schema::{
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
};
|
};
|
||||||
use lemmy_db_views::structs::{CommentView, LocalUserView};
|
use lemmy_db_views::structs::{CommentView, LocalUserView};
|
||||||
use lemmy_utils::{error::LemmyResult, LemmyErrorType};
|
use lemmy_utils::error::LemmyResult;
|
||||||
|
|
||||||
#[tracing::instrument(skip(context))]
|
#[tracing::instrument(skip(context))]
|
||||||
pub async fn purge_comment(
|
pub async fn purge_comment(
|
||||||
|
@ -35,8 +35,7 @@ pub async fn purge_comment(
|
||||||
comment_id,
|
comment_id,
|
||||||
Some(&local_user_view.local_user),
|
Some(&local_user_view.local_user),
|
||||||
)
|
)
|
||||||
.await?
|
.await?;
|
||||||
.ok_or(LemmyErrorType::CouldntFindComment)?;
|
|
||||||
|
|
||||||
// Also check that you're a higher admin
|
// Also check that you're a higher admin
|
||||||
LocalUser::is_higher_admin_check(
|
LocalUser::is_higher_admin_check(
|
||||||
|
|
|
@ -19,7 +19,7 @@ use lemmy_db_schema::{
|
||||||
};
|
};
|
||||||
use lemmy_db_views::structs::LocalUserView;
|
use lemmy_db_views::structs::LocalUserView;
|
||||||
use lemmy_db_views_actor::structs::CommunityModeratorView;
|
use lemmy_db_views_actor::structs::CommunityModeratorView;
|
||||||
use lemmy_utils::{error::LemmyResult, LemmyErrorType};
|
use lemmy_utils::error::LemmyResult;
|
||||||
|
|
||||||
#[tracing::instrument(skip(context))]
|
#[tracing::instrument(skip(context))]
|
||||||
pub async fn purge_community(
|
pub async fn purge_community(
|
||||||
|
@ -31,9 +31,7 @@ pub async fn purge_community(
|
||||||
is_admin(&local_user_view)?;
|
is_admin(&local_user_view)?;
|
||||||
|
|
||||||
// Read the community to get its images
|
// Read the community to get its images
|
||||||
let community = Community::read(&mut context.pool(), data.community_id)
|
let community = Community::read(&mut context.pool(), data.community_id).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindCommunity)?;
|
|
||||||
|
|
||||||
// Also check that you're a higher admin than all the mods
|
// Also check that you're a higher admin than all the mods
|
||||||
let community_mod_person_ids =
|
let community_mod_person_ids =
|
||||||
|
|
|
@ -17,7 +17,7 @@ use lemmy_db_schema::{
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
};
|
};
|
||||||
use lemmy_db_views::structs::LocalUserView;
|
use lemmy_db_views::structs::LocalUserView;
|
||||||
use lemmy_utils::{error::LemmyResult, LemmyErrorType};
|
use lemmy_utils::error::LemmyResult;
|
||||||
|
|
||||||
#[tracing::instrument(skip(context))]
|
#[tracing::instrument(skip(context))]
|
||||||
pub async fn purge_person(
|
pub async fn purge_person(
|
||||||
|
@ -36,9 +36,7 @@ pub async fn purge_person(
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let person = Person::read(&mut context.pool(), data.person_id)
|
let person = Person::read(&mut context.pool(), data.person_id).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindPerson)?;
|
|
||||||
|
|
||||||
ban_nonlocal_user_from_local_communities(
|
ban_nonlocal_user_from_local_communities(
|
||||||
&local_user_view,
|
&local_user_view,
|
||||||
|
|
|
@ -17,7 +17,7 @@ use lemmy_db_schema::{
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
};
|
};
|
||||||
use lemmy_db_views::structs::LocalUserView;
|
use lemmy_db_views::structs::LocalUserView;
|
||||||
use lemmy_utils::{error::LemmyResult, LemmyErrorType};
|
use lemmy_utils::error::LemmyResult;
|
||||||
|
|
||||||
#[tracing::instrument(skip(context))]
|
#[tracing::instrument(skip(context))]
|
||||||
pub async fn purge_post(
|
pub async fn purge_post(
|
||||||
|
@ -29,9 +29,7 @@ pub async fn purge_post(
|
||||||
is_admin(&local_user_view)?;
|
is_admin(&local_user_view)?;
|
||||||
|
|
||||||
// Read the post to get the community_id
|
// Read the post to get the community_id
|
||||||
let post = Post::read(&mut context.pool(), data.post_id)
|
let post = Post::read(&mut context.pool(), data.post_id).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindPost)?;
|
|
||||||
|
|
||||||
// Also check that you're a higher admin
|
// Also check that you're a higher admin
|
||||||
LocalUser::is_higher_admin_check(
|
LocalUser::is_higher_admin_check(
|
||||||
|
|
|
@ -14,10 +14,7 @@ use lemmy_db_schema::{
|
||||||
utils::{diesel_string_update, get_conn},
|
utils::{diesel_string_update, get_conn},
|
||||||
};
|
};
|
||||||
use lemmy_db_views::structs::{LocalUserView, RegistrationApplicationView};
|
use lemmy_db_views::structs::{LocalUserView, RegistrationApplicationView};
|
||||||
use lemmy_utils::{
|
use lemmy_utils::error::{LemmyError, LemmyResult};
|
||||||
error::{LemmyError, LemmyResult},
|
|
||||||
LemmyErrorType,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub async fn approve_registration_application(
|
pub async fn approve_registration_application(
|
||||||
data: Json<ApproveRegistrationApplication>,
|
data: Json<ApproveRegistrationApplication>,
|
||||||
|
@ -61,9 +58,8 @@ pub async fn approve_registration_application(
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
if data.approve {
|
if data.approve {
|
||||||
let approved_local_user_view = LocalUserView::read(&mut context.pool(), approved_user_id)
|
let approved_local_user_view =
|
||||||
.await?
|
LocalUserView::read(&mut context.pool(), approved_user_id).await?;
|
||||||
.ok_or(LemmyErrorType::CouldntFindLocalUser)?;
|
|
||||||
if approved_local_user_view.local_user.email.is_some() {
|
if approved_local_user_view.local_user.email.is_some() {
|
||||||
// Email sending may fail, but this won't revert the application approval
|
// Email sending may fail, but this won't revert the application approval
|
||||||
send_application_approved_email(&approved_local_user_view, context.settings()).await?;
|
send_application_approved_email(&approved_local_user_view, context.settings()).await?;
|
||||||
|
@ -71,9 +67,8 @@ pub async fn approve_registration_application(
|
||||||
};
|
};
|
||||||
|
|
||||||
// Read the view
|
// Read the view
|
||||||
let registration_application = RegistrationApplicationView::read(&mut context.pool(), app_id)
|
let registration_application =
|
||||||
.await?
|
RegistrationApplicationView::read(&mut context.pool(), app_id).await?;
|
||||||
.ok_or(LemmyErrorType::CouldntFindRegistrationApplication)?;
|
|
||||||
|
|
||||||
Ok(Json(RegistrationApplicationResponse {
|
Ok(Json(RegistrationApplicationResponse {
|
||||||
registration_application,
|
registration_application,
|
||||||
|
|
|
@ -5,7 +5,7 @@ use lemmy_api_common::{
|
||||||
utils::is_admin,
|
utils::is_admin,
|
||||||
};
|
};
|
||||||
use lemmy_db_views::structs::{LocalUserView, RegistrationApplicationView};
|
use lemmy_db_views::structs::{LocalUserView, RegistrationApplicationView};
|
||||||
use lemmy_utils::{error::LemmyResult, LemmyErrorType};
|
use lemmy_utils::error::LemmyResult;
|
||||||
|
|
||||||
/// Lists registration applications, filterable by undenied only.
|
/// Lists registration applications, filterable by undenied only.
|
||||||
pub async fn get_registration_application(
|
pub async fn get_registration_application(
|
||||||
|
@ -18,9 +18,7 @@ pub async fn get_registration_application(
|
||||||
|
|
||||||
// Read the view
|
// Read the view
|
||||||
let registration_application =
|
let registration_application =
|
||||||
RegistrationApplicationView::read_by_person(&mut context.pool(), data.person_id)
|
RegistrationApplicationView::read_by_person(&mut context.pool(), data.person_id).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindRegistrationApplication)?;
|
|
||||||
|
|
||||||
Ok(Json(RegistrationApplicationResponse {
|
Ok(Json(RegistrationApplicationResponse {
|
||||||
registration_application,
|
registration_application,
|
||||||
|
|
|
@ -54,9 +54,7 @@ async fn create_test_site(context: &Data<LemmyContext>) -> LemmyResult<(Instance
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let admin_local_user_view = LocalUserView::read_person(pool, admin_person.id)
|
let admin_local_user_view = LocalUserView::read_person(pool, admin_person.id).await?;
|
||||||
.await?
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let site_form = SiteInsertForm::builder()
|
let site_form = SiteInsertForm::builder()
|
||||||
.name("test site".to_string())
|
.name("test site".to_string())
|
||||||
|
|
|
@ -27,7 +27,6 @@ use lemmy_db_views_actor::structs::CommunityView;
|
||||||
use lemmy_utils::{
|
use lemmy_utils::{
|
||||||
error::LemmyResult,
|
error::LemmyResult,
|
||||||
utils::{markdown::markdown_to_html, mention::MentionData},
|
utils::{markdown::markdown_to_html, mention::MentionData},
|
||||||
LemmyErrorType,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub async fn build_comment_response(
|
pub async fn build_comment_response(
|
||||||
|
@ -37,9 +36,8 @@ pub async fn build_comment_response(
|
||||||
recipient_ids: Vec<LocalUserId>,
|
recipient_ids: Vec<LocalUserId>,
|
||||||
) -> LemmyResult<CommentResponse> {
|
) -> LemmyResult<CommentResponse> {
|
||||||
let local_user = local_user_view.map(|l| l.local_user);
|
let local_user = local_user_view.map(|l| l.local_user);
|
||||||
let comment_view = CommentView::read(&mut context.pool(), comment_id, local_user.as_ref())
|
let comment_view =
|
||||||
.await?
|
CommentView::read(&mut context.pool(), comment_id, local_user.as_ref()).await?;
|
||||||
.ok_or(LemmyErrorType::CouldntFindComment)?;
|
|
||||||
Ok(CommentResponse {
|
Ok(CommentResponse {
|
||||||
comment_view,
|
comment_view,
|
||||||
recipient_ids,
|
recipient_ids,
|
||||||
|
@ -61,8 +59,7 @@ pub async fn build_community_response(
|
||||||
Some(&local_user),
|
Some(&local_user),
|
||||||
is_mod_or_admin,
|
is_mod_or_admin,
|
||||||
)
|
)
|
||||||
.await?
|
.await?;
|
||||||
.ok_or(LemmyErrorType::CouldntFindCommunity)?;
|
|
||||||
let discussion_languages = CommunityLanguage::read(&mut context.pool(), community_id).await?;
|
let discussion_languages = CommunityLanguage::read(&mut context.pool(), community_id).await?;
|
||||||
|
|
||||||
Ok(Json(CommunityResponse {
|
Ok(Json(CommunityResponse {
|
||||||
|
@ -111,8 +108,7 @@ pub async fn send_local_notifs(
|
||||||
comment_id,
|
comment_id,
|
||||||
local_user_view.map(|view| &view.local_user),
|
local_user_view.map(|view| &view.local_user),
|
||||||
)
|
)
|
||||||
.await?
|
.await?;
|
||||||
.ok_or(LemmyErrorType::CouldntFindComment)?;
|
|
||||||
let comment = comment_view.comment;
|
let comment = comment_view.comment;
|
||||||
let post = comment_view.post;
|
let post = comment_view.post;
|
||||||
let community = comment_view.community;
|
let community = comment_view.community;
|
||||||
|
@ -124,7 +120,7 @@ pub async fn send_local_notifs(
|
||||||
{
|
{
|
||||||
let mention_name = mention.name.clone();
|
let mention_name = mention.name.clone();
|
||||||
let user_view = LocalUserView::read_from_name(&mut context.pool(), &mention_name).await;
|
let user_view = LocalUserView::read_from_name(&mut context.pool(), &mention_name).await;
|
||||||
if let Ok(Some(mention_user_view)) = user_view {
|
if let Ok(mention_user_view) = user_view {
|
||||||
// TODO
|
// TODO
|
||||||
// At some point, make it so you can't tag the parent creator either
|
// At some point, make it so you can't tag the parent creator either
|
||||||
// Potential duplication of notifications, one for reply and the other for mention, is handled
|
// Potential duplication of notifications, one for reply and the other for mention, is handled
|
||||||
|
@ -160,9 +156,7 @@ pub async fn send_local_notifs(
|
||||||
|
|
||||||
// Send comment_reply to the parent commenter / poster
|
// Send comment_reply to the parent commenter / poster
|
||||||
if let Some(parent_comment_id) = comment.parent_comment_id() {
|
if let Some(parent_comment_id) = comment.parent_comment_id() {
|
||||||
let parent_comment = Comment::read(&mut context.pool(), parent_comment_id)
|
let parent_comment = Comment::read(&mut context.pool(), parent_comment_id).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindComment)?;
|
|
||||||
|
|
||||||
// Get the parent commenter local_user
|
// Get the parent commenter local_user
|
||||||
let parent_creator_id = parent_comment.creator_id;
|
let parent_creator_id = parent_comment.creator_id;
|
||||||
|
@ -181,7 +175,7 @@ pub async fn send_local_notifs(
|
||||||
// Don't send a notif to yourself
|
// Don't send a notif to yourself
|
||||||
if parent_comment.creator_id != person.id && !check_blocks {
|
if parent_comment.creator_id != person.id && !check_blocks {
|
||||||
let user_view = LocalUserView::read_person(&mut context.pool(), parent_creator_id).await;
|
let user_view = LocalUserView::read_person(&mut context.pool(), parent_creator_id).await;
|
||||||
if let Ok(Some(parent_user_view)) = user_view {
|
if let Ok(parent_user_view) = user_view {
|
||||||
// Don't duplicate notif if already mentioned by checking recipient ids
|
// Don't duplicate notif if already mentioned by checking recipient ids
|
||||||
if !recipient_ids.contains(&parent_user_view.local_user.id) {
|
if !recipient_ids.contains(&parent_user_view.local_user.id) {
|
||||||
recipient_ids.push(parent_user_view.local_user.id);
|
recipient_ids.push(parent_user_view.local_user.id);
|
||||||
|
@ -228,7 +222,7 @@ pub async fn send_local_notifs(
|
||||||
if post.creator_id != person.id && !check_blocks {
|
if post.creator_id != person.id && !check_blocks {
|
||||||
let creator_id = post.creator_id;
|
let creator_id = post.creator_id;
|
||||||
let parent_user = LocalUserView::read_person(&mut context.pool(), creator_id).await;
|
let parent_user = LocalUserView::read_person(&mut context.pool(), creator_id).await;
|
||||||
if let Ok(Some(parent_user_view)) = parent_user {
|
if let Ok(parent_user_view) = parent_user {
|
||||||
if !recipient_ids.contains(&parent_user_view.local_user.id) {
|
if !recipient_ids.contains(&parent_user_view.local_user.id) {
|
||||||
recipient_ids.push(parent_user_view.local_user.id);
|
recipient_ids.push(parent_user_view.local_user.id);
|
||||||
|
|
||||||
|
|
|
@ -175,9 +175,7 @@ pub async fn update_read_comments(
|
||||||
..PersonPostAggregatesForm::default()
|
..PersonPostAggregatesForm::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
PersonPostAggregates::upsert(pool, &person_post_agg_form)
|
PersonPostAggregates::upsert(pool, &person_post_agg_form).await?;
|
||||||
.await
|
|
||||||
.with_lemmy_type(LemmyErrorType::CouldntFindPost)?;
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -223,9 +221,7 @@ pub async fn check_registration_application(
|
||||||
// Fetch the registration application. If no admin id is present its still pending. Otherwise it
|
// Fetch the registration application. If no admin id is present its still pending. Otherwise it
|
||||||
// was processed (either accepted or denied).
|
// was processed (either accepted or denied).
|
||||||
let local_user_id = local_user_view.local_user.id;
|
let local_user_id = local_user_view.local_user.id;
|
||||||
let registration = RegistrationApplication::find_by_local_user_id(pool, local_user_id)
|
let registration = RegistrationApplication::find_by_local_user_id(pool, local_user_id).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindRegistrationApplication)?;
|
|
||||||
if registration.admin_id.is_some() {
|
if registration.admin_id.is_some() {
|
||||||
Err(LemmyErrorType::RegistrationDenied(registration.deny_reason))?
|
Err(LemmyErrorType::RegistrationDenied(registration.deny_reason))?
|
||||||
} else {
|
} else {
|
||||||
|
@ -254,9 +250,7 @@ async fn check_community_deleted_removed(
|
||||||
community_id: CommunityId,
|
community_id: CommunityId,
|
||||||
pool: &mut DbPool<'_>,
|
pool: &mut DbPool<'_>,
|
||||||
) -> LemmyResult<()> {
|
) -> LemmyResult<()> {
|
||||||
let community = Community::read(pool, community_id)
|
let community = Community::read(pool, community_id).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindCommunity)?;
|
|
||||||
if community.deleted || community.removed {
|
if community.deleted || community.removed {
|
||||||
Err(LemmyErrorType::Deleted)?
|
Err(LemmyErrorType::Deleted)?
|
||||||
}
|
}
|
||||||
|
@ -704,7 +698,7 @@ pub async fn purge_image_posts_for_person(
|
||||||
|
|
||||||
/// Delete a local_user's images
|
/// Delete a local_user's images
|
||||||
async fn delete_local_user_images(person_id: PersonId, context: &LemmyContext) -> LemmyResult<()> {
|
async fn delete_local_user_images(person_id: PersonId, context: &LemmyContext) -> LemmyResult<()> {
|
||||||
if let Ok(Some(local_user)) = LocalUserView::read_person(&mut context.pool(), person_id).await {
|
if let Ok(local_user) = LocalUserView::read_person(&mut context.pool(), person_id).await {
|
||||||
let pictrs_uploads =
|
let pictrs_uploads =
|
||||||
LocalImageView::get_all_by_local_user_id(&mut context.pool(), local_user.local_user.id)
|
LocalImageView::get_all_by_local_user_id(&mut context.pool(), local_user.local_user.id)
|
||||||
.await?;
|
.await?;
|
||||||
|
@ -749,9 +743,7 @@ pub async fn remove_user_data(
|
||||||
) -> LemmyResult<()> {
|
) -> LemmyResult<()> {
|
||||||
let pool = &mut context.pool();
|
let pool = &mut context.pool();
|
||||||
// Purge user images
|
// Purge user images
|
||||||
let person = Person::read(pool, banned_person_id)
|
let person = Person::read(pool, banned_person_id).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindPerson)?;
|
|
||||||
if let Some(avatar) = person.avatar {
|
if let Some(avatar) = person.avatar {
|
||||||
purge_image_from_pictrs(&avatar, context).await.ok();
|
purge_image_from_pictrs(&avatar, context).await.ok();
|
||||||
}
|
}
|
||||||
|
@ -881,9 +873,7 @@ pub async fn remove_or_restore_user_data_in_community(
|
||||||
pub async fn purge_user_account(person_id: PersonId, context: &LemmyContext) -> LemmyResult<()> {
|
pub async fn purge_user_account(person_id: PersonId, context: &LemmyContext) -> LemmyResult<()> {
|
||||||
let pool = &mut context.pool();
|
let pool = &mut context.pool();
|
||||||
|
|
||||||
let person = Person::read(pool, person_id)
|
let person = Person::read(pool, person_id).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindPerson)?;
|
|
||||||
|
|
||||||
// Delete their local images, if they're a local user
|
// Delete their local images, if they're a local user
|
||||||
delete_local_user_images(person_id, context).await.ok();
|
delete_local_user_images(person_id, context).await.ok();
|
||||||
|
@ -913,7 +903,7 @@ pub async fn purge_user_account(person_id: PersonId, context: &LemmyContext) ->
|
||||||
CommunityModerator::leave_all_communities(pool, person_id).await?;
|
CommunityModerator::leave_all_communities(pool, person_id).await?;
|
||||||
|
|
||||||
// Delete the oauth accounts linked to the local user
|
// Delete the oauth accounts linked to the local user
|
||||||
if let Ok(Some(local_user)) = LocalUserView::read_person(pool, person_id).await {
|
if let Ok(local_user) = LocalUserView::read_person(pool, person_id).await {
|
||||||
OAuthAccount::delete_user_accounts(pool, local_user.local_user.id).await?;
|
OAuthAccount::delete_user_accounts(pool, local_user.local_user.id).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,8 +57,7 @@ pub async fn create_comment(
|
||||||
Some(&local_user_view.local_user),
|
Some(&local_user_view.local_user),
|
||||||
true,
|
true,
|
||||||
)
|
)
|
||||||
.await?
|
.await?;
|
||||||
.ok_or(LemmyErrorType::CouldntFindPost)?;
|
|
||||||
|
|
||||||
let post = post_view.post;
|
let post = post_view.post;
|
||||||
let community_id = post_view.community.id;
|
let community_id = post_view.community.id;
|
||||||
|
@ -79,8 +78,7 @@ pub async fn create_comment(
|
||||||
Comment::read(&mut context.pool(), parent_id).await.ok()
|
Comment::read(&mut context.pool(), parent_id).await.ok()
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
};
|
||||||
.flatten();
|
|
||||||
|
|
||||||
// If there's a parent_id, check to make sure that comment is in that post
|
// If there's a parent_id, check to make sure that comment is in that post
|
||||||
// Strange issue where sometimes the post ID of the parent comment is incorrect
|
// Strange issue where sometimes the post ID of the parent comment is incorrect
|
||||||
|
|
|
@ -26,8 +26,7 @@ pub async fn delete_comment(
|
||||||
comment_id,
|
comment_id,
|
||||||
Some(&local_user_view.local_user),
|
Some(&local_user_view.local_user),
|
||||||
)
|
)
|
||||||
.await?
|
.await?;
|
||||||
.ok_or(LemmyErrorType::CouldntFindComment)?;
|
|
||||||
|
|
||||||
// Dont delete it if its already been deleted.
|
// Dont delete it if its already been deleted.
|
||||||
if orig_comment.comment.deleted == data.deleted {
|
if orig_comment.comment.deleted == data.deleted {
|
||||||
|
|
|
@ -31,8 +31,7 @@ pub async fn remove_comment(
|
||||||
comment_id,
|
comment_id,
|
||||||
Some(&local_user_view.local_user),
|
Some(&local_user_view.local_user),
|
||||||
)
|
)
|
||||||
.await?
|
.await?;
|
||||||
.ok_or(LemmyErrorType::CouldntFindComment)?;
|
|
||||||
|
|
||||||
check_community_mod_action(
|
check_community_mod_action(
|
||||||
&local_user_view.person,
|
&local_user_view.person,
|
||||||
|
|
|
@ -41,8 +41,7 @@ pub async fn update_comment(
|
||||||
comment_id,
|
comment_id,
|
||||||
Some(&local_user_view.local_user),
|
Some(&local_user_view.local_user),
|
||||||
)
|
)
|
||||||
.await?
|
.await?;
|
||||||
.ok_or(LemmyErrorType::CouldntFindComment)?;
|
|
||||||
|
|
||||||
check_community_user_action(
|
check_community_user_action(
|
||||||
&local_user_view.person,
|
&local_user_view.person,
|
||||||
|
|
|
@ -51,9 +51,7 @@ pub async fn update_community(
|
||||||
is_valid_body_field(desc, false)?;
|
is_valid_body_field(desc, false)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let old_community = Community::read(&mut context.pool(), data.community_id)
|
let old_community = Community::read(&mut context.pool(), data.community_id).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindCommunity)?;
|
|
||||||
|
|
||||||
let icon = diesel_url_update(data.icon.as_deref())?;
|
let icon = diesel_url_update(data.icon.as_deref())?;
|
||||||
replace_image(&icon, &old_community.icon, &context).await?;
|
replace_image(&icon, &old_community.icon, &context).await?;
|
||||||
|
|
|
@ -7,7 +7,7 @@ use lemmy_db_schema::{
|
||||||
utils::{diesel_required_string_update, diesel_required_url_update, naive_now},
|
utils::{diesel_required_string_update, diesel_required_url_update, naive_now},
|
||||||
};
|
};
|
||||||
use lemmy_db_views::structs::LocalUserView;
|
use lemmy_db_views::structs::LocalUserView;
|
||||||
use lemmy_utils::{error::LemmyError, LemmyErrorType};
|
use lemmy_utils::error::LemmyError;
|
||||||
|
|
||||||
#[tracing::instrument(skip(context))]
|
#[tracing::instrument(skip(context))]
|
||||||
pub async fn update_oauth_provider(
|
pub async fn update_oauth_provider(
|
||||||
|
@ -37,8 +37,6 @@ pub async fn update_oauth_provider(
|
||||||
|
|
||||||
let update_result =
|
let update_result =
|
||||||
OAuthProvider::update(&mut context.pool(), data.id, &oauth_provider_form).await?;
|
OAuthProvider::update(&mut context.pool(), data.id, &oauth_provider_form).await?;
|
||||||
let oauth_provider = OAuthProvider::read(&mut context.pool(), update_result.id)
|
let oauth_provider = OAuthProvider::read(&mut context.pool(), update_result.id).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindOauthProvider)?;
|
|
||||||
Ok(Json(oauth_provider))
|
Ok(Json(oauth_provider))
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,9 +92,7 @@ pub async fn create_post(
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let community_id = data.community_id;
|
let community_id = data.community_id;
|
||||||
let community = Community::read(&mut context.pool(), community_id)
|
let community = Community::read(&mut context.pool(), community_id).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindCommunity)?;
|
|
||||||
if community.posting_restricted_to_mods {
|
if community.posting_restricted_to_mods {
|
||||||
let community_id = data.community_id;
|
let community_id = data.community_id;
|
||||||
let is_mod = CommunityModeratorView::is_community_moderator(
|
let is_mod = CommunityModeratorView::is_community_moderator(
|
||||||
|
|
|
@ -21,9 +21,7 @@ pub async fn delete_post(
|
||||||
local_user_view: LocalUserView,
|
local_user_view: LocalUserView,
|
||||||
) -> LemmyResult<Json<PostResponse>> {
|
) -> LemmyResult<Json<PostResponse>> {
|
||||||
let post_id = data.post_id;
|
let post_id = data.post_id;
|
||||||
let orig_post = Post::read(&mut context.pool(), post_id)
|
let orig_post = Post::read(&mut context.pool(), post_id).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindPost)?;
|
|
||||||
|
|
||||||
// Dont delete it if its already been deleted.
|
// Dont delete it if its already been deleted.
|
||||||
if orig_post.deleted == data.deleted {
|
if orig_post.deleted == data.deleted {
|
||||||
|
|
|
@ -33,10 +33,9 @@ pub async fn get_post(
|
||||||
} else if let Some(comment_id) = data.comment_id {
|
} else if let Some(comment_id) = data.comment_id {
|
||||||
Comment::read(&mut context.pool(), comment_id)
|
Comment::read(&mut context.pool(), comment_id)
|
||||||
.await?
|
.await?
|
||||||
.ok_or(LemmyErrorType::CouldntFindComment)?
|
|
||||||
.post_id
|
.post_id
|
||||||
} else {
|
} else {
|
||||||
Err(LemmyErrorType::CouldntFindPost)?
|
Err(LemmyErrorType::NotFound)?
|
||||||
};
|
};
|
||||||
|
|
||||||
// Check to see if the person is a mod or admin, to show deleted / removed
|
// Check to see if the person is a mod or admin, to show deleted / removed
|
||||||
|
@ -59,8 +58,7 @@ pub async fn get_post(
|
||||||
local_user.as_ref(),
|
local_user.as_ref(),
|
||||||
is_mod_or_admin,
|
is_mod_or_admin,
|
||||||
)
|
)
|
||||||
.await?
|
.await?;
|
||||||
.ok_or(LemmyErrorType::CouldntFindPost)?;
|
|
||||||
|
|
||||||
let post_id = post_view.post.id;
|
let post_id = post_view.post.id;
|
||||||
if let Some(person_id) = person_id {
|
if let Some(person_id) = person_id {
|
||||||
|
@ -82,8 +80,7 @@ pub async fn get_post(
|
||||||
local_user.as_ref(),
|
local_user.as_ref(),
|
||||||
is_mod_or_admin,
|
is_mod_or_admin,
|
||||||
)
|
)
|
||||||
.await?
|
.await?;
|
||||||
.ok_or(LemmyErrorType::CouldntFindCommunity)?;
|
|
||||||
|
|
||||||
let moderators = CommunityModeratorView::for_community(&mut context.pool(), community_id).await?;
|
let moderators = CommunityModeratorView::for_community(&mut context.pool(), community_id).await?;
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ use lemmy_db_schema::{
|
||||||
traits::{Crud, Reportable},
|
traits::{Crud, Reportable},
|
||||||
};
|
};
|
||||||
use lemmy_db_views::structs::LocalUserView;
|
use lemmy_db_views::structs::LocalUserView;
|
||||||
use lemmy_utils::{error::LemmyResult, LemmyErrorType};
|
use lemmy_utils::error::LemmyResult;
|
||||||
|
|
||||||
#[tracing::instrument(skip(context))]
|
#[tracing::instrument(skip(context))]
|
||||||
pub async fn remove_post(
|
pub async fn remove_post(
|
||||||
|
@ -26,9 +26,7 @@ pub async fn remove_post(
|
||||||
local_user_view: LocalUserView,
|
local_user_view: LocalUserView,
|
||||||
) -> LemmyResult<Json<PostResponse>> {
|
) -> LemmyResult<Json<PostResponse>> {
|
||||||
let post_id = data.post_id;
|
let post_id = data.post_id;
|
||||||
let orig_post = Post::read(&mut context.pool(), post_id)
|
let orig_post = Post::read(&mut context.pool(), post_id).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindPost)?;
|
|
||||||
|
|
||||||
check_community_mod_action(
|
check_community_mod_action(
|
||||||
&local_user_view.person,
|
&local_user_view.person,
|
||||||
|
|
|
@ -85,9 +85,7 @@ pub async fn update_post(
|
||||||
}
|
}
|
||||||
|
|
||||||
let post_id = data.post_id;
|
let post_id = data.post_id;
|
||||||
let orig_post = Post::read(&mut context.pool(), post_id)
|
let orig_post = Post::read(&mut context.pool(), post_id).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindPost)?;
|
|
||||||
|
|
||||||
check_community_user_action(
|
check_community_user_action(
|
||||||
&local_user_view.person,
|
&local_user_view.person,
|
||||||
|
|
|
@ -56,16 +56,12 @@ pub async fn create_private_message(
|
||||||
.await
|
.await
|
||||||
.with_lemmy_type(LemmyErrorType::CouldntCreatePrivateMessage)?;
|
.with_lemmy_type(LemmyErrorType::CouldntCreatePrivateMessage)?;
|
||||||
|
|
||||||
let view = PrivateMessageView::read(&mut context.pool(), inserted_private_message.id)
|
let view = PrivateMessageView::read(&mut context.pool(), inserted_private_message.id).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindPrivateMessage)?;
|
|
||||||
|
|
||||||
// Send email to the local recipient, if one exists
|
// Send email to the local recipient, if one exists
|
||||||
if view.recipient.local {
|
if view.recipient.local {
|
||||||
let recipient_id = data.recipient_id;
|
let recipient_id = data.recipient_id;
|
||||||
let local_recipient = LocalUserView::read_person(&mut context.pool(), recipient_id)
|
let local_recipient = LocalUserView::read_person(&mut context.pool(), recipient_id).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindPerson)?;
|
|
||||||
let lang = get_interface_language(&local_recipient);
|
let lang = get_interface_language(&local_recipient);
|
||||||
let inbox_link = format!("{}/inbox", context.settings().get_protocol_and_hostname());
|
let inbox_link = format!("{}/inbox", context.settings().get_protocol_and_hostname());
|
||||||
let sender_name = &local_user_view.person.name;
|
let sender_name = &local_user_view.person.name;
|
||||||
|
|
|
@ -20,9 +20,7 @@ pub async fn delete_private_message(
|
||||||
) -> LemmyResult<Json<PrivateMessageResponse>> {
|
) -> LemmyResult<Json<PrivateMessageResponse>> {
|
||||||
// Checking permissions
|
// Checking permissions
|
||||||
let private_message_id = data.private_message_id;
|
let private_message_id = data.private_message_id;
|
||||||
let orig_private_message = PrivateMessage::read(&mut context.pool(), private_message_id)
|
let orig_private_message = PrivateMessage::read(&mut context.pool(), private_message_id).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindPrivateMessage)?;
|
|
||||||
if local_user_view.person.id != orig_private_message.creator_id {
|
if local_user_view.person.id != orig_private_message.creator_id {
|
||||||
Err(LemmyErrorType::EditPrivateMessageNotAllowed)?
|
Err(LemmyErrorType::EditPrivateMessageNotAllowed)?
|
||||||
}
|
}
|
||||||
|
@ -47,9 +45,7 @@ pub async fn delete_private_message(
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let view = PrivateMessageView::read(&mut context.pool(), private_message_id)
|
let view = PrivateMessageView::read(&mut context.pool(), private_message_id).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindPrivateMessage)?;
|
|
||||||
Ok(Json(PrivateMessageResponse {
|
Ok(Json(PrivateMessageResponse {
|
||||||
private_message_view: view,
|
private_message_view: view,
|
||||||
}))
|
}))
|
||||||
|
|
|
@ -30,9 +30,7 @@ pub async fn update_private_message(
|
||||||
|
|
||||||
// Checking permissions
|
// Checking permissions
|
||||||
let private_message_id = data.private_message_id;
|
let private_message_id = data.private_message_id;
|
||||||
let orig_private_message = PrivateMessage::read(&mut context.pool(), private_message_id)
|
let orig_private_message = PrivateMessage::read(&mut context.pool(), private_message_id).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindPrivateMessage)?;
|
|
||||||
if local_user_view.person.id != orig_private_message.creator_id {
|
if local_user_view.person.id != orig_private_message.creator_id {
|
||||||
Err(LemmyErrorType::EditPrivateMessageNotAllowed)?
|
Err(LemmyErrorType::EditPrivateMessageNotAllowed)?
|
||||||
}
|
}
|
||||||
|
@ -56,9 +54,7 @@ pub async fn update_private_message(
|
||||||
.await
|
.await
|
||||||
.with_lemmy_type(LemmyErrorType::CouldntUpdatePrivateMessage)?;
|
.with_lemmy_type(LemmyErrorType::CouldntUpdatePrivateMessage)?;
|
||||||
|
|
||||||
let view = PrivateMessageView::read(&mut context.pool(), private_message_id)
|
let view = PrivateMessageView::read(&mut context.pool(), private_message_id).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindPrivateMessage)?;
|
|
||||||
|
|
||||||
ActivityChannel::submit_activity(
|
ActivityChannel::submit_activity(
|
||||||
SendActivityData::UpdatePrivateMessage(view.clone()),
|
SendActivityData::UpdatePrivateMessage(view.clone()),
|
||||||
|
|
|
@ -234,7 +234,6 @@ pub async fn authenticate_with_oauth(
|
||||||
let oauth_provider = OAuthProvider::read(&mut context.pool(), oauth_provider_id)
|
let oauth_provider = OAuthProvider::read(&mut context.pool(), oauth_provider_id)
|
||||||
.await
|
.await
|
||||||
.ok()
|
.ok()
|
||||||
.flatten()
|
|
||||||
.ok_or(LemmyErrorType::OauthAuthorizationInvalid)?;
|
.ok_or(LemmyErrorType::OauthAuthorizationInvalid)?;
|
||||||
|
|
||||||
if !oauth_provider.enabled {
|
if !oauth_provider.enabled {
|
||||||
|
@ -262,10 +261,10 @@ pub async fn authenticate_with_oauth(
|
||||||
|
|
||||||
// Lookup user by oauth_user_id
|
// Lookup user by oauth_user_id
|
||||||
let mut local_user_view =
|
let mut local_user_view =
|
||||||
LocalUserView::find_by_oauth_id(&mut context.pool(), oauth_provider.id, &oauth_user_id).await?;
|
LocalUserView::find_by_oauth_id(&mut context.pool(), oauth_provider.id, &oauth_user_id).await;
|
||||||
|
|
||||||
let local_user: LocalUser;
|
let local_user: LocalUser;
|
||||||
if let Some(user_view) = local_user_view {
|
if let Ok(user_view) = local_user_view {
|
||||||
// user found by oauth_user_id => Login user
|
// user found by oauth_user_id => Login user
|
||||||
local_user = user_view.clone().local_user;
|
local_user = user_view.clone().local_user;
|
||||||
|
|
||||||
|
@ -292,10 +291,10 @@ pub async fn authenticate_with_oauth(
|
||||||
local_site.registration_mode == RegistrationMode::RequireApplication;
|
local_site.registration_mode == RegistrationMode::RequireApplication;
|
||||||
|
|
||||||
// Lookup user by OAUTH email and link accounts
|
// Lookup user by OAUTH email and link accounts
|
||||||
local_user_view = LocalUserView::find_by_email(&mut context.pool(), &email).await?;
|
local_user_view = LocalUserView::find_by_email(&mut context.pool(), &email).await;
|
||||||
|
|
||||||
let person;
|
let person;
|
||||||
if let Some(user_view) = local_user_view {
|
if let Ok(user_view) = local_user_view {
|
||||||
// user found by email => link and login if linking is allowed
|
// user found by email => link and login if linking is allowed
|
||||||
|
|
||||||
// we only allow linking by email when email_verification is required otherwise emails cannot
|
// we only allow linking by email when email_verification is required otherwise emails cannot
|
||||||
|
|
|
@ -22,10 +22,7 @@ use lemmy_db_schema::{
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
utils::DbPool,
|
utils::DbPool,
|
||||||
};
|
};
|
||||||
use lemmy_utils::{
|
use lemmy_utils::error::{LemmyError, LemmyResult};
|
||||||
error::{LemmyError, LemmyResult},
|
|
||||||
LemmyErrorType,
|
|
||||||
};
|
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
|
@ -182,7 +179,6 @@ pub(crate) async fn send_ban_from_community(
|
||||||
) -> LemmyResult<()> {
|
) -> LemmyResult<()> {
|
||||||
let community: ApubCommunity = Community::read(&mut context.pool(), community_id)
|
let community: ApubCommunity = Community::read(&mut context.pool(), community_id)
|
||||||
.await?
|
.await?
|
||||||
.ok_or(LemmyErrorType::CouldntFindCommunity)?
|
|
||||||
.into();
|
.into();
|
||||||
let expires = check_expire_time(data.expires)?;
|
let expires = check_expire_time(data.expires)?;
|
||||||
|
|
||||||
|
|
|
@ -220,7 +220,7 @@ async fn can_accept_activity_in_community(
|
||||||
}
|
}
|
||||||
// Local only community can't federate
|
// Local only community can't federate
|
||||||
if community.visibility != CommunityVisibility::Public {
|
if community.visibility != CommunityVisibility::Public {
|
||||||
return Err(LemmyErrorType::CouldntFindCommunity.into());
|
return Err(LemmyErrorType::NotFound.into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -36,10 +36,7 @@ use lemmy_db_schema::{
|
||||||
},
|
},
|
||||||
traits::{Crud, Joinable},
|
traits::{Crud, Joinable},
|
||||||
};
|
};
|
||||||
use lemmy_utils::{
|
use lemmy_utils::error::{LemmyError, LemmyResult};
|
||||||
error::{LemmyError, LemmyResult},
|
|
||||||
LemmyErrorType,
|
|
||||||
};
|
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
impl CollectionAdd {
|
impl CollectionAdd {
|
||||||
|
@ -129,9 +126,7 @@ impl ActivityHandler for CollectionAdd {
|
||||||
async fn receive(self, context: &Data<Self::DataType>) -> LemmyResult<()> {
|
async fn receive(self, context: &Data<Self::DataType>) -> LemmyResult<()> {
|
||||||
insert_received_activity(&self.id, context).await?;
|
insert_received_activity(&self.id, context).await?;
|
||||||
let (community, collection_type) =
|
let (community, collection_type) =
|
||||||
Community::get_by_collection_url(&mut context.pool(), &self.target.into())
|
Community::get_by_collection_url(&mut context.pool(), &self.target.into()).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindCommunity)?;
|
|
||||||
match collection_type {
|
match collection_type {
|
||||||
CollectionType::Moderators => {
|
CollectionType::Moderators => {
|
||||||
let new_mod = ObjectId::<ApubPerson>::from(self.object)
|
let new_mod = ObjectId::<ApubPerson>::from(self.object)
|
||||||
|
@ -188,11 +183,9 @@ pub(crate) async fn send_add_mod_to_community(
|
||||||
let actor: ApubPerson = actor.into();
|
let actor: ApubPerson = actor.into();
|
||||||
let community: ApubCommunity = Community::read(&mut context.pool(), community_id)
|
let community: ApubCommunity = Community::read(&mut context.pool(), community_id)
|
||||||
.await?
|
.await?
|
||||||
.ok_or(LemmyErrorType::CouldntFindCommunity)?
|
|
||||||
.into();
|
.into();
|
||||||
let updated_mod: ApubPerson = Person::read(&mut context.pool(), updated_mod_id)
|
let updated_mod: ApubPerson = Person::read(&mut context.pool(), updated_mod_id)
|
||||||
.await?
|
.await?
|
||||||
.ok_or(LemmyErrorType::CouldntFindPerson)?
|
|
||||||
.into();
|
.into();
|
||||||
if added {
|
if added {
|
||||||
CollectionAdd::send_add_mod(&community, &updated_mod, &actor, &context).await
|
CollectionAdd::send_add_mod(&community, &updated_mod, &actor, &context).await
|
||||||
|
@ -211,7 +204,6 @@ pub(crate) async fn send_feature_post(
|
||||||
let post: ApubPost = post.into();
|
let post: ApubPost = post.into();
|
||||||
let community = Community::read(&mut context.pool(), post.community_id)
|
let community = Community::read(&mut context.pool(), post.community_id)
|
||||||
.await?
|
.await?
|
||||||
.ok_or(LemmyErrorType::CouldntFindCommunity)?
|
|
||||||
.into();
|
.into();
|
||||||
if featured {
|
if featured {
|
||||||
CollectionAdd::send_add_featured_post(&community, &post, &actor, &context).await
|
CollectionAdd::send_add_featured_post(&community, &post, &actor, &context).await
|
||||||
|
|
|
@ -31,10 +31,7 @@ use lemmy_db_schema::{
|
||||||
},
|
},
|
||||||
traits::{Crud, Joinable},
|
traits::{Crud, Joinable},
|
||||||
};
|
};
|
||||||
use lemmy_utils::{
|
use lemmy_utils::error::{LemmyError, LemmyResult};
|
||||||
error::{LemmyError, LemmyResult},
|
|
||||||
LemmyErrorType,
|
|
||||||
};
|
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
impl CollectionRemove {
|
impl CollectionRemove {
|
||||||
|
@ -124,9 +121,7 @@ impl ActivityHandler for CollectionRemove {
|
||||||
async fn receive(self, context: &Data<Self::DataType>) -> LemmyResult<()> {
|
async fn receive(self, context: &Data<Self::DataType>) -> LemmyResult<()> {
|
||||||
insert_received_activity(&self.id, context).await?;
|
insert_received_activity(&self.id, context).await?;
|
||||||
let (community, collection_type) =
|
let (community, collection_type) =
|
||||||
Community::get_by_collection_url(&mut context.pool(), &self.target.into())
|
Community::get_by_collection_url(&mut context.pool(), &self.target.into()).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindCommunity)?;
|
|
||||||
match collection_type {
|
match collection_type {
|
||||||
CollectionType::Moderators => {
|
CollectionType::Moderators => {
|
||||||
let remove_mod = ObjectId::<ApubPerson>::from(self.object)
|
let remove_mod = ObjectId::<ApubPerson>::from(self.object)
|
||||||
|
|
|
@ -32,10 +32,7 @@ use lemmy_db_schema::{
|
||||||
},
|
},
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
};
|
};
|
||||||
use lemmy_utils::{
|
use lemmy_utils::error::{LemmyError, LemmyResult};
|
||||||
error::{LemmyError, LemmyResult},
|
|
||||||
LemmyErrorType,
|
|
||||||
};
|
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
|
@ -132,7 +129,6 @@ pub(crate) async fn send_lock_post(
|
||||||
) -> LemmyResult<()> {
|
) -> LemmyResult<()> {
|
||||||
let community: ApubCommunity = Community::read(&mut context.pool(), post.community_id)
|
let community: ApubCommunity = Community::read(&mut context.pool(), post.community_id)
|
||||||
.await?
|
.await?
|
||||||
.ok_or(LemmyErrorType::CouldntFindCommunity)?
|
|
||||||
.into();
|
.into();
|
||||||
let id = generate_activity_id(
|
let id = generate_activity_id(
|
||||||
LockType::Lock,
|
LockType::Lock,
|
||||||
|
|
|
@ -29,10 +29,7 @@ use lemmy_db_schema::{
|
||||||
},
|
},
|
||||||
traits::{Crud, Reportable},
|
traits::{Crud, Reportable},
|
||||||
};
|
};
|
||||||
use lemmy_utils::{
|
use lemmy_utils::error::{LemmyError, LemmyResult};
|
||||||
error::{LemmyError, LemmyResult},
|
|
||||||
LemmyErrorType,
|
|
||||||
};
|
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
impl Report {
|
impl Report {
|
||||||
|
@ -70,9 +67,7 @@ impl Report {
|
||||||
PostOrComment::Post(p) => p.creator_id,
|
PostOrComment::Post(p) => p.creator_id,
|
||||||
PostOrComment::Comment(c) => c.creator_id,
|
PostOrComment::Comment(c) => c.creator_id,
|
||||||
};
|
};
|
||||||
let object_creator = Person::read(&mut context.pool(), object_creator_id)
|
let object_creator = Person::read(&mut context.pool(), object_creator_id).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindPerson)?;
|
|
||||||
let object_creator_site: Option<ApubSite> =
|
let object_creator_site: Option<ApubSite> =
|
||||||
Site::read_from_instance_id(&mut context.pool(), object_creator.instance_id)
|
Site::read_from_instance_id(&mut context.pool(), object_creator.instance_id)
|
||||||
.await?
|
.await?
|
||||||
|
|
|
@ -42,7 +42,6 @@ use lemmy_db_schema::{
|
||||||
use lemmy_utils::{
|
use lemmy_utils::{
|
||||||
error::{LemmyError, LemmyResult},
|
error::{LemmyError, LemmyResult},
|
||||||
utils::mention::scrape_text_for_mentions,
|
utils::mention::scrape_text_for_mentions,
|
||||||
LemmyErrorType,
|
|
||||||
};
|
};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
|
@ -56,17 +55,11 @@ impl CreateOrUpdateNote {
|
||||||
) -> LemmyResult<()> {
|
) -> LemmyResult<()> {
|
||||||
// TODO: might be helpful to add a comment method to retrieve community directly
|
// TODO: might be helpful to add a comment method to retrieve community directly
|
||||||
let post_id = comment.post_id;
|
let post_id = comment.post_id;
|
||||||
let post = Post::read(&mut context.pool(), post_id)
|
let post = Post::read(&mut context.pool(), post_id).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindPost)?;
|
|
||||||
let community_id = post.community_id;
|
let community_id = post.community_id;
|
||||||
let person: ApubPerson = Person::read(&mut context.pool(), person_id)
|
let person: ApubPerson = Person::read(&mut context.pool(), person_id).await?.into();
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindPerson)?
|
|
||||||
.into();
|
|
||||||
let community: ApubCommunity = Community::read(&mut context.pool(), community_id)
|
let community: ApubCommunity = Community::read(&mut context.pool(), community_id)
|
||||||
.await?
|
.await?
|
||||||
.ok_or(LemmyErrorType::CouldntFindCommunity)?
|
|
||||||
.into();
|
.into();
|
||||||
|
|
||||||
let id = generate_activity_id(
|
let id = generate_activity_id(
|
||||||
|
|
|
@ -32,7 +32,7 @@ use lemmy_db_schema::{
|
||||||
},
|
},
|
||||||
traits::{Crud, Likeable},
|
traits::{Crud, Likeable},
|
||||||
};
|
};
|
||||||
use lemmy_utils::error::{LemmyError, LemmyErrorType, LemmyResult};
|
use lemmy_utils::error::{LemmyError, LemmyResult};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
impl CreateOrUpdatePage {
|
impl CreateOrUpdatePage {
|
||||||
|
@ -66,13 +66,9 @@ impl CreateOrUpdatePage {
|
||||||
context: Data<LemmyContext>,
|
context: Data<LemmyContext>,
|
||||||
) -> LemmyResult<()> {
|
) -> LemmyResult<()> {
|
||||||
let community_id = post.community_id;
|
let community_id = post.community_id;
|
||||||
let person: ApubPerson = Person::read(&mut context.pool(), person_id)
|
let person: ApubPerson = Person::read(&mut context.pool(), person_id).await?.into();
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindPerson)?
|
|
||||||
.into();
|
|
||||||
let community: ApubCommunity = Community::read(&mut context.pool(), community_id)
|
let community: ApubCommunity = Community::read(&mut context.pool(), community_id)
|
||||||
.await?
|
.await?
|
||||||
.ok_or(LemmyErrorType::CouldntFindCommunity)?
|
|
||||||
.into();
|
.into();
|
||||||
|
|
||||||
let create_or_update =
|
let create_or_update =
|
||||||
|
|
|
@ -176,8 +176,8 @@ pub(in crate::activities) async fn receive_remove_action(
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
// TODO these need to be implemented yet, for now, return errors
|
// TODO these need to be implemented yet, for now, return errors
|
||||||
DeletableObjects::PrivateMessage(_) => Err(LemmyErrorType::CouldntFindPrivateMessage)?,
|
DeletableObjects::PrivateMessage(_) => Err(LemmyErrorType::NotFound)?,
|
||||||
DeletableObjects::Person(_) => Err(LemmyErrorType::CouldntFindPerson)?,
|
DeletableObjects::Person(_) => Err(LemmyErrorType::NotFound)?,
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,7 @@ use lemmy_db_schema::{
|
||||||
},
|
},
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
};
|
};
|
||||||
use lemmy_utils::{error::LemmyResult, LemmyErrorType};
|
use lemmy_utils::error::LemmyResult;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
|
@ -87,7 +87,6 @@ pub(crate) async fn send_apub_delete_private_message(
|
||||||
let recipient_id = pm.recipient_id;
|
let recipient_id = pm.recipient_id;
|
||||||
let recipient: ApubPerson = Person::read(&mut context.pool(), recipient_id)
|
let recipient: ApubPerson = Person::read(&mut context.pool(), recipient_id)
|
||||||
.await?
|
.await?
|
||||||
.ok_or(LemmyErrorType::CouldntFindPerson)?
|
|
||||||
.into();
|
.into();
|
||||||
|
|
||||||
let deletable = DeletableObjects::PrivateMessage(pm.into());
|
let deletable = DeletableObjects::PrivateMessage(pm.into());
|
||||||
|
|
|
@ -156,8 +156,8 @@ impl UndoDelete {
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
// TODO these need to be implemented yet, for now, return errors
|
// TODO these need to be implemented yet, for now, return errors
|
||||||
DeletableObjects::PrivateMessage(_) => Err(LemmyErrorType::CouldntFindPrivateMessage)?,
|
DeletableObjects::PrivateMessage(_) => Err(LemmyErrorType::NotFound)?,
|
||||||
DeletableObjects::Person(_) => Err(LemmyErrorType::CouldntFindPerson)?,
|
DeletableObjects::Person(_) => Err(LemmyErrorType::NotFound)?,
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,7 +106,7 @@ impl ActivityHandler for Follow {
|
||||||
UserOrCommunity::Community(c) => {
|
UserOrCommunity::Community(c) => {
|
||||||
// Dont allow following local-only community via federation.
|
// Dont allow following local-only community via federation.
|
||||||
if c.visibility != CommunityVisibility::Public {
|
if c.visibility != CommunityVisibility::Public {
|
||||||
return Err(LemmyErrorType::CouldntFindCommunity.into());
|
return Err(LemmyErrorType::NotFound.into());
|
||||||
}
|
}
|
||||||
let form = CommunityFollowerForm {
|
let form = CommunityFollowerForm {
|
||||||
community_id: c.id,
|
community_id: c.id,
|
||||||
|
|
|
@ -245,9 +245,7 @@ pub async fn match_outgoing_activities(
|
||||||
CreateOrUpdatePage::send(post, creator_id, CreateOrUpdateType::Update, context).await
|
CreateOrUpdatePage::send(post, creator_id, CreateOrUpdateType::Update, context).await
|
||||||
}
|
}
|
||||||
DeletePost(post, person, data) => {
|
DeletePost(post, person, data) => {
|
||||||
let community = Community::read(&mut context.pool(), post.community_id)
|
let community = Community::read(&mut context.pool(), post.community_id).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindCommunity)?;
|
|
||||||
send_apub_delete_in_community(
|
send_apub_delete_in_community(
|
||||||
person,
|
person,
|
||||||
community,
|
community,
|
||||||
|
@ -264,9 +262,7 @@ pub async fn match_outgoing_activities(
|
||||||
reason,
|
reason,
|
||||||
removed,
|
removed,
|
||||||
} => {
|
} => {
|
||||||
let community = Community::read(&mut context.pool(), post.community_id)
|
let community = Community::read(&mut context.pool(), post.community_id).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindCommunity)?;
|
|
||||||
send_apub_delete_in_community(
|
send_apub_delete_in_community(
|
||||||
moderator,
|
moderator,
|
||||||
community,
|
community,
|
||||||
|
|
|
@ -117,7 +117,7 @@ impl InCommunity for AnnouncableActivities {
|
||||||
CollectionRemove(a) => a.community(context).await,
|
CollectionRemove(a) => a.community(context).await,
|
||||||
LockPost(a) => a.community(context).await,
|
LockPost(a) => a.community(context).await,
|
||||||
UndoLockPost(a) => a.community(context).await,
|
UndoLockPost(a) => a.community(context).await,
|
||||||
Page(_) => Err(LemmyErrorType::CouldntFindPost.into()),
|
Page(_) => Err(LemmyErrorType::NotFound.into()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,12 +64,7 @@ pub async fn list_comments(
|
||||||
|
|
||||||
// If a parent_id is given, fetch the comment to get the path
|
// If a parent_id is given, fetch the comment to get the path
|
||||||
let parent_path = if let Some(parent_id) = parent_id {
|
let parent_path = if let Some(parent_id) = parent_id {
|
||||||
Some(
|
Some(Comment::read(&mut context.pool(), parent_id).await?.path)
|
||||||
Comment::read(&mut context.pool(), parent_id)
|
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindComment)?
|
|
||||||
.path,
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
|
@ -13,7 +13,7 @@ use lemmy_db_schema::source::{
|
||||||
};
|
};
|
||||||
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};
|
||||||
use lemmy_utils::error::{LemmyErrorExt, LemmyErrorExt2, LemmyErrorType, LemmyResult};
|
use lemmy_utils::error::{LemmyErrorType, LemmyResult};
|
||||||
|
|
||||||
#[tracing::instrument(skip(context))]
|
#[tracing::instrument(skip(context))]
|
||||||
pub async fn get_community(
|
pub async fn get_community(
|
||||||
|
@ -36,8 +36,7 @@ pub async fn get_community(
|
||||||
None => {
|
None => {
|
||||||
let name = data.name.clone().unwrap_or_else(|| "main".to_string());
|
let name = data.name.clone().unwrap_or_else(|| "main".to_string());
|
||||||
resolve_actor_identifier::<ApubCommunity, Community>(&name, &context, &local_user_view, true)
|
resolve_actor_identifier::<ApubCommunity, Community>(&name, &context, &local_user_view, true)
|
||||||
.await
|
.await?
|
||||||
.with_lemmy_type(LemmyErrorType::CouldntFindCommunity)?
|
|
||||||
.id
|
.id
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -56,12 +55,9 @@ pub async fn get_community(
|
||||||
local_user,
|
local_user,
|
||||||
is_mod_or_admin,
|
is_mod_or_admin,
|
||||||
)
|
)
|
||||||
.await?
|
.await?;
|
||||||
.ok_or(LemmyErrorType::CouldntFindCommunity)?;
|
|
||||||
|
|
||||||
let moderators = CommunityModeratorView::for_community(&mut context.pool(), community_id)
|
let moderators = CommunityModeratorView::for_community(&mut context.pool(), community_id).await?;
|
||||||
.await
|
|
||||||
.with_lemmy_type(LemmyErrorType::CouldntFindCommunity)?;
|
|
||||||
|
|
||||||
let site = read_site_for_actor(community_view.community.actor_id.clone(), &context).await?;
|
let site = read_site_for_actor(community_view.community.actor_id.clone(), &context).await?;
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ use lemmy_db_views::{
|
||||||
structs::{LocalUserView, SiteView},
|
structs::{LocalUserView, SiteView},
|
||||||
};
|
};
|
||||||
use lemmy_db_views_actor::structs::{CommunityModeratorView, PersonView};
|
use lemmy_db_views_actor::structs::{CommunityModeratorView, PersonView};
|
||||||
use lemmy_utils::error::{LemmyErrorExt2, LemmyErrorType, LemmyResult};
|
use lemmy_utils::error::{LemmyErrorType, LemmyResult};
|
||||||
|
|
||||||
#[tracing::instrument(skip(context))]
|
#[tracing::instrument(skip(context))]
|
||||||
pub async fn read_person(
|
pub async fn read_person(
|
||||||
|
@ -35,20 +35,17 @@ pub async fn read_person(
|
||||||
None => {
|
None => {
|
||||||
if let Some(username) = &data.username {
|
if let Some(username) = &data.username {
|
||||||
resolve_actor_identifier::<ApubPerson, Person>(username, &context, &local_user_view, true)
|
resolve_actor_identifier::<ApubPerson, Person>(username, &context, &local_user_view, true)
|
||||||
.await
|
.await?
|
||||||
.with_lemmy_type(LemmyErrorType::CouldntFindPerson)?
|
|
||||||
.id
|
.id
|
||||||
} else {
|
} else {
|
||||||
Err(LemmyErrorType::CouldntFindPerson)?
|
Err(LemmyErrorType::NotFound)?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// 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)
|
let person_view = PersonView::read(&mut context.pool(), person_details_id).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindPerson)?;
|
|
||||||
|
|
||||||
let sort = data.sort;
|
let sort = data.sort;
|
||||||
let page = data.page;
|
let page = data.page;
|
||||||
|
|
|
@ -34,11 +34,11 @@ pub async fn resolve_object(
|
||||||
// user isn't authenticated only allow a local search.
|
// user isn't authenticated only allow a local search.
|
||||||
search_query_to_object_id_local(&data.q, &context).await
|
search_query_to_object_id_local(&data.q, &context).await
|
||||||
}
|
}
|
||||||
.with_lemmy_type(LemmyErrorType::CouldntFindObject)?;
|
.with_lemmy_type(LemmyErrorType::NotFound)?;
|
||||||
|
|
||||||
convert_response(res, local_user_view, &mut context.pool())
|
convert_response(res, local_user_view, &mut context.pool())
|
||||||
.await
|
.await
|
||||||
.with_lemmy_type(LemmyErrorType::CouldntFindObject)
|
.with_lemmy_type(LemmyErrorType::NotFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn convert_response(
|
async fn convert_response(
|
||||||
|
@ -54,36 +54,20 @@ async fn convert_response(
|
||||||
match object {
|
match object {
|
||||||
Post(p) => {
|
Post(p) => {
|
||||||
removed_or_deleted = p.deleted || p.removed;
|
removed_or_deleted = p.deleted || p.removed;
|
||||||
res.post = Some(
|
res.post = Some(PostView::read(pool, p.id, local_user.as_ref(), false).await?)
|
||||||
PostView::read(pool, p.id, local_user.as_ref(), false)
|
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindPost)?,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
Comment(c) => {
|
Comment(c) => {
|
||||||
removed_or_deleted = c.deleted || c.removed;
|
removed_or_deleted = c.deleted || c.removed;
|
||||||
res.comment = Some(
|
res.comment = Some(CommentView::read(pool, c.id, local_user.as_ref()).await?)
|
||||||
CommentView::read(pool, c.id, local_user.as_ref())
|
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindComment)?,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
PersonOrCommunity(p) => match *p {
|
PersonOrCommunity(p) => match *p {
|
||||||
UserOrCommunity::User(u) => {
|
UserOrCommunity::User(u) => {
|
||||||
removed_or_deleted = u.deleted;
|
removed_or_deleted = u.deleted;
|
||||||
res.person = Some(
|
res.person = Some(PersonView::read(pool, u.id).await?)
|
||||||
PersonView::read(pool, u.id)
|
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindPerson)?,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
UserOrCommunity::Community(c) => {
|
UserOrCommunity::Community(c) => {
|
||||||
removed_or_deleted = c.deleted || c.removed;
|
removed_or_deleted = c.deleted || c.removed;
|
||||||
res.community = Some(
|
res.community = Some(CommunityView::read(pool, c.id, local_user.as_ref(), false).await?)
|
||||||
CommunityView::read(pool, c.id, local_user.as_ref(), false)
|
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindCommunity)?,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -348,11 +348,7 @@ mod tests {
|
||||||
let user_form = LocalUserInsertForm::test_form(person.id);
|
let user_form = LocalUserInsertForm::test_form(person.id);
|
||||||
let local_user = LocalUser::create(&mut context.pool(), &user_form, vec![]).await?;
|
let local_user = LocalUser::create(&mut context.pool(), &user_form, vec![]).await?;
|
||||||
|
|
||||||
Ok(
|
Ok(LocalUserView::read(&mut context.pool(), local_user.id).await?)
|
||||||
LocalUserView::read(&mut context.pool(), local_user.id)
|
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindLocalUser)?,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
|
@ -385,9 +381,8 @@ mod tests {
|
||||||
// wait for background task to finish
|
// wait for background task to finish
|
||||||
sleep(Duration::from_millis(1000)).await;
|
sleep(Duration::from_millis(1000)).await;
|
||||||
|
|
||||||
let import_user_updated = LocalUserView::read(&mut context.pool(), import_user.local_user.id)
|
let import_user_updated =
|
||||||
.await?
|
LocalUserView::read(&mut context.pool(), import_user.local_user.id).await?;
|
||||||
.ok_or(LemmyErrorType::CouldntFindLocalUser)?;
|
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
export_user.person.display_name,
|
export_user.person.display_name,
|
||||||
|
|
|
@ -12,10 +12,7 @@ use lemmy_db_schema::{
|
||||||
source::{community::Community, post::Post},
|
source::{community::Community, post::Post},
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
};
|
};
|
||||||
use lemmy_utils::{
|
use lemmy_utils::error::{LemmyError, LemmyResult};
|
||||||
error::{LemmyError, LemmyResult},
|
|
||||||
LemmyErrorType,
|
|
||||||
};
|
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
|
@ -97,15 +94,9 @@ impl InCommunity for PostOrComment {
|
||||||
PostOrComment::Comment(c) => {
|
PostOrComment::Comment(c) => {
|
||||||
Post::read(&mut context.pool(), c.post_id)
|
Post::read(&mut context.pool(), c.post_id)
|
||||||
.await?
|
.await?
|
||||||
.ok_or(LemmyErrorType::CouldntFindPost)?
|
|
||||||
.community_id
|
.community_id
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Ok(
|
Ok(Community::read(&mut context.pool(), cid).await?.into())
|
||||||
Community::read(&mut context.pool(), cid)
|
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindCommunity)?
|
|
||||||
.into(),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ use lemmy_db_schema::{
|
||||||
source::{comment::Comment, community::Community, post::Post},
|
source::{comment::Comment, community::Community, post::Post},
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
};
|
};
|
||||||
use lemmy_utils::{error::LemmyResult, LemmyErrorType};
|
use lemmy_utils::error::LemmyResult;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
|
@ -31,16 +31,9 @@ pub(crate) async fn get_apub_comment(
|
||||||
) -> LemmyResult<HttpResponse> {
|
) -> LemmyResult<HttpResponse> {
|
||||||
let id = CommentId(info.comment_id.parse::<i32>()?);
|
let id = CommentId(info.comment_id.parse::<i32>()?);
|
||||||
// Can't use CommentView here because it excludes deleted/removed/local-only items
|
// Can't use CommentView here because it excludes deleted/removed/local-only items
|
||||||
let comment: ApubComment = Comment::read(&mut context.pool(), id)
|
let comment: ApubComment = Comment::read(&mut context.pool(), id).await?.into();
|
||||||
.await?
|
let post = Post::read(&mut context.pool(), comment.post_id).await?;
|
||||||
.ok_or(LemmyErrorType::CouldntFindComment)?
|
let community = Community::read(&mut context.pool(), post.community_id).await?;
|
||||||
.into();
|
|
||||||
let post = Post::read(&mut context.pool(), comment.post_id)
|
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindPost)?;
|
|
||||||
let community = Community::read(&mut context.pool(), post.community_id)
|
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindCommunity)?;
|
|
||||||
check_community_public(&community)?;
|
check_community_public(&community)?;
|
||||||
|
|
||||||
if !comment.local {
|
if !comment.local {
|
||||||
|
|
|
@ -35,7 +35,7 @@ pub(crate) async fn get_apub_community_http(
|
||||||
let community: ApubCommunity =
|
let community: ApubCommunity =
|
||||||
Community::read_from_name(&mut context.pool(), &info.community_name, true)
|
Community::read_from_name(&mut context.pool(), &info.community_name, true)
|
||||||
.await?
|
.await?
|
||||||
.ok_or(LemmyErrorType::CouldntFindCommunity)?
|
.ok_or(LemmyErrorType::NotFound)?
|
||||||
.into();
|
.into();
|
||||||
|
|
||||||
if community.deleted || community.removed {
|
if community.deleted || community.removed {
|
||||||
|
@ -67,7 +67,7 @@ pub(crate) async fn get_apub_community_followers(
|
||||||
) -> LemmyResult<HttpResponse> {
|
) -> LemmyResult<HttpResponse> {
|
||||||
let community = Community::read_from_name(&mut context.pool(), &info.community_name, false)
|
let community = Community::read_from_name(&mut context.pool(), &info.community_name, false)
|
||||||
.await?
|
.await?
|
||||||
.ok_or(LemmyErrorType::CouldntFindCommunity)?;
|
.ok_or(LemmyErrorType::NotFound)?;
|
||||||
check_community_public(&community)?;
|
check_community_public(&community)?;
|
||||||
let followers = ApubCommunityFollower::read_local(&community.into(), &context).await?;
|
let followers = ApubCommunityFollower::read_local(&community.into(), &context).await?;
|
||||||
create_apub_response(&followers)
|
create_apub_response(&followers)
|
||||||
|
@ -82,7 +82,7 @@ pub(crate) async fn get_apub_community_outbox(
|
||||||
let community: ApubCommunity =
|
let community: ApubCommunity =
|
||||||
Community::read_from_name(&mut context.pool(), &info.community_name, false)
|
Community::read_from_name(&mut context.pool(), &info.community_name, false)
|
||||||
.await?
|
.await?
|
||||||
.ok_or(LemmyErrorType::CouldntFindCommunity)?
|
.ok_or(LemmyErrorType::NotFound)?
|
||||||
.into();
|
.into();
|
||||||
check_community_public(&community)?;
|
check_community_public(&community)?;
|
||||||
let outbox = ApubCommunityOutbox::read_local(&community, &context).await?;
|
let outbox = ApubCommunityOutbox::read_local(&community, &context).await?;
|
||||||
|
@ -97,7 +97,7 @@ pub(crate) async fn get_apub_community_moderators(
|
||||||
let community: ApubCommunity =
|
let community: ApubCommunity =
|
||||||
Community::read_from_name(&mut context.pool(), &info.community_name, false)
|
Community::read_from_name(&mut context.pool(), &info.community_name, false)
|
||||||
.await?
|
.await?
|
||||||
.ok_or(LemmyErrorType::CouldntFindCommunity)?
|
.ok_or(LemmyErrorType::NotFound)?
|
||||||
.into();
|
.into();
|
||||||
check_community_public(&community)?;
|
check_community_public(&community)?;
|
||||||
let moderators = ApubCommunityModerators::read_local(&community, &context).await?;
|
let moderators = ApubCommunityModerators::read_local(&community, &context).await?;
|
||||||
|
@ -112,7 +112,7 @@ pub(crate) async fn get_apub_community_featured(
|
||||||
let community: ApubCommunity =
|
let community: ApubCommunity =
|
||||||
Community::read_from_name(&mut context.pool(), &info.community_name, false)
|
Community::read_from_name(&mut context.pool(), &info.community_name, false)
|
||||||
.await?
|
.await?
|
||||||
.ok_or(LemmyErrorType::CouldntFindCommunity)?
|
.ok_or(LemmyErrorType::NotFound)?
|
||||||
.into();
|
.into();
|
||||||
check_community_public(&community)?;
|
check_community_public(&community)?;
|
||||||
let featured = ApubCommunityFeatured::read_local(&community, &context).await?;
|
let featured = ApubCommunityFeatured::read_local(&community, &context).await?;
|
||||||
|
|
|
@ -122,7 +122,7 @@ fn check_community_public(community: &Community) -> LemmyResult<()> {
|
||||||
Err(LemmyErrorType::Deleted)?
|
Err(LemmyErrorType::Deleted)?
|
||||||
}
|
}
|
||||||
if community.visibility != CommunityVisibility::Public {
|
if community.visibility != CommunityVisibility::Public {
|
||||||
return Err(LemmyErrorType::CouldntFindCommunity.into());
|
return Err(LemmyErrorType::NotFound.into());
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ pub(crate) async fn get_apub_person_http(
|
||||||
// TODO: this needs to be able to read deleted persons, so that it can send tombstones
|
// TODO: this needs to be able to read deleted persons, so that it can send tombstones
|
||||||
let person: ApubPerson = Person::read_from_name(&mut context.pool(), &user_name, true)
|
let person: ApubPerson = Person::read_from_name(&mut context.pool(), &user_name, true)
|
||||||
.await?
|
.await?
|
||||||
.ok_or(LemmyErrorType::CouldntFindPerson)?
|
.ok_or(LemmyErrorType::NotFound)?
|
||||||
.into();
|
.into();
|
||||||
|
|
||||||
if !person.deleted {
|
if !person.deleted {
|
||||||
|
@ -63,7 +63,7 @@ pub(crate) async fn get_apub_person_outbox(
|
||||||
) -> LemmyResult<HttpResponse> {
|
) -> LemmyResult<HttpResponse> {
|
||||||
let person = Person::read_from_name(&mut context.pool(), &info.user_name, false)
|
let person = Person::read_from_name(&mut context.pool(), &info.user_name, false)
|
||||||
.await?
|
.await?
|
||||||
.ok_or(LemmyErrorType::CouldntFindPerson)?;
|
.ok_or(LemmyErrorType::NotFound)?;
|
||||||
let outbox_id = generate_outbox_url(&person.actor_id)?.into();
|
let outbox_id = generate_outbox_url(&person.actor_id)?.into();
|
||||||
let outbox = EmptyOutbox::new(outbox_id)?;
|
let outbox = EmptyOutbox::new(outbox_id)?;
|
||||||
create_apub_response(&outbox)
|
create_apub_response(&outbox)
|
||||||
|
|
|
@ -15,7 +15,7 @@ use lemmy_db_schema::{
|
||||||
source::{community::Community, post::Post},
|
source::{community::Community, post::Post},
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
};
|
};
|
||||||
use lemmy_utils::{error::LemmyResult, LemmyErrorType};
|
use lemmy_utils::error::LemmyResult;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
|
@ -31,13 +31,8 @@ pub(crate) async fn get_apub_post(
|
||||||
) -> LemmyResult<HttpResponse> {
|
) -> LemmyResult<HttpResponse> {
|
||||||
let id = PostId(info.post_id.parse::<i32>()?);
|
let id = PostId(info.post_id.parse::<i32>()?);
|
||||||
// Can't use PostView here because it excludes deleted/removed/local-only items
|
// Can't use PostView here because it excludes deleted/removed/local-only items
|
||||||
let post: ApubPost = Post::read(&mut context.pool(), id)
|
let post: ApubPost = Post::read(&mut context.pool(), id).await?.into();
|
||||||
.await?
|
let community = Community::read(&mut context.pool(), post.community_id).await?;
|
||||||
.ok_or(LemmyErrorType::CouldntFindPost)?
|
|
||||||
.into();
|
|
||||||
let community = Community::read(&mut context.pool(), post.community_id)
|
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindCommunity)?;
|
|
||||||
check_community_public(&community)?;
|
check_community_public(&community)?;
|
||||||
|
|
||||||
if !post.local {
|
if !post.local {
|
||||||
|
|
|
@ -99,21 +99,12 @@ async fn get_comment_parent_creator(
|
||||||
comment: &Comment,
|
comment: &Comment,
|
||||||
) -> LemmyResult<ApubPerson> {
|
) -> LemmyResult<ApubPerson> {
|
||||||
let parent_creator_id = if let Some(parent_comment_id) = comment.parent_comment_id() {
|
let parent_creator_id = if let Some(parent_comment_id) = comment.parent_comment_id() {
|
||||||
let parent_comment = Comment::read(pool, parent_comment_id)
|
let parent_comment = Comment::read(pool, parent_comment_id).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindComment)?;
|
|
||||||
parent_comment.creator_id
|
parent_comment.creator_id
|
||||||
} else {
|
} else {
|
||||||
let parent_post_id = comment.post_id;
|
let parent_post_id = comment.post_id;
|
||||||
let parent_post = Post::read(pool, parent_post_id)
|
let parent_post = Post::read(pool, parent_post_id).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindPost)?;
|
|
||||||
parent_post.creator_id
|
parent_post.creator_id
|
||||||
};
|
};
|
||||||
Ok(
|
Ok(Person::read(pool, parent_creator_id).await?.into())
|
||||||
Person::read(pool, parent_creator_id)
|
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindPerson)?
|
|
||||||
.into(),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,23 +91,15 @@ impl Object for ApubComment {
|
||||||
#[tracing::instrument(skip_all)]
|
#[tracing::instrument(skip_all)]
|
||||||
async fn into_json(self, context: &Data<Self::DataType>) -> LemmyResult<Note> {
|
async fn into_json(self, context: &Data<Self::DataType>) -> LemmyResult<Note> {
|
||||||
let creator_id = self.creator_id;
|
let creator_id = self.creator_id;
|
||||||
let creator = Person::read(&mut context.pool(), creator_id)
|
let creator = Person::read(&mut context.pool(), creator_id).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindPerson)?;
|
|
||||||
|
|
||||||
let post_id = self.post_id;
|
let post_id = self.post_id;
|
||||||
let post = Post::read(&mut context.pool(), post_id)
|
let post = Post::read(&mut context.pool(), post_id).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindPost)?;
|
|
||||||
let community_id = post.community_id;
|
let community_id = post.community_id;
|
||||||
let community = Community::read(&mut context.pool(), community_id)
|
let community = Community::read(&mut context.pool(), community_id).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindCommunity)?;
|
|
||||||
|
|
||||||
let in_reply_to = if let Some(comment_id) = self.parent_comment_id() {
|
let in_reply_to = if let Some(comment_id) = self.parent_comment_id() {
|
||||||
let parent_comment = Comment::read(&mut context.pool(), comment_id)
|
let parent_comment = Comment::read(&mut context.pool(), comment_id).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindComment)?;
|
|
||||||
parent_comment.ap_id.into()
|
parent_comment.ap_id.into()
|
||||||
} else {
|
} else {
|
||||||
post.ap_id.into()
|
post.ap_id.into()
|
||||||
|
|
|
@ -107,13 +107,9 @@ impl Object for ApubPost {
|
||||||
#[tracing::instrument(skip_all)]
|
#[tracing::instrument(skip_all)]
|
||||||
async fn into_json(self, context: &Data<Self::DataType>) -> LemmyResult<Page> {
|
async fn into_json(self, context: &Data<Self::DataType>) -> LemmyResult<Page> {
|
||||||
let creator_id = self.creator_id;
|
let creator_id = self.creator_id;
|
||||||
let creator = Person::read(&mut context.pool(), creator_id)
|
let creator = Person::read(&mut context.pool(), creator_id).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindPerson)?;
|
|
||||||
let community_id = self.community_id;
|
let community_id = self.community_id;
|
||||||
let community = Community::read(&mut context.pool(), community_id)
|
let community = Community::read(&mut context.pool(), community_id).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindCommunity)?;
|
|
||||||
let language = LanguageTag::new_single(self.language_id, &mut context.pool()).await?;
|
let language = LanguageTag::new_single(self.language_id, &mut context.pool()).await?;
|
||||||
|
|
||||||
let attachment = self
|
let attachment = self
|
||||||
|
|
|
@ -73,20 +73,16 @@ impl Object for ApubPrivateMessage {
|
||||||
|
|
||||||
async fn delete(self, _context: &Data<Self::DataType>) -> LemmyResult<()> {
|
async fn delete(self, _context: &Data<Self::DataType>) -> LemmyResult<()> {
|
||||||
// do nothing, because pm can't be fetched over http
|
// do nothing, because pm can't be fetched over http
|
||||||
Err(LemmyErrorType::CouldntFindPrivateMessage.into())
|
Err(LemmyErrorType::NotFound.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip_all)]
|
#[tracing::instrument(skip_all)]
|
||||||
async fn into_json(self, context: &Data<Self::DataType>) -> LemmyResult<ChatMessage> {
|
async fn into_json(self, context: &Data<Self::DataType>) -> LemmyResult<ChatMessage> {
|
||||||
let creator_id = self.creator_id;
|
let creator_id = self.creator_id;
|
||||||
let creator = Person::read(&mut context.pool(), creator_id)
|
let creator = Person::read(&mut context.pool(), creator_id).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindPerson)?;
|
|
||||||
|
|
||||||
let recipient_id = self.recipient_id;
|
let recipient_id = self.recipient_id;
|
||||||
let recipient = Person::read(&mut context.pool(), recipient_id)
|
let recipient = Person::read(&mut context.pool(), recipient_id).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindPerson)?;
|
|
||||||
|
|
||||||
let note = ChatMessage {
|
let note = ChatMessage {
|
||||||
r#type: ChatMessageType::ChatMessage,
|
r#type: ChatMessageType::ChatMessage,
|
||||||
|
|
|
@ -11,7 +11,7 @@ use activitypub_federation::{
|
||||||
};
|
};
|
||||||
use lemmy_api_common::context::LemmyContext;
|
use lemmy_api_common::context::LemmyContext;
|
||||||
use lemmy_db_schema::source::community::Community;
|
use lemmy_db_schema::source::community::Community;
|
||||||
use lemmy_utils::{error::LemmyResult, LemmyErrorType};
|
use lemmy_utils::error::LemmyResult;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
|
@ -35,9 +35,7 @@ pub struct CollectionAdd {
|
||||||
impl InCommunity for CollectionAdd {
|
impl InCommunity for CollectionAdd {
|
||||||
async fn community(&self, context: &Data<LemmyContext>) -> LemmyResult<ApubCommunity> {
|
async fn community(&self, context: &Data<LemmyContext>) -> LemmyResult<ApubCommunity> {
|
||||||
let (community, _) =
|
let (community, _) =
|
||||||
Community::get_by_collection_url(&mut context.pool(), &self.clone().target.into())
|
Community::get_by_collection_url(&mut context.pool(), &self.clone().target.into()).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindCommunity)?;
|
|
||||||
if let Some(audience) = &self.audience {
|
if let Some(audience) = &self.audience {
|
||||||
verify_community_matches(audience, community.actor_id.clone())?;
|
verify_community_matches(audience, community.actor_id.clone())?;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ use activitypub_federation::{
|
||||||
};
|
};
|
||||||
use lemmy_api_common::context::LemmyContext;
|
use lemmy_api_common::context::LemmyContext;
|
||||||
use lemmy_db_schema::source::community::Community;
|
use lemmy_db_schema::source::community::Community;
|
||||||
use lemmy_utils::{error::LemmyResult, LemmyErrorType};
|
use lemmy_utils::error::LemmyResult;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
|
@ -35,9 +35,7 @@ pub struct CollectionRemove {
|
||||||
impl InCommunity for CollectionRemove {
|
impl InCommunity for CollectionRemove {
|
||||||
async fn community(&self, context: &Data<LemmyContext>) -> LemmyResult<ApubCommunity> {
|
async fn community(&self, context: &Data<LemmyContext>) -> LemmyResult<ApubCommunity> {
|
||||||
let (community, _) =
|
let (community, _) =
|
||||||
Community::get_by_collection_url(&mut context.pool(), &self.clone().target.into())
|
Community::get_by_collection_url(&mut context.pool(), &self.clone().target.into()).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindCommunity)?;
|
|
||||||
if let Some(audience) = &self.audience {
|
if let Some(audience) = &self.audience {
|
||||||
verify_community_matches(audience, community.actor_id.clone())?;
|
verify_community_matches(audience, community.actor_id.clone())?;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ use activitypub_federation::{
|
||||||
};
|
};
|
||||||
use lemmy_api_common::context::LemmyContext;
|
use lemmy_api_common::context::LemmyContext;
|
||||||
use lemmy_db_schema::{source::community::Community, traits::Crud};
|
use lemmy_db_schema::{source::community::Community, traits::Crud};
|
||||||
use lemmy_utils::{error::LemmyResult, LemmyErrorType};
|
use lemmy_utils::error::LemmyResult;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use strum::Display;
|
use strum::Display;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
@ -55,9 +55,7 @@ pub struct UndoLockPage {
|
||||||
impl InCommunity for LockPage {
|
impl InCommunity for LockPage {
|
||||||
async fn community(&self, context: &Data<LemmyContext>) -> LemmyResult<ApubCommunity> {
|
async fn community(&self, context: &Data<LemmyContext>) -> LemmyResult<ApubCommunity> {
|
||||||
let post = self.object.dereference(context).await?;
|
let post = self.object.dereference(context).await?;
|
||||||
let community = Community::read(&mut context.pool(), post.community_id)
|
let community = Community::read(&mut context.pool(), post.community_id).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindCommunity)?;
|
|
||||||
if let Some(audience) = &self.audience {
|
if let Some(audience) = &self.audience {
|
||||||
verify_community_matches(audience, community.actor_id.clone())?;
|
verify_community_matches(audience, community.actor_id.clone())?;
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ impl Report {
|
||||||
.summary
|
.summary
|
||||||
.clone()
|
.clone()
|
||||||
.or(self.content.clone())
|
.or(self.content.clone())
|
||||||
.ok_or(LemmyErrorType::CouldntFindObject.into())
|
.ok_or(LemmyErrorType::NotFound.into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ impl ReportObject {
|
||||||
return deref;
|
return deref;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(LemmyErrorType::CouldntFindObject.into())
|
Err(LemmyErrorType::NotFound.into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ use activitypub_federation::{
|
||||||
};
|
};
|
||||||
use lemmy_api_common::context::LemmyContext;
|
use lemmy_api_common::context::LemmyContext;
|
||||||
use lemmy_db_schema::{source::community::Community, traits::Crud};
|
use lemmy_db_schema::{source::community::Community, traits::Crud};
|
||||||
use lemmy_utils::{error::LemmyResult, LemmyErrorType};
|
use lemmy_utils::error::LemmyResult;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
|
@ -36,9 +36,7 @@ pub struct CreateOrUpdateNote {
|
||||||
impl InCommunity for CreateOrUpdateNote {
|
impl InCommunity for CreateOrUpdateNote {
|
||||||
async fn community(&self, context: &Data<LemmyContext>) -> LemmyResult<ApubCommunity> {
|
async fn community(&self, context: &Data<LemmyContext>) -> LemmyResult<ApubCommunity> {
|
||||||
let post = self.object.get_parents(context).await?.0;
|
let post = self.object.get_parents(context).await?.0;
|
||||||
let community = Community::read(&mut context.pool(), post.community_id)
|
let community = Community::read(&mut context.pool(), post.community_id).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindCommunity)?;
|
|
||||||
if let Some(audience) = &self.audience {
|
if let Some(audience) = &self.audience {
|
||||||
verify_community_matches(audience, community.actor_id.clone())?;
|
verify_community_matches(audience, community.actor_id.clone())?;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ use lemmy_db_schema::{
|
||||||
source::{community::Community, post::Post},
|
source::{community::Community, post::Post},
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
};
|
};
|
||||||
use lemmy_utils::{error::LemmyResult, LemmyErrorType};
|
use lemmy_utils::error::LemmyResult;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_with::skip_serializing_none;
|
use serde_with::skip_serializing_none;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
@ -51,9 +51,7 @@ impl InCommunity for Delete {
|
||||||
let community_id = match DeletableObjects::read_from_db(self.object.id(), context).await? {
|
let community_id = match DeletableObjects::read_from_db(self.object.id(), context).await? {
|
||||||
DeletableObjects::Community(c) => c.id,
|
DeletableObjects::Community(c) => c.id,
|
||||||
DeletableObjects::Comment(c) => {
|
DeletableObjects::Comment(c) => {
|
||||||
let post = Post::read(&mut context.pool(), c.post_id)
|
let post = Post::read(&mut context.pool(), c.post_id).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindPost)?;
|
|
||||||
post.community_id
|
post.community_id
|
||||||
}
|
}
|
||||||
DeletableObjects::Post(p) => p.community_id,
|
DeletableObjects::Post(p) => p.community_id,
|
||||||
|
@ -62,9 +60,7 @@ impl InCommunity for Delete {
|
||||||
return Err(anyhow!("Private message is not part of community").into())
|
return Err(anyhow!("Private message is not part of community").into())
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let community = Community::read(&mut context.pool(), community_id)
|
let community = Community::read(&mut context.pool(), community_id).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindCommunity)?;
|
|
||||||
if let Some(audience) = &self.audience {
|
if let Some(audience) = &self.audience {
|
||||||
verify_community_matches(audience, community.actor_id.clone())?;
|
verify_community_matches(audience, community.actor_id.clone())?;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ use lemmy_db_schema::{
|
||||||
source::{community::Community, post::Post},
|
source::{community::Community, post::Post},
|
||||||
traits::Crud,
|
traits::Crud,
|
||||||
};
|
};
|
||||||
use lemmy_utils::{error::LemmyResult, LemmyErrorType};
|
use lemmy_utils::error::LemmyResult;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_with::skip_serializing_none;
|
use serde_with::skip_serializing_none;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
@ -64,9 +64,7 @@ impl Note {
|
||||||
PostOrComment::Post(p) => Ok((p.clone(), None)),
|
PostOrComment::Post(p) => Ok((p.clone(), None)),
|
||||||
PostOrComment::Comment(c) => {
|
PostOrComment::Comment(c) => {
|
||||||
let post_id = c.post_id;
|
let post_id = c.post_id;
|
||||||
let post = Post::read(&mut context.pool(), post_id)
|
let post = Post::read(&mut context.pool(), post_id).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindPost)?;
|
|
||||||
Ok((post.into(), Some(c.clone())))
|
Ok((post.into(), Some(c.clone())))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -77,9 +75,7 @@ impl Note {
|
||||||
impl InCommunity for Note {
|
impl InCommunity for Note {
|
||||||
async fn community(&self, context: &Data<LemmyContext>) -> LemmyResult<ApubCommunity> {
|
async fn community(&self, context: &Data<LemmyContext>) -> LemmyResult<ApubCommunity> {
|
||||||
let (post, _) = self.get_parents(context).await?;
|
let (post, _) = self.get_parents(context).await?;
|
||||||
let community = Community::read(&mut context.pool(), post.community_id)
|
let community = Community::read(&mut context.pool(), post.community_id).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindCommunity)?;
|
|
||||||
if let Some(audience) = &self.audience {
|
if let Some(audience) = &self.audience {
|
||||||
verify_community_matches(audience, community.actor_id.clone())?;
|
verify_community_matches(audience, community.actor_id.clone())?;
|
||||||
}
|
}
|
||||||
|
|
|
@ -226,7 +226,7 @@ impl InCommunity for Page {
|
||||||
break c;
|
break c;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Err(LemmyErrorType::CouldntFindCommunity)?;
|
Err(LemmyErrorType::NotFound)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -234,7 +234,7 @@ impl InCommunity for Page {
|
||||||
p.iter()
|
p.iter()
|
||||||
.find(|a| a.kind == PersonOrGroupType::Group)
|
.find(|a| a.kind == PersonOrGroupType::Group)
|
||||||
.map(|a| ObjectId::<ApubCommunity>::from(a.id.clone().into_inner()))
|
.map(|a| ObjectId::<ApubCommunity>::from(a.id.clone().into_inner()))
|
||||||
.ok_or(LemmyErrorType::CouldntFindCommunity)?
|
.ok_or(LemmyErrorType::NotFound)?
|
||||||
.dereference(context)
|
.dereference(context)
|
||||||
.await?
|
.await?
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
aggregates::structs::CommentAggregates,
|
aggregates::structs::CommentAggregates,
|
||||||
diesel::OptionalExtension,
|
|
||||||
newtypes::CommentId,
|
newtypes::CommentId,
|
||||||
schema::comment_aggregates,
|
schema::comment_aggregates,
|
||||||
utils::{functions::hot_rank, get_conn, DbPool},
|
utils::{functions::hot_rank, get_conn, DbPool},
|
||||||
|
@ -9,13 +8,9 @@ use diesel::{result::Error, ExpressionMethods, QueryDsl};
|
||||||
use diesel_async::RunQueryDsl;
|
use diesel_async::RunQueryDsl;
|
||||||
|
|
||||||
impl CommentAggregates {
|
impl CommentAggregates {
|
||||||
pub async fn read(pool: &mut DbPool<'_>, comment_id: CommentId) -> Result<Option<Self>, Error> {
|
pub async fn read(pool: &mut DbPool<'_>, comment_id: CommentId) -> Result<Self, Error> {
|
||||||
let conn = &mut get_conn(pool).await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
comment_aggregates::table
|
comment_aggregates::table.find(comment_id).first(conn).await
|
||||||
.find(comment_id)
|
|
||||||
.first(conn)
|
|
||||||
.await
|
|
||||||
.optional()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn update_hot_rank(
|
pub async fn update_hot_rank(
|
||||||
|
@ -119,7 +114,6 @@ mod tests {
|
||||||
|
|
||||||
let comment_aggs_before_delete = CommentAggregates::read(pool, inserted_comment.id)
|
let comment_aggs_before_delete = CommentAggregates::read(pool, inserted_comment.id)
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(1, comment_aggs_before_delete.score);
|
assert_eq!(1, comment_aggs_before_delete.score);
|
||||||
|
@ -138,7 +132,6 @@ mod tests {
|
||||||
|
|
||||||
let comment_aggs_after_dislike = CommentAggregates::read(pool, inserted_comment.id)
|
let comment_aggs_after_dislike = CommentAggregates::read(pool, inserted_comment.id)
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
assert_eq!(0, comment_aggs_after_dislike.score);
|
assert_eq!(0, comment_aggs_after_dislike.score);
|
||||||
|
@ -151,7 +144,6 @@ mod tests {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let after_like_remove = CommentAggregates::read(pool, inserted_comment.id)
|
let after_like_remove = CommentAggregates::read(pool, inserted_comment.id)
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(-1, after_like_remove.score);
|
assert_eq!(-1, after_like_remove.score);
|
||||||
assert_eq!(0, after_like_remove.upvotes);
|
assert_eq!(0, after_like_remove.upvotes);
|
||||||
|
@ -161,10 +153,8 @@ mod tests {
|
||||||
Post::delete(pool, inserted_post.id).await.unwrap();
|
Post::delete(pool, inserted_post.id).await.unwrap();
|
||||||
|
|
||||||
// Should be none found, since the post was deleted
|
// Should be none found, since the post was deleted
|
||||||
let after_delete = CommentAggregates::read(pool, inserted_comment.id)
|
let after_delete = CommentAggregates::read(pool, inserted_comment.id).await;
|
||||||
.await
|
assert!(after_delete.is_err());
|
||||||
.unwrap();
|
|
||||||
assert!(after_delete.is_none());
|
|
||||||
|
|
||||||
// This should delete all the associated rows, and fire triggers
|
// This should delete all the associated rows, and fire triggers
|
||||||
Person::delete(pool, another_inserted_person.id)
|
Person::delete(pool, another_inserted_person.id)
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
aggregates::structs::PostAggregates,
|
aggregates::structs::PostAggregates,
|
||||||
diesel::OptionalExtension,
|
|
||||||
newtypes::PostId,
|
newtypes::PostId,
|
||||||
schema::{community_aggregates, post, post_aggregates},
|
schema::{community_aggregates, post, post_aggregates},
|
||||||
utils::{
|
utils::{
|
||||||
|
@ -13,13 +12,9 @@ use diesel::{result::Error, ExpressionMethods, JoinOnDsl, QueryDsl};
|
||||||
use diesel_async::RunQueryDsl;
|
use diesel_async::RunQueryDsl;
|
||||||
|
|
||||||
impl PostAggregates {
|
impl PostAggregates {
|
||||||
pub async fn read(pool: &mut DbPool<'_>, post_id: PostId) -> Result<Option<Self>, Error> {
|
pub async fn read(pool: &mut DbPool<'_>, post_id: PostId) -> Result<Self, Error> {
|
||||||
let conn = &mut get_conn(pool).await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
post_aggregates::table
|
post_aggregates::table.find(post_id).first(conn).await
|
||||||
.find(post_id)
|
|
||||||
.first(conn)
|
|
||||||
.await
|
|
||||||
.optional()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn update_ranks(pool: &mut DbPool<'_>, post_id: PostId) -> Result<Self, Error> {
|
pub async fn update_ranks(pool: &mut DbPool<'_>, post_id: PostId) -> Result<Self, Error> {
|
||||||
|
@ -135,10 +130,7 @@ mod tests {
|
||||||
|
|
||||||
PostLike::like(pool, &post_like).await.unwrap();
|
PostLike::like(pool, &post_like).await.unwrap();
|
||||||
|
|
||||||
let post_aggs_before_delete = PostAggregates::read(pool, inserted_post.id)
|
let post_aggs_before_delete = PostAggregates::read(pool, inserted_post.id).await.unwrap();
|
||||||
.await
|
|
||||||
.unwrap()
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
assert_eq!(2, post_aggs_before_delete.comments);
|
assert_eq!(2, post_aggs_before_delete.comments);
|
||||||
assert_eq!(1, post_aggs_before_delete.score);
|
assert_eq!(1, post_aggs_before_delete.score);
|
||||||
|
@ -154,10 +146,7 @@ mod tests {
|
||||||
|
|
||||||
PostLike::like(pool, &post_dislike).await.unwrap();
|
PostLike::like(pool, &post_dislike).await.unwrap();
|
||||||
|
|
||||||
let post_aggs_after_dislike = PostAggregates::read(pool, inserted_post.id)
|
let post_aggs_after_dislike = PostAggregates::read(pool, inserted_post.id).await.unwrap();
|
||||||
.await
|
|
||||||
.unwrap()
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
assert_eq!(2, post_aggs_after_dislike.comments);
|
assert_eq!(2, post_aggs_after_dislike.comments);
|
||||||
assert_eq!(0, post_aggs_after_dislike.score);
|
assert_eq!(0, post_aggs_after_dislike.score);
|
||||||
|
@ -169,10 +158,7 @@ mod tests {
|
||||||
Comment::delete(pool, inserted_child_comment.id)
|
Comment::delete(pool, inserted_child_comment.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let after_comment_delete = PostAggregates::read(pool, inserted_post.id)
|
let after_comment_delete = PostAggregates::read(pool, inserted_post.id).await.unwrap();
|
||||||
.await
|
|
||||||
.unwrap()
|
|
||||||
.unwrap();
|
|
||||||
assert_eq!(0, after_comment_delete.comments);
|
assert_eq!(0, after_comment_delete.comments);
|
||||||
assert_eq!(0, after_comment_delete.score);
|
assert_eq!(0, after_comment_delete.score);
|
||||||
assert_eq!(1, after_comment_delete.upvotes);
|
assert_eq!(1, after_comment_delete.upvotes);
|
||||||
|
@ -182,10 +168,7 @@ mod tests {
|
||||||
PostLike::remove(pool, inserted_person.id, inserted_post.id)
|
PostLike::remove(pool, inserted_person.id, inserted_post.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let after_like_remove = PostAggregates::read(pool, inserted_post.id)
|
let after_like_remove = PostAggregates::read(pool, inserted_post.id).await.unwrap();
|
||||||
.await
|
|
||||||
.unwrap()
|
|
||||||
.unwrap();
|
|
||||||
assert_eq!(0, after_like_remove.comments);
|
assert_eq!(0, after_like_remove.comments);
|
||||||
assert_eq!(-1, after_like_remove.score);
|
assert_eq!(-1, after_like_remove.score);
|
||||||
assert_eq!(0, after_like_remove.upvotes);
|
assert_eq!(0, after_like_remove.upvotes);
|
||||||
|
@ -205,8 +188,8 @@ mod tests {
|
||||||
assert_eq!(1, community_num_deleted);
|
assert_eq!(1, community_num_deleted);
|
||||||
|
|
||||||
// Should be none found, since the creator was deleted
|
// Should be none found, since the creator was deleted
|
||||||
let after_delete = PostAggregates::read(pool, inserted_post.id).await.unwrap();
|
let after_delete = PostAggregates::read(pool, inserted_post.id).await;
|
||||||
assert!(after_delete.is_none());
|
assert!(after_delete.is_err());
|
||||||
|
|
||||||
Instance::delete(pool, inserted_instance.id).await.unwrap();
|
Instance::delete(pool, inserted_instance.id).await.unwrap();
|
||||||
}
|
}
|
||||||
|
@ -250,10 +233,7 @@ mod tests {
|
||||||
|
|
||||||
let inserted_comment = Comment::create(pool, &comment_form, None).await.unwrap();
|
let inserted_comment = Comment::create(pool, &comment_form, None).await.unwrap();
|
||||||
|
|
||||||
let post_aggregates_before = PostAggregates::read(pool, inserted_post.id)
|
let post_aggregates_before = PostAggregates::read(pool, inserted_post.id).await.unwrap();
|
||||||
.await
|
|
||||||
.unwrap()
|
|
||||||
.unwrap();
|
|
||||||
assert_eq!(1, post_aggregates_before.comments);
|
assert_eq!(1, post_aggregates_before.comments);
|
||||||
|
|
||||||
Comment::update(
|
Comment::update(
|
||||||
|
@ -267,10 +247,7 @@ mod tests {
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let post_aggregates_after_remove = PostAggregates::read(pool, inserted_post.id)
|
let post_aggregates_after_remove = PostAggregates::read(pool, inserted_post.id).await.unwrap();
|
||||||
.await
|
|
||||||
.unwrap()
|
|
||||||
.unwrap();
|
|
||||||
assert_eq!(0, post_aggregates_after_remove.comments);
|
assert_eq!(0, post_aggregates_after_remove.comments);
|
||||||
|
|
||||||
Comment::update(
|
Comment::update(
|
||||||
|
@ -295,10 +272,7 @@ mod tests {
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let post_aggregates_after_delete = PostAggregates::read(pool, inserted_post.id)
|
let post_aggregates_after_delete = PostAggregates::read(pool, inserted_post.id).await.unwrap();
|
||||||
.await
|
|
||||||
.unwrap()
|
|
||||||
.unwrap();
|
|
||||||
assert_eq!(0, post_aggregates_after_delete.comments);
|
assert_eq!(0, post_aggregates_after_delete.comments);
|
||||||
|
|
||||||
Comment::update(
|
Comment::update(
|
||||||
|
@ -312,10 +286,8 @@ mod tests {
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let post_aggregates_after_delete_remove = PostAggregates::read(pool, inserted_post.id)
|
let post_aggregates_after_delete_remove =
|
||||||
.await
|
PostAggregates::read(pool, inserted_post.id).await.unwrap();
|
||||||
.unwrap()
|
|
||||||
.unwrap();
|
|
||||||
assert_eq!(0, post_aggregates_after_delete_remove.comments);
|
assert_eq!(0, post_aggregates_after_delete_remove.comments);
|
||||||
|
|
||||||
Comment::delete(pool, inserted_comment.id).await.unwrap();
|
Comment::delete(pool, inserted_comment.id).await.unwrap();
|
||||||
|
|
|
@ -337,10 +337,7 @@ mod tests {
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let read_comment = Comment::read(pool, inserted_comment.id)
|
let read_comment = Comment::read(pool, inserted_comment.id).await.unwrap();
|
||||||
.await
|
|
||||||
.unwrap()
|
|
||||||
.unwrap();
|
|
||||||
let like_removed = CommentLike::remove(pool, inserted_person.id, inserted_comment.id)
|
let like_removed = CommentLike::remove(pool, inserted_person.id, inserted_comment.id)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
|
@ -152,26 +152,24 @@ impl Community {
|
||||||
pub async fn get_by_collection_url(
|
pub async fn get_by_collection_url(
|
||||||
pool: &mut DbPool<'_>,
|
pool: &mut DbPool<'_>,
|
||||||
url: &DbUrl,
|
url: &DbUrl,
|
||||||
) -> Result<Option<(Community, CollectionType)>, Error> {
|
) -> LemmyResult<(Community, CollectionType)> {
|
||||||
let conn = &mut get_conn(pool).await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
let res = community::table
|
let res = community::table
|
||||||
.filter(community::moderators_url.eq(url))
|
.filter(community::moderators_url.eq(url))
|
||||||
.first(conn)
|
.first(conn)
|
||||||
.await
|
.await;
|
||||||
.optional()?;
|
|
||||||
|
|
||||||
if let Some(c) = res {
|
if let Ok(c) = res {
|
||||||
Ok(Some((c, CollectionType::Moderators)))
|
Ok((c, CollectionType::Moderators))
|
||||||
} else {
|
} else {
|
||||||
let res = community::table
|
let res = community::table
|
||||||
.filter(community::featured_url.eq(url))
|
.filter(community::featured_url.eq(url))
|
||||||
.first(conn)
|
.first(conn)
|
||||||
.await
|
.await;
|
||||||
.optional()?;
|
if let Ok(c) = res {
|
||||||
if let Some(c) = res {
|
Ok((c, CollectionType::Featured))
|
||||||
Ok(Some((c, CollectionType::Featured)))
|
|
||||||
} else {
|
} else {
|
||||||
Ok(None)
|
Err(LemmyErrorType::NotFound.into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -455,7 +453,7 @@ mod tests {
|
||||||
utils::build_db_pool_for_tests,
|
utils::build_db_pool_for_tests,
|
||||||
CommunityVisibility,
|
CommunityVisibility,
|
||||||
};
|
};
|
||||||
use lemmy_utils::{error::LemmyResult, LemmyErrorType};
|
use lemmy_utils::error::LemmyResult;
|
||||||
use pretty_assertions::assert_eq;
|
use pretty_assertions::assert_eq;
|
||||||
use serial_test::serial;
|
use serial_test::serial;
|
||||||
|
|
||||||
|
@ -595,9 +593,7 @@ mod tests {
|
||||||
expires: None,
|
expires: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let read_community = Community::read(pool, inserted_community.id)
|
let read_community = Community::read(pool, inserted_community.id).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindCommunity)?;
|
|
||||||
|
|
||||||
let update_community_form = CommunityUpdateForm {
|
let update_community_form = CommunityUpdateForm {
|
||||||
title: Some("nada".to_owned()),
|
title: Some("nada".to_owned()),
|
||||||
|
|
|
@ -16,7 +16,6 @@ use diesel::{
|
||||||
sql_types::Timestamptz,
|
sql_types::Timestamptz,
|
||||||
ExpressionMethods,
|
ExpressionMethods,
|
||||||
IntoSql,
|
IntoSql,
|
||||||
OptionalExtension,
|
|
||||||
QueryDsl,
|
QueryDsl,
|
||||||
};
|
};
|
||||||
use diesel_async::RunQueryDsl;
|
use diesel_async::RunQueryDsl;
|
||||||
|
@ -30,14 +29,13 @@ impl EmailVerification {
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn read_for_token(pool: &mut DbPool<'_>, token: &str) -> Result<Option<Self>, Error> {
|
pub async fn read_for_token(pool: &mut DbPool<'_>, token: &str) -> Result<Self, Error> {
|
||||||
let conn = &mut get_conn(pool).await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
email_verification
|
email_verification
|
||||||
.filter(verification_token.eq(token))
|
.filter(verification_token.eq(token))
|
||||||
.filter(published.gt(now.into_sql::<Timestamptz>() - 7.days()))
|
.filter(published.gt(now.into_sql::<Timestamptz>() - 7.days()))
|
||||||
.first(conn)
|
.first(conn)
|
||||||
.await
|
.await
|
||||||
.optional()
|
|
||||||
}
|
}
|
||||||
pub async fn delete_old_tokens_for_local_user(
|
pub async fn delete_old_tokens_for_local_user(
|
||||||
pool: &mut DbPool<'_>,
|
pool: &mut DbPool<'_>,
|
||||||
|
|
|
@ -560,7 +560,6 @@ mod tests {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let read_mod_remove_post = ModRemovePost::read(pool, inserted_mod_remove_post.id)
|
let read_mod_remove_post = ModRemovePost::read(pool, inserted_mod_remove_post.id)
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let expected_mod_remove_post = ModRemovePost {
|
let expected_mod_remove_post = ModRemovePost {
|
||||||
id: inserted_mod_remove_post.id,
|
id: inserted_mod_remove_post.id,
|
||||||
|
@ -583,7 +582,6 @@ mod tests {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let read_mod_lock_post = ModLockPost::read(pool, inserted_mod_lock_post.id)
|
let read_mod_lock_post = ModLockPost::read(pool, inserted_mod_lock_post.id)
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let expected_mod_lock_post = ModLockPost {
|
let expected_mod_lock_post = ModLockPost {
|
||||||
id: inserted_mod_lock_post.id,
|
id: inserted_mod_lock_post.id,
|
||||||
|
@ -606,7 +604,6 @@ mod tests {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let read_mod_feature_post = ModFeaturePost::read(pool, inserted_mod_feature_post.id)
|
let read_mod_feature_post = ModFeaturePost::read(pool, inserted_mod_feature_post.id)
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let expected_mod_feature_post = ModFeaturePost {
|
let expected_mod_feature_post = ModFeaturePost {
|
||||||
id: inserted_mod_feature_post.id,
|
id: inserted_mod_feature_post.id,
|
||||||
|
@ -630,7 +627,6 @@ mod tests {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let read_mod_remove_comment = ModRemoveComment::read(pool, inserted_mod_remove_comment.id)
|
let read_mod_remove_comment = ModRemoveComment::read(pool, inserted_mod_remove_comment.id)
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let expected_mod_remove_comment = ModRemoveComment {
|
let expected_mod_remove_comment = ModRemoveComment {
|
||||||
id: inserted_mod_remove_comment.id,
|
id: inserted_mod_remove_comment.id,
|
||||||
|
@ -656,7 +652,6 @@ mod tests {
|
||||||
let read_mod_remove_community =
|
let read_mod_remove_community =
|
||||||
ModRemoveCommunity::read(pool, inserted_mod_remove_community.id)
|
ModRemoveCommunity::read(pool, inserted_mod_remove_community.id)
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let expected_mod_remove_community = ModRemoveCommunity {
|
let expected_mod_remove_community = ModRemoveCommunity {
|
||||||
id: inserted_mod_remove_community.id,
|
id: inserted_mod_remove_community.id,
|
||||||
|
@ -684,7 +679,6 @@ mod tests {
|
||||||
let read_mod_ban_from_community =
|
let read_mod_ban_from_community =
|
||||||
ModBanFromCommunity::read(pool, inserted_mod_ban_from_community.id)
|
ModBanFromCommunity::read(pool, inserted_mod_ban_from_community.id)
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let expected_mod_ban_from_community = ModBanFromCommunity {
|
let expected_mod_ban_from_community = ModBanFromCommunity {
|
||||||
id: inserted_mod_ban_from_community.id,
|
id: inserted_mod_ban_from_community.id,
|
||||||
|
@ -707,10 +701,7 @@ mod tests {
|
||||||
expires: None,
|
expires: None,
|
||||||
};
|
};
|
||||||
let inserted_mod_ban = ModBan::create(pool, &mod_ban_form).await.unwrap();
|
let inserted_mod_ban = ModBan::create(pool, &mod_ban_form).await.unwrap();
|
||||||
let read_mod_ban = ModBan::read(pool, inserted_mod_ban.id)
|
let read_mod_ban = ModBan::read(pool, inserted_mod_ban.id).await.unwrap();
|
||||||
.await
|
|
||||||
.unwrap()
|
|
||||||
.unwrap();
|
|
||||||
let expected_mod_ban = ModBan {
|
let expected_mod_ban = ModBan {
|
||||||
id: inserted_mod_ban.id,
|
id: inserted_mod_ban.id,
|
||||||
mod_person_id: inserted_mod.id,
|
mod_person_id: inserted_mod.id,
|
||||||
|
@ -734,7 +725,6 @@ mod tests {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let read_mod_add_community = ModAddCommunity::read(pool, inserted_mod_add_community.id)
|
let read_mod_add_community = ModAddCommunity::read(pool, inserted_mod_add_community.id)
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let expected_mod_add_community = ModAddCommunity {
|
let expected_mod_add_community = ModAddCommunity {
|
||||||
id: inserted_mod_add_community.id,
|
id: inserted_mod_add_community.id,
|
||||||
|
@ -753,10 +743,7 @@ mod tests {
|
||||||
removed: None,
|
removed: None,
|
||||||
};
|
};
|
||||||
let inserted_mod_add = ModAdd::create(pool, &mod_add_form).await.unwrap();
|
let inserted_mod_add = ModAdd::create(pool, &mod_add_form).await.unwrap();
|
||||||
let read_mod_add = ModAdd::read(pool, inserted_mod_add.id)
|
let read_mod_add = ModAdd::read(pool, inserted_mod_add.id).await.unwrap();
|
||||||
.await
|
|
||||||
.unwrap()
|
|
||||||
.unwrap();
|
|
||||||
let expected_mod_add = ModAdd {
|
let expected_mod_add = ModAdd {
|
||||||
id: inserted_mod_add.id,
|
id: inserted_mod_add.id,
|
||||||
mod_person_id: inserted_mod.id,
|
mod_person_id: inserted_mod.id,
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
diesel::OptionalExtension,
|
|
||||||
newtypes::LocalUserId,
|
newtypes::LocalUserId,
|
||||||
schema::password_reset_request::dsl::{password_reset_request, published, token},
|
schema::password_reset_request::dsl::{password_reset_request, published, token},
|
||||||
source::password_reset_request::{PasswordResetRequest, PasswordResetRequestForm},
|
source::password_reset_request::{PasswordResetRequest, PasswordResetRequestForm},
|
||||||
|
@ -32,14 +31,13 @@ impl PasswordResetRequest {
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn read_and_delete(pool: &mut DbPool<'_>, token_: &str) -> Result<Option<Self>, Error> {
|
pub async fn read_and_delete(pool: &mut DbPool<'_>, token_: &str) -> Result<Self, Error> {
|
||||||
let conn = &mut get_conn(pool).await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
delete(password_reset_request)
|
delete(password_reset_request)
|
||||||
.filter(token.eq(token_))
|
.filter(token.eq(token_))
|
||||||
.filter(published.gt(now.into_sql::<Timestamptz>() - 1.days()))
|
.filter(published.gt(now.into_sql::<Timestamptz>() - 1.days()))
|
||||||
.get_result(conn)
|
.get_result(conn)
|
||||||
.await
|
.await
|
||||||
.optional()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,9 +79,7 @@ mod tests {
|
||||||
PasswordResetRequest::create(pool, inserted_local_user.id, token.to_string()).await?;
|
PasswordResetRequest::create(pool, inserted_local_user.id, token.to_string()).await?;
|
||||||
|
|
||||||
// Read it and verify
|
// Read it and verify
|
||||||
let read_password_reset_request = PasswordResetRequest::read_and_delete(pool, token)
|
let read_password_reset_request = PasswordResetRequest::read_and_delete(pool, token).await?;
|
||||||
.await?
|
|
||||||
.unwrap();
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
inserted_password_reset_request.id,
|
inserted_password_reset_request.id,
|
||||||
read_password_reset_request.id
|
read_password_reset_request.id
|
||||||
|
@ -102,8 +98,8 @@ mod tests {
|
||||||
);
|
);
|
||||||
|
|
||||||
// Cannot reuse same token again
|
// Cannot reuse same token again
|
||||||
let read_password_reset_request = PasswordResetRequest::read_and_delete(pool, token).await?;
|
let read_password_reset_request = PasswordResetRequest::read_and_delete(pool, token).await;
|
||||||
assert!(read_password_reset_request.is_none());
|
assert!(read_password_reset_request.is_err());
|
||||||
|
|
||||||
// Cleanup
|
// Cleanup
|
||||||
let num_deleted = Person::delete(pool, inserted_person.id).await?;
|
let num_deleted = Person::delete(pool, inserted_person.id).await?;
|
||||||
|
|
|
@ -29,14 +29,13 @@ impl Crud for Person {
|
||||||
type IdType = PersonId;
|
type IdType = PersonId;
|
||||||
|
|
||||||
// Override this, so that you don't get back deleted
|
// Override this, so that you don't get back deleted
|
||||||
async fn read(pool: &mut DbPool<'_>, person_id: PersonId) -> Result<Option<Self>, Error> {
|
async fn read(pool: &mut DbPool<'_>, person_id: PersonId) -> Result<Self, Error> {
|
||||||
let conn = &mut get_conn(pool).await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
person::table
|
person::table
|
||||||
.filter(person::deleted.eq(false))
|
.filter(person::deleted.eq(false))
|
||||||
.find(person_id)
|
.find(person_id)
|
||||||
.first(conn)
|
.first(conn)
|
||||||
.await
|
.await
|
||||||
.optional()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create(pool: &mut DbPool<'_>, form: &PersonInsertForm) -> Result<Self, Error> {
|
async fn create(pool: &mut DbPool<'_>, form: &PersonInsertForm) -> Result<Self, Error> {
|
||||||
|
@ -244,7 +243,7 @@ mod tests {
|
||||||
traits::{Crud, Followable},
|
traits::{Crud, Followable},
|
||||||
utils::build_db_pool_for_tests,
|
utils::build_db_pool_for_tests,
|
||||||
};
|
};
|
||||||
use lemmy_utils::{error::LemmyResult, LemmyErrorType};
|
use lemmy_utils::error::LemmyResult;
|
||||||
use pretty_assertions::assert_eq;
|
use pretty_assertions::assert_eq;
|
||||||
use serial_test::serial;
|
use serial_test::serial;
|
||||||
|
|
||||||
|
@ -284,9 +283,7 @@ mod tests {
|
||||||
instance_id: inserted_instance.id,
|
instance_id: inserted_instance.id,
|
||||||
};
|
};
|
||||||
|
|
||||||
let read_person = Person::read(pool, inserted_person.id)
|
let read_person = Person::read(pool, inserted_person.id).await?;
|
||||||
.await?
|
|
||||||
.ok_or(LemmyErrorType::CouldntFindPerson)?;
|
|
||||||
|
|
||||||
let update_person_form = PersonUpdateForm {
|
let update_person_form = PersonUpdateForm {
|
||||||
actor_id: Some(inserted_person.actor_id.clone()),
|
actor_id: Some(inserted_person.actor_id.clone()),
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue