mirror of
https://github.com/LemmyNet/lemmy
synced 2024-11-10 06:54:12 +00:00
Try to use DbPool enum
This commit is contained in:
parent
23accf7e4f
commit
e4d1712646
215 changed files with 1771 additions and 1472 deletions
|
@ -22,18 +22,18 @@ impl Perform for DistinguishComment {
|
|||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||
|
||||
let comment_id = data.comment_id;
|
||||
let orig_comment = CommentView::read(context.pool(), comment_id, None).await?;
|
||||
let orig_comment = CommentView::read(&mut context.pool(), comment_id, None).await?;
|
||||
|
||||
check_community_ban(
|
||||
local_user_view.person.id,
|
||||
orig_comment.community.id,
|
||||
context.pool(),
|
||||
&mut context.pool(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
// Verify that only a mod or admin can distinguish a comment
|
||||
is_mod_or_admin(
|
||||
context.pool(),
|
||||
&mut context.pool(),
|
||||
local_user_view.person.id,
|
||||
orig_comment.community.id,
|
||||
)
|
||||
|
@ -44,13 +44,13 @@ impl Perform for DistinguishComment {
|
|||
let form = CommentUpdateForm::builder()
|
||||
.distinguished(Some(data.distinguished))
|
||||
.build();
|
||||
Comment::update(context.pool(), comment_id, &form)
|
||||
Comment::update(&mut context.pool(), comment_id, &form)
|
||||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_comment"))?;
|
||||
|
||||
let comment_id = data.comment_id;
|
||||
let person_id = local_user_view.person.id;
|
||||
let comment_view = CommentView::read(context.pool(), comment_id, Some(person_id)).await?;
|
||||
let comment_view = CommentView::read(&mut context.pool(), comment_id, Some(person_id)).await?;
|
||||
|
||||
Ok(CommentResponse {
|
||||
comment_view,
|
||||
|
|
|
@ -25,7 +25,7 @@ impl Perform for CreateCommentLike {
|
|||
#[tracing::instrument(skip(context))]
|
||||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<CommentResponse, LemmyError> {
|
||||
let data: &CreateCommentLike = self;
|
||||
let local_site = LocalSite::read(context.pool()).await?;
|
||||
let local_site = LocalSite::read(&mut context.pool()).await?;
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||
|
||||
let mut recipient_ids = Vec::<LocalUserId>::new();
|
||||
|
@ -34,20 +34,22 @@ impl Perform for CreateCommentLike {
|
|||
check_downvotes_enabled(data.score, &local_site)?;
|
||||
|
||||
let comment_id = data.comment_id;
|
||||
let orig_comment = CommentView::read(context.pool(), comment_id, None).await?;
|
||||
let orig_comment = CommentView::read(&mut context.pool(), comment_id, None).await?;
|
||||
|
||||
check_community_ban(
|
||||
local_user_view.person.id,
|
||||
orig_comment.community.id,
|
||||
context.pool(),
|
||||
&mut context.pool(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
// Add parent poster or commenter to recipients
|
||||
let comment_reply = CommentReply::read_by_comment(context.pool(), comment_id).await;
|
||||
let comment_reply = CommentReply::read_by_comment(&mut context.pool(), comment_id).await;
|
||||
if let Ok(reply) = comment_reply {
|
||||
let recipient_id = reply.recipient_id;
|
||||
if let Ok(local_recipient) = LocalUserView::read_person(context.pool(), recipient_id).await {
|
||||
if let Ok(local_recipient) =
|
||||
LocalUserView::read_person(&mut context.pool(), recipient_id).await
|
||||
{
|
||||
recipient_ids.push(local_recipient.local_user.id);
|
||||
}
|
||||
}
|
||||
|
@ -62,12 +64,12 @@ impl Perform for CreateCommentLike {
|
|||
// Remove any likes first
|
||||
let person_id = local_user_view.person.id;
|
||||
|
||||
CommentLike::remove(context.pool(), person_id, comment_id).await?;
|
||||
CommentLike::remove(&mut context.pool(), person_id, comment_id).await?;
|
||||
|
||||
// Only add the like if the score isnt 0
|
||||
let do_add = like_form.score != 0 && (like_form.score == 1 || like_form.score == -1);
|
||||
if do_add {
|
||||
CommentLike::like(context.pool(), &like_form)
|
||||
CommentLike::like(&mut context.pool(), &like_form)
|
||||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "couldnt_like_comment"))?;
|
||||
}
|
||||
|
|
|
@ -27,18 +27,18 @@ impl Perform for SaveComment {
|
|||
};
|
||||
|
||||
if data.save {
|
||||
CommentSaved::save(context.pool(), &comment_saved_form)
|
||||
CommentSaved::save(&mut context.pool(), &comment_saved_form)
|
||||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "couldnt_save_comment"))?;
|
||||
} else {
|
||||
CommentSaved::unsave(context.pool(), &comment_saved_form)
|
||||
CommentSaved::unsave(&mut context.pool(), &comment_saved_form)
|
||||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "couldnt_save_comment"))?;
|
||||
}
|
||||
|
||||
let comment_id = data.comment_id;
|
||||
let person_id = local_user_view.person.id;
|
||||
let comment_view = CommentView::read(context.pool(), comment_id, Some(person_id)).await?;
|
||||
let comment_view = CommentView::read(&mut context.pool(), comment_id, Some(person_id)).await?;
|
||||
|
||||
Ok(CommentResponse {
|
||||
comment_view,
|
||||
|
|
|
@ -27,16 +27,16 @@ impl Perform for CreateCommentReport {
|
|||
) -> Result<CommentReportResponse, LemmyError> {
|
||||
let data: &CreateCommentReport = self;
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||
let local_site = LocalSite::read(context.pool()).await?;
|
||||
let local_site = LocalSite::read(&mut context.pool()).await?;
|
||||
|
||||
let reason = self.reason.trim();
|
||||
check_report_reason(reason, &local_site)?;
|
||||
|
||||
let person_id = local_user_view.person.id;
|
||||
let comment_id = data.comment_id;
|
||||
let comment_view = CommentView::read(context.pool(), comment_id, None).await?;
|
||||
let comment_view = CommentView::read(&mut context.pool(), comment_id, None).await?;
|
||||
|
||||
check_community_ban(person_id, comment_view.community.id, context.pool()).await?;
|
||||
check_community_ban(person_id, comment_view.community.id, &mut context.pool()).await?;
|
||||
|
||||
let report_form = CommentReportForm {
|
||||
creator_id: person_id,
|
||||
|
@ -45,18 +45,19 @@ impl Perform for CreateCommentReport {
|
|||
reason: reason.to_owned(),
|
||||
};
|
||||
|
||||
let report = CommentReport::report(context.pool(), &report_form)
|
||||
let report = CommentReport::report(&mut context.pool(), &report_form)
|
||||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "couldnt_create_report"))?;
|
||||
|
||||
let comment_report_view = CommentReportView::read(context.pool(), report.id, person_id).await?;
|
||||
let comment_report_view =
|
||||
CommentReportView::read(&mut context.pool(), report.id, person_id).await?;
|
||||
|
||||
// Email the admins
|
||||
if local_site.reports_email_admins {
|
||||
send_new_report_email_to_admins(
|
||||
&comment_report_view.creator.name,
|
||||
&comment_report_view.comment_creator.name,
|
||||
context.pool(),
|
||||
&mut context.pool(),
|
||||
context.settings(),
|
||||
)
|
||||
.await?;
|
||||
|
|
|
@ -30,7 +30,7 @@ impl Perform for ListCommentReports {
|
|||
let page = data.page;
|
||||
let limit = data.limit;
|
||||
let comment_reports = CommentReportQuery::builder()
|
||||
.pool(context.pool())
|
||||
.pool(&mut context.pool())
|
||||
.my_person_id(person_id)
|
||||
.admin(admin)
|
||||
.community_id(community_id)
|
||||
|
|
|
@ -24,23 +24,24 @@ impl Perform for ResolveCommentReport {
|
|||
|
||||
let report_id = data.report_id;
|
||||
let person_id = local_user_view.person.id;
|
||||
let report = CommentReportView::read(context.pool(), report_id, person_id).await?;
|
||||
let report = CommentReportView::read(&mut context.pool(), report_id, person_id).await?;
|
||||
|
||||
let person_id = local_user_view.person.id;
|
||||
is_mod_or_admin(context.pool(), person_id, report.community.id).await?;
|
||||
is_mod_or_admin(&mut context.pool(), person_id, report.community.id).await?;
|
||||
|
||||
if data.resolved {
|
||||
CommentReport::resolve(context.pool(), report_id, person_id)
|
||||
CommentReport::resolve(&mut context.pool(), report_id, person_id)
|
||||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "couldnt_resolve_report"))?;
|
||||
} else {
|
||||
CommentReport::unresolve(context.pool(), report_id, person_id)
|
||||
CommentReport::unresolve(&mut context.pool(), report_id, person_id)
|
||||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "couldnt_resolve_report"))?;
|
||||
}
|
||||
|
||||
let report_id = data.report_id;
|
||||
let comment_report_view = CommentReportView::read(context.pool(), report_id, person_id).await?;
|
||||
let comment_report_view =
|
||||
CommentReportView::read(&mut context.pool(), report_id, person_id).await?;
|
||||
|
||||
Ok(CommentReportResponse {
|
||||
comment_report_view,
|
||||
|
|
|
@ -30,8 +30,8 @@ impl Perform for AddModToCommunity {
|
|||
let community_id = data.community_id;
|
||||
|
||||
// Verify that only mods or admins can add mod
|
||||
is_mod_or_admin(context.pool(), local_user_view.person.id, community_id).await?;
|
||||
let community = Community::read(context.pool(), community_id).await?;
|
||||
is_mod_or_admin(&mut context.pool(), local_user_view.person.id, community_id).await?;
|
||||
let community = Community::read(&mut context.pool(), community_id).await?;
|
||||
if local_user_view.person.admin && !community.local {
|
||||
return Err(LemmyError::from_message("not_a_moderator"));
|
||||
}
|
||||
|
@ -42,11 +42,11 @@ impl Perform for AddModToCommunity {
|
|||
person_id: data.person_id,
|
||||
};
|
||||
if data.added {
|
||||
CommunityModerator::join(context.pool(), &community_moderator_form)
|
||||
CommunityModerator::join(&mut context.pool(), &community_moderator_form)
|
||||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "community_moderator_already_exists"))?;
|
||||
} else {
|
||||
CommunityModerator::leave(context.pool(), &community_moderator_form)
|
||||
CommunityModerator::leave(&mut context.pool(), &community_moderator_form)
|
||||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "community_moderator_already_exists"))?;
|
||||
}
|
||||
|
@ -59,12 +59,13 @@ impl Perform for AddModToCommunity {
|
|||
removed: Some(!data.added),
|
||||
};
|
||||
|
||||
ModAddCommunity::create(context.pool(), &form).await?;
|
||||
ModAddCommunity::create(&mut context.pool(), &form).await?;
|
||||
|
||||
// Note: in case a remote mod is added, this returns the old moderators list, it will only get
|
||||
// updated once we receive an activity from the community (like `Announce/Add/Moderator`)
|
||||
let community_id = data.community_id;
|
||||
let moderators = CommunityModeratorView::for_community(context.pool(), community_id).await?;
|
||||
let moderators =
|
||||
CommunityModeratorView::for_community(&mut context.pool(), community_id).await?;
|
||||
|
||||
Ok(AddModToCommunityResponse { moderators })
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ impl Perform for BanFromCommunity {
|
|||
let expires = data.expires.map(naive_from_unix);
|
||||
|
||||
// Verify that only mods or admins can ban
|
||||
is_mod_or_admin(context.pool(), local_user_view.person.id, community_id).await?;
|
||||
is_mod_or_admin(&mut context.pool(), local_user_view.person.id, community_id).await?;
|
||||
is_valid_body_field(&data.reason, false)?;
|
||||
|
||||
let community_user_ban_form = CommunityPersonBanForm {
|
||||
|
@ -51,7 +51,7 @@ impl Perform for BanFromCommunity {
|
|||
};
|
||||
|
||||
if data.ban {
|
||||
CommunityPersonBan::ban(context.pool(), &community_user_ban_form)
|
||||
CommunityPersonBan::ban(&mut context.pool(), &community_user_ban_form)
|
||||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "community_user_already_banned"))?;
|
||||
|
||||
|
@ -62,18 +62,18 @@ impl Perform for BanFromCommunity {
|
|||
pending: false,
|
||||
};
|
||||
|
||||
CommunityFollower::unfollow(context.pool(), &community_follower_form)
|
||||
CommunityFollower::unfollow(&mut context.pool(), &community_follower_form)
|
||||
.await
|
||||
.ok();
|
||||
} else {
|
||||
CommunityPersonBan::unban(context.pool(), &community_user_ban_form)
|
||||
CommunityPersonBan::unban(&mut context.pool(), &community_user_ban_form)
|
||||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "community_user_already_banned"))?;
|
||||
}
|
||||
|
||||
// Remove/Restore their data if that's desired
|
||||
if remove_data {
|
||||
remove_user_data_in_community(community_id, banned_person_id, context.pool()).await?;
|
||||
remove_user_data_in_community(community_id, banned_person_id, &mut context.pool()).await?;
|
||||
}
|
||||
|
||||
// Mod tables
|
||||
|
@ -86,10 +86,10 @@ impl Perform for BanFromCommunity {
|
|||
expires,
|
||||
};
|
||||
|
||||
ModBanFromCommunity::create(context.pool(), &form).await?;
|
||||
ModBanFromCommunity::create(&mut context.pool(), &form).await?;
|
||||
|
||||
let person_id = data.person_id;
|
||||
let person_view = PersonView::read(context.pool(), person_id).await?;
|
||||
let person_view = PersonView::read(&mut context.pool(), person_id).await?;
|
||||
|
||||
Ok(BanFromCommunityResponse {
|
||||
person_view,
|
||||
|
|
|
@ -35,7 +35,7 @@ impl Perform for BlockCommunity {
|
|||
};
|
||||
|
||||
if data.block {
|
||||
CommunityBlock::block(context.pool(), &community_block_form)
|
||||
CommunityBlock::block(&mut context.pool(), &community_block_form)
|
||||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "community_block_already_exists"))?;
|
||||
|
||||
|
@ -46,17 +46,17 @@ impl Perform for BlockCommunity {
|
|||
pending: false,
|
||||
};
|
||||
|
||||
CommunityFollower::unfollow(context.pool(), &community_follower_form)
|
||||
CommunityFollower::unfollow(&mut context.pool(), &community_follower_form)
|
||||
.await
|
||||
.ok();
|
||||
} else {
|
||||
CommunityBlock::unblock(context.pool(), &community_block_form)
|
||||
CommunityBlock::unblock(&mut context.pool(), &community_block_form)
|
||||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "community_block_already_exists"))?;
|
||||
}
|
||||
|
||||
let community_view =
|
||||
CommunityView::read(context.pool(), community_id, Some(person_id), None).await?;
|
||||
CommunityView::read(&mut context.pool(), community_id, Some(person_id), None).await?;
|
||||
|
||||
Ok(BlockCommunityResponse {
|
||||
blocked: data.block,
|
||||
|
|
|
@ -25,7 +25,7 @@ impl Perform for FollowCommunity {
|
|||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||
|
||||
let community_id = data.community_id;
|
||||
let community = Community::read(context.pool(), community_id).await?;
|
||||
let community = Community::read(&mut context.pool(), community_id).await?;
|
||||
let mut community_follower_form = CommunityFollowerForm {
|
||||
community_id: data.community_id,
|
||||
person_id: local_user_view.person.id,
|
||||
|
@ -34,22 +34,22 @@ impl Perform for FollowCommunity {
|
|||
|
||||
if data.follow {
|
||||
if community.local {
|
||||
check_community_ban(local_user_view.person.id, community_id, context.pool()).await?;
|
||||
check_community_deleted_or_removed(community_id, context.pool()).await?;
|
||||
check_community_ban(local_user_view.person.id, community_id, &mut context.pool()).await?;
|
||||
check_community_deleted_or_removed(community_id, &mut context.pool()).await?;
|
||||
|
||||
CommunityFollower::follow(context.pool(), &community_follower_form)
|
||||
CommunityFollower::follow(&mut context.pool(), &community_follower_form)
|
||||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "community_follower_already_exists"))?;
|
||||
} else {
|
||||
// Mark as pending, the actual federation activity is sent via `SendActivity` handler
|
||||
community_follower_form.pending = true;
|
||||
CommunityFollower::follow(context.pool(), &community_follower_form)
|
||||
CommunityFollower::follow(&mut context.pool(), &community_follower_form)
|
||||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "community_follower_already_exists"))?;
|
||||
}
|
||||
}
|
||||
if !data.follow {
|
||||
CommunityFollower::unfollow(context.pool(), &community_follower_form)
|
||||
CommunityFollower::unfollow(&mut context.pool(), &community_follower_form)
|
||||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "community_follower_already_exists"))?;
|
||||
}
|
||||
|
@ -57,8 +57,8 @@ impl Perform for FollowCommunity {
|
|||
let community_id = data.community_id;
|
||||
let person_id = local_user_view.person.id;
|
||||
let community_view =
|
||||
CommunityView::read(context.pool(), community_id, Some(person_id), None).await?;
|
||||
let discussion_languages = CommunityLanguage::read(context.pool(), community_id).await?;
|
||||
CommunityView::read(&mut context.pool(), community_id, Some(person_id), None).await?;
|
||||
let discussion_languages = CommunityLanguage::read(&mut context.pool(), community_id).await?;
|
||||
|
||||
Ok(Self::Response {
|
||||
community_view,
|
||||
|
|
|
@ -39,11 +39,11 @@ impl Perform for HideCommunity {
|
|||
};
|
||||
|
||||
let community_id = data.community_id;
|
||||
Community::update(context.pool(), community_id, &community_form)
|
||||
Community::update(&mut context.pool(), community_id, &community_form)
|
||||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_community_hidden_status"))?;
|
||||
|
||||
ModHideCommunity::create(context.pool(), &mod_hide_community_form).await?;
|
||||
ModHideCommunity::create(&mut context.pool(), &mod_hide_community_form).await?;
|
||||
|
||||
build_community_response(context, local_user_view, community_id).await
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ impl Perform for TransferCommunity {
|
|||
// Fetch the community mods
|
||||
let community_id = data.community_id;
|
||||
let mut community_mods =
|
||||
CommunityModeratorView::for_community(context.pool(), community_id).await?;
|
||||
CommunityModeratorView::for_community(&mut context.pool(), community_id).await?;
|
||||
|
||||
// Make sure transferrer is either the top community mod, or an admin
|
||||
if !(is_top_mod(&local_user_view, &community_mods).is_ok()
|
||||
|
@ -54,7 +54,7 @@ impl Perform for TransferCommunity {
|
|||
// Delete all the mods
|
||||
let community_id = data.community_id;
|
||||
|
||||
CommunityModerator::delete_for_community(context.pool(), community_id).await?;
|
||||
CommunityModerator::delete_for_community(&mut context.pool(), community_id).await?;
|
||||
|
||||
// TODO: this should probably be a bulk operation
|
||||
// Re-add the mods, in the new order
|
||||
|
@ -64,7 +64,7 @@ impl Perform for TransferCommunity {
|
|||
person_id: cmod.moderator.id,
|
||||
};
|
||||
|
||||
CommunityModerator::join(context.pool(), &community_moderator_form)
|
||||
CommunityModerator::join(&mut context.pool(), &community_moderator_form)
|
||||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "community_moderator_already_exists"))?;
|
||||
}
|
||||
|
@ -76,16 +76,17 @@ impl Perform for TransferCommunity {
|
|||
community_id: data.community_id,
|
||||
};
|
||||
|
||||
ModTransferCommunity::create(context.pool(), &form).await?;
|
||||
ModTransferCommunity::create(&mut context.pool(), &form).await?;
|
||||
|
||||
let community_id = data.community_id;
|
||||
let person_id = local_user_view.person.id;
|
||||
let community_view = CommunityView::read(context.pool(), community_id, Some(person_id), None)
|
||||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "couldnt_find_community"))?;
|
||||
let community_view =
|
||||
CommunityView::read(&mut context.pool(), community_id, Some(person_id), None)
|
||||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "couldnt_find_community"))?;
|
||||
|
||||
let community_id = data.community_id;
|
||||
let moderators = CommunityModeratorView::for_community(context.pool(), community_id)
|
||||
let moderators = CommunityModeratorView::for_community(&mut context.pool(), community_id)
|
||||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "couldnt_find_community"))?;
|
||||
|
||||
|
|
|
@ -94,7 +94,7 @@ mod tests {
|
|||
#[tokio::test]
|
||||
#[serial]
|
||||
async fn test_should_not_validate_user_token_after_password_change() {
|
||||
let pool = &build_db_pool_for_tests().await;
|
||||
let mut pool = &mut lemmy_db_schema::utils::DbPool::Pool(&build_db_pool_for_tests().await);
|
||||
let secret = Secret::init(pool).await.unwrap();
|
||||
let settings = &SETTINGS.to_owned();
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ impl Perform for AddAdmin {
|
|||
let added = data.added;
|
||||
let added_person_id = data.person_id;
|
||||
let added_admin = Person::update(
|
||||
context.pool(),
|
||||
&mut context.pool(),
|
||||
added_person_id,
|
||||
&PersonUpdateForm::builder().admin(Some(added)).build(),
|
||||
)
|
||||
|
@ -44,9 +44,9 @@ impl Perform for AddAdmin {
|
|||
removed: Some(!data.added),
|
||||
};
|
||||
|
||||
ModAdd::create(context.pool(), &form).await?;
|
||||
ModAdd::create(&mut context.pool(), &form).await?;
|
||||
|
||||
let admins = PersonView::admins(context.pool()).await?;
|
||||
let admins = PersonView::admins(&mut context.pool()).await?;
|
||||
|
||||
Ok(AddAdminResponse { admins })
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ impl Perform for BanPerson {
|
|||
let expires = data.expires.map(naive_from_unix);
|
||||
|
||||
let person = Person::update(
|
||||
context.pool(),
|
||||
&mut context.pool(),
|
||||
banned_person_id,
|
||||
&PersonUpdateForm::builder()
|
||||
.banned(Some(ban))
|
||||
|
@ -52,7 +52,7 @@ impl Perform for BanPerson {
|
|||
if remove_data {
|
||||
remove_user_data(
|
||||
person.id,
|
||||
context.pool(),
|
||||
&mut context.pool(),
|
||||
context.settings(),
|
||||
context.client(),
|
||||
)
|
||||
|
@ -68,10 +68,10 @@ impl Perform for BanPerson {
|
|||
expires,
|
||||
};
|
||||
|
||||
ModBan::create(context.pool(), &form).await?;
|
||||
ModBan::create(&mut context.pool(), &form).await?;
|
||||
|
||||
let person_id = data.person_id;
|
||||
let person_view = PersonView::read(context.pool(), person_id).await?;
|
||||
let person_view = PersonView::read(&mut context.pool(), person_id).await?;
|
||||
|
||||
Ok(BanPersonResponse {
|
||||
person_view,
|
||||
|
|
|
@ -34,18 +34,18 @@ impl Perform for BlockPerson {
|
|||
target_id,
|
||||
};
|
||||
|
||||
let target_person_view = PersonView::read(context.pool(), target_id).await?;
|
||||
let target_person_view = PersonView::read(&mut context.pool(), target_id).await?;
|
||||
|
||||
if target_person_view.person.admin {
|
||||
return Err(LemmyError::from_message("cant_block_admin"));
|
||||
}
|
||||
|
||||
if data.block {
|
||||
PersonBlock::block(context.pool(), &person_block_form)
|
||||
PersonBlock::block(&mut context.pool(), &person_block_form)
|
||||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "person_block_already_exists"))?;
|
||||
} else {
|
||||
PersonBlock::unblock(context.pool(), &person_block_form)
|
||||
PersonBlock::unblock(&mut context.pool(), &person_block_form)
|
||||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "person_block_already_exists"))?;
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ impl Perform for ChangePassword {
|
|||
let local_user_id = local_user_view.local_user.id;
|
||||
let new_password = data.new_password.clone();
|
||||
let updated_local_user =
|
||||
LocalUser::update_password(context.pool(), local_user_id, &new_password).await?;
|
||||
LocalUser::update_password(&mut context.pool(), local_user_id, &new_password).await?;
|
||||
|
||||
// Return the jwt
|
||||
Ok(LoginResponse {
|
||||
|
|
|
@ -22,7 +22,7 @@ impl Perform for PasswordChangeAfterReset {
|
|||
|
||||
// Fetch the user_id from the token
|
||||
let token = data.token.clone();
|
||||
let local_user_id = PasswordResetRequest::read_from_token(context.pool(), &token)
|
||||
let local_user_id = PasswordResetRequest::read_from_token(&mut context.pool(), &token)
|
||||
.await
|
||||
.map(|p| p.local_user_id)?;
|
||||
|
||||
|
@ -35,12 +35,13 @@ impl Perform for PasswordChangeAfterReset {
|
|||
|
||||
// Update the user with the new password
|
||||
let password = data.password.clone();
|
||||
let updated_local_user = LocalUser::update_password(context.pool(), local_user_id, &password)
|
||||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_user"))?;
|
||||
let updated_local_user =
|
||||
LocalUser::update_password(&mut context.pool(), local_user_id, &password)
|
||||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_user"))?;
|
||||
|
||||
// Return the jwt if login is allowed
|
||||
let site_view = SiteView::read_local(context.pool()).await?;
|
||||
let site_view = SiteView::read_local(&mut context.pool()).await?;
|
||||
let jwt = if site_view.local_site.registration_mode == RegistrationMode::RequireApplication
|
||||
&& !updated_local_user.accepted_application
|
||||
{
|
||||
|
|
|
@ -17,7 +17,7 @@ impl Perform for GetCaptcha {
|
|||
|
||||
#[tracing::instrument(skip(context))]
|
||||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> {
|
||||
let local_site = LocalSite::read(context.pool()).await?;
|
||||
let local_site = LocalSite::read(&mut context.pool()).await?;
|
||||
|
||||
if !local_site.captcha_enabled {
|
||||
return Ok(GetCaptchaResponse { ok: None });
|
||||
|
@ -37,7 +37,7 @@ impl Perform for GetCaptcha {
|
|||
|
||||
let captcha_form: CaptchaAnswerForm = CaptchaAnswerForm { answer };
|
||||
// Stores the captcha item in the db
|
||||
let captcha = CaptchaAnswer::insert(context.pool(), &captcha_form).await?;
|
||||
let captcha = CaptchaAnswer::insert(&mut context.pool(), &captcha_form).await?;
|
||||
|
||||
Ok(GetCaptchaResponse {
|
||||
ok: Some(CaptchaResponse {
|
||||
|
|
|
@ -19,7 +19,7 @@ impl Perform for GetBannedPersons {
|
|||
// Make sure user is an admin
|
||||
is_admin(&local_user_view)?;
|
||||
|
||||
let banned = PersonView::banned(context.pool()).await?;
|
||||
let banned = PersonView::banned(&mut context.pool()).await?;
|
||||
|
||||
Ok(Self::Response { banned })
|
||||
}
|
||||
|
|
|
@ -17,13 +17,14 @@ impl Perform for Login {
|
|||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<LoginResponse, LemmyError> {
|
||||
let data: &Login = self;
|
||||
|
||||
let site_view = SiteView::read_local(context.pool()).await?;
|
||||
let site_view = SiteView::read_local(&mut context.pool()).await?;
|
||||
|
||||
// Fetch that username / email
|
||||
let username_or_email = data.username_or_email.clone();
|
||||
let local_user_view = LocalUserView::find_by_email_or_name(context.pool(), &username_or_email)
|
||||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "couldnt_find_that_username_or_email"))?;
|
||||
let local_user_view =
|
||||
LocalUserView::find_by_email_or_name(&mut context.pool(), &username_or_email)
|
||||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "couldnt_find_that_username_or_email"))?;
|
||||
|
||||
// Verify the password
|
||||
let valid: bool = verify(
|
||||
|
@ -49,7 +50,8 @@ impl Perform for Login {
|
|||
return Err(LemmyError::from_message("email_not_verified"));
|
||||
}
|
||||
|
||||
check_registration_application(&local_user_view, &site_view.local_site, context.pool()).await?;
|
||||
check_registration_application(&local_user_view, &site_view.local_site, &mut context.pool())
|
||||
.await?;
|
||||
|
||||
// Check the totp
|
||||
check_totp_2fa_valid(
|
||||
|
|
|
@ -28,7 +28,7 @@ impl Perform for GetPersonMentions {
|
|||
let show_bot_accounts = Some(local_user_view.local_user.show_bot_accounts);
|
||||
|
||||
let mentions = PersonMentionQuery::builder()
|
||||
.pool(context.pool())
|
||||
.pool(&mut context.pool())
|
||||
.recipient_id(person_id)
|
||||
.my_person_id(person_id)
|
||||
.sort(sort)
|
||||
|
|
|
@ -25,7 +25,7 @@ impl Perform for GetReplies {
|
|||
let show_bot_accounts = Some(local_user_view.local_user.show_bot_accounts);
|
||||
|
||||
let replies = CommentReplyQuery::builder()
|
||||
.pool(context.pool())
|
||||
.pool(&mut context.pool())
|
||||
.recipient_id(person_id)
|
||||
.my_person_id(person_id)
|
||||
.sort(sort)
|
||||
|
|
|
@ -23,17 +23,17 @@ impl Perform for MarkAllAsRead {
|
|||
let person_id = local_user_view.person.id;
|
||||
|
||||
// Mark all comment_replies as read
|
||||
CommentReply::mark_all_as_read(context.pool(), person_id)
|
||||
CommentReply::mark_all_as_read(&mut context.pool(), person_id)
|
||||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_comment"))?;
|
||||
|
||||
// Mark all user mentions as read
|
||||
PersonMention::mark_all_as_read(context.pool(), person_id)
|
||||
PersonMention::mark_all_as_read(&mut context.pool(), person_id)
|
||||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_comment"))?;
|
||||
|
||||
// Mark all private_messages as read
|
||||
PrivateMessage::mark_all_as_read(context.pool(), person_id)
|
||||
PrivateMessage::mark_all_as_read(&mut context.pool(), person_id)
|
||||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_private_message"))?;
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ impl Perform for MarkPersonMentionAsRead {
|
|||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||
|
||||
let person_mention_id = data.person_mention_id;
|
||||
let read_person_mention = PersonMention::read(context.pool(), person_mention_id).await?;
|
||||
let read_person_mention = PersonMention::read(&mut context.pool(), person_mention_id).await?;
|
||||
|
||||
if local_user_view.person.id != read_person_mention.recipient_id {
|
||||
return Err(LemmyError::from_message("couldnt_update_comment"));
|
||||
|
@ -34,7 +34,7 @@ impl Perform for MarkPersonMentionAsRead {
|
|||
let person_mention_id = read_person_mention.id;
|
||||
let read = Some(data.read);
|
||||
PersonMention::update(
|
||||
context.pool(),
|
||||
&mut context.pool(),
|
||||
person_mention_id,
|
||||
&PersonMentionUpdateForm { read },
|
||||
)
|
||||
|
@ -44,7 +44,7 @@ impl Perform for MarkPersonMentionAsRead {
|
|||
let person_mention_id = read_person_mention.id;
|
||||
let person_id = local_user_view.person.id;
|
||||
let person_mention_view =
|
||||
PersonMentionView::read(context.pool(), person_mention_id, Some(person_id)).await?;
|
||||
PersonMentionView::read(&mut context.pool(), person_mention_id, Some(person_id)).await?;
|
||||
|
||||
Ok(PersonMentionResponse {
|
||||
person_mention_view,
|
||||
|
|
|
@ -25,7 +25,7 @@ impl Perform for MarkCommentReplyAsRead {
|
|||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||
|
||||
let comment_reply_id = data.comment_reply_id;
|
||||
let read_comment_reply = CommentReply::read(context.pool(), comment_reply_id).await?;
|
||||
let read_comment_reply = CommentReply::read(&mut context.pool(), comment_reply_id).await?;
|
||||
|
||||
if local_user_view.person.id != read_comment_reply.recipient_id {
|
||||
return Err(LemmyError::from_message("couldnt_update_comment"));
|
||||
|
@ -35,7 +35,7 @@ impl Perform for MarkCommentReplyAsRead {
|
|||
let read = Some(data.read);
|
||||
|
||||
CommentReply::update(
|
||||
context.pool(),
|
||||
&mut context.pool(),
|
||||
comment_reply_id,
|
||||
&CommentReplyUpdateForm { read },
|
||||
)
|
||||
|
@ -45,7 +45,7 @@ impl Perform for MarkCommentReplyAsRead {
|
|||
let comment_reply_id = read_comment_reply.id;
|
||||
let person_id = local_user_view.person.id;
|
||||
let comment_reply_view =
|
||||
CommentReplyView::read(context.pool(), comment_reply_id, Some(person_id)).await?;
|
||||
CommentReplyView::read(&mut context.pool(), comment_reply_id, Some(person_id)).await?;
|
||||
|
||||
Ok(CommentReplyResponse { comment_reply_view })
|
||||
}
|
||||
|
|
|
@ -20,12 +20,12 @@ impl Perform for GetUnreadCount {
|
|||
|
||||
let person_id = local_user_view.person.id;
|
||||
|
||||
let replies = CommentReplyView::get_unread_replies(context.pool(), person_id).await?;
|
||||
let replies = CommentReplyView::get_unread_replies(&mut context.pool(), person_id).await?;
|
||||
|
||||
let mentions = PersonMentionView::get_unread_mentions(context.pool(), person_id).await?;
|
||||
let mentions = PersonMentionView::get_unread_mentions(&mut context.pool(), person_id).await?;
|
||||
|
||||
let private_messages =
|
||||
PrivateMessageView::get_unread_messages(context.pool(), person_id).await?;
|
||||
PrivateMessageView::get_unread_messages(&mut context.pool(), person_id).await?;
|
||||
|
||||
Ok(Self::Response {
|
||||
replies,
|
||||
|
|
|
@ -25,13 +25,14 @@ impl Perform for GetReportCount {
|
|||
let community_id = data.community_id;
|
||||
|
||||
let comment_reports =
|
||||
CommentReportView::get_report_count(context.pool(), person_id, admin, community_id).await?;
|
||||
CommentReportView::get_report_count(&mut context.pool(), person_id, admin, community_id)
|
||||
.await?;
|
||||
|
||||
let post_reports =
|
||||
PostReportView::get_report_count(context.pool(), person_id, admin, community_id).await?;
|
||||
PostReportView::get_report_count(&mut context.pool(), person_id, admin, community_id).await?;
|
||||
|
||||
let private_message_reports = if admin && community_id.is_none() {
|
||||
Some(PrivateMessageReportView::get_report_count(context.pool()).await?)
|
||||
Some(PrivateMessageReportView::get_report_count(&mut context.pool()).await?)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
|
|
@ -22,13 +22,13 @@ impl Perform for PasswordReset {
|
|||
|
||||
// Fetch that email
|
||||
let email = data.email.to_lowercase();
|
||||
let local_user_view = LocalUserView::find_by_email(context.pool(), &email)
|
||||
let local_user_view = LocalUserView::find_by_email(&mut context.pool(), &email)
|
||||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "couldnt_find_that_username_or_email"))?;
|
||||
|
||||
// Check for too many attempts (to limit potential abuse)
|
||||
let recent_resets_count = PasswordResetRequest::get_recent_password_resets_count(
|
||||
context.pool(),
|
||||
&mut context.pool(),
|
||||
local_user_view.local_user.id,
|
||||
)
|
||||
.await?;
|
||||
|
@ -37,7 +37,7 @@ impl Perform for PasswordReset {
|
|||
}
|
||||
|
||||
// Email the pure token to the user.
|
||||
send_password_reset_email(&local_user_view, context.pool(), context.settings()).await?;
|
||||
send_password_reset_email(&local_user_view, &mut context.pool(), context.settings()).await?;
|
||||
Ok(PasswordResetResponse {})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ impl Perform for SaveUserSettings {
|
|||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<LoginResponse, LemmyError> {
|
||||
let data: &SaveUserSettings = self;
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||
let site_view = SiteView::read_local(context.pool()).await?;
|
||||
let site_view = SiteView::read_local(&mut context.pool()).await?;
|
||||
|
||||
let avatar = diesel_option_overwrite_to_url(&data.avatar)?;
|
||||
let banner = diesel_option_overwrite_to_url(&data.banner)?;
|
||||
|
@ -49,8 +49,13 @@ impl Perform for SaveUserSettings {
|
|||
let previous_email = local_user_view.local_user.email.clone().unwrap_or_default();
|
||||
// Only send the verification email if there was an email change
|
||||
if previous_email.ne(email) {
|
||||
send_verification_email(&local_user_view, email, context.pool(), context.settings())
|
||||
.await?;
|
||||
send_verification_email(
|
||||
&local_user_view,
|
||||
email,
|
||||
&mut context.pool(),
|
||||
context.settings(),
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -90,12 +95,12 @@ impl Perform for SaveUserSettings {
|
|||
.banner(banner)
|
||||
.build();
|
||||
|
||||
Person::update(context.pool(), person_id, &person_form)
|
||||
Person::update(&mut context.pool(), person_id, &person_form)
|
||||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "user_already_exists"))?;
|
||||
|
||||
if let Some(discussion_languages) = data.discussion_languages.clone() {
|
||||
LocalUserLanguage::update(context.pool(), discussion_languages, local_user_id).await?;
|
||||
LocalUserLanguage::update(&mut context.pool(), discussion_languages, local_user_id).await?;
|
||||
}
|
||||
|
||||
// If generate_totp is Some(false), this will clear it out from the database.
|
||||
|
@ -130,7 +135,8 @@ impl Perform for SaveUserSettings {
|
|||
.open_links_in_new_tab(data.open_links_in_new_tab)
|
||||
.build();
|
||||
|
||||
let local_user_res = LocalUser::update(context.pool(), local_user_id, &local_user_form).await;
|
||||
let local_user_res =
|
||||
LocalUser::update(&mut context.pool(), local_user_id, &local_user_form).await;
|
||||
let updated_local_user = match local_user_res {
|
||||
Ok(u) => u,
|
||||
Err(e) => {
|
||||
|
|
|
@ -19,7 +19,7 @@ impl Perform for VerifyEmail {
|
|||
|
||||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> {
|
||||
let token = self.token.clone();
|
||||
let verification = EmailVerification::read_for_token(context.pool(), &token)
|
||||
let verification = EmailVerification::read_for_token(&mut context.pool(), &token)
|
||||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "token_not_found"))?;
|
||||
|
||||
|
@ -31,9 +31,9 @@ impl Perform for VerifyEmail {
|
|||
.build();
|
||||
let local_user_id = verification.local_user_id;
|
||||
|
||||
LocalUser::update(context.pool(), local_user_id, &form).await?;
|
||||
LocalUser::update(&mut context.pool(), local_user_id, &form).await?;
|
||||
|
||||
EmailVerification::delete_old_tokens_for_local_user(context.pool(), local_user_id).await?;
|
||||
EmailVerification::delete_old_tokens_for_local_user(&mut context.pool(), local_user_id).await?;
|
||||
|
||||
Ok(VerifyEmailResponse {})
|
||||
}
|
||||
|
|
|
@ -32,20 +32,20 @@ impl Perform for FeaturePost {
|
|||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||
|
||||
let post_id = data.post_id;
|
||||
let orig_post = Post::read(context.pool(), post_id).await?;
|
||||
let orig_post = Post::read(&mut context.pool(), post_id).await?;
|
||||
|
||||
check_community_ban(
|
||||
local_user_view.person.id,
|
||||
orig_post.community_id,
|
||||
context.pool(),
|
||||
&mut context.pool(),
|
||||
)
|
||||
.await?;
|
||||
check_community_deleted_or_removed(orig_post.community_id, context.pool()).await?;
|
||||
check_community_deleted_or_removed(orig_post.community_id, &mut context.pool()).await?;
|
||||
|
||||
if data.feature_type == PostFeatureType::Community {
|
||||
// Verify that only the mods can feature in community
|
||||
is_mod_or_admin(
|
||||
context.pool(),
|
||||
&mut context.pool(),
|
||||
local_user_view.person.id,
|
||||
orig_post.community_id,
|
||||
)
|
||||
|
@ -65,7 +65,7 @@ impl Perform for FeaturePost {
|
|||
.featured_local(Some(data.featured))
|
||||
.build()
|
||||
};
|
||||
Post::update(context.pool(), post_id, &new_post).await?;
|
||||
Post::update(&mut context.pool(), post_id, &new_post).await?;
|
||||
|
||||
// Mod tables
|
||||
let form = ModFeaturePostForm {
|
||||
|
@ -75,7 +75,7 @@ impl Perform for FeaturePost {
|
|||
is_featured_community: data.feature_type == PostFeatureType::Community,
|
||||
};
|
||||
|
||||
ModFeaturePost::create(context.pool(), &form).await?;
|
||||
ModFeaturePost::create(&mut context.pool(), &form).await?;
|
||||
|
||||
build_post_response(
|
||||
context,
|
||||
|
|
|
@ -29,17 +29,22 @@ impl Perform for CreatePostLike {
|
|||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<PostResponse, LemmyError> {
|
||||
let data: &CreatePostLike = self;
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||
let local_site = LocalSite::read(context.pool()).await?;
|
||||
let local_site = LocalSite::read(&mut context.pool()).await?;
|
||||
|
||||
// Don't do a downvote if site has downvotes disabled
|
||||
check_downvotes_enabled(data.score, &local_site)?;
|
||||
|
||||
// Check for a community ban
|
||||
let post_id = data.post_id;
|
||||
let post = Post::read(context.pool(), post_id).await?;
|
||||
let post = Post::read(&mut context.pool(), post_id).await?;
|
||||
|
||||
check_community_ban(local_user_view.person.id, post.community_id, context.pool()).await?;
|
||||
check_community_deleted_or_removed(post.community_id, context.pool()).await?;
|
||||
check_community_ban(
|
||||
local_user_view.person.id,
|
||||
post.community_id,
|
||||
&mut context.pool(),
|
||||
)
|
||||
.await?;
|
||||
check_community_deleted_or_removed(post.community_id, &mut context.pool()).await?;
|
||||
|
||||
let like_form = PostLikeForm {
|
||||
post_id: data.post_id,
|
||||
|
@ -50,18 +55,18 @@ impl Perform for CreatePostLike {
|
|||
// Remove any likes first
|
||||
let person_id = local_user_view.person.id;
|
||||
|
||||
PostLike::remove(context.pool(), person_id, post_id).await?;
|
||||
PostLike::remove(&mut context.pool(), person_id, post_id).await?;
|
||||
|
||||
// Only add the like if the score isnt 0
|
||||
let do_add = like_form.score != 0 && (like_form.score == 1 || like_form.score == -1);
|
||||
if do_add {
|
||||
PostLike::like(context.pool(), &like_form)
|
||||
PostLike::like(&mut context.pool(), &like_form)
|
||||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "couldnt_like_post"))?;
|
||||
}
|
||||
|
||||
// Mark the post as read
|
||||
mark_post_as_read(person_id, post_id, context.pool()).await?;
|
||||
mark_post_as_read(person_id, post_id, &mut context.pool()).await?;
|
||||
|
||||
build_post_response(
|
||||
context,
|
||||
|
|
|
@ -30,19 +30,19 @@ impl Perform for LockPost {
|
|||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||
|
||||
let post_id = data.post_id;
|
||||
let orig_post = Post::read(context.pool(), post_id).await?;
|
||||
let orig_post = Post::read(&mut context.pool(), post_id).await?;
|
||||
|
||||
check_community_ban(
|
||||
local_user_view.person.id,
|
||||
orig_post.community_id,
|
||||
context.pool(),
|
||||
&mut context.pool(),
|
||||
)
|
||||
.await?;
|
||||
check_community_deleted_or_removed(orig_post.community_id, context.pool()).await?;
|
||||
check_community_deleted_or_removed(orig_post.community_id, &mut context.pool()).await?;
|
||||
|
||||
// Verify that only the mods can lock
|
||||
is_mod_or_admin(
|
||||
context.pool(),
|
||||
&mut context.pool(),
|
||||
local_user_view.person.id,
|
||||
orig_post.community_id,
|
||||
)
|
||||
|
@ -52,7 +52,7 @@ impl Perform for LockPost {
|
|||
let post_id = data.post_id;
|
||||
let locked = data.locked;
|
||||
Post::update(
|
||||
context.pool(),
|
||||
&mut context.pool(),
|
||||
post_id,
|
||||
&PostUpdateForm::builder().locked(Some(locked)).build(),
|
||||
)
|
||||
|
@ -64,7 +64,7 @@ impl Perform for LockPost {
|
|||
post_id: data.post_id,
|
||||
locked: Some(locked),
|
||||
};
|
||||
ModLockPost::create(context.pool(), &form).await?;
|
||||
ModLockPost::create(&mut context.pool(), &form).await?;
|
||||
|
||||
build_post_response(
|
||||
context,
|
||||
|
|
|
@ -22,13 +22,13 @@ impl Perform for MarkPostAsRead {
|
|||
|
||||
// Mark the post as read / unread
|
||||
if data.read {
|
||||
mark_post_as_read(person_id, post_id, context.pool()).await?;
|
||||
mark_post_as_read(person_id, post_id, &mut context.pool()).await?;
|
||||
} else {
|
||||
mark_post_as_unread(person_id, post_id, context.pool()).await?;
|
||||
mark_post_as_unread(person_id, post_id, &mut context.pool()).await?;
|
||||
}
|
||||
|
||||
// Fetch it
|
||||
let post_view = PostView::read(context.pool(), post_id, Some(person_id), None).await?;
|
||||
let post_view = PostView::read(&mut context.pool(), post_id, Some(person_id), None).await?;
|
||||
|
||||
Ok(Self::Response { post_view })
|
||||
}
|
||||
|
|
|
@ -27,21 +27,21 @@ impl Perform for SavePost {
|
|||
};
|
||||
|
||||
if data.save {
|
||||
PostSaved::save(context.pool(), &post_saved_form)
|
||||
PostSaved::save(&mut context.pool(), &post_saved_form)
|
||||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "couldnt_save_post"))?;
|
||||
} else {
|
||||
PostSaved::unsave(context.pool(), &post_saved_form)
|
||||
PostSaved::unsave(&mut context.pool(), &post_saved_form)
|
||||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "couldnt_save_post"))?;
|
||||
}
|
||||
|
||||
let post_id = data.post_id;
|
||||
let person_id = local_user_view.person.id;
|
||||
let post_view = PostView::read(context.pool(), post_id, Some(person_id), None).await?;
|
||||
let post_view = PostView::read(&mut context.pool(), post_id, Some(person_id), None).await?;
|
||||
|
||||
// Mark the post as read
|
||||
mark_post_as_read(person_id, post_id, context.pool()).await?;
|
||||
mark_post_as_read(person_id, post_id, &mut context.pool()).await?;
|
||||
|
||||
Ok(PostResponse { post_view })
|
||||
}
|
||||
|
|
|
@ -24,16 +24,16 @@ impl Perform for CreatePostReport {
|
|||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<PostReportResponse, LemmyError> {
|
||||
let data: &CreatePostReport = self;
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||
let local_site = LocalSite::read(context.pool()).await?;
|
||||
let local_site = LocalSite::read(&mut context.pool()).await?;
|
||||
|
||||
let reason = self.reason.trim();
|
||||
check_report_reason(reason, &local_site)?;
|
||||
|
||||
let person_id = local_user_view.person.id;
|
||||
let post_id = data.post_id;
|
||||
let post_view = PostView::read(context.pool(), post_id, None, None).await?;
|
||||
let post_view = PostView::read(&mut context.pool(), post_id, None, None).await?;
|
||||
|
||||
check_community_ban(person_id, post_view.community.id, context.pool()).await?;
|
||||
check_community_ban(person_id, post_view.community.id, &mut context.pool()).await?;
|
||||
|
||||
let report_form = PostReportForm {
|
||||
creator_id: person_id,
|
||||
|
@ -44,18 +44,18 @@ impl Perform for CreatePostReport {
|
|||
reason: reason.to_owned(),
|
||||
};
|
||||
|
||||
let report = PostReport::report(context.pool(), &report_form)
|
||||
let report = PostReport::report(&mut context.pool(), &report_form)
|
||||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "couldnt_create_report"))?;
|
||||
|
||||
let post_report_view = PostReportView::read(context.pool(), report.id, person_id).await?;
|
||||
let post_report_view = PostReportView::read(&mut context.pool(), report.id, person_id).await?;
|
||||
|
||||
// Email the admins
|
||||
if local_site.reports_email_admins {
|
||||
send_new_report_email_to_admins(
|
||||
&post_report_view.creator.name,
|
||||
&post_report_view.post_creator.name,
|
||||
context.pool(),
|
||||
&mut context.pool(),
|
||||
context.settings(),
|
||||
)
|
||||
.await?;
|
||||
|
|
|
@ -30,7 +30,7 @@ impl Perform for ListPostReports {
|
|||
let page = data.page;
|
||||
let limit = data.limit;
|
||||
let post_reports = PostReportQuery::builder()
|
||||
.pool(context.pool())
|
||||
.pool(&mut context.pool())
|
||||
.my_person_id(person_id)
|
||||
.admin(admin)
|
||||
.community_id(community_id)
|
||||
|
|
|
@ -21,22 +21,22 @@ impl Perform for ResolvePostReport {
|
|||
|
||||
let report_id = data.report_id;
|
||||
let person_id = local_user_view.person.id;
|
||||
let report = PostReportView::read(context.pool(), report_id, person_id).await?;
|
||||
let report = PostReportView::read(&mut context.pool(), report_id, person_id).await?;
|
||||
|
||||
let person_id = local_user_view.person.id;
|
||||
is_mod_or_admin(context.pool(), person_id, report.community.id).await?;
|
||||
is_mod_or_admin(&mut context.pool(), person_id, report.community.id).await?;
|
||||
|
||||
if data.resolved {
|
||||
PostReport::resolve(context.pool(), report_id, person_id)
|
||||
PostReport::resolve(&mut context.pool(), report_id, person_id)
|
||||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "couldnt_resolve_report"))?;
|
||||
} else {
|
||||
PostReport::unresolve(context.pool(), report_id, person_id)
|
||||
PostReport::unresolve(&mut context.pool(), report_id, person_id)
|
||||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "couldnt_resolve_report"))?;
|
||||
}
|
||||
|
||||
let post_report_view = PostReportView::read(context.pool(), report_id, person_id).await?;
|
||||
let post_report_view = PostReportView::read(&mut context.pool(), report_id, person_id).await?;
|
||||
|
||||
Ok(PostReportResponse { post_report_view })
|
||||
}
|
||||
|
|
|
@ -26,7 +26,8 @@ impl Perform for MarkPrivateMessageAsRead {
|
|||
|
||||
// Checking permissions
|
||||
let private_message_id = data.private_message_id;
|
||||
let orig_private_message = PrivateMessage::read(context.pool(), private_message_id).await?;
|
||||
let orig_private_message =
|
||||
PrivateMessage::read(&mut context.pool(), private_message_id).await?;
|
||||
if local_user_view.person.id != orig_private_message.recipient_id {
|
||||
return Err(LemmyError::from_message("couldnt_update_private_message"));
|
||||
}
|
||||
|
@ -35,14 +36,14 @@ impl Perform for MarkPrivateMessageAsRead {
|
|||
let private_message_id = data.private_message_id;
|
||||
let read = data.read;
|
||||
PrivateMessage::update(
|
||||
context.pool(),
|
||||
&mut context.pool(),
|
||||
private_message_id,
|
||||
&PrivateMessageUpdateForm::builder().read(Some(read)).build(),
|
||||
)
|
||||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_private_message"))?;
|
||||
|
||||
let view = PrivateMessageView::read(context.pool(), private_message_id).await?;
|
||||
let view = PrivateMessageView::read(&mut context.pool(), private_message_id).await?;
|
||||
Ok(PrivateMessageResponse {
|
||||
private_message_view: view,
|
||||
})
|
||||
|
|
|
@ -23,14 +23,14 @@ impl Perform for CreatePrivateMessageReport {
|
|||
#[tracing::instrument(skip(context))]
|
||||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> {
|
||||
let local_user_view = local_user_view_from_jwt(&self.auth, context).await?;
|
||||
let local_site = LocalSite::read(context.pool()).await?;
|
||||
let local_site = LocalSite::read(&mut context.pool()).await?;
|
||||
|
||||
let reason = self.reason.trim();
|
||||
check_report_reason(reason, &local_site)?;
|
||||
|
||||
let person_id = local_user_view.person.id;
|
||||
let private_message_id = self.private_message_id;
|
||||
let private_message = PrivateMessage::read(context.pool(), private_message_id).await?;
|
||||
let private_message = PrivateMessage::read(&mut context.pool(), private_message_id).await?;
|
||||
|
||||
let report_form = PrivateMessageReportForm {
|
||||
creator_id: person_id,
|
||||
|
@ -39,19 +39,19 @@ impl Perform for CreatePrivateMessageReport {
|
|||
reason: reason.to_owned(),
|
||||
};
|
||||
|
||||
let report = PrivateMessageReport::report(context.pool(), &report_form)
|
||||
let report = PrivateMessageReport::report(&mut context.pool(), &report_form)
|
||||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "couldnt_create_report"))?;
|
||||
|
||||
let private_message_report_view =
|
||||
PrivateMessageReportView::read(context.pool(), report.id).await?;
|
||||
PrivateMessageReportView::read(&mut context.pool(), report.id).await?;
|
||||
|
||||
// Email the admins
|
||||
if local_site.reports_email_admins {
|
||||
send_new_report_email_to_admins(
|
||||
&private_message_report_view.creator.name,
|
||||
&private_message_report_view.private_message_creator.name,
|
||||
context.pool(),
|
||||
&mut context.pool(),
|
||||
context.settings(),
|
||||
)
|
||||
.await?;
|
||||
|
|
|
@ -22,7 +22,7 @@ impl Perform for ListPrivateMessageReports {
|
|||
let page = self.page;
|
||||
let limit = self.limit;
|
||||
let private_message_reports = PrivateMessageReportQuery::builder()
|
||||
.pool(context.pool())
|
||||
.pool(&mut context.pool())
|
||||
.unresolved_only(unresolved_only)
|
||||
.page(page)
|
||||
.limit(limit)
|
||||
|
|
|
@ -22,17 +22,17 @@ impl Perform for ResolvePrivateMessageReport {
|
|||
let report_id = self.report_id;
|
||||
let person_id = local_user_view.person.id;
|
||||
if self.resolved {
|
||||
PrivateMessageReport::resolve(context.pool(), report_id, person_id)
|
||||
PrivateMessageReport::resolve(&mut context.pool(), report_id, person_id)
|
||||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "couldnt_resolve_report"))?;
|
||||
} else {
|
||||
PrivateMessageReport::unresolve(context.pool(), report_id, person_id)
|
||||
PrivateMessageReport::unresolve(&mut context.pool(), report_id, person_id)
|
||||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "couldnt_resolve_report"))?;
|
||||
}
|
||||
|
||||
let private_message_report_view =
|
||||
PrivateMessageReportView::read(context.pool(), report_id).await?;
|
||||
PrivateMessageReportView::read(&mut context.pool(), report_id).await?;
|
||||
|
||||
Ok(PrivateMessageReportResponse {
|
||||
private_message_report_view,
|
||||
|
|
|
@ -14,9 +14,9 @@ impl Perform for GetFederatedInstances {
|
|||
|
||||
#[tracing::instrument(skip(context))]
|
||||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> {
|
||||
let site_view = SiteView::read_local(context.pool()).await?;
|
||||
let site_view = SiteView::read_local(&mut context.pool()).await?;
|
||||
let federated_instances =
|
||||
build_federated_instances(&site_view.local_site, context.pool()).await?;
|
||||
build_federated_instances(&site_view.local_site, &mut context.pool()).await?;
|
||||
|
||||
Ok(Self::Response {
|
||||
federated_instances,
|
||||
|
|
|
@ -31,14 +31,14 @@ impl Perform for LeaveAdmin {
|
|||
is_admin(&local_user_view)?;
|
||||
|
||||
// Make sure there isn't just one admin (so if one leaves, there will still be one left)
|
||||
let admins = PersonView::admins(context.pool()).await?;
|
||||
let admins = PersonView::admins(&mut context.pool()).await?;
|
||||
if admins.len() == 1 {
|
||||
return Err(LemmyError::from_message("cannot_leave_admin"));
|
||||
}
|
||||
|
||||
let person_id = local_user_view.person.id;
|
||||
Person::update(
|
||||
context.pool(),
|
||||
&mut context.pool(),
|
||||
person_id,
|
||||
&PersonUpdateForm::builder().admin(Some(false)).build(),
|
||||
)
|
||||
|
@ -51,16 +51,17 @@ impl Perform for LeaveAdmin {
|
|||
removed: Some(true),
|
||||
};
|
||||
|
||||
ModAdd::create(context.pool(), &form).await?;
|
||||
ModAdd::create(&mut context.pool(), &form).await?;
|
||||
|
||||
// Reread site and admins
|
||||
let site_view = SiteView::read_local(context.pool()).await?;
|
||||
let admins = PersonView::admins(context.pool()).await?;
|
||||
let site_view = SiteView::read_local(&mut context.pool()).await?;
|
||||
let admins = PersonView::admins(&mut context.pool()).await?;
|
||||
|
||||
let all_languages = Language::read_all(context.pool()).await?;
|
||||
let discussion_languages = SiteLanguage::read_local_raw(context.pool()).await?;
|
||||
let taglines = Tagline::get_all(context.pool(), site_view.local_site.id).await?;
|
||||
let custom_emojis = CustomEmojiView::get_all(context.pool(), site_view.local_site.id).await?;
|
||||
let all_languages = Language::read_all(&mut context.pool()).await?;
|
||||
let discussion_languages = SiteLanguage::read_local_raw(&mut context.pool()).await?;
|
||||
let taglines = Tagline::get_all(&mut context.pool(), site_view.local_site.id).await?;
|
||||
let custom_emojis =
|
||||
CustomEmojiView::get_all(&mut context.pool(), site_view.local_site.id).await?;
|
||||
|
||||
Ok(GetSiteResponse {
|
||||
site_view,
|
||||
|
|
|
@ -40,7 +40,7 @@ impl Perform for GetModlog {
|
|||
let data: &GetModlog = self;
|
||||
|
||||
let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), context).await;
|
||||
let local_site = LocalSite::read(context.pool()).await?;
|
||||
let local_site = LocalSite::read(&mut context.pool()).await?;
|
||||
|
||||
check_private_instance(&local_user_view, &local_site)?;
|
||||
|
||||
|
@ -56,7 +56,7 @@ impl Perform for GetModlog {
|
|||
None => CommunityId(-1),
|
||||
};
|
||||
let is_mod_of_community = data.community_id.is_some()
|
||||
&& is_mod_or_admin(context.pool(), local_person_id, community_id_value)
|
||||
&& is_mod_or_admin(&mut context.pool(), local_person_id, community_id_value)
|
||||
.await
|
||||
.is_ok();
|
||||
let hide_modlog_names = local_site.hide_modlog_mod_names && !is_mod_of_community && !is_admin;
|
||||
|
@ -76,43 +76,47 @@ impl Perform for GetModlog {
|
|||
hide_modlog_names,
|
||||
};
|
||||
let removed_posts = match type_ {
|
||||
All | ModRemovePost => ModRemovePostView::list(context.pool(), params).await?,
|
||||
All | ModRemovePost => ModRemovePostView::list(&mut context.pool(), params).await?,
|
||||
_ => Default::default(),
|
||||
};
|
||||
|
||||
let locked_posts = match type_ {
|
||||
All | ModLockPost => ModLockPostView::list(context.pool(), params).await?,
|
||||
All | ModLockPost => ModLockPostView::list(&mut context.pool(), params).await?,
|
||||
_ => Default::default(),
|
||||
};
|
||||
|
||||
let featured_posts = match type_ {
|
||||
All | ModFeaturePost => ModFeaturePostView::list(context.pool(), params).await?,
|
||||
All | ModFeaturePost => ModFeaturePostView::list(&mut context.pool(), params).await?,
|
||||
_ => Default::default(),
|
||||
};
|
||||
|
||||
let removed_comments = match type_ {
|
||||
All | ModRemoveComment => ModRemoveCommentView::list(context.pool(), params).await?,
|
||||
All | ModRemoveComment => ModRemoveCommentView::list(&mut context.pool(), params).await?,
|
||||
_ => Default::default(),
|
||||
};
|
||||
|
||||
let banned_from_community = match type_ {
|
||||
All | ModBanFromCommunity => ModBanFromCommunityView::list(context.pool(), params).await?,
|
||||
All | ModBanFromCommunity => {
|
||||
ModBanFromCommunityView::list(&mut context.pool(), params).await?
|
||||
}
|
||||
_ => Default::default(),
|
||||
};
|
||||
|
||||
let added_to_community = match type_ {
|
||||
All | ModAddCommunity => ModAddCommunityView::list(context.pool(), params).await?,
|
||||
All | ModAddCommunity => ModAddCommunityView::list(&mut context.pool(), params).await?,
|
||||
_ => Default::default(),
|
||||
};
|
||||
|
||||
let transferred_to_community = match type_ {
|
||||
All | ModTransferCommunity => ModTransferCommunityView::list(context.pool(), params).await?,
|
||||
All | ModTransferCommunity => {
|
||||
ModTransferCommunityView::list(&mut context.pool(), params).await?
|
||||
}
|
||||
_ => Default::default(),
|
||||
};
|
||||
|
||||
let hidden_communities = match type_ {
|
||||
All | ModHideCommunity if other_person_id.is_none() => {
|
||||
ModHideCommunityView::list(context.pool(), params).await?
|
||||
ModHideCommunityView::list(&mut context.pool(), params).await?
|
||||
}
|
||||
_ => Default::default(),
|
||||
};
|
||||
|
@ -129,40 +133,40 @@ impl Perform for GetModlog {
|
|||
) = if data.community_id.is_none() {
|
||||
(
|
||||
match type_ {
|
||||
All | ModBan => ModBanView::list(context.pool(), params).await?,
|
||||
All | ModBan => ModBanView::list(&mut context.pool(), params).await?,
|
||||
_ => Default::default(),
|
||||
},
|
||||
match type_ {
|
||||
All | ModAdd => ModAddView::list(context.pool(), params).await?,
|
||||
All | ModAdd => ModAddView::list(&mut context.pool(), params).await?,
|
||||
_ => Default::default(),
|
||||
},
|
||||
match type_ {
|
||||
All | ModRemoveCommunity if other_person_id.is_none() => {
|
||||
ModRemoveCommunityView::list(context.pool(), params).await?
|
||||
ModRemoveCommunityView::list(&mut context.pool(), params).await?
|
||||
}
|
||||
_ => Default::default(),
|
||||
},
|
||||
match type_ {
|
||||
All | AdminPurgePerson if other_person_id.is_none() => {
|
||||
AdminPurgePersonView::list(context.pool(), params).await?
|
||||
AdminPurgePersonView::list(&mut context.pool(), params).await?
|
||||
}
|
||||
_ => Default::default(),
|
||||
},
|
||||
match type_ {
|
||||
All | AdminPurgeCommunity if other_person_id.is_none() => {
|
||||
AdminPurgeCommunityView::list(context.pool(), params).await?
|
||||
AdminPurgeCommunityView::list(&mut context.pool(), params).await?
|
||||
}
|
||||
_ => Default::default(),
|
||||
},
|
||||
match type_ {
|
||||
All | AdminPurgePost if other_person_id.is_none() => {
|
||||
AdminPurgePostView::list(context.pool(), params).await?
|
||||
AdminPurgePostView::list(&mut context.pool(), params).await?
|
||||
}
|
||||
_ => Default::default(),
|
||||
},
|
||||
match type_ {
|
||||
All | AdminPurgeComment if other_person_id.is_none() => {
|
||||
AdminPurgeCommentView::list(context.pool(), params).await?
|
||||
AdminPurgeCommentView::list(&mut context.pool(), params).await?
|
||||
}
|
||||
_ => Default::default(),
|
||||
},
|
||||
|
|
|
@ -29,13 +29,13 @@ impl Perform for PurgeComment {
|
|||
let comment_id = data.comment_id;
|
||||
|
||||
// Read the comment to get the post_id
|
||||
let comment = Comment::read(context.pool(), comment_id).await?;
|
||||
let comment = Comment::read(&mut context.pool(), comment_id).await?;
|
||||
|
||||
let post_id = comment.post_id;
|
||||
|
||||
// TODO read comments for pictrs images and purge them
|
||||
|
||||
Comment::delete(context.pool(), comment_id).await?;
|
||||
Comment::delete(&mut context.pool(), comment_id).await?;
|
||||
|
||||
// Mod tables
|
||||
let reason = data.reason.clone();
|
||||
|
@ -45,7 +45,7 @@ impl Perform for PurgeComment {
|
|||
post_id,
|
||||
};
|
||||
|
||||
AdminPurgeComment::create(context.pool(), &form).await?;
|
||||
AdminPurgeComment::create(&mut context.pool(), &form).await?;
|
||||
|
||||
Ok(PurgeItemResponse { success: true })
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ impl Perform for PurgeCommunity {
|
|||
let community_id = data.community_id;
|
||||
|
||||
// Read the community to get its images
|
||||
let community = Community::read(context.pool(), community_id).await?;
|
||||
let community = Community::read(&mut context.pool(), community_id).await?;
|
||||
|
||||
if let Some(banner) = community.banner {
|
||||
purge_image_from_pictrs(context.client(), context.settings(), &banner)
|
||||
|
@ -46,13 +46,13 @@ impl Perform for PurgeCommunity {
|
|||
|
||||
purge_image_posts_for_community(
|
||||
community_id,
|
||||
context.pool(),
|
||||
&mut context.pool(),
|
||||
context.settings(),
|
||||
context.client(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
Community::delete(context.pool(), community_id).await?;
|
||||
Community::delete(&mut context.pool(), community_id).await?;
|
||||
|
||||
// Mod tables
|
||||
let reason = data.reason.clone();
|
||||
|
@ -61,7 +61,7 @@ impl Perform for PurgeCommunity {
|
|||
reason,
|
||||
};
|
||||
|
||||
AdminPurgeCommunity::create(context.pool(), &form).await?;
|
||||
AdminPurgeCommunity::create(&mut context.pool(), &form).await?;
|
||||
|
||||
Ok(PurgeItemResponse { success: true })
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ impl Perform for PurgePerson {
|
|||
|
||||
// Read the person to get their images
|
||||
let person_id = data.person_id;
|
||||
let person = Person::read(context.pool(), person_id).await?;
|
||||
let person = Person::read(&mut context.pool(), person_id).await?;
|
||||
|
||||
if let Some(banner) = person.banner {
|
||||
purge_image_from_pictrs(context.client(), context.settings(), &banner)
|
||||
|
@ -45,13 +45,13 @@ impl Perform for PurgePerson {
|
|||
|
||||
purge_image_posts_for_person(
|
||||
person_id,
|
||||
context.pool(),
|
||||
&mut context.pool(),
|
||||
context.settings(),
|
||||
context.client(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
Person::delete(context.pool(), person_id).await?;
|
||||
Person::delete(&mut context.pool(), person_id).await?;
|
||||
|
||||
// Mod tables
|
||||
let reason = data.reason.clone();
|
||||
|
@ -60,7 +60,7 @@ impl Perform for PurgePerson {
|
|||
reason,
|
||||
};
|
||||
|
||||
AdminPurgePerson::create(context.pool(), &form).await?;
|
||||
AdminPurgePerson::create(&mut context.pool(), &form).await?;
|
||||
|
||||
Ok(PurgeItemResponse { success: true })
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ impl Perform for PurgePost {
|
|||
let post_id = data.post_id;
|
||||
|
||||
// Read the post to get the community_id
|
||||
let post = Post::read(context.pool(), post_id).await?;
|
||||
let post = Post::read(&mut context.pool(), post_id).await?;
|
||||
|
||||
// Purge image
|
||||
if let Some(url) = post.url {
|
||||
|
@ -47,7 +47,7 @@ impl Perform for PurgePost {
|
|||
|
||||
let community_id = post.community_id;
|
||||
|
||||
Post::delete(context.pool(), post_id).await?;
|
||||
Post::delete(&mut context.pool(), post_id).await?;
|
||||
|
||||
// Mod tables
|
||||
let reason = data.reason.clone();
|
||||
|
@ -57,7 +57,7 @@ impl Perform for PurgePost {
|
|||
community_id,
|
||||
};
|
||||
|
||||
AdminPurgePost::create(context.pool(), &form).await?;
|
||||
AdminPurgePost::create(&mut context.pool(), &form).await?;
|
||||
|
||||
Ok(PurgeItemResponse { success: true })
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ impl Perform for ApproveRegistrationApplication {
|
|||
};
|
||||
|
||||
let registration_application =
|
||||
RegistrationApplication::update(context.pool(), app_id, &app_form).await?;
|
||||
RegistrationApplication::update(&mut context.pool(), app_id, &app_form).await?;
|
||||
|
||||
// Update the local_user row
|
||||
let local_user_form = LocalUserUpdateForm::builder()
|
||||
|
@ -45,10 +45,11 @@ impl Perform for ApproveRegistrationApplication {
|
|||
.build();
|
||||
|
||||
let approved_user_id = registration_application.local_user_id;
|
||||
LocalUser::update(context.pool(), approved_user_id, &local_user_form).await?;
|
||||
LocalUser::update(&mut context.pool(), approved_user_id, &local_user_form).await?;
|
||||
|
||||
if data.approve {
|
||||
let approved_local_user_view = LocalUserView::read(context.pool(), approved_user_id).await?;
|
||||
let approved_local_user_view =
|
||||
LocalUserView::read(&mut context.pool(), approved_user_id).await?;
|
||||
|
||||
if approved_local_user_view.local_user.email.is_some() {
|
||||
send_application_approved_email(&approved_local_user_view, context.settings())?;
|
||||
|
@ -57,7 +58,7 @@ impl Perform for ApproveRegistrationApplication {
|
|||
|
||||
// Read the view
|
||||
let registration_application =
|
||||
RegistrationApplicationView::read(context.pool(), app_id).await?;
|
||||
RegistrationApplicationView::read(&mut context.pool(), app_id).await?;
|
||||
|
||||
Ok(Self::Response {
|
||||
registration_application,
|
||||
|
|
|
@ -17,7 +17,7 @@ impl Perform for ListRegistrationApplications {
|
|||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> {
|
||||
let data = self;
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||
let local_site = LocalSite::read(context.pool()).await?;
|
||||
let local_site = LocalSite::read(&mut context.pool()).await?;
|
||||
|
||||
// Make sure user is an admin
|
||||
is_admin(&local_user_view)?;
|
||||
|
@ -28,7 +28,7 @@ impl Perform for ListRegistrationApplications {
|
|||
let page = data.page;
|
||||
let limit = data.limit;
|
||||
let registration_applications = RegistrationApplicationQuery::builder()
|
||||
.pool(context.pool())
|
||||
.pool(&mut context.pool())
|
||||
.unread_only(unread_only)
|
||||
.verified_email_only(Some(verified_email_only))
|
||||
.page(page)
|
||||
|
|
|
@ -16,7 +16,7 @@ impl Perform for GetUnreadRegistrationApplicationCount {
|
|||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> {
|
||||
let data = self;
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||
let local_site = LocalSite::read(context.pool()).await?;
|
||||
let local_site = LocalSite::read(&mut context.pool()).await?;
|
||||
|
||||
// Only let admins do this
|
||||
is_admin(&local_user_view)?;
|
||||
|
@ -24,7 +24,8 @@ impl Perform for GetUnreadRegistrationApplicationCount {
|
|||
let verified_email_only = local_site.require_email_verification;
|
||||
|
||||
let registration_applications =
|
||||
RegistrationApplicationView::get_unread_count(context.pool(), verified_email_only).await?;
|
||||
RegistrationApplicationView::get_unread_count(&mut context.pool(), verified_email_only)
|
||||
.await?;
|
||||
|
||||
Ok(Self::Response {
|
||||
registration_applications,
|
||||
|
|
|
@ -30,7 +30,7 @@ pub async fn build_comment_response(
|
|||
recipient_ids: Vec<LocalUserId>,
|
||||
) -> Result<CommentResponse, LemmyError> {
|
||||
let person_id = local_user_view.map(|l| l.person.id);
|
||||
let comment_view = CommentView::read(context.pool(), comment_id, person_id).await?;
|
||||
let comment_view = CommentView::read(&mut context.pool(), comment_id, person_id).await?;
|
||||
Ok(CommentResponse {
|
||||
comment_view,
|
||||
recipient_ids,
|
||||
|
@ -43,18 +43,19 @@ pub async fn build_community_response(
|
|||
local_user_view: LocalUserView,
|
||||
community_id: CommunityId,
|
||||
) -> Result<CommunityResponse, LemmyError> {
|
||||
let is_mod_or_admin = is_mod_or_admin(context.pool(), local_user_view.person.id, community_id)
|
||||
.await
|
||||
.is_ok();
|
||||
let is_mod_or_admin =
|
||||
is_mod_or_admin(&mut context.pool(), local_user_view.person.id, community_id)
|
||||
.await
|
||||
.is_ok();
|
||||
let person_id = local_user_view.person.id;
|
||||
let community_view = CommunityView::read(
|
||||
context.pool(),
|
||||
&mut context.pool(),
|
||||
community_id,
|
||||
Some(person_id),
|
||||
Some(is_mod_or_admin),
|
||||
)
|
||||
.await?;
|
||||
let discussion_languages = CommunityLanguage::read(context.pool(), community_id).await?;
|
||||
let discussion_languages = CommunityLanguage::read(&mut context.pool(), community_id).await?;
|
||||
|
||||
Ok(CommunityResponse {
|
||||
community_view,
|
||||
|
@ -68,11 +69,11 @@ pub async fn build_post_response(
|
|||
person_id: PersonId,
|
||||
post_id: PostId,
|
||||
) -> Result<PostResponse, LemmyError> {
|
||||
let is_mod_or_admin = is_mod_or_admin(context.pool(), person_id, community_id)
|
||||
let is_mod_or_admin = is_mod_or_admin(&mut context.pool(), person_id, community_id)
|
||||
.await
|
||||
.is_ok();
|
||||
let post_view = PostView::read(
|
||||
context.pool(),
|
||||
&mut context.pool(),
|
||||
post_id,
|
||||
Some(person_id),
|
||||
Some(is_mod_or_admin),
|
||||
|
@ -100,7 +101,7 @@ pub async fn send_local_notifs(
|
|||
.filter(|m| m.is_local(&context.settings().hostname) && m.name.ne(&person.name))
|
||||
{
|
||||
let mention_name = mention.name.clone();
|
||||
let user_view = LocalUserView::read_from_name(context.pool(), &mention_name).await;
|
||||
let user_view = LocalUserView::read_from_name(&mut context.pool(), &mention_name).await;
|
||||
if let Ok(mention_user_view) = user_view {
|
||||
// TODO
|
||||
// At some point, make it so you can't tag the parent creator either
|
||||
|
@ -115,7 +116,7 @@ pub async fn send_local_notifs(
|
|||
|
||||
// Allow this to fail softly, since comment edits might re-update or replace it
|
||||
// Let the uniqueness handle this fail
|
||||
PersonMention::create(context.pool(), &user_mention_form)
|
||||
PersonMention::create(&mut context.pool(), &user_mention_form)
|
||||
.await
|
||||
.ok();
|
||||
|
||||
|
@ -134,19 +135,19 @@ pub async fn send_local_notifs(
|
|||
|
||||
// Send comment_reply to the parent commenter / poster
|
||||
if let Some(parent_comment_id) = comment.parent_comment_id() {
|
||||
let parent_comment = Comment::read(context.pool(), parent_comment_id).await?;
|
||||
let parent_comment = Comment::read(&mut context.pool(), parent_comment_id).await?;
|
||||
|
||||
// Get the parent commenter local_user
|
||||
let parent_creator_id = parent_comment.creator_id;
|
||||
|
||||
// Only add to recipients if that person isn't blocked
|
||||
let creator_blocked = check_person_block(person.id, parent_creator_id, context.pool())
|
||||
let creator_blocked = check_person_block(person.id, parent_creator_id, &mut context.pool())
|
||||
.await
|
||||
.is_err();
|
||||
|
||||
// Don't send a notif to yourself
|
||||
if parent_comment.creator_id != person.id && !creator_blocked {
|
||||
let user_view = LocalUserView::read_person(context.pool(), parent_creator_id).await;
|
||||
let user_view = LocalUserView::read_person(&mut context.pool(), parent_creator_id).await;
|
||||
if let Ok(parent_user_view) = user_view {
|
||||
recipient_ids.push(parent_user_view.local_user.id);
|
||||
|
||||
|
@ -158,7 +159,7 @@ pub async fn send_local_notifs(
|
|||
|
||||
// Allow this to fail softly, since comment edits might re-update or replace it
|
||||
// Let the uniqueness handle this fail
|
||||
CommentReply::create(context.pool(), &comment_reply_form)
|
||||
CommentReply::create(&mut context.pool(), &comment_reply_form)
|
||||
.await
|
||||
.ok();
|
||||
|
||||
|
@ -176,13 +177,13 @@ pub async fn send_local_notifs(
|
|||
} else {
|
||||
// If there's no parent, its the post creator
|
||||
// Only add to recipients if that person isn't blocked
|
||||
let creator_blocked = check_person_block(person.id, post.creator_id, context.pool())
|
||||
let creator_blocked = check_person_block(person.id, post.creator_id, &mut context.pool())
|
||||
.await
|
||||
.is_err();
|
||||
|
||||
if post.creator_id != person.id && !creator_blocked {
|
||||
let creator_id = post.creator_id;
|
||||
let parent_user = LocalUserView::read_person(context.pool(), creator_id).await;
|
||||
let parent_user = LocalUserView::read_person(&mut context.pool(), creator_id).await;
|
||||
if let Ok(parent_user_view) = parent_user {
|
||||
recipient_ids.push(parent_user_view.local_user.id);
|
||||
|
||||
|
@ -194,7 +195,7 @@ pub async fn send_local_notifs(
|
|||
|
||||
// Allow this to fail softly, since comment edits might re-update or replace it
|
||||
// Let the uniqueness handle this fail
|
||||
CommentReply::create(context.pool(), &comment_reply_form)
|
||||
CommentReply::create(&mut context.pool(), &comment_reply_form)
|
||||
.await
|
||||
.ok();
|
||||
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
use lemmy_db_schema::{source::secret::Secret, utils::DbPool};
|
||||
use lemmy_db_schema::{
|
||||
source::secret::Secret,
|
||||
utils::{DbPool, DbPoolRef, OwnedDbPool},
|
||||
};
|
||||
use lemmy_utils::{
|
||||
rate_limit::RateLimitCell,
|
||||
settings::{structs::Settings, SETTINGS},
|
||||
|
@ -8,7 +11,7 @@ use std::sync::Arc;
|
|||
|
||||
#[derive(Clone)]
|
||||
pub struct LemmyContext {
|
||||
pool: DbPool,
|
||||
pool: OwnedDbPool,
|
||||
client: Arc<ClientWithMiddleware>,
|
||||
secret: Arc<Secret>,
|
||||
rate_limit_cell: RateLimitCell,
|
||||
|
@ -16,7 +19,7 @@ pub struct LemmyContext {
|
|||
|
||||
impl LemmyContext {
|
||||
pub fn create(
|
||||
pool: DbPool,
|
||||
pool: OwnedDbPool,
|
||||
client: ClientWithMiddleware,
|
||||
secret: Secret,
|
||||
rate_limit_cell: RateLimitCell,
|
||||
|
@ -28,8 +31,8 @@ impl LemmyContext {
|
|||
rate_limit_cell,
|
||||
}
|
||||
}
|
||||
pub fn pool(&self) -> &DbPool {
|
||||
&self.pool
|
||||
pub fn pool(&self) -> DbPool<'_> {
|
||||
DbPool::Pool(&self.pool)
|
||||
}
|
||||
pub fn client(&self) -> &ClientWithMiddleware {
|
||||
&self.client
|
||||
|
|
|
@ -25,6 +25,7 @@ use lemmy_db_schema::{
|
|||
},
|
||||
traits::{Crud, Readable},
|
||||
utils::DbPool,
|
||||
DbPoolRef,
|
||||
RegistrationMode,
|
||||
};
|
||||
use lemmy_db_views::{comment_view::CommentQuery, structs::LocalUserView};
|
||||
|
@ -50,7 +51,7 @@ use url::{ParseError, Url};
|
|||
|
||||
#[tracing::instrument(skip_all)]
|
||||
pub async fn is_mod_or_admin(
|
||||
pool: &DbPool,
|
||||
pool: DbPoolRef<'_>,
|
||||
person_id: PersonId,
|
||||
community_id: CommunityId,
|
||||
) -> Result<(), LemmyError> {
|
||||
|
@ -63,7 +64,7 @@ pub async fn is_mod_or_admin(
|
|||
|
||||
#[tracing::instrument(skip_all)]
|
||||
pub async fn is_mod_or_admin_opt(
|
||||
pool: &DbPool,
|
||||
pool: DbPoolRef<'_>,
|
||||
local_user_view: Option<&LocalUserView>,
|
||||
community_id: Option<CommunityId>,
|
||||
) -> Result<(), LemmyError> {
|
||||
|
@ -101,7 +102,7 @@ pub fn is_top_mod(
|
|||
}
|
||||
|
||||
#[tracing::instrument(skip_all)]
|
||||
pub async fn get_post(post_id: PostId, pool: &DbPool) -> Result<Post, LemmyError> {
|
||||
pub async fn get_post(post_id: PostId, pool: DbPoolRef<'_>) -> Result<Post, LemmyError> {
|
||||
Post::read(pool, post_id)
|
||||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "couldnt_find_post"))
|
||||
|
@ -111,7 +112,7 @@ pub async fn get_post(post_id: PostId, pool: &DbPool) -> Result<Post, LemmyError
|
|||
pub async fn mark_post_as_read(
|
||||
person_id: PersonId,
|
||||
post_id: PostId,
|
||||
pool: &DbPool,
|
||||
pool: DbPoolRef<'_>,
|
||||
) -> Result<PostRead, LemmyError> {
|
||||
let post_read_form = PostReadForm { post_id, person_id };
|
||||
|
||||
|
@ -124,7 +125,7 @@ pub async fn mark_post_as_read(
|
|||
pub async fn mark_post_as_unread(
|
||||
person_id: PersonId,
|
||||
post_id: PostId,
|
||||
pool: &DbPool,
|
||||
pool: DbPoolRef<'_>,
|
||||
) -> Result<usize, LemmyError> {
|
||||
let post_read_form = PostReadForm { post_id, person_id };
|
||||
|
||||
|
@ -142,7 +143,7 @@ pub async fn local_user_view_from_jwt(
|
|||
.map_err(|e| e.with_message("not_logged_in"))?
|
||||
.claims;
|
||||
let local_user_id = LocalUserId(claims.sub);
|
||||
let local_user_view = LocalUserView::read(context.pool(), local_user_id).await?;
|
||||
let local_user_view = LocalUserView::read(&mut context.pool(), local_user_id).await?;
|
||||
check_user_valid(
|
||||
local_user_view.person.banned,
|
||||
local_user_view.person.ban_expires,
|
||||
|
@ -197,7 +198,7 @@ pub fn check_user_valid(
|
|||
pub async fn check_community_ban(
|
||||
person_id: PersonId,
|
||||
community_id: CommunityId,
|
||||
pool: &DbPool,
|
||||
pool: DbPoolRef<'_>,
|
||||
) -> Result<(), LemmyError> {
|
||||
let is_banned = CommunityPersonBanView::get(pool, person_id, community_id)
|
||||
.await
|
||||
|
@ -212,7 +213,7 @@ pub async fn check_community_ban(
|
|||
#[tracing::instrument(skip_all)]
|
||||
pub async fn check_community_deleted_or_removed(
|
||||
community_id: CommunityId,
|
||||
pool: &DbPool,
|
||||
pool: DbPoolRef<'_>,
|
||||
) -> Result<(), LemmyError> {
|
||||
let community = Community::read(pool, community_id)
|
||||
.await
|
||||
|
@ -236,7 +237,7 @@ pub fn check_post_deleted_or_removed(post: &Post) -> Result<(), LemmyError> {
|
|||
pub async fn check_person_block(
|
||||
my_id: PersonId,
|
||||
potential_blocker_id: PersonId,
|
||||
pool: &DbPool,
|
||||
pool: DbPoolRef<'_>,
|
||||
) -> Result<(), LemmyError> {
|
||||
let is_blocked = PersonBlock::read(pool, potential_blocker_id, my_id)
|
||||
.await
|
||||
|
@ -270,7 +271,7 @@ pub fn check_private_instance(
|
|||
#[tracing::instrument(skip_all)]
|
||||
pub async fn build_federated_instances(
|
||||
local_site: &LocalSite,
|
||||
pool: &DbPool,
|
||||
pool: DbPoolRef<'_>,
|
||||
) -> Result<Option<FederatedInstances>, LemmyError> {
|
||||
if local_site.federation_enabled {
|
||||
// TODO I hate that this requires 3 queries
|
||||
|
@ -334,7 +335,7 @@ pub fn send_email_to_user(
|
|||
|
||||
pub async fn send_password_reset_email(
|
||||
user: &LocalUserView,
|
||||
pool: &DbPool,
|
||||
pool: DbPoolRef<'_>,
|
||||
settings: &Settings,
|
||||
) -> Result<(), LemmyError> {
|
||||
// Generate a random token
|
||||
|
@ -358,7 +359,7 @@ pub async fn send_password_reset_email(
|
|||
pub async fn send_verification_email(
|
||||
user: &LocalUserView,
|
||||
new_email: &str,
|
||||
pool: &DbPool,
|
||||
pool: DbPoolRef<'_>,
|
||||
settings: &Settings,
|
||||
) -> Result<(), LemmyError> {
|
||||
let form = EmailVerificationForm {
|
||||
|
@ -449,7 +450,7 @@ pub fn send_application_approved_email(
|
|||
/// Send a new applicant email notification to all admins
|
||||
pub async fn send_new_applicant_email_to_admins(
|
||||
applicant_username: &str,
|
||||
pool: &DbPool,
|
||||
pool: DbPoolRef<'_>,
|
||||
settings: &Settings,
|
||||
) -> Result<(), LemmyError> {
|
||||
// Collect the admins with emails
|
||||
|
@ -474,7 +475,7 @@ pub async fn send_new_applicant_email_to_admins(
|
|||
pub async fn send_new_report_email_to_admins(
|
||||
reporter_username: &str,
|
||||
reported_username: &str,
|
||||
pool: &DbPool,
|
||||
pool: DbPoolRef<'_>,
|
||||
settings: &Settings,
|
||||
) -> Result<(), LemmyError> {
|
||||
// Collect the admins with emails
|
||||
|
@ -495,7 +496,7 @@ pub async fn send_new_report_email_to_admins(
|
|||
pub async fn check_registration_application(
|
||||
local_user_view: &LocalUserView,
|
||||
local_site: &LocalSite,
|
||||
pool: &DbPool,
|
||||
pool: DbPoolRef<'_>,
|
||||
) -> Result<(), LemmyError> {
|
||||
if (local_site.registration_mode == RegistrationMode::RequireApplication
|
||||
|| local_site.registration_mode == RegistrationMode::Closed)
|
||||
|
@ -529,7 +530,7 @@ pub fn check_private_instance_and_federation_enabled(
|
|||
|
||||
pub async fn purge_image_posts_for_person(
|
||||
banned_person_id: PersonId,
|
||||
pool: &DbPool,
|
||||
pool: DbPoolRef<'_>,
|
||||
settings: &Settings,
|
||||
client: &ClientWithMiddleware,
|
||||
) -> Result<(), LemmyError> {
|
||||
|
@ -552,7 +553,7 @@ pub async fn purge_image_posts_for_person(
|
|||
|
||||
pub async fn purge_image_posts_for_community(
|
||||
banned_community_id: CommunityId,
|
||||
pool: &DbPool,
|
||||
pool: DbPoolRef<'_>,
|
||||
settings: &Settings,
|
||||
client: &ClientWithMiddleware,
|
||||
) -> Result<(), LemmyError> {
|
||||
|
@ -575,7 +576,7 @@ pub async fn purge_image_posts_for_community(
|
|||
|
||||
pub async fn remove_user_data(
|
||||
banned_person_id: PersonId,
|
||||
pool: &DbPool,
|
||||
pool: DbPoolRef<'_>,
|
||||
settings: &Settings,
|
||||
client: &ClientWithMiddleware,
|
||||
) -> Result<(), LemmyError> {
|
||||
|
@ -659,7 +660,7 @@ pub async fn remove_user_data(
|
|||
pub async fn remove_user_data_in_community(
|
||||
community_id: CommunityId,
|
||||
banned_person_id: PersonId,
|
||||
pool: &DbPool,
|
||||
pool: DbPoolRef<'_>,
|
||||
) -> Result<(), LemmyError> {
|
||||
// Posts
|
||||
Post::update_removed_for_creator(pool, banned_person_id, Some(community_id), true).await?;
|
||||
|
@ -689,7 +690,7 @@ pub async fn remove_user_data_in_community(
|
|||
|
||||
pub async fn delete_user_account(
|
||||
person_id: PersonId,
|
||||
pool: &DbPool,
|
||||
pool: DbPoolRef<'_>,
|
||||
settings: &Settings,
|
||||
client: &ClientWithMiddleware,
|
||||
) -> Result<(), LemmyError> {
|
||||
|
|
|
@ -43,7 +43,7 @@ impl PerformCrud for CreateComment {
|
|||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<CommentResponse, LemmyError> {
|
||||
let data: &CreateComment = self;
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||
let local_site = LocalSite::read(context.pool()).await?;
|
||||
let local_site = LocalSite::read(&mut context.pool()).await?;
|
||||
|
||||
let content_slurs_removed = remove_slurs(
|
||||
&data.content.clone(),
|
||||
|
@ -53,11 +53,11 @@ impl PerformCrud for CreateComment {
|
|||
|
||||
// Check for a community ban
|
||||
let post_id = data.post_id;
|
||||
let post = get_post(post_id, context.pool()).await?;
|
||||
let post = get_post(post_id, &mut context.pool()).await?;
|
||||
let community_id = post.community_id;
|
||||
|
||||
check_community_ban(local_user_view.person.id, community_id, context.pool()).await?;
|
||||
check_community_deleted_or_removed(community_id, context.pool()).await?;
|
||||
check_community_ban(local_user_view.person.id, community_id, &mut context.pool()).await?;
|
||||
check_community_deleted_or_removed(community_id, &mut context.pool()).await?;
|
||||
check_post_deleted_or_removed(&post)?;
|
||||
|
||||
// Check if post is locked, no new comments
|
||||
|
@ -67,7 +67,7 @@ impl PerformCrud for CreateComment {
|
|||
|
||||
// Fetch the parent, if it exists
|
||||
let parent_opt = if let Some(parent_id) = data.parent_id {
|
||||
Comment::read(context.pool(), parent_id).await.ok()
|
||||
Comment::read(&mut context.pool(), parent_id).await.ok()
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
@ -89,7 +89,7 @@ impl PerformCrud for CreateComment {
|
|||
let language_id = data.language_id.unwrap_or(parent_language);
|
||||
|
||||
CommunityLanguage::is_allowed_community_language(
|
||||
context.pool(),
|
||||
&mut context.pool(),
|
||||
Some(language_id),
|
||||
community_id,
|
||||
)
|
||||
|
@ -104,9 +104,10 @@ impl PerformCrud for CreateComment {
|
|||
|
||||
// Create the comment
|
||||
let parent_path = parent_opt.clone().map(|t| t.path);
|
||||
let inserted_comment = Comment::create(context.pool(), &comment_form, parent_path.as_ref())
|
||||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "couldnt_create_comment"))?;
|
||||
let inserted_comment =
|
||||
Comment::create(&mut context.pool(), &comment_form, parent_path.as_ref())
|
||||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "couldnt_create_comment"))?;
|
||||
|
||||
// Necessary to update the ap_id
|
||||
let inserted_comment_id = inserted_comment.id;
|
||||
|
@ -118,7 +119,7 @@ impl PerformCrud for CreateComment {
|
|||
&protocol_and_hostname,
|
||||
)?;
|
||||
let updated_comment = Comment::update(
|
||||
context.pool(),
|
||||
&mut context.pool(),
|
||||
inserted_comment_id,
|
||||
&CommentUpdateForm::builder().ap_id(Some(apub_id)).build(),
|
||||
)
|
||||
|
@ -145,17 +146,17 @@ impl PerformCrud for CreateComment {
|
|||
score: 1,
|
||||
};
|
||||
|
||||
CommentLike::like(context.pool(), &like_form)
|
||||
CommentLike::like(&mut context.pool(), &like_form)
|
||||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "couldnt_like_comment"))?;
|
||||
|
||||
// If its a reply, mark the parent as read
|
||||
if let Some(parent) = parent_opt {
|
||||
let parent_id = parent.id;
|
||||
let comment_reply = CommentReply::read_by_comment(context.pool(), parent_id).await;
|
||||
let comment_reply = CommentReply::read_by_comment(&mut context.pool(), parent_id).await;
|
||||
if let Ok(reply) = comment_reply {
|
||||
CommentReply::update(
|
||||
context.pool(),
|
||||
&mut context.pool(),
|
||||
reply.id,
|
||||
&CommentReplyUpdateForm { read: Some(true) },
|
||||
)
|
||||
|
@ -166,10 +167,10 @@ impl PerformCrud for CreateComment {
|
|||
// If the parent has PersonMentions mark them as read too
|
||||
let person_id = local_user_view.person.id;
|
||||
let person_mention =
|
||||
PersonMention::read_by_comment_and_person(context.pool(), parent_id, person_id).await;
|
||||
PersonMention::read_by_comment_and_person(&mut context.pool(), parent_id, person_id).await;
|
||||
if let Ok(mention) = person_mention {
|
||||
PersonMention::update(
|
||||
context.pool(),
|
||||
&mut context.pool(),
|
||||
mention.id,
|
||||
&PersonMentionUpdateForm { read: Some(true) },
|
||||
)
|
||||
|
|
|
@ -26,7 +26,7 @@ impl PerformCrud for DeleteComment {
|
|||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||
|
||||
let comment_id = data.comment_id;
|
||||
let orig_comment = CommentView::read(context.pool(), comment_id, None).await?;
|
||||
let orig_comment = CommentView::read(&mut context.pool(), comment_id, None).await?;
|
||||
|
||||
// Dont delete it if its already been deleted.
|
||||
if orig_comment.comment.deleted == data.deleted {
|
||||
|
@ -36,7 +36,7 @@ impl PerformCrud for DeleteComment {
|
|||
check_community_ban(
|
||||
local_user_view.person.id,
|
||||
orig_comment.community.id,
|
||||
context.pool(),
|
||||
&mut context.pool(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
|
@ -48,7 +48,7 @@ impl PerformCrud for DeleteComment {
|
|||
// Do the delete
|
||||
let deleted = data.deleted;
|
||||
let updated_comment = Comment::update(
|
||||
context.pool(),
|
||||
&mut context.pool(),
|
||||
comment_id,
|
||||
&CommentUpdateForm::builder().deleted(Some(deleted)).build(),
|
||||
)
|
||||
|
@ -56,7 +56,7 @@ impl PerformCrud for DeleteComment {
|
|||
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_comment"))?;
|
||||
|
||||
let post_id = updated_comment.post_id;
|
||||
let post = Post::read(context.pool(), post_id).await?;
|
||||
let post = Post::read(&mut context.pool(), post_id).await?;
|
||||
let recipient_ids = send_local_notifs(
|
||||
vec![],
|
||||
&updated_comment,
|
||||
|
|
|
@ -17,7 +17,7 @@ impl PerformCrud for GetComment {
|
|||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<Self::Response, LemmyError> {
|
||||
let data = self;
|
||||
let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), context).await;
|
||||
let local_site = LocalSite::read(context.pool()).await?;
|
||||
let local_site = LocalSite::read(&mut context.pool()).await?;
|
||||
|
||||
check_private_instance(&local_user_view, &local_site)?;
|
||||
|
||||
|
|
|
@ -27,18 +27,18 @@ impl PerformCrud for RemoveComment {
|
|||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||
|
||||
let comment_id = data.comment_id;
|
||||
let orig_comment = CommentView::read(context.pool(), comment_id, None).await?;
|
||||
let orig_comment = CommentView::read(&mut context.pool(), comment_id, None).await?;
|
||||
|
||||
check_community_ban(
|
||||
local_user_view.person.id,
|
||||
orig_comment.community.id,
|
||||
context.pool(),
|
||||
&mut context.pool(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
// Verify that only a mod or admin can remove
|
||||
is_mod_or_admin(
|
||||
context.pool(),
|
||||
&mut context.pool(),
|
||||
local_user_view.person.id,
|
||||
orig_comment.community.id,
|
||||
)
|
||||
|
@ -47,7 +47,7 @@ impl PerformCrud for RemoveComment {
|
|||
// Do the remove
|
||||
let removed = data.removed;
|
||||
let updated_comment = Comment::update(
|
||||
context.pool(),
|
||||
&mut context.pool(),
|
||||
comment_id,
|
||||
&CommentUpdateForm::builder().removed(Some(removed)).build(),
|
||||
)
|
||||
|
@ -61,10 +61,10 @@ impl PerformCrud for RemoveComment {
|
|||
removed: Some(removed),
|
||||
reason: data.reason.clone(),
|
||||
};
|
||||
ModRemoveComment::create(context.pool(), &form).await?;
|
||||
ModRemoveComment::create(&mut context.pool(), &form).await?;
|
||||
|
||||
let post_id = updated_comment.post_id;
|
||||
let post = Post::read(context.pool(), post_id).await?;
|
||||
let post = Post::read(&mut context.pool(), post_id).await?;
|
||||
let recipient_ids = send_local_notifs(
|
||||
vec![],
|
||||
&updated_comment,
|
||||
|
|
|
@ -33,15 +33,15 @@ impl PerformCrud for EditComment {
|
|||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<CommentResponse, LemmyError> {
|
||||
let data: &EditComment = self;
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||
let local_site = LocalSite::read(context.pool()).await?;
|
||||
let local_site = LocalSite::read(&mut context.pool()).await?;
|
||||
|
||||
let comment_id = data.comment_id;
|
||||
let orig_comment = CommentView::read(context.pool(), comment_id, None).await?;
|
||||
let orig_comment = CommentView::read(&mut context.pool(), comment_id, None).await?;
|
||||
|
||||
check_community_ban(
|
||||
local_user_view.person.id,
|
||||
orig_comment.community.id,
|
||||
context.pool(),
|
||||
&mut context.pool(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
|
@ -52,7 +52,7 @@ impl PerformCrud for EditComment {
|
|||
|
||||
let language_id = self.language_id;
|
||||
CommunityLanguage::is_allowed_community_language(
|
||||
context.pool(),
|
||||
&mut context.pool(),
|
||||
language_id,
|
||||
orig_comment.community.id,
|
||||
)
|
||||
|
@ -72,7 +72,7 @@ impl PerformCrud for EditComment {
|
|||
.language_id(data.language_id)
|
||||
.updated(Some(Some(naive_now())))
|
||||
.build();
|
||||
let updated_comment = Comment::update(context.pool(), comment_id, &form)
|
||||
let updated_comment = Comment::update(&mut context.pool(), comment_id, &form)
|
||||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_comment"))?;
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ impl PerformCrud for CreateCommunity {
|
|||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<CommunityResponse, LemmyError> {
|
||||
let data: &CreateCommunity = self;
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||
let site_view = SiteView::read_local(context.pool()).await?;
|
||||
let site_view = SiteView::read_local(&mut context.pool()).await?;
|
||||
let local_site = site_view.local_site;
|
||||
|
||||
if local_site.community_creation_admin_only && is_admin(&local_user_view).is_err() {
|
||||
|
@ -75,7 +75,8 @@ impl PerformCrud for CreateCommunity {
|
|||
&data.name,
|
||||
&context.settings().get_protocol_and_hostname(),
|
||||
)?;
|
||||
let community_dupe = Community::read_from_apub_id(context.pool(), &community_actor_id).await?;
|
||||
let community_dupe =
|
||||
Community::read_from_apub_id(&mut context.pool(), &community_actor_id).await?;
|
||||
if community_dupe.is_some() {
|
||||
return Err(LemmyError::from_message("community_already_exists"));
|
||||
}
|
||||
|
@ -100,7 +101,7 @@ impl PerformCrud for CreateCommunity {
|
|||
.instance_id(site_view.site.instance_id)
|
||||
.build();
|
||||
|
||||
let inserted_community = Community::create(context.pool(), &community_form)
|
||||
let inserted_community = Community::create(&mut context.pool(), &community_form)
|
||||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "community_already_exists"))?;
|
||||
|
||||
|
@ -110,7 +111,7 @@ impl PerformCrud for CreateCommunity {
|
|||
person_id: local_user_view.person.id,
|
||||
};
|
||||
|
||||
CommunityModerator::join(context.pool(), &community_moderator_form)
|
||||
CommunityModerator::join(&mut context.pool(), &community_moderator_form)
|
||||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "community_moderator_already_exists"))?;
|
||||
|
||||
|
@ -121,21 +122,21 @@ impl PerformCrud for CreateCommunity {
|
|||
pending: false,
|
||||
};
|
||||
|
||||
CommunityFollower::follow(context.pool(), &community_follower_form)
|
||||
CommunityFollower::follow(&mut context.pool(), &community_follower_form)
|
||||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "community_follower_already_exists"))?;
|
||||
|
||||
// Update the discussion_languages if that's provided
|
||||
let community_id = inserted_community.id;
|
||||
if let Some(languages) = data.discussion_languages.clone() {
|
||||
let site_languages = SiteLanguage::read_local_raw(context.pool()).await?;
|
||||
let site_languages = SiteLanguage::read_local_raw(&mut context.pool()).await?;
|
||||
// check that community languages are a subset of site languages
|
||||
// https://stackoverflow.com/a/64227550
|
||||
let is_subset = languages.iter().all(|item| site_languages.contains(item));
|
||||
if !is_subset {
|
||||
return Err(LemmyError::from_message("language_not_allowed"));
|
||||
}
|
||||
CommunityLanguage::update(context.pool(), languages, community_id).await?;
|
||||
CommunityLanguage::update(&mut context.pool(), languages, community_id).await?;
|
||||
}
|
||||
|
||||
build_community_response(context, local_user_view, community_id).await
|
||||
|
|
|
@ -25,7 +25,7 @@ impl PerformCrud for DeleteCommunity {
|
|||
// Fetch the community mods
|
||||
let community_id = data.community_id;
|
||||
let community_mods =
|
||||
CommunityModeratorView::for_community(context.pool(), community_id).await?;
|
||||
CommunityModeratorView::for_community(&mut context.pool(), community_id).await?;
|
||||
|
||||
// Make sure deleter is the top mod
|
||||
is_top_mod(&local_user_view, &community_mods)?;
|
||||
|
@ -34,7 +34,7 @@ impl PerformCrud for DeleteCommunity {
|
|||
let community_id = data.community_id;
|
||||
let deleted = data.deleted;
|
||||
Community::update(
|
||||
context.pool(),
|
||||
&mut context.pool(),
|
||||
community_id,
|
||||
&CommunityUpdateForm::builder()
|
||||
.deleted(Some(deleted))
|
||||
|
|
|
@ -20,7 +20,7 @@ impl PerformCrud for ListCommunities {
|
|||
) -> Result<ListCommunitiesResponse, LemmyError> {
|
||||
let data: &ListCommunities = self;
|
||||
let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), context).await;
|
||||
let local_site = LocalSite::read(context.pool()).await?;
|
||||
let local_site = LocalSite::read(&mut context.pool()).await?;
|
||||
let is_admin = local_user_view.as_ref().map(|luv| is_admin(luv).is_ok());
|
||||
|
||||
check_private_instance(&local_user_view, &local_site)?;
|
||||
|
@ -32,7 +32,7 @@ impl PerformCrud for ListCommunities {
|
|||
let limit = data.limit;
|
||||
let local_user = local_user_view.map(|l| l.local_user);
|
||||
let communities = CommunityQuery::builder()
|
||||
.pool(context.pool())
|
||||
.pool(&mut context.pool())
|
||||
.listing_type(listing_type)
|
||||
.show_nsfw(show_nsfw)
|
||||
.sort(sort)
|
||||
|
|
|
@ -31,7 +31,7 @@ impl PerformCrud for RemoveCommunity {
|
|||
let community_id = data.community_id;
|
||||
let removed = data.removed;
|
||||
Community::update(
|
||||
context.pool(),
|
||||
&mut context.pool(),
|
||||
community_id,
|
||||
&CommunityUpdateForm::builder()
|
||||
.removed(Some(removed))
|
||||
|
@ -49,7 +49,7 @@ impl PerformCrud for RemoveCommunity {
|
|||
reason: data.reason.clone(),
|
||||
expires,
|
||||
};
|
||||
ModRemoveCommunity::create(context.pool(), &form).await?;
|
||||
ModRemoveCommunity::create(&mut context.pool(), &form).await?;
|
||||
|
||||
build_community_response(context, local_user_view, community_id).await
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ impl PerformCrud for EditCommunity {
|
|||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<CommunityResponse, LemmyError> {
|
||||
let data: &EditCommunity = self;
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||
let local_site = LocalSite::read(context.pool()).await?;
|
||||
let local_site = LocalSite::read(&mut context.pool()).await?;
|
||||
|
||||
let icon = diesel_option_overwrite_to_url(&data.icon)?;
|
||||
let banner = diesel_option_overwrite_to_url(&data.banner)?;
|
||||
|
@ -43,23 +43,24 @@ impl PerformCrud for EditCommunity {
|
|||
|
||||
// Verify its a mod (only mods can edit it)
|
||||
let community_id = data.community_id;
|
||||
let mods: Vec<PersonId> = CommunityModeratorView::for_community(context.pool(), community_id)
|
||||
.await
|
||||
.map(|v| v.into_iter().map(|m| m.moderator.id).collect())?;
|
||||
let mods: Vec<PersonId> =
|
||||
CommunityModeratorView::for_community(&mut context.pool(), community_id)
|
||||
.await
|
||||
.map(|v| v.into_iter().map(|m| m.moderator.id).collect())?;
|
||||
if !mods.contains(&local_user_view.person.id) {
|
||||
return Err(LemmyError::from_message("not_a_moderator"));
|
||||
}
|
||||
|
||||
let community_id = data.community_id;
|
||||
if let Some(languages) = data.discussion_languages.clone() {
|
||||
let site_languages = SiteLanguage::read_local_raw(context.pool()).await?;
|
||||
let site_languages = SiteLanguage::read_local_raw(&mut context.pool()).await?;
|
||||
// check that community languages are a subset of site languages
|
||||
// https://stackoverflow.com/a/64227550
|
||||
let is_subset = languages.iter().all(|item| site_languages.contains(item));
|
||||
if !is_subset {
|
||||
return Err(LemmyError::from_message("language_not_allowed"));
|
||||
}
|
||||
CommunityLanguage::update(context.pool(), languages, community_id).await?;
|
||||
CommunityLanguage::update(&mut context.pool(), languages, community_id).await?;
|
||||
}
|
||||
|
||||
let community_form = CommunityUpdateForm::builder()
|
||||
|
@ -73,7 +74,7 @@ impl PerformCrud for EditCommunity {
|
|||
.build();
|
||||
|
||||
let community_id = data.community_id;
|
||||
Community::update(context.pool(), community_id, &community_form)
|
||||
Community::update(&mut context.pool(), community_id, &community_form)
|
||||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_community"))?;
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ impl PerformCrud for CreateCustomEmoji {
|
|||
let data: &CreateCustomEmoji = self;
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||
|
||||
let local_site = LocalSite::read(context.pool()).await?;
|
||||
let local_site = LocalSite::read(&mut context.pool()).await?;
|
||||
// Make sure user is an admin
|
||||
is_admin(&local_user_view)?;
|
||||
|
||||
|
@ -33,7 +33,7 @@ impl PerformCrud for CreateCustomEmoji {
|
|||
.category(data.category.to_string())
|
||||
.image_url(data.clone().image_url.into())
|
||||
.build();
|
||||
let emoji = CustomEmoji::create(context.pool(), &emoji_form).await?;
|
||||
let emoji = CustomEmoji::create(&mut context.pool(), &emoji_form).await?;
|
||||
let mut keywords = vec![];
|
||||
for keyword in &data.keywords {
|
||||
let keyword_form = CustomEmojiKeywordInsertForm::builder()
|
||||
|
@ -42,8 +42,8 @@ impl PerformCrud for CreateCustomEmoji {
|
|||
.build();
|
||||
keywords.push(keyword_form);
|
||||
}
|
||||
CustomEmojiKeyword::create(context.pool(), keywords).await?;
|
||||
let view = CustomEmojiView::get(context.pool(), emoji.id).await?;
|
||||
CustomEmojiKeyword::create(&mut context.pool(), keywords).await?;
|
||||
let view = CustomEmojiView::get(&mut context.pool(), emoji.id).await?;
|
||||
Ok(CustomEmojiResponse { custom_emoji: view })
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ impl PerformCrud for DeleteCustomEmoji {
|
|||
|
||||
// Make sure user is an admin
|
||||
is_admin(&local_user_view)?;
|
||||
CustomEmoji::delete(context.pool(), data.id).await?;
|
||||
CustomEmoji::delete(&mut context.pool(), data.id).await?;
|
||||
Ok(DeleteCustomEmojiResponse {
|
||||
id: data.id,
|
||||
success: true,
|
||||
|
|
|
@ -22,7 +22,7 @@ impl PerformCrud for EditCustomEmoji {
|
|||
let data: &EditCustomEmoji = self;
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||
|
||||
let local_site = LocalSite::read(context.pool()).await?;
|
||||
let local_site = LocalSite::read(&mut context.pool()).await?;
|
||||
// Make sure user is an admin
|
||||
is_admin(&local_user_view)?;
|
||||
|
||||
|
@ -32,8 +32,8 @@ impl PerformCrud for EditCustomEmoji {
|
|||
.category(data.category.to_string())
|
||||
.image_url(data.clone().image_url.into())
|
||||
.build();
|
||||
let emoji = CustomEmoji::update(context.pool(), data.id, &emoji_form).await?;
|
||||
CustomEmojiKeyword::delete(context.pool(), data.id).await?;
|
||||
let emoji = CustomEmoji::update(&mut context.pool(), data.id, &emoji_form).await?;
|
||||
CustomEmojiKeyword::delete(&mut context.pool(), data.id).await?;
|
||||
let mut keywords = vec![];
|
||||
for keyword in &data.keywords {
|
||||
let keyword_form = CustomEmojiKeywordInsertForm::builder()
|
||||
|
@ -42,8 +42,8 @@ impl PerformCrud for EditCustomEmoji {
|
|||
.build();
|
||||
keywords.push(keyword_form);
|
||||
}
|
||||
CustomEmojiKeyword::create(context.pool(), keywords).await?;
|
||||
let view = CustomEmojiView::get(context.pool(), emoji.id).await?;
|
||||
CustomEmojiKeyword::create(&mut context.pool(), keywords).await?;
|
||||
let view = CustomEmojiView::get(&mut context.pool(), emoji.id).await?;
|
||||
Ok(CustomEmojiResponse { custom_emoji: view })
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ impl PerformCrud for CreatePost {
|
|||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<PostResponse, LemmyError> {
|
||||
let data: &CreatePost = self;
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||
let local_site = LocalSite::read(context.pool()).await?;
|
||||
let local_site = LocalSite::read(&mut context.pool()).await?;
|
||||
|
||||
let slur_regex = local_site_to_slur_regex(&local_site);
|
||||
check_slurs(&data.name, &slur_regex)?;
|
||||
|
@ -59,15 +59,20 @@ impl PerformCrud for CreatePost {
|
|||
is_valid_post_title(&data.name)?;
|
||||
is_valid_body_field(&data.body, true)?;
|
||||
|
||||
check_community_ban(local_user_view.person.id, data.community_id, context.pool()).await?;
|
||||
check_community_deleted_or_removed(data.community_id, context.pool()).await?;
|
||||
check_community_ban(
|
||||
local_user_view.person.id,
|
||||
data.community_id,
|
||||
&mut context.pool(),
|
||||
)
|
||||
.await?;
|
||||
check_community_deleted_or_removed(data.community_id, &mut context.pool()).await?;
|
||||
|
||||
let community_id = data.community_id;
|
||||
let community = Community::read(context.pool(), community_id).await?;
|
||||
let community = Community::read(&mut context.pool(), community_id).await?;
|
||||
if community.posting_restricted_to_mods {
|
||||
let community_id = data.community_id;
|
||||
let is_mod = CommunityView::is_mod_or_admin(
|
||||
context.pool(),
|
||||
&mut context.pool(),
|
||||
local_user_view.local_user.person_id,
|
||||
community_id,
|
||||
)
|
||||
|
@ -87,11 +92,20 @@ impl PerformCrud for CreatePost {
|
|||
let language_id = match data.language_id {
|
||||
Some(lid) => Some(lid),
|
||||
None => {
|
||||
default_post_language(context.pool(), community_id, local_user_view.local_user.id).await?
|
||||
default_post_language(
|
||||
&mut context.pool(),
|
||||
community_id,
|
||||
local_user_view.local_user.id,
|
||||
)
|
||||
.await?
|
||||
}
|
||||
};
|
||||
CommunityLanguage::is_allowed_community_language(context.pool(), language_id, community_id)
|
||||
.await?;
|
||||
CommunityLanguage::is_allowed_community_language(
|
||||
&mut context.pool(),
|
||||
language_id,
|
||||
community_id,
|
||||
)
|
||||
.await?;
|
||||
|
||||
let post_form = PostInsertForm::builder()
|
||||
.name(data.name.trim().to_owned())
|
||||
|
@ -107,7 +121,7 @@ impl PerformCrud for CreatePost {
|
|||
.thumbnail_url(thumbnail_url)
|
||||
.build();
|
||||
|
||||
let inserted_post = Post::create(context.pool(), &post_form)
|
||||
let inserted_post = Post::create(&mut context.pool(), &post_form)
|
||||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "couldnt_create_post"))?;
|
||||
|
||||
|
@ -119,7 +133,7 @@ impl PerformCrud for CreatePost {
|
|||
&protocol_and_hostname,
|
||||
)?;
|
||||
let updated_post = Post::update(
|
||||
context.pool(),
|
||||
&mut context.pool(),
|
||||
inserted_post_id,
|
||||
&PostUpdateForm::builder().ap_id(Some(apub_id)).build(),
|
||||
)
|
||||
|
@ -135,12 +149,12 @@ impl PerformCrud for CreatePost {
|
|||
score: 1,
|
||||
};
|
||||
|
||||
PostLike::like(context.pool(), &like_form)
|
||||
PostLike::like(&mut context.pool(), &like_form)
|
||||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "couldnt_like_post"))?;
|
||||
|
||||
// Mark the post as read
|
||||
mark_post_as_read(person_id, post_id, context.pool()).await?;
|
||||
mark_post_as_read(person_id, post_id, &mut context.pool()).await?;
|
||||
|
||||
if let Some(url) = &updated_post.url {
|
||||
let mut webmention =
|
||||
|
|
|
@ -22,7 +22,7 @@ impl PerformCrud for DeletePost {
|
|||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||
|
||||
let post_id = data.post_id;
|
||||
let orig_post = Post::read(context.pool(), post_id).await?;
|
||||
let orig_post = Post::read(&mut context.pool(), post_id).await?;
|
||||
|
||||
// Dont delete it if its already been deleted.
|
||||
if orig_post.deleted == data.deleted {
|
||||
|
@ -32,10 +32,10 @@ impl PerformCrud for DeletePost {
|
|||
check_community_ban(
|
||||
local_user_view.person.id,
|
||||
orig_post.community_id,
|
||||
context.pool(),
|
||||
&mut context.pool(),
|
||||
)
|
||||
.await?;
|
||||
check_community_deleted_or_removed(orig_post.community_id, context.pool()).await?;
|
||||
check_community_deleted_or_removed(orig_post.community_id, &mut context.pool()).await?;
|
||||
|
||||
// Verify that only the creator can delete
|
||||
if !Post::is_post_creator(local_user_view.person.id, orig_post.creator_id) {
|
||||
|
@ -46,7 +46,7 @@ impl PerformCrud for DeletePost {
|
|||
let post_id = data.post_id;
|
||||
let deleted = data.deleted;
|
||||
Post::update(
|
||||
context.pool(),
|
||||
&mut context.pool(),
|
||||
post_id,
|
||||
&PostUpdateForm::builder().deleted(Some(deleted)).build(),
|
||||
)
|
||||
|
|
|
@ -27,7 +27,7 @@ impl PerformCrud for GetPost {
|
|||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<GetPostResponse, LemmyError> {
|
||||
let data: &GetPost = self;
|
||||
let local_user_view = local_user_view_from_jwt_opt(data.auth.as_ref(), context).await;
|
||||
let local_site = LocalSite::read(context.pool()).await?;
|
||||
let local_site = LocalSite::read(&mut context.pool()).await?;
|
||||
|
||||
check_private_instance(&local_user_view, &local_site)?;
|
||||
|
||||
|
@ -37,7 +37,7 @@ impl PerformCrud for GetPost {
|
|||
let post_id = if let Some(id) = data.id {
|
||||
id
|
||||
} else if let Some(comment_id) = data.comment_id {
|
||||
Comment::read(context.pool(), comment_id)
|
||||
Comment::read(&mut context.pool(), comment_id)
|
||||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "couldnt_find_post"))?
|
||||
.post_id
|
||||
|
@ -46,25 +46,33 @@ impl PerformCrud for GetPost {
|
|||
};
|
||||
|
||||
// Check to see if the person is a mod or admin, to show deleted / removed
|
||||
let community_id = Post::read(context.pool(), post_id).await?.community_id;
|
||||
let is_mod_or_admin =
|
||||
is_mod_or_admin_opt(context.pool(), local_user_view.as_ref(), Some(community_id))
|
||||
.await
|
||||
.is_ok();
|
||||
let community_id = Post::read(&mut context.pool(), post_id).await?.community_id;
|
||||
let is_mod_or_admin = is_mod_or_admin_opt(
|
||||
&mut context.pool(),
|
||||
local_user_view.as_ref(),
|
||||
Some(community_id),
|
||||
)
|
||||
.await
|
||||
.is_ok();
|
||||
|
||||
let post_view = PostView::read(context.pool(), post_id, person_id, Some(is_mod_or_admin))
|
||||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "couldnt_find_post"))?;
|
||||
let post_view = PostView::read(
|
||||
&mut context.pool(),
|
||||
post_id,
|
||||
person_id,
|
||||
Some(is_mod_or_admin),
|
||||
)
|
||||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "couldnt_find_post"))?;
|
||||
|
||||
// Mark the post as read
|
||||
let post_id = post_view.post.id;
|
||||
if let Some(person_id) = person_id {
|
||||
mark_post_as_read(person_id, post_id, context.pool()).await?;
|
||||
mark_post_as_read(person_id, post_id, &mut context.pool()).await?;
|
||||
}
|
||||
|
||||
// Necessary for the sidebar subscribed
|
||||
let community_view = CommunityView::read(
|
||||
context.pool(),
|
||||
&mut context.pool(),
|
||||
community_id,
|
||||
person_id,
|
||||
Some(is_mod_or_admin),
|
||||
|
@ -82,17 +90,18 @@ impl PerformCrud for GetPost {
|
|||
read_comments,
|
||||
..PersonPostAggregatesForm::default()
|
||||
};
|
||||
PersonPostAggregates::upsert(context.pool(), &person_post_agg_form)
|
||||
PersonPostAggregates::upsert(&mut context.pool(), &person_post_agg_form)
|
||||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "couldnt_find_post"))?;
|
||||
}
|
||||
|
||||
let moderators = CommunityModeratorView::for_community(context.pool(), community_id).await?;
|
||||
let moderators =
|
||||
CommunityModeratorView::for_community(&mut context.pool(), community_id).await?;
|
||||
|
||||
// Fetch the cross_posts
|
||||
let cross_posts = if let Some(url) = &post_view.post.url {
|
||||
let mut x_posts = PostQuery::builder()
|
||||
.pool(context.pool())
|
||||
.pool(&mut context.pool())
|
||||
.url_search(Some(url.inner().as_str().into()))
|
||||
.build()
|
||||
.list()
|
||||
|
|
|
@ -25,18 +25,18 @@ impl PerformCrud for RemovePost {
|
|||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||
|
||||
let post_id = data.post_id;
|
||||
let orig_post = Post::read(context.pool(), post_id).await?;
|
||||
let orig_post = Post::read(&mut context.pool(), post_id).await?;
|
||||
|
||||
check_community_ban(
|
||||
local_user_view.person.id,
|
||||
orig_post.community_id,
|
||||
context.pool(),
|
||||
&mut context.pool(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
// Verify that only the mods can remove
|
||||
is_mod_or_admin(
|
||||
context.pool(),
|
||||
&mut context.pool(),
|
||||
local_user_view.person.id,
|
||||
orig_post.community_id,
|
||||
)
|
||||
|
@ -46,7 +46,7 @@ impl PerformCrud for RemovePost {
|
|||
let post_id = data.post_id;
|
||||
let removed = data.removed;
|
||||
Post::update(
|
||||
context.pool(),
|
||||
&mut context.pool(),
|
||||
post_id,
|
||||
&PostUpdateForm::builder().removed(Some(removed)).build(),
|
||||
)
|
||||
|
@ -59,7 +59,7 @@ impl PerformCrud for RemovePost {
|
|||
removed: Some(removed),
|
||||
reason: data.reason.clone(),
|
||||
};
|
||||
ModRemovePost::create(context.pool(), &form).await?;
|
||||
ModRemovePost::create(&mut context.pool(), &form).await?;
|
||||
|
||||
build_post_response(
|
||||
context,
|
||||
|
|
|
@ -32,7 +32,7 @@ impl PerformCrud for EditPost {
|
|||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<PostResponse, LemmyError> {
|
||||
let data: &EditPost = self;
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||
let local_site = LocalSite::read(context.pool()).await?;
|
||||
let local_site = LocalSite::read(&mut context.pool()).await?;
|
||||
|
||||
let data_url = data.url.as_ref();
|
||||
|
||||
|
@ -52,12 +52,12 @@ impl PerformCrud for EditPost {
|
|||
is_valid_body_field(&data.body, true)?;
|
||||
|
||||
let post_id = data.post_id;
|
||||
let orig_post = Post::read(context.pool(), post_id).await?;
|
||||
let orig_post = Post::read(&mut context.pool(), post_id).await?;
|
||||
|
||||
check_community_ban(
|
||||
local_user_view.person.id,
|
||||
orig_post.community_id,
|
||||
context.pool(),
|
||||
&mut context.pool(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
|
@ -76,7 +76,7 @@ impl PerformCrud for EditPost {
|
|||
|
||||
let language_id = self.language_id;
|
||||
CommunityLanguage::is_allowed_community_language(
|
||||
context.pool(),
|
||||
&mut context.pool(),
|
||||
language_id,
|
||||
orig_post.community_id,
|
||||
)
|
||||
|
@ -96,7 +96,7 @@ impl PerformCrud for EditPost {
|
|||
.build();
|
||||
|
||||
let post_id = data.post_id;
|
||||
Post::update(context.pool(), post_id, &post_form)
|
||||
Post::update(&mut context.pool(), post_id, &post_form)
|
||||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "couldnt_create_post"))?;
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ impl PerformCrud for CreatePrivateMessage {
|
|||
) -> Result<PrivateMessageResponse, LemmyError> {
|
||||
let data: &CreatePrivateMessage = self;
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||
let local_site = LocalSite::read(context.pool()).await?;
|
||||
let local_site = LocalSite::read(&mut context.pool()).await?;
|
||||
|
||||
let content_slurs_removed = remove_slurs(
|
||||
&data.content.clone(),
|
||||
|
@ -45,7 +45,12 @@ impl PerformCrud for CreatePrivateMessage {
|
|||
);
|
||||
is_valid_body_field(&Some(content_slurs_removed.clone()), false)?;
|
||||
|
||||
check_person_block(local_user_view.person.id, data.recipient_id, context.pool()).await?;
|
||||
check_person_block(
|
||||
local_user_view.person.id,
|
||||
data.recipient_id,
|
||||
&mut context.pool(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
let private_message_form = PrivateMessageInsertForm::builder()
|
||||
.content(content_slurs_removed.clone())
|
||||
|
@ -54,7 +59,7 @@ impl PerformCrud for CreatePrivateMessage {
|
|||
.build();
|
||||
|
||||
let inserted_private_message =
|
||||
match PrivateMessage::create(context.pool(), &private_message_form).await {
|
||||
match PrivateMessage::create(&mut context.pool(), &private_message_form).await {
|
||||
Ok(private_message) => private_message,
|
||||
Err(e) => {
|
||||
return Err(LemmyError::from_error_message(
|
||||
|
@ -72,7 +77,7 @@ impl PerformCrud for CreatePrivateMessage {
|
|||
&protocol_and_hostname,
|
||||
)?;
|
||||
PrivateMessage::update(
|
||||
context.pool(),
|
||||
&mut context.pool(),
|
||||
inserted_private_message.id,
|
||||
&PrivateMessageUpdateForm::builder()
|
||||
.ap_id(Some(apub_id))
|
||||
|
@ -81,12 +86,12 @@ impl PerformCrud for CreatePrivateMessage {
|
|||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "couldnt_create_private_message"))?;
|
||||
|
||||
let view = PrivateMessageView::read(context.pool(), inserted_private_message.id).await?;
|
||||
let view = PrivateMessageView::read(&mut context.pool(), inserted_private_message.id).await?;
|
||||
|
||||
// Send email to the local recipient, if one exists
|
||||
if view.recipient.local {
|
||||
let recipient_id = data.recipient_id;
|
||||
let local_recipient = LocalUserView::read_person(context.pool(), recipient_id).await?;
|
||||
let local_recipient = LocalUserView::read_person(&mut context.pool(), recipient_id).await?;
|
||||
let lang = get_interface_language(&local_recipient);
|
||||
let inbox_link = format!("{}/inbox", context.settings().get_protocol_and_hostname());
|
||||
let sender_name = &local_user_view.person.name;
|
||||
|
|
|
@ -26,7 +26,8 @@ impl PerformCrud for DeletePrivateMessage {
|
|||
|
||||
// Checking permissions
|
||||
let private_message_id = data.private_message_id;
|
||||
let orig_private_message = PrivateMessage::read(context.pool(), private_message_id).await?;
|
||||
let orig_private_message =
|
||||
PrivateMessage::read(&mut context.pool(), private_message_id).await?;
|
||||
if local_user_view.person.id != orig_private_message.creator_id {
|
||||
return Err(LemmyError::from_message("no_private_message_edit_allowed"));
|
||||
}
|
||||
|
@ -35,7 +36,7 @@ impl PerformCrud for DeletePrivateMessage {
|
|||
let private_message_id = data.private_message_id;
|
||||
let deleted = data.deleted;
|
||||
PrivateMessage::update(
|
||||
context.pool(),
|
||||
&mut context.pool(),
|
||||
private_message_id,
|
||||
&PrivateMessageUpdateForm::builder()
|
||||
.deleted(Some(deleted))
|
||||
|
@ -44,7 +45,7 @@ impl PerformCrud for DeletePrivateMessage {
|
|||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_private_message"))?;
|
||||
|
||||
let view = PrivateMessageView::read(context.pool(), private_message_id).await?;
|
||||
let view = PrivateMessageView::read(&mut context.pool(), private_message_id).await?;
|
||||
Ok(PrivateMessageResponse {
|
||||
private_message_view: view,
|
||||
})
|
||||
|
|
|
@ -25,7 +25,7 @@ impl PerformCrud for GetPrivateMessages {
|
|||
let limit = data.limit;
|
||||
let unread_only = data.unread_only;
|
||||
let mut messages = PrivateMessageQuery::builder()
|
||||
.pool(context.pool())
|
||||
.pool(&mut context.pool())
|
||||
.recipient_id(person_id)
|
||||
.page(page)
|
||||
.limit(limit)
|
||||
|
|
|
@ -30,11 +30,12 @@ impl PerformCrud for EditPrivateMessage {
|
|||
) -> Result<PrivateMessageResponse, LemmyError> {
|
||||
let data: &EditPrivateMessage = self;
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||
let local_site = LocalSite::read(context.pool()).await?;
|
||||
let local_site = LocalSite::read(&mut context.pool()).await?;
|
||||
|
||||
// Checking permissions
|
||||
let private_message_id = data.private_message_id;
|
||||
let orig_private_message = PrivateMessage::read(context.pool(), private_message_id).await?;
|
||||
let orig_private_message =
|
||||
PrivateMessage::read(&mut context.pool(), private_message_id).await?;
|
||||
if local_user_view.person.id != orig_private_message.creator_id {
|
||||
return Err(LemmyError::from_message("no_private_message_edit_allowed"));
|
||||
}
|
||||
|
@ -45,7 +46,7 @@ impl PerformCrud for EditPrivateMessage {
|
|||
|
||||
let private_message_id = data.private_message_id;
|
||||
PrivateMessage::update(
|
||||
context.pool(),
|
||||
&mut context.pool(),
|
||||
private_message_id,
|
||||
&PrivateMessageUpdateForm::builder()
|
||||
.content(Some(content_slurs_removed))
|
||||
|
@ -55,7 +56,7 @@ impl PerformCrud for EditPrivateMessage {
|
|||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "couldnt_update_private_message"))?;
|
||||
|
||||
let view = PrivateMessageView::read(context.pool(), private_message_id).await?;
|
||||
let view = PrivateMessageView::read(&mut context.pool(), private_message_id).await?;
|
||||
|
||||
Ok(PrivateMessageResponse {
|
||||
private_message_view: view,
|
||||
|
|
|
@ -49,7 +49,7 @@ impl PerformCrud for CreateSite {
|
|||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<SiteResponse, LemmyError> {
|
||||
let data: &CreateSite = self;
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||
let local_site = LocalSite::read(context.pool()).await?;
|
||||
let local_site = LocalSite::read(&mut context.pool()).await?;
|
||||
|
||||
// Make sure user is an admin; other types of users should not create site data...
|
||||
is_admin(&local_user_view)?;
|
||||
|
@ -74,7 +74,7 @@ impl PerformCrud for CreateSite {
|
|||
|
||||
let site_id = local_site.site_id;
|
||||
|
||||
Site::update(context.pool(), site_id, &site_form).await?;
|
||||
Site::update(&mut context.pool(), site_id, &site_form).await?;
|
||||
|
||||
let local_site_form = LocalSiteUpdateForm::builder()
|
||||
// Set the site setup to true
|
||||
|
@ -99,7 +99,7 @@ impl PerformCrud for CreateSite {
|
|||
.captcha_difficulty(data.captcha_difficulty.clone())
|
||||
.build();
|
||||
|
||||
LocalSite::update(context.pool(), &local_site_form).await?;
|
||||
LocalSite::update(&mut context.pool(), &local_site_form).await?;
|
||||
|
||||
let local_site_rate_limit_form = LocalSiteRateLimitUpdateForm::builder()
|
||||
.message(data.rate_limit_message)
|
||||
|
@ -116,12 +116,12 @@ impl PerformCrud for CreateSite {
|
|||
.search_per_second(data.rate_limit_search_per_second)
|
||||
.build();
|
||||
|
||||
LocalSiteRateLimit::update(context.pool(), &local_site_rate_limit_form).await?;
|
||||
LocalSiteRateLimit::update(&mut context.pool(), &local_site_rate_limit_form).await?;
|
||||
|
||||
let site_view = SiteView::read_local(context.pool()).await?;
|
||||
let site_view = SiteView::read_local(&mut context.pool()).await?;
|
||||
|
||||
let new_taglines = data.taglines.clone();
|
||||
let taglines = Tagline::replace(context.pool(), local_site.id, new_taglines).await?;
|
||||
let taglines = Tagline::replace(&mut context.pool(), local_site.id, new_taglines).await?;
|
||||
|
||||
let rate_limit_config =
|
||||
local_site_rate_limit_to_rate_limit_config(&site_view.local_site_rate_limit);
|
||||
|
|
|
@ -32,9 +32,9 @@ impl PerformCrud for GetSite {
|
|||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<GetSiteResponse, LemmyError> {
|
||||
let data: &GetSite = self;
|
||||
|
||||
let site_view = SiteView::read_local(context.pool()).await?;
|
||||
let site_view = SiteView::read_local(&mut context.pool()).await?;
|
||||
|
||||
let admins = PersonView::admins(context.pool()).await?;
|
||||
let admins = PersonView::admins(&mut context.pool()).await?;
|
||||
|
||||
// Build the local user
|
||||
let my_user = if let Some(local_user_view) =
|
||||
|
@ -43,25 +43,25 @@ impl PerformCrud for GetSite {
|
|||
let person_id = local_user_view.person.id;
|
||||
let local_user_id = local_user_view.local_user.id;
|
||||
|
||||
let follows = CommunityFollowerView::for_person(context.pool(), person_id)
|
||||
let follows = CommunityFollowerView::for_person(&mut context.pool(), person_id)
|
||||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "system_err_login"))?;
|
||||
|
||||
let person_id = local_user_view.person.id;
|
||||
let community_blocks = CommunityBlockView::for_person(context.pool(), person_id)
|
||||
let community_blocks = CommunityBlockView::for_person(&mut context.pool(), person_id)
|
||||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "system_err_login"))?;
|
||||
|
||||
let person_id = local_user_view.person.id;
|
||||
let person_blocks = PersonBlockView::for_person(context.pool(), person_id)
|
||||
let person_blocks = PersonBlockView::for_person(&mut context.pool(), person_id)
|
||||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "system_err_login"))?;
|
||||
|
||||
let moderates = CommunityModeratorView::for_person(context.pool(), person_id)
|
||||
let moderates = CommunityModeratorView::for_person(&mut context.pool(), person_id)
|
||||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "system_err_login"))?;
|
||||
|
||||
let discussion_languages = LocalUserLanguage::read(context.pool(), local_user_id)
|
||||
let discussion_languages = LocalUserLanguage::read(&mut context.pool(), local_user_id)
|
||||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "system_err_login"))?;
|
||||
|
||||
|
@ -77,10 +77,11 @@ impl PerformCrud for GetSite {
|
|||
None
|
||||
};
|
||||
|
||||
let all_languages = Language::read_all(context.pool()).await?;
|
||||
let discussion_languages = SiteLanguage::read_local_raw(context.pool()).await?;
|
||||
let taglines = Tagline::get_all(context.pool(), site_view.local_site.id).await?;
|
||||
let custom_emojis = CustomEmojiView::get_all(context.pool(), site_view.local_site.id).await?;
|
||||
let all_languages = Language::read_all(&mut context.pool()).await?;
|
||||
let discussion_languages = SiteLanguage::read_local_raw(&mut context.pool()).await?;
|
||||
let taglines = Tagline::get_all(&mut context.pool(), site_view.local_site.id).await?;
|
||||
let custom_emojis =
|
||||
CustomEmojiView::get_all(&mut context.pool(), site_view.local_site.id).await?;
|
||||
|
||||
Ok(GetSiteResponse {
|
||||
site_view,
|
||||
|
@ -106,7 +107,7 @@ async fn local_user_settings_view_from_jwt_opt(
|
|||
.ok()?
|
||||
.claims;
|
||||
let local_user_id = LocalUserId(claims.sub);
|
||||
let local_user_view = LocalUserView::read(context.pool(), local_user_id)
|
||||
let local_user_view = LocalUserView::read(&mut context.pool(), local_user_id)
|
||||
.await
|
||||
.ok()?;
|
||||
check_user_valid(
|
||||
|
|
|
@ -46,7 +46,7 @@ impl PerformCrud for EditSite {
|
|||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<SiteResponse, LemmyError> {
|
||||
let data: &EditSite = self;
|
||||
let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
|
||||
let site_view = SiteView::read_local(context.pool()).await?;
|
||||
let site_view = SiteView::read_local(&mut context.pool()).await?;
|
||||
let local_site = site_view.local_site;
|
||||
let site = site_view.site;
|
||||
|
||||
|
@ -56,7 +56,7 @@ impl PerformCrud for EditSite {
|
|||
validate_update_payload(&local_site, data)?;
|
||||
|
||||
if let Some(discussion_languages) = data.discussion_languages.clone() {
|
||||
SiteLanguage::update(context.pool(), discussion_languages.clone(), &site).await?;
|
||||
SiteLanguage::update(&mut context.pool(), discussion_languages.clone(), &site).await?;
|
||||
}
|
||||
|
||||
let site_form = SiteUpdateForm::builder()
|
||||
|
@ -68,7 +68,7 @@ impl PerformCrud for EditSite {
|
|||
.updated(Some(Some(naive_now())))
|
||||
.build();
|
||||
|
||||
Site::update(context.pool(), site.id, &site_form)
|
||||
Site::update(&mut context.pool(), site.id, &site_form)
|
||||
.await
|
||||
// Ignore errors for all these, so as to not throw errors if no update occurs
|
||||
// Diesel will throw an error for empty update forms
|
||||
|
@ -96,7 +96,7 @@ impl PerformCrud for EditSite {
|
|||
.reports_email_admins(data.reports_email_admins)
|
||||
.build();
|
||||
|
||||
let update_local_site = LocalSite::update(context.pool(), &local_site_form)
|
||||
let update_local_site = LocalSite::update(&mut context.pool(), &local_site_form)
|
||||
.await
|
||||
.ok();
|
||||
|
||||
|
@ -115,15 +115,15 @@ impl PerformCrud for EditSite {
|
|||
.search_per_second(data.rate_limit_search_per_second)
|
||||
.build();
|
||||
|
||||
LocalSiteRateLimit::update(context.pool(), &local_site_rate_limit_form)
|
||||
LocalSiteRateLimit::update(&mut context.pool(), &local_site_rate_limit_form)
|
||||
.await
|
||||
.ok();
|
||||
|
||||
// Replace the blocked and allowed instances
|
||||
let allowed = data.allowed_instances.clone();
|
||||
FederationAllowList::replace(context.pool(), allowed).await?;
|
||||
FederationAllowList::replace(&mut context.pool(), allowed).await?;
|
||||
let blocked = data.blocked_instances.clone();
|
||||
FederationBlockList::replace(context.pool(), blocked).await?;
|
||||
FederationBlockList::replace(&mut context.pool(), blocked).await?;
|
||||
|
||||
// TODO can't think of a better way to do this.
|
||||
// If the server suddenly requires email verification, or required applications, no old users
|
||||
|
@ -137,7 +137,7 @@ impl PerformCrud for EditSite {
|
|||
.map(|ols| ols.registration_mode == RegistrationMode::RequireApplication)
|
||||
.unwrap_or(false);
|
||||
if !old_require_application && new_require_application {
|
||||
LocalUser::set_all_users_registration_applications_accepted(context.pool())
|
||||
LocalUser::set_all_users_registration_applications_accepted(&mut context.pool())
|
||||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "couldnt_set_all_registrations_accepted"))?;
|
||||
}
|
||||
|
@ -147,15 +147,15 @@ impl PerformCrud for EditSite {
|
|||
.map(|ols| ols.require_email_verification)
|
||||
.unwrap_or(false);
|
||||
if !local_site.require_email_verification && new_require_email_verification {
|
||||
LocalUser::set_all_users_email_verified(context.pool())
|
||||
LocalUser::set_all_users_email_verified(&mut context.pool())
|
||||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "couldnt_set_all_email_verified"))?;
|
||||
}
|
||||
|
||||
let new_taglines = data.taglines.clone();
|
||||
let taglines = Tagline::replace(context.pool(), local_site.id, new_taglines).await?;
|
||||
let taglines = Tagline::replace(&mut context.pool(), local_site.id, new_taglines).await?;
|
||||
|
||||
let site_view = SiteView::read_local(context.pool()).await?;
|
||||
let site_view = SiteView::read_local(&mut context.pool()).await?;
|
||||
|
||||
let rate_limit_config =
|
||||
local_site_rate_limit_to_rate_limit_config(&site_view.local_site_rate_limit);
|
||||
|
|
|
@ -45,7 +45,7 @@ impl PerformCrud for Register {
|
|||
async fn perform(&self, context: &Data<LemmyContext>) -> Result<LoginResponse, LemmyError> {
|
||||
let data: &Register = self;
|
||||
|
||||
let site_view = SiteView::read_local(context.pool()).await?;
|
||||
let site_view = SiteView::read_local(&mut context.pool()).await?;
|
||||
let local_site = site_view.local_site;
|
||||
let require_registration_application =
|
||||
local_site.registration_mode == RegistrationMode::RequireApplication;
|
||||
|
@ -76,7 +76,7 @@ impl PerformCrud for Register {
|
|||
if let Some(captcha_uuid) = &data.captcha_uuid {
|
||||
let uuid = uuid::Uuid::parse_str(captcha_uuid)?;
|
||||
let check = CaptchaAnswer::check_captcha(
|
||||
context.pool(),
|
||||
&mut context.pool(),
|
||||
CheckCaptchaAnswer {
|
||||
uuid,
|
||||
answer: data.captcha_answer.clone().unwrap_or_default(),
|
||||
|
@ -104,7 +104,7 @@ impl PerformCrud for Register {
|
|||
)?;
|
||||
|
||||
if let Some(email) = &data.email {
|
||||
if LocalUser::is_email_taken(context.pool(), email).await? {
|
||||
if LocalUser::is_email_taken(&mut context.pool(), email).await? {
|
||||
return Err(LemmyError::from_message("email_already_exists"));
|
||||
}
|
||||
}
|
||||
|
@ -125,7 +125,7 @@ impl PerformCrud for Register {
|
|||
.build();
|
||||
|
||||
// insert the person
|
||||
let inserted_person = Person::create(context.pool(), &person_form)
|
||||
let inserted_person = Person::create(&mut context.pool(), &person_form)
|
||||
.await
|
||||
.map_err(|e| LemmyError::from_error_message(e, "user_already_exists"))?;
|
||||
|
||||
|
@ -142,7 +142,7 @@ impl PerformCrud for Register {
|
|||
.accepted_application(accepted_application)
|
||||
.build();
|
||||
|
||||
let inserted_local_user = LocalUser::create(context.pool(), &local_user_form).await?;
|
||||
let inserted_local_user = LocalUser::create(&mut context.pool(), &local_user_form).await?;
|
||||
|
||||
if local_site.site_setup && require_registration_application {
|
||||
// Create the registration application
|
||||
|
@ -152,12 +152,12 @@ impl PerformCrud for Register {
|
|||
answer: data.answer.clone().expect("must have an answer"),
|
||||
};
|
||||
|
||||
RegistrationApplication::create(context.pool(), &form).await?;
|
||||
RegistrationApplication::create(&mut context.pool(), &form).await?;
|
||||
}
|
||||
|
||||
// Email the admins
|
||||
if local_site.application_email_admins {
|
||||
send_new_applicant_email_to_admins(&data.username, context.pool(), context.settings())
|
||||
send_new_applicant_email_to_admins(&data.username, &mut context.pool(), context.settings())
|
||||
.await?;
|
||||
}
|
||||
|
||||
|
@ -193,8 +193,13 @@ impl PerformCrud for Register {
|
|||
.clone()
|
||||
.expect("email was provided");
|
||||
|
||||
send_verification_email(&local_user_view, &email, context.pool(), context.settings())
|
||||
.await?;
|
||||
send_verification_email(
|
||||
&local_user_view,
|
||||
&email,
|
||||
&mut context.pool(),
|
||||
context.settings(),
|
||||
)
|
||||
.await?;
|
||||
login_response.verify_email_sent = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ impl BlockUser {
|
|||
actor: mod_.id().into(),
|
||||
to: vec![public()],
|
||||
object: user.id().into(),
|
||||
cc: generate_cc(target, context.pool()).await?,
|
||||
cc: generate_cc(target, &mut context.pool()).await?,
|
||||
target: target.id(),
|
||||
kind: BlockType::Block,
|
||||
remove_data,
|
||||
|
@ -97,7 +97,7 @@ impl BlockUser {
|
|||
|
||||
match target {
|
||||
SiteOrCommunity::Site(_) => {
|
||||
let inboxes = remote_instance_inboxes(context.pool()).await?;
|
||||
let inboxes = remote_instance_inboxes(&mut context.pool()).await?;
|
||||
send_lemmy_activity(context, block, mod_, inboxes, false).await
|
||||
}
|
||||
SiteOrCommunity::Community(c) => {
|
||||
|
@ -155,7 +155,7 @@ impl ActivityHandler for BlockUser {
|
|||
match target {
|
||||
SiteOrCommunity::Site(_site) => {
|
||||
let blocked_person = Person::update(
|
||||
context.pool(),
|
||||
&mut context.pool(),
|
||||
blocked_person.id,
|
||||
&PersonUpdateForm::builder()
|
||||
.banned(Some(true))
|
||||
|
@ -166,7 +166,7 @@ impl ActivityHandler for BlockUser {
|
|||
if self.remove_data.unwrap_or(false) {
|
||||
remove_user_data(
|
||||
blocked_person.id,
|
||||
context.pool(),
|
||||
&mut context.pool(),
|
||||
context.settings(),
|
||||
context.client(),
|
||||
)
|
||||
|
@ -181,7 +181,7 @@ impl ActivityHandler for BlockUser {
|
|||
banned: Some(true),
|
||||
expires,
|
||||
};
|
||||
ModBan::create(context.pool(), &form).await?;
|
||||
ModBan::create(&mut context.pool(), &form).await?;
|
||||
}
|
||||
SiteOrCommunity::Community(community) => {
|
||||
let community_user_ban_form = CommunityPersonBanForm {
|
||||
|
@ -189,7 +189,7 @@ impl ActivityHandler for BlockUser {
|
|||
person_id: blocked_person.id,
|
||||
expires: Some(expires),
|
||||
};
|
||||
CommunityPersonBan::ban(context.pool(), &community_user_ban_form).await?;
|
||||
CommunityPersonBan::ban(&mut context.pool(), &community_user_ban_form).await?;
|
||||
|
||||
// Also unsubscribe them from the community, if they are subscribed
|
||||
let community_follower_form = CommunityFollowerForm {
|
||||
|
@ -197,12 +197,13 @@ impl ActivityHandler for BlockUser {
|
|||
person_id: blocked_person.id,
|
||||
pending: false,
|
||||
};
|
||||
CommunityFollower::unfollow(context.pool(), &community_follower_form)
|
||||
CommunityFollower::unfollow(&mut context.pool(), &community_follower_form)
|
||||
.await
|
||||
.ok();
|
||||
|
||||
if self.remove_data.unwrap_or(false) {
|
||||
remove_user_data_in_community(community.id, blocked_person.id, context.pool()).await?;
|
||||
remove_user_data_in_community(community.id, blocked_person.id, &mut context.pool())
|
||||
.await?;
|
||||
}
|
||||
|
||||
// write to mod log
|
||||
|
@ -214,7 +215,7 @@ impl ActivityHandler for BlockUser {
|
|||
banned: Some(true),
|
||||
expires,
|
||||
};
|
||||
ModBanFromCommunity::create(context.pool(), &form).await?;
|
||||
ModBanFromCommunity::create(&mut context.pool(), &form).await?;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ use lemmy_db_schema::{
|
|||
source::{community::Community, person::Person, site::Site},
|
||||
traits::Crud,
|
||||
utils::DbPool,
|
||||
DbPoolRef,
|
||||
};
|
||||
use lemmy_db_views::structs::SiteView;
|
||||
use lemmy_utils::{error::LemmyError, utils::time::naive_from_unix};
|
||||
|
@ -118,7 +119,10 @@ impl SiteOrCommunity {
|
|||
}
|
||||
}
|
||||
|
||||
async fn generate_cc(target: &SiteOrCommunity, pool: &DbPool) -> Result<Vec<Url>, LemmyError> {
|
||||
async fn generate_cc(
|
||||
target: &SiteOrCommunity,
|
||||
pool: DbPoolRef<'_>,
|
||||
) -> Result<Vec<Url>, LemmyError> {
|
||||
Ok(match target {
|
||||
SiteOrCommunity::Site(_) => Site::read_remote_sites(pool)
|
||||
.await?
|
||||
|
@ -139,8 +143,8 @@ impl SendActivity for BanPerson {
|
|||
context: &Data<LemmyContext>,
|
||||
) -> Result<(), LemmyError> {
|
||||
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
|
||||
let person = Person::read(context.pool(), request.person_id).await?;
|
||||
let site = SiteOrCommunity::Site(SiteView::read_local(context.pool()).await?.site.into());
|
||||
let person = Person::read(&mut context.pool(), request.person_id).await?;
|
||||
let site = SiteOrCommunity::Site(SiteView::read_local(&mut context.pool()).await?.site.into());
|
||||
let expires = request.expires.map(naive_from_unix);
|
||||
|
||||
// if the action affects a local user, federate to other instances
|
||||
|
@ -182,10 +186,10 @@ impl SendActivity for BanFromCommunity {
|
|||
context: &Data<LemmyContext>,
|
||||
) -> Result<(), LemmyError> {
|
||||
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
|
||||
let community: ApubCommunity = Community::read(context.pool(), request.community_id)
|
||||
let community: ApubCommunity = Community::read(&mut context.pool(), request.community_id)
|
||||
.await?
|
||||
.into();
|
||||
let banned_person: ApubPerson = Person::read(context.pool(), request.person_id)
|
||||
let banned_person: ApubPerson = Person::read(&mut context.pool(), request.person_id)
|
||||
.await?
|
||||
.into();
|
||||
let expires = request.expires.map(naive_from_unix);
|
||||
|
|
|
@ -53,7 +53,7 @@ impl UndoBlockUser {
|
|||
actor: mod_.id().into(),
|
||||
to: vec![public()],
|
||||
object: block,
|
||||
cc: generate_cc(target, context.pool()).await?,
|
||||
cc: generate_cc(target, &mut context.pool()).await?,
|
||||
kind: UndoType::Undo,
|
||||
id: id.clone(),
|
||||
audience,
|
||||
|
@ -62,7 +62,7 @@ impl UndoBlockUser {
|
|||
let mut inboxes = vec![user.shared_inbox_or_inbox()];
|
||||
match target {
|
||||
SiteOrCommunity::Site(_) => {
|
||||
inboxes.append(&mut remote_instance_inboxes(context.pool()).await?);
|
||||
inboxes.append(&mut remote_instance_inboxes(&mut context.pool()).await?);
|
||||
send_lemmy_activity(context, undo, mod_, inboxes, false).await
|
||||
}
|
||||
SiteOrCommunity::Community(c) => {
|
||||
|
@ -103,7 +103,7 @@ impl ActivityHandler for UndoBlockUser {
|
|||
match self.object.target.dereference(context).await? {
|
||||
SiteOrCommunity::Site(_site) => {
|
||||
let blocked_person = Person::update(
|
||||
context.pool(),
|
||||
&mut context.pool(),
|
||||
blocked_person.id,
|
||||
&PersonUpdateForm::builder()
|
||||
.banned(Some(false))
|
||||
|
@ -120,7 +120,7 @@ impl ActivityHandler for UndoBlockUser {
|
|||
banned: Some(false),
|
||||
expires,
|
||||
};
|
||||
ModBan::create(context.pool(), &form).await?;
|
||||
ModBan::create(&mut context.pool(), &form).await?;
|
||||
}
|
||||
SiteOrCommunity::Community(community) => {
|
||||
let community_user_ban_form = CommunityPersonBanForm {
|
||||
|
@ -128,7 +128,7 @@ impl ActivityHandler for UndoBlockUser {
|
|||
person_id: blocked_person.id,
|
||||
expires: None,
|
||||
};
|
||||
CommunityPersonBan::unban(context.pool(), &community_user_ban_form).await?;
|
||||
CommunityPersonBan::unban(&mut context.pool(), &community_user_ban_form).await?;
|
||||
|
||||
// write to mod log
|
||||
let form = ModBanFromCommunityForm {
|
||||
|
@ -139,7 +139,7 @@ impl ActivityHandler for UndoBlockUser {
|
|||
banned: Some(false),
|
||||
expires,
|
||||
};
|
||||
ModBanFromCommunity::create(context.pool(), &form).await?;
|
||||
ModBanFromCommunity::create(&mut context.pool(), &form).await?;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -119,7 +119,7 @@ impl ActivityHandler for CollectionAdd {
|
|||
async fn receive(self, context: &Data<Self::DataType>) -> Result<(), LemmyError> {
|
||||
insert_activity(&self.id, &self, false, false, context).await?;
|
||||
let (community, collection_type) =
|
||||
Community::get_by_collection_url(context.pool(), &self.target.into()).await?;
|
||||
Community::get_by_collection_url(&mut context.pool(), &self.target.into()).await?;
|
||||
match collection_type {
|
||||
CollectionType::Moderators => {
|
||||
let new_mod = ObjectId::<ApubPerson>::from(self.object)
|
||||
|
@ -130,13 +130,14 @@ impl ActivityHandler for CollectionAdd {
|
|||
// been added. Skip it here as it would result in a duplicate key error.
|
||||
let new_mod_id = new_mod.id;
|
||||
let moderated_communities =
|
||||
CommunityModerator::get_person_moderated_communities(context.pool(), new_mod_id).await?;
|
||||
CommunityModerator::get_person_moderated_communities(&mut context.pool(), new_mod_id)
|
||||
.await?;
|
||||
if !moderated_communities.contains(&community.id) {
|
||||
let form = CommunityModeratorForm {
|
||||
community_id: community.id,
|
||||
person_id: new_mod.id,
|
||||
};
|
||||
CommunityModerator::join(context.pool(), &form).await?;
|
||||
CommunityModerator::join(&mut context.pool(), &form).await?;
|
||||
|
||||
// write mod log
|
||||
let actor = self.actor.dereference(context).await?;
|
||||
|
@ -146,7 +147,7 @@ impl ActivityHandler for CollectionAdd {
|
|||
community_id: community.id,
|
||||
removed: Some(false),
|
||||
};
|
||||
ModAddCommunity::create(context.pool(), &form).await?;
|
||||
ModAddCommunity::create(&mut context.pool(), &form).await?;
|
||||
}
|
||||
// TODO: send websocket notification about added mod
|
||||
}
|
||||
|
@ -157,7 +158,7 @@ impl ActivityHandler for CollectionAdd {
|
|||
let form = PostUpdateForm::builder()
|
||||
.featured_community(Some(true))
|
||||
.build();
|
||||
Post::update(context.pool(), post.id, &form).await?;
|
||||
Post::update(&mut context.pool(), post.id, &form).await?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
@ -174,10 +175,10 @@ impl SendActivity for AddModToCommunity {
|
|||
context: &Data<LemmyContext>,
|
||||
) -> Result<(), LemmyError> {
|
||||
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
|
||||
let community: ApubCommunity = Community::read(context.pool(), request.community_id)
|
||||
let community: ApubCommunity = Community::read(&mut context.pool(), request.community_id)
|
||||
.await?
|
||||
.into();
|
||||
let updated_mod: ApubPerson = Person::read(context.pool(), request.person_id)
|
||||
let updated_mod: ApubPerson = Person::read(&mut context.pool(), request.person_id)
|
||||
.await?
|
||||
.into();
|
||||
if request.added {
|
||||
|
@ -210,7 +211,7 @@ impl SendActivity for FeaturePost {
|
|||
context: &Data<LemmyContext>,
|
||||
) -> Result<(), LemmyError> {
|
||||
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
|
||||
let community = Community::read(context.pool(), response.post_view.community.id)
|
||||
let community = Community::read(&mut context.pool(), response.post_view.community.id)
|
||||
.await?
|
||||
.into();
|
||||
let post = response.post_view.post.clone().into();
|
||||
|
|
|
@ -112,7 +112,7 @@ impl ActivityHandler for CollectionRemove {
|
|||
async fn receive(self, context: &Data<Self::DataType>) -> Result<(), LemmyError> {
|
||||
insert_activity(&self.id, &self, false, false, context).await?;
|
||||
let (community, collection_type) =
|
||||
Community::get_by_collection_url(context.pool(), &self.target.into()).await?;
|
||||
Community::get_by_collection_url(&mut context.pool(), &self.target.into()).await?;
|
||||
match collection_type {
|
||||
CollectionType::Moderators => {
|
||||
let remove_mod = ObjectId::<ApubPerson>::from(self.object)
|
||||
|
@ -123,7 +123,7 @@ impl ActivityHandler for CollectionRemove {
|
|||
community_id: community.id,
|
||||
person_id: remove_mod.id,
|
||||
};
|
||||
CommunityModerator::leave(context.pool(), &form).await?;
|
||||
CommunityModerator::leave(&mut context.pool(), &form).await?;
|
||||
|
||||
// write mod log
|
||||
let actor = self.actor.dereference(context).await?;
|
||||
|
@ -133,7 +133,7 @@ impl ActivityHandler for CollectionRemove {
|
|||
community_id: community.id,
|
||||
removed: Some(true),
|
||||
};
|
||||
ModAddCommunity::create(context.pool(), &form).await?;
|
||||
ModAddCommunity::create(&mut context.pool(), &form).await?;
|
||||
|
||||
// TODO: send websocket notification about removed mod
|
||||
}
|
||||
|
@ -144,7 +144,7 @@ impl ActivityHandler for CollectionRemove {
|
|||
let form = PostUpdateForm::builder()
|
||||
.featured_community(Some(false))
|
||||
.build();
|
||||
Post::update(context.pool(), post.id, &form).await?;
|
||||
Post::update(&mut context.pool(), post.id, &form).await?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
|
|
@ -60,7 +60,7 @@ impl ActivityHandler for LockPage {
|
|||
async fn receive(self, context: &Data<Self::DataType>) -> Result<(), Self::Error> {
|
||||
let form = PostUpdateForm::builder().locked(Some(true)).build();
|
||||
let post = self.object.dereference(context).await?;
|
||||
Post::update(context.pool(), post.id, &form).await?;
|
||||
Post::update(&mut context.pool(), post.id, &form).await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
@ -97,7 +97,7 @@ impl ActivityHandler for UndoLockPage {
|
|||
insert_activity(&self.id, &self, false, false, context).await?;
|
||||
let form = PostUpdateForm::builder().locked(Some(false)).build();
|
||||
let post = self.object.object.dereference(context).await?;
|
||||
Post::update(context.pool(), post.id, &form).await?;
|
||||
Post::update(&mut context.pool(), post.id, &form).await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
@ -145,7 +145,7 @@ impl SendActivity for LockPost {
|
|||
};
|
||||
AnnouncableActivities::UndoLockPost(undo)
|
||||
};
|
||||
let community = Community::read(context.pool(), response.post_view.community.id).await?;
|
||||
let community = Community::read(&mut context.pool(), response.post_view.community.id).await?;
|
||||
send_activity_in_community(
|
||||
activity,
|
||||
&local_user_view.person.into(),
|
||||
|
|
|
@ -44,7 +44,7 @@ pub(crate) async fn send_activity_in_community(
|
|||
// send to user followers
|
||||
if !is_mod_action {
|
||||
inboxes.extend(
|
||||
&mut PersonFollower::list_followers(context.pool(), actor.id)
|
||||
&mut PersonFollower::list_followers(&mut context.pool(), actor.id)
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(|p| ApubPerson(p).shared_inbox_or_inbox()),
|
||||
|
|
|
@ -134,7 +134,7 @@ impl ActivityHandler for Report {
|
|||
reason: self.summary,
|
||||
original_post_body: post.body.clone(),
|
||||
};
|
||||
PostReport::report(context.pool(), &report_form).await?;
|
||||
PostReport::report(&mut context.pool(), &report_form).await?;
|
||||
}
|
||||
PostOrComment::Comment(comment) => {
|
||||
let report_form = CommentReportForm {
|
||||
|
@ -143,7 +143,7 @@ impl ActivityHandler for Report {
|
|||
original_comment_text: comment.content.clone(),
|
||||
reason: self.summary,
|
||||
};
|
||||
CommentReport::report(context.pool(), &report_form).await?;
|
||||
CommentReport::report(&mut context.pool(), &report_form).await?;
|
||||
}
|
||||
};
|
||||
Ok(())
|
||||
|
|
|
@ -36,7 +36,7 @@ impl SendActivity for EditCommunity {
|
|||
context: &Data<LemmyContext>,
|
||||
) -> Result<(), LemmyError> {
|
||||
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
|
||||
let community = Community::read(context.pool(), request.community_id).await?;
|
||||
let community = Community::read(&mut context.pool(), request.community_id).await?;
|
||||
UpdateCommunity::send(community.into(), &local_user_view.person.into(), context).await
|
||||
}
|
||||
}
|
||||
|
@ -97,7 +97,7 @@ impl ActivityHandler for UpdateCommunity {
|
|||
|
||||
let community_update_form = self.object.into_update_form();
|
||||
|
||||
Community::update(context.pool(), community.id, &community_update_form).await?;
|
||||
Community::update(&mut context.pool(), community.id, &community_update_form).await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
@ -112,7 +112,7 @@ impl SendActivity for HideCommunity {
|
|||
context: &Data<LemmyContext>,
|
||||
) -> Result<(), LemmyError> {
|
||||
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
|
||||
let community = Community::read(context.pool(), request.community_id).await?;
|
||||
let community = Community::read(&mut context.pool(), request.community_id).await?;
|
||||
UpdateCommunity::send(community.into(), &local_user_view.person.into(), context).await
|
||||
}
|
||||
}
|
||||
|
|
|
@ -91,10 +91,12 @@ impl CreateOrUpdateNote {
|
|||
) -> Result<(), LemmyError> {
|
||||
// TODO: might be helpful to add a comment method to retrieve community directly
|
||||
let post_id = comment.post_id;
|
||||
let post = Post::read(context.pool(), post_id).await?;
|
||||
let post = Post::read(&mut context.pool(), post_id).await?;
|
||||
let community_id = post.community_id;
|
||||
let person: ApubPerson = Person::read(context.pool(), person_id).await?.into();
|
||||
let community: ApubCommunity = Community::read(context.pool(), community_id).await?.into();
|
||||
let person: ApubPerson = Person::read(&mut context.pool(), person_id).await?.into();
|
||||
let community: ApubCommunity = Community::read(&mut context.pool(), community_id)
|
||||
.await?
|
||||
.into();
|
||||
|
||||
let id = generate_activity_id(
|
||||
kind.clone(),
|
||||
|
@ -177,7 +179,7 @@ impl ActivityHandler for CreateOrUpdateNote {
|
|||
if distinguished != existing_comment.distinguished {
|
||||
let creator = self.actor.dereference(context).await?;
|
||||
let (post, _) = self.object.get_parents(context).await?;
|
||||
is_mod_or_admin(context.pool(), creator.id, post.community_id).await?;
|
||||
is_mod_or_admin(&mut context.pool(), creator.id, post.community_id).await?;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -190,14 +192,14 @@ impl ActivityHandler for CreateOrUpdateNote {
|
|||
person_id: comment.creator_id,
|
||||
score: 1,
|
||||
};
|
||||
CommentLike::like(context.pool(), &like_form).await?;
|
||||
CommentLike::like(&mut context.pool(), &like_form).await?;
|
||||
|
||||
// Calculate initial hot_rank
|
||||
CommentAggregates::update_hot_rank(context.pool(), comment.id).await?;
|
||||
CommentAggregates::update_hot_rank(&mut context.pool(), comment.id).await?;
|
||||
|
||||
let do_send_email = self.kind == CreateOrUpdateType::Create;
|
||||
let post_id = comment.post_id;
|
||||
let post = Post::read(context.pool(), post_id).await?;
|
||||
let post = Post::read(&mut context.pool(), post_id).await?;
|
||||
let actor = self.actor.dereference(context).await?;
|
||||
|
||||
// Note:
|
||||
|
|
|
@ -109,8 +109,10 @@ impl CreateOrUpdatePage {
|
|||
) -> Result<(), LemmyError> {
|
||||
let post = ApubPost(post.clone());
|
||||
let community_id = post.community_id;
|
||||
let person: ApubPerson = Person::read(context.pool(), person_id).await?.into();
|
||||
let community: ApubCommunity = Community::read(context.pool(), community_id).await?.into();
|
||||
let person: ApubPerson = Person::read(&mut context.pool(), person_id).await?.into();
|
||||
let community: ApubCommunity = Community::read(&mut context.pool(), community_id)
|
||||
.await?
|
||||
.into();
|
||||
|
||||
let create_or_update =
|
||||
CreateOrUpdatePage::new(post, &person, &community, kind, context).await?;
|
||||
|
@ -187,10 +189,10 @@ impl ActivityHandler for CreateOrUpdatePage {
|
|||
person_id: post.creator_id,
|
||||
score: 1,
|
||||
};
|
||||
PostLike::like(context.pool(), &like_form).await?;
|
||||
PostLike::like(&mut context.pool(), &like_form).await?;
|
||||
|
||||
// Calculate initial hot_rank for post
|
||||
PostAggregates::update_hot_rank(context.pool(), post.id).await?;
|
||||
PostAggregates::update_hot_rank(&mut context.pool(), post.id).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -71,8 +71,10 @@ impl CreateOrUpdateChatMessage {
|
|||
context: &Data<LemmyContext>,
|
||||
) -> Result<(), LemmyError> {
|
||||
let recipient_id = private_message.recipient_id;
|
||||
let sender: ApubPerson = Person::read(context.pool(), sender_id).await?.into();
|
||||
let recipient: ApubPerson = Person::read(context.pool(), recipient_id).await?.into();
|
||||
let sender: ApubPerson = Person::read(&mut context.pool(), sender_id).await?.into();
|
||||
let recipient: ApubPerson = Person::read(&mut context.pool(), recipient_id)
|
||||
.await?
|
||||
.into();
|
||||
|
||||
let id = generate_activity_id(
|
||||
kind.clone(),
|
||||
|
|
|
@ -119,9 +119,9 @@ pub(in crate::activities) async fn receive_remove_action(
|
|||
reason,
|
||||
expires: None,
|
||||
};
|
||||
ModRemoveCommunity::create(context.pool(), &form).await?;
|
||||
ModRemoveCommunity::create(&mut context.pool(), &form).await?;
|
||||
Community::update(
|
||||
context.pool(),
|
||||
&mut context.pool(),
|
||||
community.id,
|
||||
&CommunityUpdateForm::builder().removed(Some(true)).build(),
|
||||
)
|
||||
|
@ -134,9 +134,9 @@ pub(in crate::activities) async fn receive_remove_action(
|
|||
removed: Some(true),
|
||||
reason,
|
||||
};
|
||||
ModRemovePost::create(context.pool(), &form).await?;
|
||||
ModRemovePost::create(&mut context.pool(), &form).await?;
|
||||
Post::update(
|
||||
context.pool(),
|
||||
&mut context.pool(),
|
||||
post.id,
|
||||
&PostUpdateForm::builder().removed(Some(true)).build(),
|
||||
)
|
||||
|
@ -149,9 +149,9 @@ pub(in crate::activities) async fn receive_remove_action(
|
|||
removed: Some(true),
|
||||
reason,
|
||||
};
|
||||
ModRemoveComment::create(context.pool(), &form).await?;
|
||||
ModRemoveComment::create(&mut context.pool(), &form).await?;
|
||||
Comment::update(
|
||||
context.pool(),
|
||||
&mut context.pool(),
|
||||
comment.id,
|
||||
&CommentUpdateForm::builder().removed(Some(true)).build(),
|
||||
)
|
||||
|
|
|
@ -32,7 +32,7 @@ impl SendActivity for DeleteAccount {
|
|||
let actor: ApubPerson = local_user_view.person.into();
|
||||
delete_user_account(
|
||||
actor.id,
|
||||
context.pool(),
|
||||
&mut context.pool(),
|
||||
context.settings(),
|
||||
context.client(),
|
||||
)
|
||||
|
@ -51,7 +51,7 @@ impl SendActivity for DeleteAccount {
|
|||
cc: vec![],
|
||||
};
|
||||
|
||||
let inboxes = remote_instance_inboxes(context.pool()).await?;
|
||||
let inboxes = remote_instance_inboxes(&mut context.pool()).await?;
|
||||
send_lemmy_activity(context, delete, &actor, inboxes, true).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
@ -84,7 +84,7 @@ impl ActivityHandler for DeleteUser {
|
|||
let actor = self.actor.dereference(context).await?;
|
||||
delete_user_account(
|
||||
actor.id,
|
||||
context.pool(),
|
||||
&mut context.pool(),
|
||||
context.settings(),
|
||||
context.client(),
|
||||
)
|
||||
|
|
|
@ -64,7 +64,7 @@ impl SendActivity for DeletePost {
|
|||
context: &Data<LemmyContext>,
|
||||
) -> Result<(), LemmyError> {
|
||||
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
|
||||
let community = Community::read(context.pool(), response.post_view.community.id).await?;
|
||||
let community = Community::read(&mut context.pool(), response.post_view.community.id).await?;
|
||||
let deletable = DeletableObjects::Post(response.post_view.post.clone().into());
|
||||
send_apub_delete_in_community(
|
||||
local_user_view.person,
|
||||
|
@ -88,7 +88,7 @@ impl SendActivity for RemovePost {
|
|||
context: &Data<LemmyContext>,
|
||||
) -> Result<(), LemmyError> {
|
||||
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
|
||||
let community = Community::read(context.pool(), response.post_view.community.id).await?;
|
||||
let community = Community::read(&mut context.pool(), response.post_view.community.id).await?;
|
||||
let deletable = DeletableObjects::Post(response.post_view.post.clone().into());
|
||||
send_apub_delete_in_community(
|
||||
local_user_view.person,
|
||||
|
@ -112,8 +112,8 @@ impl SendActivity for DeleteComment {
|
|||
context: &Data<LemmyContext>,
|
||||
) -> Result<(), LemmyError> {
|
||||
let community_id = response.comment_view.community.id;
|
||||
let community = Community::read(context.pool(), community_id).await?;
|
||||
let person = Person::read(context.pool(), response.comment_view.creator.id).await?;
|
||||
let community = Community::read(&mut context.pool(), community_id).await?;
|
||||
let person = Person::read(&mut context.pool(), response.comment_view.creator.id).await?;
|
||||
let deletable = DeletableObjects::Comment(response.comment_view.comment.clone().into());
|
||||
send_apub_delete_in_community(person, community, deletable, None, request.deleted, context)
|
||||
.await
|
||||
|
@ -130,8 +130,9 @@ impl SendActivity for RemoveComment {
|
|||
context: &Data<LemmyContext>,
|
||||
) -> Result<(), LemmyError> {
|
||||
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
|
||||
let comment = Comment::read(context.pool(), request.comment_id).await?;
|
||||
let community = Community::read(context.pool(), response.comment_view.community.id).await?;
|
||||
let comment = Comment::read(&mut context.pool(), request.comment_id).await?;
|
||||
let community =
|
||||
Community::read(&mut context.pool(), response.comment_view.community.id).await?;
|
||||
let deletable = DeletableObjects::Comment(comment.into());
|
||||
send_apub_delete_in_community(
|
||||
local_user_view.person,
|
||||
|
@ -175,7 +176,7 @@ impl SendActivity for DeleteCommunity {
|
|||
context: &Data<LemmyContext>,
|
||||
) -> Result<(), LemmyError> {
|
||||
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
|
||||
let community = Community::read(context.pool(), request.community_id).await?;
|
||||
let community = Community::read(&mut context.pool(), request.community_id).await?;
|
||||
let deletable = DeletableObjects::Community(community.clone().into());
|
||||
send_apub_delete_in_community(
|
||||
local_user_view.person,
|
||||
|
@ -199,7 +200,7 @@ impl SendActivity for RemoveCommunity {
|
|||
context: &Data<LemmyContext>,
|
||||
) -> Result<(), LemmyError> {
|
||||
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
|
||||
let community = Community::read(context.pool(), request.community_id).await?;
|
||||
let community = Community::read(&mut context.pool(), request.community_id).await?;
|
||||
let deletable = DeletableObjects::Community(community.clone().into());
|
||||
send_apub_delete_in_community(
|
||||
local_user_view.person,
|
||||
|
@ -252,7 +253,9 @@ async fn send_apub_delete_private_message(
|
|||
context: &Data<LemmyContext>,
|
||||
) -> Result<(), LemmyError> {
|
||||
let recipient_id = pm.recipient_id;
|
||||
let recipient: ApubPerson = Person::read(context.pool(), recipient_id).await?.into();
|
||||
let recipient: ApubPerson = Person::read(&mut context.pool(), recipient_id)
|
||||
.await?
|
||||
.into();
|
||||
|
||||
let deletable = DeletableObjects::PrivateMessage(pm.into());
|
||||
let inbox = vec![recipient.shared_inbox_or_inbox()];
|
||||
|
@ -388,7 +391,7 @@ async fn receive_delete_action(
|
|||
}
|
||||
|
||||
Community::update(
|
||||
context.pool(),
|
||||
&mut context.pool(),
|
||||
community.id,
|
||||
&CommunityUpdateForm::builder()
|
||||
.deleted(Some(deleted))
|
||||
|
@ -399,7 +402,7 @@ async fn receive_delete_action(
|
|||
DeletableObjects::Post(post) => {
|
||||
if deleted != post.deleted {
|
||||
Post::update(
|
||||
context.pool(),
|
||||
&mut context.pool(),
|
||||
post.id,
|
||||
&PostUpdateForm::builder().deleted(Some(deleted)).build(),
|
||||
)
|
||||
|
@ -409,7 +412,7 @@ async fn receive_delete_action(
|
|||
DeletableObjects::Comment(comment) => {
|
||||
if deleted != comment.deleted {
|
||||
Comment::update(
|
||||
context.pool(),
|
||||
&mut context.pool(),
|
||||
comment.id,
|
||||
&CommentUpdateForm::builder().deleted(Some(deleted)).build(),
|
||||
)
|
||||
|
@ -418,7 +421,7 @@ async fn receive_delete_action(
|
|||
}
|
||||
DeletableObjects::PrivateMessage(pm) => {
|
||||
PrivateMessage::update(
|
||||
context.pool(),
|
||||
&mut context.pool(),
|
||||
pm.id,
|
||||
&PrivateMessageUpdateForm::builder()
|
||||
.deleted(Some(deleted))
|
||||
|
|
|
@ -111,9 +111,9 @@ impl UndoDelete {
|
|||
reason: None,
|
||||
expires: None,
|
||||
};
|
||||
ModRemoveCommunity::create(context.pool(), &form).await?;
|
||||
ModRemoveCommunity::create(&mut context.pool(), &form).await?;
|
||||
Community::update(
|
||||
context.pool(),
|
||||
&mut context.pool(),
|
||||
community.id,
|
||||
&CommunityUpdateForm::builder().removed(Some(false)).build(),
|
||||
)
|
||||
|
@ -126,9 +126,9 @@ impl UndoDelete {
|
|||
removed: Some(false),
|
||||
reason: None,
|
||||
};
|
||||
ModRemovePost::create(context.pool(), &form).await?;
|
||||
ModRemovePost::create(&mut context.pool(), &form).await?;
|
||||
Post::update(
|
||||
context.pool(),
|
||||
&mut context.pool(),
|
||||
post.id,
|
||||
&PostUpdateForm::builder().removed(Some(false)).build(),
|
||||
)
|
||||
|
@ -141,9 +141,9 @@ impl UndoDelete {
|
|||
removed: Some(false),
|
||||
reason: None,
|
||||
};
|
||||
ModRemoveComment::create(context.pool(), &form).await?;
|
||||
ModRemoveComment::create(&mut context.pool(), &form).await?;
|
||||
Comment::update(
|
||||
context.pool(),
|
||||
&mut context.pool(),
|
||||
comment.id,
|
||||
&CommentUpdateForm::builder().removed(Some(false)).build(),
|
||||
)
|
||||
|
|
|
@ -66,7 +66,7 @@ impl ActivityHandler for AcceptFollow {
|
|||
// This will throw an error if no follow was requested
|
||||
let community_id = community.id;
|
||||
let person_id = person.id;
|
||||
CommunityFollower::follow_accepted(context.pool(), community_id, person_id).await?;
|
||||
CommunityFollower::follow_accepted(&mut context.pool(), community_id, person_id).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@ impl Follow {
|
|||
person_id: actor.id,
|
||||
pending: true,
|
||||
};
|
||||
CommunityFollower::follow(context.pool(), &community_follower_form)
|
||||
CommunityFollower::follow(&mut context.pool(), &community_follower_form)
|
||||
.await
|
||||
.ok();
|
||||
|
||||
|
@ -113,7 +113,7 @@ impl ActivityHandler for Follow {
|
|||
follower_id: actor.id,
|
||||
pending: false,
|
||||
};
|
||||
PersonFollower::follow(context.pool(), &form).await?;
|
||||
PersonFollower::follow(&mut context.pool(), &form).await?;
|
||||
}
|
||||
UserOrCommunity::Community(c) => {
|
||||
let form = CommunityFollowerForm {
|
||||
|
@ -121,7 +121,7 @@ impl ActivityHandler for Follow {
|
|||
person_id: actor.id,
|
||||
pending: false,
|
||||
};
|
||||
CommunityFollower::follow(context.pool(), &form).await?;
|
||||
CommunityFollower::follow(&mut context.pool(), &form).await?;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -139,7 +139,7 @@ impl SendActivity for BlockCommunity {
|
|||
context: &Data<LemmyContext>,
|
||||
) -> Result<(), LemmyError> {
|
||||
let local_user_view = local_user_view_from_jwt(&request.auth, context).await?;
|
||||
let community = Community::read(context.pool(), request.community_id).await?;
|
||||
let community = Community::read(&mut context.pool(), request.community_id).await?;
|
||||
UndoFollow::send(&local_user_view.person.into(), &community.into(), context).await
|
||||
}
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue