commentRes.comment_view.comment.id
);
expect(deleteCommentRes.comment_view.comment.deleted).toBe(true);
- expect(deleteCommentRes.comment_view.comment.content).toBe("");
// Make sure that comment is undefined on beta
let betaCommentRes = (await resolveComment(
// The beta admin removes it (the community lives on beta)
let removeCommentRes = await removeComment(beta, true, betaCommentId);
expect(removeCommentRes.comment_view.comment.removed).toBe(true);
- expect(removeCommentRes.comment_view.comment.content).toBe("");
// Make sure that comment is removed on alpha (it gets pushed since an admin from beta removed it)
let refetchedPostComments = await getComments(
// existing alpha post should be removed on beta
let searchBeta2 = await searchPostLocal(beta, postRes1.post_view.post);
- expect(searchBeta2.posts[0]).toBeUndefined();
+ expect(searchBeta2.posts[0].post.removed).toBe(true);
// Unban alpha
let unBanAlpha = await banPersonFromSite(
// ensure that the post by alpha got removed
let searchAlpha1 = await searchPostLocal(alpha, postRes1.post_view.post);
- expect(searchAlpha1.posts[0]).toBeUndefined();
+ expect(searchAlpha1.posts[0].post.removed).toBe(true);
// Alpha tries to make post on beta, but it fails because of ban
let postRes2 = await createPost(alpha, betaCommunity.community.id);
pmRes.private_message_view.private_message.id
);
expect(deletedPmRes.private_message_view.private_message.deleted).toBe(true);
- expect(deletedPmRes.private_message_view.private_message.content).toBe("");
// The GetPrivateMessages filters out deleted,
// even though they are in the actual database.
resolved "https://registry.yarnpkg.com/kleur/-/kleur-3.0.3.tgz#a79c9ecc86ee1ce3fa6206d1216c501f147fc07e"
integrity sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==
-lemmy-js-client@0.17.0-rc.61:
- version "0.17.0-rc.61"
- resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.17.0-rc.61.tgz#c01e129a3d4c3483ecf337f1e4acf0ad91f9684f"
- integrity sha512-xauBCD5i4vlUEWqsTMIXLCXeIjAK7ivVIN3C/g+RMAM7mD3CTcRkDZUerwnvLipIfr7V/4iYLWZW0orBaiV1CQ==
+lemmy-js-client@0.17.2-rc.1:
+ version "0.17.2-rc.1"
+ resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.17.2-rc.1.tgz#fe8d1508311bbf245acc98c2c3e47e2165a95b14"
+ integrity sha512-YrOXuCofgkqp28krmPTQZAfUWL5zEDA0sRJ0abKcgf/I8YYkYkUkPS9TOORN5Lv3bc8RAAz4+2/zLHqYL/Tnow==
dependencies:
node-fetch "2.6.6"
.map_err(|e| LemmyError::from_error_message(e, "community_block_already_exists"))?;
}
- let community_view = CommunityView::read(context.pool(), community_id, Some(person_id)).await?;
+ let community_view =
+ CommunityView::read(context.pool(), community_id, Some(person_id), None).await?;
Ok(BlockCommunityResponse {
blocked: data.block,
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)).await?;
+ let community_view =
+ CommunityView::read(context.pool(), community_id, Some(person_id), None).await?;
let discussion_languages = CommunityLanguage::read(context.pool(), community_id).await?;
Ok(Self::Response {
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))
+ 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"))?;
}
// Fetch it
- let post_view = PostView::read(context.pool(), post_id, Some(person_id)).await?;
+ let post_view = PostView::read(context.pool(), post_id, Some(person_id), None).await?;
let res = Self::Response { post_view };
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)).await?;
+ let post_view = PostView::read(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?;
let person_id = local_user_view.person.id;
let post_id = data.post_id;
- let post_view = PostView::read(context.pool(), post_id, None).await?;
+ let post_view = PostView::read(context.pool(), post_id, None, None).await?;
check_community_ban(person_id, post_view.community.id, context.pool()).await?;
Ok(())
}
+#[tracing::instrument(skip_all)]
+pub async fn is_mod_or_admin_opt(
+ pool: &DbPool,
+ local_user_view: Option<&LocalUserView>,
+ community_id: Option<CommunityId>,
+) -> Result<(), LemmyError> {
+ if let Some(local_user_view) = local_user_view {
+ if let Some(community_id) = community_id {
+ is_mod_or_admin(pool, local_user_view.person.id, community_id).await
+ } else {
+ is_admin(local_user_view)
+ }
+ } else {
+ Err(LemmyError::from_message("not_a_mod_or_admin"))
+ }
+}
+
pub async fn is_top_admin(pool: &DbPool, person_id: PersonId) -> Result<(), LemmyError> {
let admins = PersonViewSafe::admins(pool).await?;
let top_admin = admins
person_mention::{PersonMention, PersonMentionInsertForm},
post::Post,
},
- traits::{Crud, DeleteableOrRemoveable},
+ traits::Crud,
SubscribedType,
};
use lemmy_db_views::structs::{CommentView, LocalUserView, PostView, PrivateMessageView};
person_id: Option<PersonId>,
context: &LemmyContext,
) -> Result<PostResponse, LemmyError> {
- let post_view = PostView::read(context.pool(), post_id, person_id).await?;
+ let post_view = PostView::read(context.pool(), post_id, person_id, Some(true)).await?;
let res = PostResponse { post_view };
recipient_ids: Vec<LocalUserId>,
context: &LemmyContext,
) -> Result<CommentResponse, LemmyError> {
- let mut view = CommentView::read(context.pool(), comment_id, person_id).await?;
-
- if view.comment.deleted || view.comment.removed {
- view.comment = view.comment.blank_out_deleted_or_removed_info();
- }
+ let view = CommentView::read(context.pool(), comment_id, person_id).await?;
let mut res = CommentResponse {
comment_view: view,
person_id: Option<PersonId>,
context: &LemmyContext,
) -> Result<CommunityResponse, LemmyError> {
- let community_view = CommunityView::read(context.pool(), community_id, person_id).await?;
+ let community_view =
+ CommunityView::read(context.pool(), community_id, person_id, Some(true)).await?;
let discussion_languages = CommunityLanguage::read(context.pool(), community_id).await?;
let mut res = CommunityResponse {
websocket_id: Option<ConnectionId>,
context: &LemmyContext,
) -> Result<PrivateMessageResponse, LemmyError> {
- let mut view = PrivateMessageView::read(context.pool(), private_message_id).await?;
-
- // Blank out deleted or removed info
- if view.private_message.deleted {
- view.private_message = view.private_message.blank_out_deleted_or_removed_info();
- }
+ let view = PrivateMessageView::read(context.pool(), private_message_id).await?;
let res = PrivateMessageResponse {
private_message_view: view,
let person_id = local_user_view.person.id;
let community_view =
- CommunityView::read(context.pool(), inserted_community.id, Some(person_id)).await?;
+ CommunityView::read(context.pool(), inserted_community.id, Some(person_id), None).await?;
let discussion_languages =
CommunityLanguage::read(context.pool(), inserted_community.id).await?;
use lemmy_api_common::{
community::{ListCommunities, ListCommunitiesResponse},
context::LemmyContext,
- utils::{check_private_instance, get_local_user_view_from_jwt_opt},
+ utils::{check_private_instance, get_local_user_view_from_jwt_opt, is_admin},
};
-use lemmy_db_schema::{source::local_site::LocalSite, traits::DeleteableOrRemoveable};
+use lemmy_db_schema::source::local_site::LocalSite;
use lemmy_db_views_actor::community_view::CommunityQuery;
use lemmy_utils::{error::LemmyError, ConnectionId};
get_local_user_view_from_jwt_opt(data.auth.as_ref(), context.pool(), context.secret())
.await?;
let local_site = LocalSite::read(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)?;
- let person_id = local_user_view.clone().map(|l| l.person.id);
-
let sort = data.sort;
let listing_type = data.type_;
let page = data.page;
let limit = data.limit;
let local_user = local_user_view.map(|l| l.local_user);
- let mut communities = CommunityQuery::builder()
+ let communities = CommunityQuery::builder()
.pool(context.pool())
.listing_type(listing_type)
.sort(sort)
.local_user(local_user.as_ref())
.page(page)
.limit(limit)
+ .is_mod_or_admin(is_admin)
.build()
.list()
.await?;
- // Blank out deleted or removed info for non-logged in users
- if person_id.is_none() {
- for cv in communities
- .iter_mut()
- .filter(|cv| cv.community.deleted || cv.community.removed)
- {
- cv.community = cv.clone().community.blank_out_deleted_or_removed_info();
- }
- }
-
// Return the jwt
Ok(ListCommunitiesResponse { communities })
}
use lemmy_api_common::{
context::LemmyContext,
post::{GetPost, GetPostResponse},
- utils::{check_private_instance, get_local_user_view_from_jwt_opt, mark_post_as_read},
+ utils::{
+ check_private_instance,
+ get_local_user_view_from_jwt_opt,
+ is_mod_or_admin_opt,
+ mark_post_as_read,
+ },
};
use lemmy_db_schema::{
aggregates::structs::{PersonPostAggregates, PersonPostAggregatesForm},
- source::{comment::Comment, local_site::LocalSite},
- traits::{Crud, DeleteableOrRemoveable},
+ source::{comment::Comment, local_site::LocalSite, post::Post},
+ traits::Crud,
};
use lemmy_db_views::structs::PostView;
use lemmy_db_views_actor::structs::{CommunityModeratorView, CommunityView};
check_private_instance(&local_user_view, &local_site)?;
- let person_id = local_user_view.map(|u| u.person.id);
+ let person_id = local_user_view.as_ref().map(|u| u.person.id);
// I'd prefer fetching the post_view by a comment join, but it adds a lot of boilerplate
let post_id = if let Some(id) = data.id {
Err(LemmyError::from_message("couldnt_find_post"))?
};
- let mut post_view = PostView::read(context.pool(), post_id, person_id)
+ // 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 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"))?;
}
// Necessary for the sidebar subscribed
- let community_id = post_view.community.id;
- let mut community_view = CommunityView::read(context.pool(), community_id, person_id)
- .await
- .map_err(|e| LemmyError::from_error_message(e, "couldnt_find_community"))?;
+ let community_view = CommunityView::read(
+ context.pool(),
+ community_id,
+ person_id,
+ Some(is_mod_or_admin),
+ )
+ .await
+ .map_err(|e| LemmyError::from_error_message(e, "couldnt_find_community"))?;
// Insert into PersonPostAggregates
// to update the read_comments count
.map_err(|e| LemmyError::from_error_message(e, "couldnt_find_post"))?;
}
- // Blank out deleted or removed info for non-logged in users
- if person_id.is_none() {
- if post_view.post.deleted || post_view.post.removed {
- post_view.post = post_view.post.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 = CommunityModeratorView::for_community(context.pool(), community_id).await?;
let online = context.chat_server().get_post_users_online(post_id)?;
private_message::{GetPrivateMessages, PrivateMessagesResponse},
utils::get_local_user_view_from_jwt,
};
-use lemmy_db_schema::traits::DeleteableOrRemoveable;
use lemmy_db_views::private_message_view::PrivateMessageQuery;
use lemmy_utils::{error::LemmyError, ConnectionId};
}
});
- // Blank out deleted or removed info
- for pmv in messages
- .iter_mut()
- .filter(|pmv| pmv.private_message.deleted)
- {
- pmv.private_message = pmv
- .clone()
- .private_message
- .blank_out_deleted_or_removed_info();
- }
-
Ok(PrivateMessagesResponse {
private_messages: messages,
})
// Send the Subscribed message over websocket
// Re-read the community_view to get the new SubscribedType
- let community_view = CommunityView::read(context.pool(), community_id, Some(person_id)).await?;
+ let community_view =
+ CommunityView::read(context.pool(), community_id, Some(person_id), None).await?;
// Get the local_user_id
let local_recipient_id = LocalUserView::read_person(context.pool(), person_id)
};
use lemmy_db_schema::{
source::{comment::Comment, community::Community, local_site::LocalSite},
- traits::{Crud, DeleteableOrRemoveable},
+ traits::Crud,
};
use lemmy_db_views::comment_view::CommentQuery;
use lemmy_utils::{error::LemmyError, ConnectionId};
let parent_path_cloned = parent_path.clone();
let post_id = data.post_id;
let local_user = local_user_view.map(|l| l.local_user);
- let mut comments = CommentQuery::builder()
+ let comments = CommentQuery::builder()
.pool(context.pool())
.listing_type(Some(listing_type))
.sort(sort)
.await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_get_comments"))?;
- // Blank out deleted or removed info
- for cv in comments
- .iter_mut()
- .filter(|cv| cv.comment.deleted || cv.comment.removed)
- {
- cv.comment = cv.clone().comment.blank_out_deleted_or_removed_info();
- }
-
Ok(GetCommentsResponse { comments })
}
}
utils::{
check_private_instance,
get_local_user_view_from_jwt_opt,
+ is_mod_or_admin_opt,
listing_type_with_site_default,
},
};
-use lemmy_db_schema::{
- source::{community::Community, local_site::LocalSite},
- traits::DeleteableOrRemoveable,
-};
+use lemmy_db_schema::source::{community::Community, local_site::LocalSite};
use lemmy_db_views::post_view::PostQuery;
use lemmy_utils::{error::LemmyError, ConnectionId};
check_private_instance(&local_user_view, &local_site)?;
- let is_logged_in = local_user_view.is_some();
-
let sort = data.sort;
let listing_type = listing_type_with_site_default(data.type_, &local_site)?;
};
let saved_only = data.saved_only;
- let mut posts = PostQuery::builder()
+ let is_mod_or_admin =
+ is_mod_or_admin_opt(context.pool(), local_user_view.as_ref(), community_id)
+ .await
+ .is_ok();
+
+ let posts = PostQuery::builder()
.pool(context.pool())
.local_user(local_user_view.map(|l| l.local_user).as_ref())
.listing_type(Some(listing_type))
.saved_only(saved_only)
.page(page)
.limit(limit)
+ .is_mod_or_admin(Some(is_mod_or_admin))
.build()
.list()
.await
.map_err(|e| LemmyError::from_error_message(e, "couldnt_get_posts"))?;
- // Blank out deleted or removed info for non-logged in users
- if !is_logged_in {
- for pv in posts
- .iter_mut()
- .filter(|p| p.post.deleted || p.post.removed)
- {
- pv.post = pv.clone().post.blank_out_deleted_or_removed_info();
- }
-
- for pv in posts
- .iter_mut()
- .filter(|p| p.community.deleted || p.community.removed)
- {
- pv.community = pv.clone().community.blank_out_deleted_or_removed_info();
- }
- }
-
Ok(GetPostsResponse { posts })
}
}
use lemmy_api_common::{
community::{GetCommunity, GetCommunityResponse},
context::LemmyContext,
- utils::{check_private_instance, get_local_user_view_from_jwt_opt},
+ utils::{check_private_instance, get_local_user_view_from_jwt_opt, is_mod_or_admin_opt},
};
use lemmy_db_schema::{
impls::actor_language::default_post_language,
local_site::LocalSite,
site::Site,
},
- traits::DeleteableOrRemoveable,
};
use lemmy_db_views_actor::structs::{CommunityModeratorView, CommunityView};
use lemmy_utils::{error::LemmyError, ConnectionId};
}
};
- let mut community_view = CommunityView::read(context.pool(), community_id, person_id)
- .await
- .map_err(|e| LemmyError::from_error_message(e, "couldnt_find_community"))?;
+ let is_mod_or_admin =
+ is_mod_or_admin_opt(context.pool(), local_user_view.as_ref(), Some(community_id))
+ .await
+ .is_ok();
- // Blank out deleted or removed info for non-logged in users
- 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();
- }
+ let community_view = CommunityView::read(
+ context.pool(),
+ community_id,
+ person_id,
+ Some(is_mod_or_admin),
+ )
+ .await
+ .map_err(|e| LemmyError::from_error_message(e, "couldnt_find_community"))?;
let moderators = CommunityModeratorView::for_community(context.pool(), community_id)
.await
use lemmy_api_common::{
context::LemmyContext,
person::{GetPersonDetails, GetPersonDetailsResponse},
- utils::{check_private_instance, get_local_user_view_from_jwt_opt},
+ utils::{check_private_instance, get_local_user_view_from_jwt_opt, is_admin},
};
use lemmy_db_schema::{
source::{local_site::LocalSite, person::Person},
get_local_user_view_from_jwt_opt(data.auth.as_ref(), context.pool(), context.secret())
.await?;
let local_site = LocalSite::read(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)?;
.saved_only(saved_only)
.local_user(local_user.as_ref())
.community_id(community_id)
+ .is_mod_or_admin(is_admin)
.page(page)
.limit(limit);
}
Community(c) => {
removed_or_deleted = c.deleted || c.removed;
- res.community = Some(CommunityView::read(pool, c.id, user_id).await?)
+ res.community = Some(CommunityView::read(pool, c.id, user_id, None).await?)
}
Post(p) => {
removed_or_deleted = p.deleted || p.removed;
- res.post = Some(PostView::read(pool, p.id, user_id).await?)
+ res.post = Some(PostView::read(pool, p.id, user_id, None).await?)
}
Comment(c) => {
removed_or_deleted = c.deleted || c.removed;
use lemmy_api_common::{
context::LemmyContext,
site::{Search, SearchResponse},
- utils::{check_private_instance, get_local_user_view_from_jwt_opt},
+ utils::{check_private_instance, get_local_user_view_from_jwt_opt, is_admin},
};
use lemmy_db_schema::{
source::{community::Community, local_site::LocalSite},
- traits::DeleteableOrRemoveable,
utils::post_to_comment_sort_type,
SearchType,
};
check_private_instance(&local_user_view, &local_site)?;
- let person_id = local_user_view.as_ref().map(|u| u.person.id);
+ let is_admin = local_user_view.as_ref().map(|luv| is_admin(luv).is_ok());
+
let local_user = local_user_view.map(|l| l.local_user);
let mut posts = Vec::new();
.creator_id(creator_id)
.local_user(local_user.as_ref())
.search_term(Some(q))
+ .is_mod_or_admin(is_admin)
.page(page)
.limit(limit)
.build()
.listing_type(listing_type)
.search_term(Some(q))
.local_user(local_user.as_ref())
+ .is_mod_or_admin(is_admin)
.page(page)
.limit(limit)
.build()
.creator_id(creator_id)
.local_user(local_user_.as_ref())
.search_term(Some(q))
+ .is_mod_or_admin(is_admin)
.page(page)
.limit(limit)
.build()
.listing_type(listing_type)
.search_term(Some(q))
.local_user(local_user.as_ref())
+ .is_mod_or_admin(is_admin)
.page(page)
.limit(limit)
.build()
.community_actor_id(community_actor_id)
.creator_id(creator_id)
.url_search(Some(q))
+ .is_mod_or_admin(is_admin)
.page(page)
.limit(limit)
.build()
}
};
- // Blank out deleted or removed info for non logged in users
- if person_id.is_none() {
- for cv in communities
- .iter_mut()
- .filter(|cv| cv.community.deleted || cv.community.removed)
- {
- cv.community = cv.clone().community.blank_out_deleted_or_removed_info();
- }
-
- for pv in posts
- .iter_mut()
- .filter(|p| p.post.deleted || p.post.removed)
- {
- pv.post = pv.clone().post.blank_out_deleted_or_removed_info();
- }
-
- for cv in comments
- .iter_mut()
- .filter(|cv| cv.comment.deleted || cv.comment.removed)
- {
- cv.comment = cv.clone().comment.blank_out_deleted_or_removed_info();
- }
- }
-
// Return the jwt
Ok(SearchResponse {
type_: search_type.to_string(),
CommentSavedForm,
CommentUpdateForm,
},
- traits::{Crud, DeleteableOrRemoveable, Likeable, Saveable},
+ traits::{Crud, Likeable, Saveable},
utils::{get_conn, naive_now, DbPool},
};
use diesel::{
}
}
-impl DeleteableOrRemoveable for Comment {
- fn blank_out_deleted_or_removed_info(mut self) -> Self {
- self.content = String::new();
- self
- }
-}
-
#[cfg(test)]
mod tests {
use crate::{
CommunityModeratorForm,
CommunityPersonBan,
CommunityPersonBanForm,
- CommunitySafe,
CommunityUpdateForm,
},
},
- traits::{ApubActor, Bannable, Crud, DeleteableOrRemoveable, Followable, Joinable},
+ traits::{ApubActor, Bannable, Crud, Followable, Joinable},
utils::{functions::lower, get_conn, DbPool},
SubscribedType,
};
}
}
-impl DeleteableOrRemoveable for CommunitySafe {
- fn blank_out_deleted_or_removed_info(mut self) -> Self {
- self.title = String::new();
- self.description = None;
- self.icon = None;
- self.banner = None;
- self
- }
-}
-
-impl DeleteableOrRemoveable for Community {
- fn blank_out_deleted_or_removed_info(mut self) -> Self {
- self.title = String::new();
- self.description = None;
- self.icon = None;
- self.banner = None;
- self
- }
-}
-
pub enum CollectionType {
Moderators,
Featured,
PostSavedForm,
PostUpdateForm,
},
- traits::{Crud, DeleteableOrRemoveable, Likeable, Readable, Saveable},
+ traits::{Crud, Likeable, Readable, Saveable},
utils::{get_conn, naive_now, DbPool, FETCH_LIMIT_MAX},
};
use ::url::Url;
}
}
-impl DeleteableOrRemoveable for Post {
- fn blank_out_deleted_or_removed_info(mut self) -> Self {
- self.name = String::new();
- self.url = None;
- self.body = None;
- self.embed_title = None;
- self.embed_description = None;
- self.embed_video_url = None;
- self.thumbnail_url = None;
-
- self
- }
-}
-
#[cfg(test)]
mod tests {
use crate::{
newtypes::{DbUrl, PersonId, PrivateMessageId},
schema::private_message::dsl::{ap_id, private_message, read, recipient_id},
source::private_message::{PrivateMessage, PrivateMessageInsertForm, PrivateMessageUpdateForm},
- traits::{Crud, DeleteableOrRemoveable},
+ traits::Crud,
utils::{get_conn, DbPool},
};
use diesel::{dsl::insert_into, result::Error, ExpressionMethods, QueryDsl};
}
}
-impl DeleteableOrRemoveable for PrivateMessage {
- fn blank_out_deleted_or_removed_info(mut self) -> Self {
- self.content = String::new();
- self
- }
-}
-
#[cfg(test)]
mod tests {
use crate::{
Self: Sized;
}
-// TODO these should be removed, there should be another way to do this
-pub trait DeleteableOrRemoveable {
- fn blank_out_deleted_or_removed_info(self) -> Self;
-}
-
pub trait ToSafe {
type SafeColumns;
fn safe_columns_tuple() -> Self::SafeColumns;
pool: &DbPool,
post_id: PostId,
my_person_id: Option<PersonId>,
+ is_mod_or_admin: Option<bool>,
) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
// The left join below will return None in this case
let person_id_join = my_person_id.unwrap_or(PersonId(-1));
- let (
- post,
- creator,
- community,
- creator_banned_from_community,
- counts,
- follower,
- saved,
- read,
- creator_blocked,
- post_like,
- unread_comments,
- ) = post::table
+ let person_alias_1 = diesel::alias!(person as person1);
+ let mut query = post::table
.find(post_id)
.inner_join(person::table)
.inner_join(community::table)
.and(person_post_aggregates::person_id.eq(person_id_join)),
),
)
+ // Used to check if you are the post creator
+ .left_join(
+ person_alias_1.on(
+ post::creator_id
+ .eq(person_alias_1.field(person::id))
+ .and(person_alias_1.field(person::id).eq(person_id_join)),
+ ),
+ )
.select((
post::all_columns,
Person::safe_columns_tuple(),
post_aggregates::comments,
),
))
- .first::<PostViewTuple>(conn)
- .await?;
+ .into_boxed();
+
+ // If you are not a moderator, exclude deleted or removed content
+ if !is_mod_or_admin.unwrap_or(true) {
+ // If you are not the creator, then remove the other fields.
+ query = query
+ .filter(
+ person_alias_1.field(person::id).is_null().and(
+ post::removed
+ .eq(false)
+ .and(post::deleted.eq(false))
+ .and(community::removed.eq(false))
+ .and(community::deleted.eq(false)),
+ ),
+ )
+ // If you are the creator, keep them
+ .or_filter(person_alias_1.field(person::id).is_not_null())
+ }
+
+ let (
+ post,
+ creator,
+ community,
+ creator_banned_from_community,
+ counts,
+ follower,
+ saved,
+ read,
+ creator_blocked,
+ post_like,
+ unread_comments,
+ ) = query.first::<PostViewTuple>(conn).await?;
// If a person is given, then my_vote, if None, should be 0, not null
// Necessary to differentiate between other person's votes
search_term: Option<String>,
url_search: Option<String>,
saved_only: Option<bool>,
+ /// Used to show deleted or removed posts for admins
+ is_mod_or_admin: Option<bool>,
page: Option<i64>,
limit: Option<i64>,
}
// The left join below will return None in this case
let person_id_join = self.local_user.map(|l| l.person_id).unwrap_or(PersonId(-1));
let local_user_id_join = self.local_user.map(|l| l.id).unwrap_or(LocalUserId(-1));
+ let person_alias_1 = diesel::alias!(person as person1);
let mut query = post::table
.inner_join(person::table)
.and(local_user_language::local_user_id.eq(local_user_id_join)),
),
)
+ // Used to check if you are the post creator
+ .left_join(
+ person_alias_1.on(
+ post::creator_id
+ .eq(person_alias_1.field(person::id))
+ .and(person_alias_1.field(person::id).eq(person_id_join)),
+ ),
+ )
.select((
post::all_columns,
Person::safe_columns_tuple(),
))
.into_boxed();
+ // If you are not a moderator, exclude deleted or removed content
+ if !self.is_mod_or_admin.unwrap_or(true) {
+ // If you are not the creator, then remove the other fields.
+ query = query
+ .filter(
+ person_alias_1.field(person::id).is_null().and(
+ post::removed
+ .eq(false)
+ .and(post::deleted.eq(false))
+ .and(community::removed.eq(false))
+ .and(community::deleted.eq(false)),
+ ),
+ )
+ // If you are the creator, keep them
+ .or_filter(person_alias_1.field(person::id).is_not_null())
+ }
+
if let Some(listing_type) = self.listing_type {
match listing_type {
ListingType::Subscribed => {
);
}
- // If its for a specific person, show the removed / deleted
if let Some(creator_id) = self.creator_id {
query = query.filter(post::creator_id.eq(creator_id));
}
let (limit, offset) = limit_and_offset(self.page, self.limit)?;
- query = query
- .limit(limit)
- .offset(offset)
- .filter(post::removed.eq(false))
- .filter(post::deleted.eq(false))
- .filter(community::removed.eq(false))
- .filter(community::deleted.eq(false));
+ query = query.limit(limit).offset(offset);
debug!("Post View Query: {:?}", debug_query::<Pg, _>(&query));
.await
.unwrap();
- let post_listing_single_with_person =
- PostView::read(pool, data.inserted_post.id, Some(data.inserted_person.id))
- .await
- .unwrap();
+ let post_listing_single_with_person = PostView::read(
+ pool,
+ data.inserted_post.id,
+ Some(data.inserted_person.id),
+ None,
+ )
+ .await
+ .unwrap();
let mut expected_post_listing_with_user = expected_post_view(&data, pool).await;
.await
.unwrap();
- let read_post_listing_single_no_person = PostView::read(pool, data.inserted_post.id, None)
- .await
- .unwrap();
+ let read_post_listing_single_no_person =
+ PostView::read(pool, data.inserted_post.id, None, None)
+ .await
+ .unwrap();
let expected_post_listing_no_person = expected_post_view(&data, pool).await;
pool: &DbPool,
community_id: CommunityId,
my_person_id: Option<PersonId>,
+ is_mod_or_admin: Option<bool>,
) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
// The left join below will return None in this case
let person_id_join = my_person_id.unwrap_or(PersonId(-1));
- let (community, counts, follower, blocked) = community::table
+ let mut query = community::table
.find(community_id)
.inner_join(community_aggregates::table)
.left_join(
community_follower::all_columns.nullable(),
community_block::all_columns.nullable(),
))
- .first::<CommunityViewTuple>(conn)
- .await?;
+ .into_boxed();
+
+ // Hide deleted and removed for non-admins or mods
+ if !is_mod_or_admin.unwrap_or(true) {
+ query = query
+ .filter(community::removed.eq(false))
+ .filter(community::deleted.eq(false));
+ }
+
+ let (community, counts, follower, blocked) = query.first::<CommunityViewTuple>(conn).await?;
Ok(CommunityView {
community,
sort: Option<SortType>,
local_user: Option<&'a LocalUser>,
search_term: Option<String>,
+ is_mod_or_admin: Option<bool>,
page: Option<i64>,
limit: Option<i64>,
}
.or_filter(community::title.ilike(searcher));
};
+ // Hide deleted and removed for non-admins or mods
+ if !self.is_mod_or_admin.unwrap_or(true) {
+ query = query
+ .filter(community::removed.eq(false))
+ .filter(community::deleted.eq(false));
+ }
+
match self.sort.unwrap_or(SortType::Hot) {
SortType::New => query = query.order_by(community::published.desc()),
SortType::TopAll => query = query.order_by(community_aggregates::subscribers.desc()),