mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-21 22:27:08 +00:00
* Dont blank out post or community info. Fixes #1813 * Fix federation tests * Only blank out info for non-logged in users. * Remove pointless trait. * Blank the community if deleted for post * Fix hook * Fixing again * Fixing again * Fixing again
This commit is contained in:
parent
f4bac6a17f
commit
d9ecabee87
|
@ -75,7 +75,7 @@ test('Delete community', async () => {
|
||||||
communityRes.community_view.community.id
|
communityRes.community_view.community.id
|
||||||
);
|
);
|
||||||
expect(deleteCommunityRes.community_view.community.deleted).toBe(true);
|
expect(deleteCommunityRes.community_view.community.deleted).toBe(true);
|
||||||
expect(deleteCommunityRes.community_view.community.title).toBe("");
|
expect(deleteCommunityRes.community_view.community.title).toBe(communityRes.community_view.community.title);
|
||||||
|
|
||||||
// Make sure it got deleted on A
|
// Make sure it got deleted on A
|
||||||
let communityOnAlphaDeleted = await getCommunity(
|
let communityOnAlphaDeleted = await getCommunity(
|
||||||
|
@ -126,7 +126,7 @@ test('Remove community', async () => {
|
||||||
communityRes.community_view.community.id
|
communityRes.community_view.community.id
|
||||||
);
|
);
|
||||||
expect(removeCommunityRes.community_view.community.removed).toBe(true);
|
expect(removeCommunityRes.community_view.community.removed).toBe(true);
|
||||||
expect(removeCommunityRes.community_view.community.title).toBe("");
|
expect(removeCommunityRes.community_view.community.title).toBe(communityRes.community_view.community.title);
|
||||||
|
|
||||||
// Make sure it got Removed on A
|
// Make sure it got Removed on A
|
||||||
let communityOnAlphaRemoved = await getCommunity(
|
let communityOnAlphaRemoved = await getCommunity(
|
||||||
|
|
|
@ -206,7 +206,7 @@ test('Delete a post', async () => {
|
||||||
|
|
||||||
let deletedPost = await deletePost(alpha, true, postRes.post_view.post);
|
let deletedPost = await deletePost(alpha, true, postRes.post_view.post);
|
||||||
expect(deletedPost.post_view.post.deleted).toBe(true);
|
expect(deletedPost.post_view.post.deleted).toBe(true);
|
||||||
expect(deletedPost.post_view.post.name).toBe("");
|
expect(deletedPost.post_view.post.name).toBe(postRes.post_view.post.name);
|
||||||
|
|
||||||
// Make sure lemmy beta sees post is deleted
|
// Make sure lemmy beta sees post is deleted
|
||||||
let betaPost = (await resolvePost(beta, postRes.post_view.post)).post;
|
let betaPost = (await resolvePost(beta, postRes.post_view.post)).post;
|
||||||
|
@ -232,7 +232,7 @@ test('Remove a post from admin and community on different instance', async () =>
|
||||||
|
|
||||||
let removedPost = await removePost(alpha, true, postRes.post_view.post);
|
let removedPost = await removePost(alpha, true, postRes.post_view.post);
|
||||||
expect(removedPost.post_view.post.removed).toBe(true);
|
expect(removedPost.post_view.post.removed).toBe(true);
|
||||||
expect(removedPost.post_view.post.name).toBe("");
|
expect(removedPost.post_view.post.name).toBe(postRes.post_view.post.name);
|
||||||
|
|
||||||
// Make sure lemmy beta sees post is NOT removed
|
// Make sure lemmy beta sees post is NOT removed
|
||||||
let betaPost = (await resolvePost(beta, postRes.post_view.post)).post;
|
let betaPost = (await resolvePost(beta, postRes.post_view.post)).post;
|
||||||
|
|
|
@ -339,26 +339,28 @@ impl Perform for Search {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Blank out deleted or removed info
|
// Blank out deleted or removed info for non logged in users
|
||||||
for cv in comments
|
if person_id.is_none() {
|
||||||
.iter_mut()
|
for cv in communities
|
||||||
.filter(|cv| cv.comment.deleted || cv.comment.removed)
|
.iter_mut()
|
||||||
{
|
.filter(|cv| cv.community.deleted || cv.community.removed)
|
||||||
cv.comment = cv.to_owned().comment.blank_out_deleted_or_removed_info();
|
{
|
||||||
}
|
cv.community = cv.to_owned().community.blank_out_deleted_or_removed_info();
|
||||||
|
}
|
||||||
|
|
||||||
for cv in communities
|
for pv in posts
|
||||||
.iter_mut()
|
.iter_mut()
|
||||||
.filter(|cv| cv.community.deleted || cv.community.removed)
|
.filter(|p| p.post.deleted || p.post.removed)
|
||||||
{
|
{
|
||||||
cv.community = cv.to_owned().community.blank_out_deleted_or_removed_info();
|
pv.post = pv.to_owned().post.blank_out_deleted_or_removed_info();
|
||||||
}
|
}
|
||||||
|
|
||||||
for pv in posts
|
for cv in comments
|
||||||
.iter_mut()
|
.iter_mut()
|
||||||
.filter(|p| p.post.deleted || p.post.removed)
|
.filter(|cv| cv.comment.deleted || cv.comment.removed)
|
||||||
{
|
{
|
||||||
pv.post = pv.to_owned().post.blank_out_deleted_or_removed_info();
|
cv.comment = cv.to_owned().comment.blank_out_deleted_or_removed_info();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the jwt
|
// Return the jwt
|
||||||
|
|
|
@ -55,8 +55,9 @@ impl PerformCrud for GetCommunity {
|
||||||
.await?
|
.await?
|
||||||
.map_err(|e| ApiError::err("couldnt_find_community", e))?;
|
.map_err(|e| ApiError::err("couldnt_find_community", e))?;
|
||||||
|
|
||||||
// Blank out deleted or removed info
|
// Blank out deleted or removed info for non-logged in users
|
||||||
if community_view.community.deleted || community_view.community.removed {
|
if person_id.is_none() && (community_view.community.deleted || community_view.community.removed)
|
||||||
|
{
|
||||||
community_view.community = community_view.community.blank_out_deleted_or_removed_info();
|
community_view.community = community_view.community.blank_out_deleted_or_removed_info();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,12 +122,14 @@ impl PerformCrud for ListCommunities {
|
||||||
})
|
})
|
||||||
.await??;
|
.await??;
|
||||||
|
|
||||||
// Blank out deleted or removed info
|
// Blank out deleted or removed info for non-logged in users
|
||||||
for cv in communities
|
if person_id.is_none() {
|
||||||
.iter_mut()
|
for cv in communities
|
||||||
.filter(|cv| cv.community.deleted || cv.community.removed)
|
.iter_mut()
|
||||||
{
|
.filter(|cv| cv.community.deleted || cv.community.removed)
|
||||||
cv.community = cv.to_owned().community.blank_out_deleted_or_removed_info();
|
{
|
||||||
|
cv.community = cv.to_owned().community.blank_out_deleted_or_removed_info();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the jwt
|
// Return the jwt
|
||||||
|
|
|
@ -44,11 +44,6 @@ impl PerformCrud for GetPost {
|
||||||
.await?
|
.await?
|
||||||
.map_err(|e| ApiError::err("couldnt_find_post", e))?;
|
.map_err(|e| ApiError::err("couldnt_find_post", e))?;
|
||||||
|
|
||||||
// Blank out deleted info
|
|
||||||
if post_view.post.deleted || post_view.post.removed {
|
|
||||||
post_view.post = post_view.post.blank_out_deleted_or_removed_info();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Mark the post as read
|
// Mark the post as read
|
||||||
if let Some(person_id) = person_id {
|
if let Some(person_id) = person_id {
|
||||||
mark_post_as_read(person_id, id, context.pool()).await?;
|
mark_post_as_read(person_id, id, context.pool()).await?;
|
||||||
|
@ -65,32 +60,36 @@ impl PerformCrud for GetPost {
|
||||||
})
|
})
|
||||||
.await??;
|
.await??;
|
||||||
|
|
||||||
// Blank out deleted or removed info
|
|
||||||
for cv in comments
|
|
||||||
.iter_mut()
|
|
||||||
.filter(|cv| cv.comment.deleted || cv.comment.removed)
|
|
||||||
{
|
|
||||||
cv.comment = cv.to_owned().comment.blank_out_deleted_or_removed_info();
|
|
||||||
}
|
|
||||||
|
|
||||||
let community_id = post_view.community.id;
|
|
||||||
let moderators = blocking(context.pool(), move |conn| {
|
|
||||||
CommunityModeratorView::for_community(conn, community_id)
|
|
||||||
})
|
|
||||||
.await??;
|
|
||||||
|
|
||||||
// Necessary for the sidebar
|
// Necessary for the sidebar
|
||||||
|
let community_id = post_view.community.id;
|
||||||
let mut community_view = blocking(context.pool(), move |conn| {
|
let mut community_view = blocking(context.pool(), move |conn| {
|
||||||
CommunityView::read(conn, community_id, person_id)
|
CommunityView::read(conn, community_id, person_id)
|
||||||
})
|
})
|
||||||
.await?
|
.await?
|
||||||
.map_err(|e| ApiError::err("couldnt_find_community", e))?;
|
.map_err(|e| ApiError::err("couldnt_find_community", e))?;
|
||||||
|
|
||||||
// Blank out deleted or removed info
|
// Blank out deleted or removed info for non-logged in users
|
||||||
if community_view.community.deleted || community_view.community.removed {
|
if person_id.is_none() {
|
||||||
community_view.community = community_view.community.blank_out_deleted_or_removed_info();
|
if post_view.post.deleted || post_view.post.removed {
|
||||||
|
post_view.post = post_view.post.blank_out_deleted_or_removed_info();
|
||||||
|
}
|
||||||
|
|
||||||
|
for cv in comments
|
||||||
|
.iter_mut()
|
||||||
|
.filter(|cv| cv.comment.deleted || cv.comment.removed)
|
||||||
|
{
|
||||||
|
cv.comment = cv.to_owned().comment.blank_out_deleted_or_removed_info();
|
||||||
|
}
|
||||||
|
if community_view.community.deleted || community_view.community.removed {
|
||||||
|
community_view.community = community_view.community.blank_out_deleted_or_removed_info();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let moderators = blocking(context.pool(), move |conn| {
|
||||||
|
CommunityModeratorView::for_community(conn, community_id)
|
||||||
|
})
|
||||||
|
.await??;
|
||||||
|
|
||||||
let online = context
|
let online = context
|
||||||
.chat_server()
|
.chat_server()
|
||||||
.send(GetPostUsersOnline { post_id: data.id })
|
.send(GetPostUsersOnline { post_id: data.id })
|
||||||
|
@ -162,12 +161,21 @@ impl PerformCrud for GetPosts {
|
||||||
.await?
|
.await?
|
||||||
.map_err(|e| ApiError::err("couldnt_get_posts", e))?;
|
.map_err(|e| ApiError::err("couldnt_get_posts", e))?;
|
||||||
|
|
||||||
// Blank out deleted or removed info
|
// Blank out deleted or removed info for non-logged in users
|
||||||
for pv in posts
|
if person_id.is_none() {
|
||||||
.iter_mut()
|
for pv in posts
|
||||||
.filter(|p| p.post.deleted || p.post.removed)
|
.iter_mut()
|
||||||
{
|
.filter(|p| p.post.deleted || p.post.removed)
|
||||||
pv.post = pv.to_owned().post.blank_out_deleted_or_removed_info();
|
{
|
||||||
|
pv.post = pv.to_owned().post.blank_out_deleted_or_removed_info();
|
||||||
|
}
|
||||||
|
|
||||||
|
for pv in posts
|
||||||
|
.iter_mut()
|
||||||
|
.filter(|p| p.community.deleted || p.community.removed)
|
||||||
|
{
|
||||||
|
pv.community = pv.to_owned().community.blank_out_deleted_or_removed_info();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(GetPostsResponse { posts })
|
Ok(GetPostsResponse { posts })
|
||||||
|
|
|
@ -43,15 +43,11 @@ pub async fn send_post_ws_message<OP: ToString + Send + OperationType + 'static>
|
||||||
person_id: Option<PersonId>,
|
person_id: Option<PersonId>,
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
) -> Result<PostResponse, LemmyError> {
|
) -> Result<PostResponse, LemmyError> {
|
||||||
let mut post_view = blocking(context.pool(), move |conn| {
|
let post_view = blocking(context.pool(), move |conn| {
|
||||||
PostView::read(conn, post_id, person_id)
|
PostView::read(conn, post_id, person_id)
|
||||||
})
|
})
|
||||||
.await??;
|
.await??;
|
||||||
|
|
||||||
if post_view.post.deleted || post_view.post.removed {
|
|
||||||
post_view.post = post_view.post.blank_out_deleted_or_removed_info();
|
|
||||||
}
|
|
||||||
|
|
||||||
let res = PostResponse { post_view };
|
let res = PostResponse { post_view };
|
||||||
|
|
||||||
context.chat_server().do_send(SendPost {
|
context.chat_server().do_send(SendPost {
|
||||||
|
@ -118,14 +114,10 @@ pub async fn send_community_ws_message<OP: ToString + Send + OperationType + 'st
|
||||||
person_id: Option<PersonId>,
|
person_id: Option<PersonId>,
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
) -> Result<CommunityResponse, LemmyError> {
|
) -> Result<CommunityResponse, LemmyError> {
|
||||||
let mut community_view = blocking(context.pool(), move |conn| {
|
let community_view = blocking(context.pool(), move |conn| {
|
||||||
CommunityView::read(conn, community_id, person_id)
|
CommunityView::read(conn, community_id, person_id)
|
||||||
})
|
})
|
||||||
.await??;
|
.await??;
|
||||||
// Blank out deleted or removed info
|
|
||||||
if community_view.community.deleted || community_view.community.removed {
|
|
||||||
community_view.community = community_view.community.blank_out_deleted_or_removed_info();
|
|
||||||
}
|
|
||||||
|
|
||||||
let res = CommunityResponse { community_view };
|
let res = CommunityResponse { community_view };
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue