Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Post remove delete federation outbound fix0 #3613

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions crates/api_common/src/build_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,25 @@ pub async fn build_post_response(
Ok(PostResponse { post_view })
}

// this is a variation of build_post_response that returns post even if end-user-delted or mod-removed.
// Assumption is that before this function is ever called, the user is already confirmed to be authorized to view post.
// See GitHub Issue #3588
pub async fn build_post_response_deleted_allowed(
context: &Data<LemmyContext>,
_community_id: CommunityId,
person_id: PersonId,
post_id: PostId,
) -> Result<PostResponse, LemmyError> {
let post_view = PostView::read(
&mut context.pool(),
post_id,
Some(person_id),
Some(true),
)
.await?;
Ok(PostResponse { post_view })
}

// TODO: this function is a mess and should be split up to handle email seperately
#[tracing::instrument(skip_all)]
pub async fn send_local_notifs(
Expand Down
4 changes: 2 additions & 2 deletions crates/api_crud/src/post/delete.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::PerformCrud;
use actix_web::web::Data;
use lemmy_api_common::{
build_response::build_post_response,
build_response::build_post_response_deleted_allowed,
context::LemmyContext,
post::{DeletePost, PostResponse},
utils::{check_community_ban, check_community_deleted_or_removed, local_user_view_from_jwt},
Expand Down Expand Up @@ -52,7 +52,7 @@ impl PerformCrud for DeletePost {
)
.await?;

build_post_response(
build_post_response_deleted_allowed(
context,
orig_post.community_id,
local_user_view.person.id,
Expand Down
4 changes: 2 additions & 2 deletions crates/api_crud/src/post/remove.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::PerformCrud;
use actix_web::web::Data;
use lemmy_api_common::{
build_response::build_post_response,
build_response::build_post_response_deleted_allowed,
context::LemmyContext,
post::{PostResponse, RemovePost},
utils::{check_community_ban, is_mod_or_admin, local_user_view_from_jwt},
Expand Down Expand Up @@ -61,7 +61,7 @@ impl PerformCrud for RemovePost {
};
ModRemovePost::create(&mut context.pool(), &form).await?;

build_post_response(
build_post_response_deleted_allowed(
context,
orig_post.community_id,
local_user_view.person.id,
Expand Down
1 change: 1 addition & 0 deletions crates/db_views/src/post_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ impl PostView {
.into_boxed();

// Hide deleted and removed for non-admins or mods
// Note: one special use case for this flag variable is when end-user-delete post or mod-removed post.
if !is_mod_or_admin.unwrap_or(false) {
query = query
.filter(community::removed.eq(false))
Expand Down