From 0a22fac56263a91325c09c553ac448e6deaccfa5 Mon Sep 17 00:00:00 2001 From: Nutomic Date: Fri, 20 Jun 2025 15:58:41 +0000 Subject: [PATCH] Remove `creator_*_actions` fields from api (ref #5532) (#5808) * Dont return action structs in api (ref #5532) * rename methods * Remove creator instance fields, add missing check * update js client * Remove remaining creator actions * update api tests --- api_tests/package.json | 2 +- api_tests/pnpm-lock.yaml | 10 +-- api_tests/src/community.spec.ts | 8 +- api_tests/src/post.spec.ts | 18 ++--- crates/api/api_crud/src/user/create.rs | 4 +- crates/api/api_utils/src/utils.rs | 2 +- crates/db_schema/src/lib.rs | 11 +++ crates/db_schema/src/utils/queries.rs | 73 ++++++++++++------- crates/db_views/comment/src/impls.rs | 16 ++-- crates/db_views/comment/src/lib.rs | 60 +++++++-------- crates/db_views/inbox_combined/src/impls.rs | 15 ++-- crates/db_views/inbox_combined/src/lib.rs | 51 +++++-------- crates/db_views/local_user/src/impls.rs | 7 -- crates/db_views/local_user/src/lib.rs | 19 +++-- crates/db_views/person/src/lib.rs | 26 +------ .../person_content_combined/src/impls.rs | 10 +-- .../person_content_combined/src/lib.rs | 48 +++++------- .../person_liked_combined/src/impls.rs | 14 ++-- .../db_views/person_liked_combined/src/lib.rs | 49 +++++-------- .../person_saved_combined/src/impls.rs | 14 ++-- .../db_views/person_saved_combined/src/lib.rs | 49 +++++-------- crates/db_views/post/src/impls.rs | 66 +++-------------- crates/db_views/post/src/lib.rs | 53 ++++++-------- crates/db_views/report_combined/src/impls.rs | 6 +- crates/db_views/report_combined/src/lib.rs | 15 +--- crates/db_views/reports/src/lib.rs | 17 ----- crates/db_views/search_combined/src/impls.rs | 14 ++-- crates/db_views/search_combined/src/lib.rs | 50 +++++-------- crates/email/src/notifications.rs | 7 +- 29 files changed, 286 insertions(+), 448 deletions(-) diff --git a/api_tests/package.json b/api_tests/package.json index 97aeeb4a1..fe7a80c3b 100644 --- a/api_tests/package.json +++ b/api_tests/package.json @@ -31,7 +31,7 @@ "eslint-plugin-prettier": "^5.4.0", "jest": "^29.5.0", "joi": "^17.13.3", - "lemmy-js-client": "1.0.0-multi-community.20", + "lemmy-js-client": "1.0.0-dont-return-actions.1", "prettier": "^3.5.3", "ts-jest": "^29.3.2", "tsoa": "^6.6.0", diff --git a/api_tests/pnpm-lock.yaml b/api_tests/pnpm-lock.yaml index eb6b1616a..d962c3c48 100644 --- a/api_tests/pnpm-lock.yaml +++ b/api_tests/pnpm-lock.yaml @@ -36,8 +36,8 @@ importers: specifier: ^17.13.3 version: 17.13.3 lemmy-js-client: - specifier: 1.0.0-multi-community.20 - version: 1.0.0-multi-community.20 + specifier: 1.0.0-dont-return-actions.1 + version: 1.0.0-dont-return-actions.1 prettier: specifier: ^3.5.3 version: 3.5.3 @@ -1594,8 +1594,8 @@ packages: resolution: {integrity: sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==} engines: {node: '>=6'} - lemmy-js-client@1.0.0-multi-community.20: - resolution: {integrity: sha512-CQdQMlzn5SMLhJx1RI6KEn+RGYKiQf3burfXLCGkCzUTkaT3oDFieDi/Az6EI1JFHhi5nSys7Ch7zZMUEBJF3w==} + lemmy-js-client@1.0.0-dont-return-actions.1: + resolution: {integrity: sha512-1eiLU+0ZBOqu//p2CRrO8hOTJbOWgpNYAB/R9I4sjuunp6i0oIzMhXNTg7hW8hQ8fyG7YO2BrgQQu861ZchnDg==} leven@3.1.0: resolution: {integrity: sha512-qsda+H8jTaUaN/x5vzW2rzc+8Rw4TAQ/4KjB46IwK5VH+IlVeeeje/EoZRpiXvIqjFgK84QffqPztGI3VBLG1A==} @@ -4404,7 +4404,7 @@ snapshots: kleur@3.0.3: {} - lemmy-js-client@1.0.0-multi-community.20: + lemmy-js-client@1.0.0-dont-return-actions.1: dependencies: '@tsoa/runtime': 6.6.0 transitivePeerDependencies: diff --git a/api_tests/src/community.spec.ts b/api_tests/src/community.spec.ts index 4c33067c2..59d76acd4 100644 --- a/api_tests/src/community.spec.ts +++ b/api_tests/src/community.spec.ts @@ -304,7 +304,7 @@ test("Admin actions in remote community are not federated to origin", async () = let gammaPost = (await createPost(gamma, gammaCommunity.community.id)) .post_view; expect(gammaPost.post.id).toBeDefined(); - expect(gammaPost.creator_community_actions?.received_ban_at).toBeUndefined(); + expect(gammaPost.creator_banned_from_community).toBe(false); // admin of beta decides to ban gamma from community let betaCommunity = await resolveCommunity( @@ -334,13 +334,11 @@ test("Admin actions in remote community are not federated to origin", async () = // ban doesn't federate to community's origin instance alpha let alphaPost = await resolvePost(alpha, gammaPost.post); - expect(alphaPost?.creator_community_actions?.received_ban_at).toBeUndefined(); + expect(alphaPost?.creator_banned_from_community).toBe(false); // and neither to gamma let gammaPost2 = await getPost(gamma, gammaPost.post.id); - expect( - gammaPost2.post_view.creator_community_actions?.received_ban_at, - ).toBeUndefined(); + expect(gammaPost2.post_view.creator_banned_from_community).toBe(false); }); test("moderator view", async () => { diff --git a/api_tests/src/post.spec.ts b/api_tests/src/post.spec.ts index c30247007..e04dc79f6 100644 --- a/api_tests/src/post.spec.ts +++ b/api_tests/src/post.spec.ts @@ -502,11 +502,9 @@ test("Enforce site ban federation for local user", async () => { // alpha ban should be federated to beta let alphaUserOnBeta1 = await waitUntil( () => resolvePerson(beta, alphaUserActorId!), - res => res?.home_instance_actions?.received_ban_at != null, + res => res?.creator_banned!, ); - expect( - alphaUserOnBeta1?.home_instance_actions?.received_ban_at, - ).toBeDefined(); + expect(alphaUserOnBeta1?.creator_banned).toBe(true); // existing alpha post should be removed on beta let betaBanRes = await waitUntil( @@ -562,9 +560,7 @@ test("Enforce site ban federation for federated user", async () => { await followBeta(alphaUserHttp); let alphaUserOnBeta2 = await resolvePerson(beta, alphaUserActorId!); - expect( - alphaUserOnBeta2?.local_instance_actions?.received_ban_at, - ).toBeUndefined(); + expect(alphaUserOnBeta2?.creator_banned).toBe(false); if (!alphaUserOnBeta2?.person) { throw "Missing alpha person"; @@ -597,7 +593,7 @@ test("Enforce site ban federation for federated user", async () => { // User should not be shown to be banned from alpha let alphaPerson2 = (await getMyUser(alphaUserHttp)).local_user_view; - expect(alphaPerson2.instance_actions?.received_ban_at).toBeUndefined(); + expect(alphaPerson2.banned).toBe(false); // but the ban should be indicated by beta community on alpha let communityWithBan = await getCommunity( @@ -649,9 +645,7 @@ test("Enforce community ban for federated user", async () => { s => s.post_view.post.removed, ); expect(removePostRes.post_view.post.removed).toBe(true); - expect( - removePostRes.post_view.creator_community_actions?.received_ban_at, - ).toBeDefined(); + expect(removePostRes.post_view.creator_banned_from_community).toBe(true); expect( removePostRes.community_view.community_actions?.received_ban_at, ).toBeDefined(); @@ -688,7 +682,7 @@ test("Enforce community ban for federated user", async () => { // Make sure that post makes it to beta community let postRes4 = await waitForPost(beta, postRes3.post_view.post); expect(postRes4.post).toBeDefined(); - expect(postRes4.creator_community_actions?.received_ban_at).toBeUndefined(); + expect(postRes4.creator_banned).toBe(false); await unfollowRemotes(alpha); }); diff --git a/crates/api/api_crud/src/user/create.rs b/crates/api/api_crud/src/user/create.rs index 28715a5f5..16c438486 100644 --- a/crates/api/api_crud/src/user/create.rs +++ b/crates/api/api_crud/src/user/create.rs @@ -167,7 +167,7 @@ pub async fn register( Ok(LocalUserView { person, local_user, - instance_actions: None, + banned: false, }) } .scope_boxed() @@ -411,7 +411,7 @@ pub async fn authenticate_with_oauth( Ok(LocalUserView { person, local_user, - instance_actions: None, + banned: false, }) } .scope_boxed() diff --git a/crates/api/api_utils/src/utils.rs b/crates/api/api_utils/src/utils.rs index 377e9da59..c0f7a4def 100644 --- a/crates/api/api_utils/src/utils.rs +++ b/crates/api/api_utils/src/utils.rs @@ -190,7 +190,7 @@ pub async fn update_read_comments( pub fn check_local_user_valid(local_user_view: &LocalUserView) -> LemmyResult<()> { // Check for a site ban - if local_user_view.banned() { + if local_user_view.banned { Err(LemmyErrorType::SiteBan)? } check_local_user_deleted(local_user_view) diff --git a/crates/db_schema/src/lib.rs b/crates/db_schema/src/lib.rs index 1e6e5aeb7..21d6b5ec2 100644 --- a/crates/db_schema/src/lib.rs +++ b/crates/db_schema/src/lib.rs @@ -17,6 +17,7 @@ pub mod aliases { diesel::alias!( community_actions as creator_community_actions: CreatorCommunityActions, instance_actions as creator_home_instance_actions: CreatorHomeInstanceActions, + instance_actions as creator_community_instance_actions: CreatorCommunityInstanceActions, instance_actions as creator_local_instance_actions: CreatorLocalInstanceActions, local_user as creator_local_user: CreatorLocalUser, person as person1: Person1, @@ -269,3 +270,13 @@ pub type CreatorLocalInstanceActionsAllColumnsTuple = ( AliasedField, AliasedField, ); + +#[cfg(feature = "full")] +/// A helper tuple for creator home instance actions. +pub type CreatorCommunityInstanceActionsAllColumnsTuple = ( + AliasedField, + AliasedField, + AliasedField, + AliasedField, + AliasedField, +); diff --git a/crates/db_schema/src/utils/queries.rs b/crates/db_schema/src/utils/queries.rs index 0ca05fd2b..1c3aebc82 100644 --- a/crates/db_schema/src/utils/queries.rs +++ b/crates/db_schema/src/utils/queries.rs @@ -1,6 +1,7 @@ use crate::{ aliases::{ creator_community_actions, + creator_community_instance_actions, creator_home_instance_actions, creator_local_instance_actions, creator_local_user, @@ -8,14 +9,11 @@ use crate::{ person2, }, newtypes::{InstanceId, PersonId}, - CreatorCommunityActionsAllColumnsTuple, - CreatorHomeInstanceActionsAllColumnsTuple, - CreatorLocalInstanceActionsAllColumnsTuple, Person1AliasAllColumnsTuple, Person2AliasAllColumnsTuple, }; use diesel::{ - dsl::{case_when, exists, not, Nullable}, + dsl::{case_when, exists, not}, expression::SqlLiteral, helper_types::{Eq, NotEq}, sql_types::Json, @@ -97,6 +95,30 @@ pub fn post_creator_is_admin() -> _ { ) } +#[diesel::dsl::auto_type] +pub fn creator_is_moderator() -> _ { + creator_community_actions + .field(community_actions::became_moderator_at) + .nullable() + .is_not_null() +} + +#[diesel::dsl::auto_type] +pub fn creator_banned_from_community() -> _ { + creator_community_actions + .field(community_actions::received_ban_at) + .nullable() + .is_not_null() +} + +#[diesel::dsl::auto_type] +pub fn creator_home_banned() -> _ { + creator_home_instance_actions + .field(instance_actions::received_ban_at) + .nullable() + .is_not_null() +} + #[diesel::dsl::auto_type] /// Checks to see if a user is site banned from any of these places: /// - Their own instance @@ -106,11 +128,18 @@ pub fn creator_banned() -> _ { .field(instance_actions::received_ban_at) .nullable() .is_not_null(); - let home_ban = creator_home_instance_actions + local_ban.or(creator_home_banned()) +} + +/// Similar to creator_banned(), but also checks if creator was banned from instance where the +/// community is hosted. +#[diesel::dsl::auto_type] +pub fn creator_banned_within_community() -> _ { + let community_ban = creator_community_instance_actions .field(instance_actions::received_ban_at) .nullable() .is_not_null(); - local_ban.or(home_ban) + creator_banned().or(community_ban) } #[diesel::dsl::auto_type] @@ -239,25 +268,6 @@ pub fn person2_select() -> Person2AliasAllColumnsTuple { person2.fields(person::all_columns) } -/// The select for the creator community actions alias. -pub fn creator_community_actions_select() -> CreatorCommunityActionsAllColumnsTuple { - creator_community_actions.fields(community_actions::all_columns) -} - -pub fn creator_home_instance_actions_select() -> Nullable -{ - creator_home_instance_actions - .fields(instance_actions::all_columns) - .nullable() -} - -pub fn creator_local_instance_actions_select( -) -> Nullable { - creator_local_instance_actions - .fields(instance_actions::all_columns) - .nullable() -} - type IsSubscribedType = Eq>; @@ -293,6 +303,19 @@ pub fn creator_home_instance_actions_join() -> _ { ), ) } +#[diesel::dsl::auto_type] +pub fn creator_community_instance_actions_join() -> _ { + creator_community_instance_actions.on( + creator_home_instance_actions + .field(instance_actions::instance_id) + .eq(community::instance_id) + .and( + creator_community_instance_actions + .field(instance_actions::person_id) + .eq(person::id), + ), + ) +} /// join with instance actions for local instance /// diff --git a/crates/db_views/comment/src/impls.rs b/crates/db_views/comment/src/impls.rs index 4c9ca667e..f28fdc169 100644 --- a/crates/db_views/comment/src/impls.rs +++ b/crates/db_views/comment/src/impls.rs @@ -27,6 +27,7 @@ use lemmy_db_schema::{ paginate, queries::{ creator_community_actions_join, + creator_community_instance_actions_join, creator_home_instance_actions_join, creator_local_instance_actions_join, filter_blocked, @@ -93,6 +94,7 @@ impl CommentView { .left_join(my_local_user_admin_join) .left_join(my_instance_actions_community_join) .left_join(creator_home_instance_actions_join()) + .left_join(creator_community_instance_actions_join()) .left_join(creator_local_instance_actions_join) .left_join(creator_community_actions_join()) } @@ -135,14 +137,13 @@ impl CommentView { comment: self.comment, creator: self.creator, comment_actions: self.comment_actions, - creator_community_actions: self.creator_community_actions, person_actions: self.person_actions, instance_actions: self.instance_actions, - creator_home_instance_actions: self.creator_home_instance_actions, - creator_local_instance_actions: self.creator_local_instance_actions, creator_is_admin: self.creator_is_admin, can_mod: self.can_mod, creator_banned: self.creator_banned, + creator_banned_from_community: self.creator_banned_from_community, + creator_is_moderator: self.creator_is_moderator, } } } @@ -458,7 +459,7 @@ mod tests { let timmy_local_user_view = LocalUserView { local_user: inserted_timmy_local_user.clone(), person: inserted_timmy_person.clone(), - instance_actions: None, + banned: false, }; let site_form = SiteInsertForm::new("test site".to_string(), inserted_instance.id); let site = Site::create(pool, &site_form).await?; @@ -711,12 +712,9 @@ mod tests { .await?; assert_eq!(comments[1].creator.name, "sara"); - assert!(comments[1] - .creator_community_actions - .as_ref() - .is_some_and(|x| x.became_moderator_at.is_some())); + assert!(comments[1].creator_is_moderator); - assert!(comments[0].creator_community_actions.is_none()); + assert!(!comments[0].creator_is_moderator); cleanup(data, pool).await } diff --git a/crates/db_views/comment/src/lib.rs b/crates/db_views/comment/src/lib.rs index 2f5c5d914..a0abcee12 100644 --- a/crates/db_views/comment/src/lib.rs +++ b/crates/db_views/comment/src/lib.rs @@ -10,21 +10,17 @@ use serde::{Deserialize, Serialize}; use serde_with::skip_serializing_none; #[cfg(feature = "full")] use { - diesel::{helper_types::Nullable, NullableExpressionMethods, Queryable, Selectable}, - lemmy_db_schema::{ - utils::queries::{ - comment_creator_is_admin, - comment_select_remove_deletes, - creator_banned, - creator_community_actions_select, - creator_home_instance_actions_select, - creator_local_instance_actions_select, - local_user_can_mod_comment, - post_tags_fragment, - }, - CreatorCommunityActionsAllColumnsTuple, - CreatorHomeInstanceActionsAllColumnsTuple, - CreatorLocalInstanceActionsAllColumnsTuple, + diesel::{Queryable, Selectable}, + lemmy_db_schema::utils::queries::{ + comment_creator_is_admin, + comment_select_remove_deletes, + local_user_can_mod_comment, + post_tags_fragment, + }, + lemmy_db_schema::utils::queries::{ + creator_banned_from_community, + creator_banned_within_community, + creator_is_moderator, }, }; @@ -60,21 +56,6 @@ pub struct CommentView { pub person_actions: Option, #[cfg_attr(feature = "full", diesel(embed))] pub instance_actions: Option, - #[cfg_attr(feature = "full", diesel( - select_expression_type = Nullable, - select_expression = creator_home_instance_actions_select()))] - pub creator_home_instance_actions: Option, - #[cfg_attr(feature = "full", diesel( - select_expression_type = Nullable, - select_expression = creator_local_instance_actions_select()))] - pub creator_local_instance_actions: Option, - #[cfg_attr(feature = "full", - diesel( - select_expression_type = Nullable, - select_expression = creator_community_actions_select().nullable() - ) - )] - pub creator_community_actions: Option, #[cfg_attr(feature = "full", diesel( select_expression = comment_creator_is_admin() @@ -95,10 +76,22 @@ pub struct CommentView { pub can_mod: bool, #[cfg_attr(feature = "full", diesel( - select_expression = creator_banned() + select_expression = creator_banned_within_community() ) )] pub creator_banned: bool, + #[cfg_attr(feature = "full", + diesel( + select_expression = creator_is_moderator() + ) + )] + pub creator_is_moderator: bool, + #[cfg_attr(feature = "full", + diesel( + select_expression = creator_banned_from_community() + ) + )] + pub creator_banned_from_community: bool, } #[skip_serializing_none] @@ -113,11 +106,10 @@ pub struct CommentSlimView { pub creator: Person, pub comment_actions: Option, pub person_actions: Option, - pub creator_community_actions: Option, pub instance_actions: Option, - pub creator_home_instance_actions: Option, - pub creator_local_instance_actions: Option, pub creator_is_admin: bool, pub can_mod: bool, pub creator_banned: bool, + pub creator_is_moderator: bool, + pub creator_banned_from_community: bool, } diff --git a/crates/db_views/inbox_combined/src/impls.rs b/crates/db_views/inbox_combined/src/impls.rs index a0676e97d..5d01b0801 100644 --- a/crates/db_views/inbox_combined/src/impls.rs +++ b/crates/db_views/inbox_combined/src/impls.rs @@ -375,13 +375,12 @@ impl InternalToCombinedView for InboxCombinedViewInternal { comment_actions: v.comment_actions, person_actions: v.person_actions, instance_actions: v.instance_actions, - creator_home_instance_actions: v.creator_home_instance_actions, - creator_local_instance_actions: v.creator_local_instance_actions, - creator_community_actions: v.creator_community_actions, creator_is_admin: v.item_creator_is_admin, post_tags: v.post_tags, can_mod: v.can_mod, creator_banned: v.creator_banned, + creator_banned_from_community: v.creator_banned_from_community, + creator_is_moderator: v.creator_is_moderator, })) } else if let (Some(person_comment_mention), Some(comment), Some(post), Some(community)) = ( v.person_comment_mention, @@ -401,12 +400,11 @@ impl InternalToCombinedView for InboxCombinedViewInternal { comment_actions: v.comment_actions, person_actions: v.person_actions, instance_actions: v.instance_actions, - creator_home_instance_actions: v.creator_home_instance_actions, - creator_local_instance_actions: v.creator_local_instance_actions, - creator_community_actions: v.creator_community_actions, creator_is_admin: v.item_creator_is_admin, can_mod: v.can_mod, creator_banned: v.creator_banned, + creator_banned_from_community: v.creator_banned_from_community, + creator_is_moderator: v.creator_is_moderator, }, )) } else if let (Some(person_post_mention), Some(post), Some(community)) = @@ -421,15 +419,14 @@ impl InternalToCombinedView for InboxCombinedViewInternal { community_actions: v.community_actions, person_actions: v.person_actions, instance_actions: v.instance_actions, - creator_home_instance_actions: v.creator_home_instance_actions, - creator_local_instance_actions: v.creator_local_instance_actions, post_actions: v.post_actions, image_details: v.image_details, - creator_community_actions: v.creator_community_actions, creator_is_admin: v.item_creator_is_admin, post_tags: v.post_tags, can_mod: v.can_mod, creator_banned: v.creator_banned, + creator_banned_from_community: v.creator_banned_from_community, + creator_is_moderator: v.creator_is_moderator, })) } else if let Some(private_message) = v.private_message { Some(InboxCombinedView::PrivateMessage(PrivateMessageView { diff --git a/crates/db_views/inbox_combined/src/lib.rs b/crates/db_views/inbox_combined/src/lib.rs index 834497262..1ab865507 100644 --- a/crates/db_views/inbox_combined/src/lib.rs +++ b/crates/db_views/inbox_combined/src/lib.rs @@ -21,21 +21,16 @@ use serde::{Deserialize, Serialize}; use serde_with::skip_serializing_none; #[cfg(feature = "full")] use { - diesel::{dsl::Nullable, NullableExpressionMethods, Queryable, Selectable}, + diesel::{Queryable, Selectable}, lemmy_db_schema::{ utils::queries::{ creator_banned, - creator_community_actions_select, - creator_home_instance_actions_select, creator_is_admin, - creator_local_instance_actions_select, local_user_can_mod, person1_select, post_tags_fragment, }, - CreatorCommunityActionsAllColumnsTuple, - CreatorHomeInstanceActionsAllColumnsTuple, - CreatorLocalInstanceActionsAllColumnsTuple, + utils::queries::{creator_banned_from_community, creator_is_moderator}, Person1AliasAllColumnsTuple, }, }; @@ -76,25 +71,10 @@ pub struct InboxCombinedViewInternal { pub item_recipient: Person, #[cfg_attr(feature = "full", diesel(embed))] pub image_details: Option, - #[cfg_attr(feature = "full", - diesel( - select_expression_type = Nullable, - select_expression = creator_community_actions_select().nullable() - ) - )] - pub creator_community_actions: Option, #[cfg_attr(feature = "full", diesel(embed))] pub community_actions: Option, #[cfg_attr(feature = "full", diesel(embed))] pub instance_actions: Option, - #[cfg_attr(feature = "full", diesel( - select_expression_type = Nullable, - select_expression = creator_home_instance_actions_select()))] - pub creator_home_instance_actions: Option, - #[cfg_attr(feature = "full", diesel( - select_expression_type = Nullable, - select_expression = creator_local_instance_actions_select()))] - pub creator_local_instance_actions: Option, #[cfg_attr(feature = "full", diesel(embed))] pub post_actions: Option, #[cfg_attr(feature = "full", diesel(embed))] @@ -125,6 +105,18 @@ pub struct InboxCombinedViewInternal { ) )] pub creator_banned: bool, + #[cfg_attr(feature = "full", + diesel( + select_expression = creator_is_moderator() + ) + )] + pub creator_is_moderator: bool, + #[cfg_attr(feature = "full", + diesel( + select_expression = creator_banned_from_community() + ) + )] + pub creator_banned_from_community: bool, } #[derive(Debug, PartialEq, Serialize, Deserialize, Clone)] @@ -156,12 +148,11 @@ pub struct PersonCommentMentionView { pub comment_actions: Option, pub person_actions: Option, pub instance_actions: Option, - pub creator_home_instance_actions: Option, - pub creator_local_instance_actions: Option, - pub creator_community_actions: Option, pub creator_is_admin: bool, pub can_mod: bool, pub creator_banned: bool, + pub creator_is_moderator: bool, + pub creator_banned_from_community: bool, } #[skip_serializing_none] @@ -182,13 +173,12 @@ pub struct PersonPostMentionView { pub person_actions: Option, pub post_actions: Option, pub instance_actions: Option, - pub creator_home_instance_actions: Option, - pub creator_local_instance_actions: Option, - pub creator_community_actions: Option, pub post_tags: TagsView, pub creator_is_admin: bool, pub can_mod: bool, pub creator_banned: bool, + pub creator_is_moderator: bool, + pub creator_banned_from_community: bool, } #[skip_serializing_none] @@ -210,13 +200,12 @@ pub struct CommentReplyView { pub person_actions: Option, #[cfg_attr(feature = "full", diesel(embed))] pub instance_actions: Option, - pub creator_home_instance_actions: Option, - pub creator_local_instance_actions: Option, - pub creator_community_actions: Option, pub creator_is_admin: bool, pub post_tags: TagsView, pub can_mod: bool, pub creator_banned: bool, + pub creator_is_moderator: bool, + pub creator_banned_from_community: bool, } #[skip_serializing_none] diff --git a/crates/db_views/local_user/src/impls.rs b/crates/db_views/local_user/src/impls.rs index 3781a07a8..b5b922303 100644 --- a/crates/db_views/local_user/src/impls.rs +++ b/crates/db_views/local_user/src/impls.rs @@ -147,13 +147,6 @@ impl LocalUserView { LocalUserView::read(pool, local_user.id).await } - - pub fn banned(&self) -> bool { - self - .instance_actions - .as_ref() - .is_some_and(|i| i.received_ban_at.is_some()) - } } #[derive(Default)] diff --git a/crates/db_views/local_user/src/lib.rs b/crates/db_views/local_user/src/lib.rs index 097bf4c65..29bf1157c 100644 --- a/crates/db_views/local_user/src/lib.rs +++ b/crates/db_views/local_user/src/lib.rs @@ -1,12 +1,9 @@ -use lemmy_db_schema::source::{instance::InstanceActions, local_user::LocalUser, person::Person}; +use lemmy_db_schema::source::{local_user::LocalUser, person::Person}; use serde::{Deserialize, Serialize}; #[cfg(feature = "full")] use { - diesel::{dsl::Nullable, Queryable, Selectable}, - lemmy_db_schema::{ - utils::queries::creator_home_instance_actions_select, - CreatorHomeInstanceActionsAllColumnsTuple, - }, + diesel::{Queryable, Selectable}, + lemmy_db_schema::utils::queries::creator_home_banned, }; pub mod api; @@ -24,8 +21,10 @@ pub struct LocalUserView { pub local_user: LocalUser, #[cfg_attr(feature = "full", diesel(embed))] pub person: Person, - #[cfg_attr(feature = "full", diesel( - select_expression_type = Nullable, - select_expression = creator_home_instance_actions_select()))] - pub instance_actions: Option, + #[cfg_attr(feature = "full", + diesel( + select_expression = creator_home_banned() + ) + )] + pub banned: bool, } diff --git a/crates/db_views/person/src/lib.rs b/crates/db_views/person/src/lib.rs index c844089a7..ee2d11190 100644 --- a/crates/db_views/person/src/lib.rs +++ b/crates/db_views/person/src/lib.rs @@ -1,23 +1,9 @@ -use lemmy_db_schema::source::{ - instance::InstanceActions, - person::{Person, PersonActions}, -}; +use lemmy_db_schema::source::person::{Person, PersonActions}; use serde::{Deserialize, Serialize}; #[cfg(feature = "full")] use { diesel::{helper_types::Nullable, NullableExpressionMethods, Queryable, Selectable}, - lemmy_db_schema::{ - utils::{ - functions::coalesce, - queries::{ - creator_banned, - creator_home_instance_actions_select, - creator_local_instance_actions_select, - }, - }, - CreatorHomeInstanceActionsAllColumnsTuple, - CreatorLocalInstanceActionsAllColumnsTuple, - }, + lemmy_db_schema::utils::{functions::coalesce, queries::creator_banned}, lemmy_db_schema_file::schema::local_user, }; @@ -43,14 +29,6 @@ pub struct PersonView { pub is_admin: bool, #[cfg_attr(feature = "full", diesel(embed))] pub person_actions: Option, - #[cfg_attr(feature = "full", diesel( - select_expression_type = Nullable, - select_expression = creator_home_instance_actions_select()))] - pub home_instance_actions: Option, - #[cfg_attr(feature = "full", diesel( - select_expression_type = Nullable, - select_expression = creator_local_instance_actions_select()))] - pub local_instance_actions: Option, #[cfg_attr(feature = "full", diesel( select_expression = creator_banned() diff --git a/crates/db_views/person_content_combined/src/impls.rs b/crates/db_views/person_content_combined/src/impls.rs index 306c595e8..5b82e8938 100644 --- a/crates/db_views/person_content_combined/src/impls.rs +++ b/crates/db_views/person_content_combined/src/impls.rs @@ -240,13 +240,12 @@ impl InternalToCombinedView for PersonContentCombinedViewInternal { comment_actions: v.comment_actions, person_actions: v.person_actions, instance_actions: v.instance_actions, - creator_home_instance_actions: v.creator_home_instance_actions, - creator_local_instance_actions: v.creator_local_instance_actions, - creator_community_actions: v.creator_community_actions, creator_is_admin: v.item_creator_is_admin, post_tags: v.post_tags, can_mod: v.can_mod, creator_banned: v.creator_banned, + creator_is_moderator: v.creator_is_moderator, + creator_banned_from_community: v.creator_banned_from_community, })) } else { Some(PersonContentCombinedView::Post(PostView { @@ -258,13 +257,12 @@ impl InternalToCombinedView for PersonContentCombinedViewInternal { post_actions: v.post_actions, person_actions: v.person_actions, instance_actions: v.instance_actions, - creator_home_instance_actions: v.creator_home_instance_actions, - creator_local_instance_actions: v.creator_local_instance_actions, - creator_community_actions: v.creator_community_actions, creator_is_admin: v.item_creator_is_admin, tags: v.post_tags, can_mod: v.can_mod, creator_banned: v.creator_banned, + creator_is_moderator: v.creator_is_moderator, + creator_banned_from_community: v.creator_banned_from_community, })) } } diff --git a/crates/db_views/person_content_combined/src/lib.rs b/crates/db_views/person_content_combined/src/lib.rs index b54db8e4a..d13973366 100644 --- a/crates/db_views/person_content_combined/src/lib.rs +++ b/crates/db_views/person_content_combined/src/lib.rs @@ -18,21 +18,14 @@ use serde::{Deserialize, Serialize}; use serde_with::skip_serializing_none; #[cfg(feature = "full")] use { - diesel::{dsl::Nullable, NullableExpressionMethods, Queryable, Selectable}, - lemmy_db_schema::{ - utils::queries::{ - creator_banned, - creator_community_actions_select, - creator_home_instance_actions_select, - creator_is_admin, - creator_local_instance_actions_select, - local_user_can_mod, - post_tags_fragment, - }, - CreatorCommunityActionsAllColumnsTuple, - CreatorHomeInstanceActionsAllColumnsTuple, - CreatorLocalInstanceActionsAllColumnsTuple, + diesel::{Queryable, Selectable}, + lemmy_db_schema::utils::queries::{ + creator_banned, + creator_is_admin, + local_user_can_mod, + post_tags_fragment, }, + lemmy_db_schema::utils::queries::{creator_banned_from_community, creator_is_moderator}, lemmy_db_views_local_user::LocalUserView, }; @@ -54,25 +47,10 @@ pub(crate) struct PersonContentCombinedViewInternal { pub item_creator: Person, #[cfg_attr(feature = "full", diesel(embed))] pub community: Community, - #[cfg_attr(feature = "full", - diesel( - select_expression_type = Nullable, - select_expression = creator_community_actions_select().nullable() - ) - )] - pub creator_community_actions: Option, #[cfg_attr(feature = "full", diesel(embed))] pub community_actions: Option, #[cfg_attr(feature = "full", diesel(embed))] pub instance_actions: Option, - #[cfg_attr(feature = "full", diesel( - select_expression_type = Nullable, - select_expression = creator_home_instance_actions_select()))] - pub creator_home_instance_actions: Option, - #[cfg_attr(feature = "full", diesel( - select_expression_type = Nullable, - select_expression = creator_local_instance_actions_select()))] - pub creator_local_instance_actions: Option, #[cfg_attr(feature = "full", diesel(embed))] pub post_actions: Option, #[cfg_attr(feature = "full", diesel(embed))] @@ -105,6 +83,18 @@ pub(crate) struct PersonContentCombinedViewInternal { ) )] pub creator_banned: bool, + #[cfg_attr(feature = "full", + diesel( + select_expression = creator_is_moderator() + ) + )] + pub creator_is_moderator: bool, + #[cfg_attr(feature = "full", + diesel( + select_expression = creator_banned_from_community() + ) + )] + pub creator_banned_from_community: bool, } #[derive(Debug, PartialEq, Serialize, Deserialize, Clone)] diff --git a/crates/db_views/person_liked_combined/src/impls.rs b/crates/db_views/person_liked_combined/src/impls.rs index 063d26cdc..c3da8c0cf 100644 --- a/crates/db_views/person_liked_combined/src/impls.rs +++ b/crates/db_views/person_liked_combined/src/impls.rs @@ -26,6 +26,7 @@ use lemmy_db_schema::{ queries::{ community_join, creator_community_actions_join, + creator_community_instance_actions_join, creator_home_instance_actions_join, creator_local_instance_actions_join, creator_local_user_admin_join, @@ -141,6 +142,7 @@ impl PersonLikedCombinedViewInternal { .left_join(my_community_actions_join) .left_join(my_instance_actions_person_join) .left_join(creator_home_instance_actions_join()) + .left_join(creator_community_instance_actions_join()) .left_join(creator_local_instance_actions_join) .left_join(my_post_actions_join) .left_join(my_person_actions_join) @@ -228,13 +230,12 @@ impl InternalToCombinedView for PersonLikedCombinedViewInternal { comment_actions: v.comment_actions, person_actions: v.person_actions, instance_actions: v.instance_actions, - creator_home_instance_actions: v.creator_home_instance_actions, - creator_local_instance_actions: v.creator_local_instance_actions, - creator_community_actions: v.creator_community_actions, creator_is_admin: v.item_creator_is_admin, post_tags: v.post_tags, can_mod: v.can_mod, creator_banned: v.creator_banned, + creator_is_moderator: v.creator_is_moderator, + creator_banned_from_community: v.creator_banned_from_community, })) } else { Some(PersonLikedCombinedView::Post(PostView { @@ -246,13 +247,12 @@ impl InternalToCombinedView for PersonLikedCombinedViewInternal { post_actions: v.post_actions, person_actions: v.person_actions, instance_actions: v.instance_actions, - creator_home_instance_actions: v.creator_home_instance_actions, - creator_local_instance_actions: v.creator_local_instance_actions, - creator_community_actions: v.creator_community_actions, creator_is_admin: v.item_creator_is_admin, tags: v.post_tags, can_mod: v.can_mod, creator_banned: v.creator_banned, + creator_is_moderator: v.creator_is_moderator, + creator_banned_from_community: v.creator_banned_from_community, })) } } @@ -300,7 +300,7 @@ mod tests { let timmy_view = LocalUserView { local_user: timmy_local_user, person: timmy.clone(), - instance_actions: None, + banned: false, }; let sara_form = PersonInsertForm::test_form(instance.id, "sara_pcv"); diff --git a/crates/db_views/person_liked_combined/src/lib.rs b/crates/db_views/person_liked_combined/src/lib.rs index ac136831d..c004445c4 100644 --- a/crates/db_views/person_liked_combined/src/lib.rs +++ b/crates/db_views/person_liked_combined/src/lib.rs @@ -19,21 +19,13 @@ use serde::{Deserialize, Serialize}; use serde_with::skip_serializing_none; #[cfg(feature = "full")] use { - diesel::{dsl::Nullable, NullableExpressionMethods, Queryable, Selectable}, - lemmy_db_schema::{ - utils::queries::{ - creator_banned, - creator_community_actions_select, - creator_home_instance_actions_select, - creator_is_admin, - creator_local_instance_actions_select, - local_user_can_mod, - post_tags_fragment, - }, - CreatorCommunityActionsAllColumnsTuple, - CreatorHomeInstanceActionsAllColumnsTuple, - CreatorLocalInstanceActionsAllColumnsTuple, + diesel::{Queryable, Selectable}, + lemmy_db_schema::utils::queries::{ + creator_banned_from_community, + creator_banned_within_community, + creator_is_moderator, }, + lemmy_db_schema::utils::queries::{creator_is_admin, local_user_can_mod, post_tags_fragment}, lemmy_db_views_local_user::LocalUserView, }; @@ -55,25 +47,10 @@ pub(crate) struct PersonLikedCombinedViewInternal { pub item_creator: Person, #[cfg_attr(feature = "full", diesel(embed))] pub community: Community, - #[cfg_attr(feature = "full", - diesel( - select_expression_type = Nullable, - select_expression = creator_community_actions_select().nullable() - ) - )] - pub creator_community_actions: Option, #[cfg_attr(feature = "full", diesel(embed))] pub community_actions: Option, #[cfg_attr(feature = "full", diesel(embed))] pub instance_actions: Option, - #[cfg_attr(feature = "full", diesel( - select_expression_type = Nullable, - select_expression = creator_home_instance_actions_select()))] - pub creator_home_instance_actions: Option, - #[cfg_attr(feature = "full", diesel( - select_expression_type = Nullable, - select_expression = creator_local_instance_actions_select()))] - pub creator_local_instance_actions: Option, #[cfg_attr(feature = "full", diesel(embed))] pub post_actions: Option, #[cfg_attr(feature = "full", diesel(embed))] @@ -102,10 +79,22 @@ pub(crate) struct PersonLikedCombinedViewInternal { pub can_mod: bool, #[cfg_attr(feature = "full", diesel( - select_expression = creator_banned() + select_expression = creator_banned_within_community() ) )] pub creator_banned: bool, + #[cfg_attr(feature = "full", + diesel( + select_expression = creator_is_moderator() + ) + )] + pub creator_is_moderator: bool, + #[cfg_attr(feature = "full", + diesel( + select_expression = creator_banned_from_community() + ) + )] + pub creator_banned_from_community: bool, } #[derive(Debug, PartialEq, Serialize, Deserialize, Clone)] diff --git a/crates/db_views/person_saved_combined/src/impls.rs b/crates/db_views/person_saved_combined/src/impls.rs index 4224ac6dc..d98f74b55 100644 --- a/crates/db_views/person_saved_combined/src/impls.rs +++ b/crates/db_views/person_saved_combined/src/impls.rs @@ -26,6 +26,7 @@ use lemmy_db_schema::{ queries::{ community_join, creator_community_actions_join, + creator_community_instance_actions_join, creator_home_instance_actions_join, creator_local_instance_actions_join, creator_local_user_admin_join, @@ -139,6 +140,7 @@ impl PersonSavedCombinedViewInternal { .left_join(my_community_actions_join) .left_join(my_instance_actions_person_join) .left_join(creator_home_instance_actions_join()) + .left_join(creator_community_instance_actions_join()) .left_join(creator_local_instance_actions_join) .left_join(my_post_actions_join) .left_join(my_person_actions_join) @@ -218,13 +220,12 @@ impl InternalToCombinedView for PersonSavedCombinedViewInternal { comment_actions: v.comment_actions, person_actions: v.person_actions, instance_actions: v.instance_actions, - creator_home_instance_actions: v.creator_home_instance_actions, - creator_local_instance_actions: v.creator_local_instance_actions, - creator_community_actions: v.creator_community_actions, creator_is_admin: v.item_creator_is_admin, post_tags: v.post_tags, can_mod: v.can_mod, creator_banned: v.creator_banned, + creator_is_moderator: v.creator_is_moderator, + creator_banned_from_community: v.creator_banned_from_community, })) } else { Some(PersonSavedCombinedView::Post(PostView { @@ -236,13 +237,12 @@ impl InternalToCombinedView for PersonSavedCombinedViewInternal { post_actions: v.post_actions, person_actions: v.person_actions, instance_actions: v.instance_actions, - creator_home_instance_actions: v.creator_home_instance_actions, - creator_local_instance_actions: v.creator_local_instance_actions, - creator_community_actions: v.creator_community_actions, creator_is_admin: v.item_creator_is_admin, tags: v.post_tags, can_mod: v.can_mod, creator_banned: v.creator_banned, + creator_is_moderator: v.creator_is_moderator, + creator_banned_from_community: v.creator_banned_from_community, })) } } @@ -289,7 +289,7 @@ mod tests { let timmy_view = LocalUserView { local_user: timmy_local_user, person: timmy.clone(), - instance_actions: None, + banned: false, }; let sara_form = PersonInsertForm::test_form(instance.id, "sara_pcv"); diff --git a/crates/db_views/person_saved_combined/src/lib.rs b/crates/db_views/person_saved_combined/src/lib.rs index adfe80e9d..a4310ef1c 100644 --- a/crates/db_views/person_saved_combined/src/lib.rs +++ b/crates/db_views/person_saved_combined/src/lib.rs @@ -18,21 +18,13 @@ use serde::{Deserialize, Serialize}; use serde_with::skip_serializing_none; #[cfg(feature = "full")] use { - diesel::{dsl::Nullable, NullableExpressionMethods, Queryable, Selectable}, - lemmy_db_schema::{ - utils::queries::{ - creator_banned, - creator_community_actions_select, - creator_home_instance_actions_select, - creator_is_admin, - creator_local_instance_actions_select, - local_user_can_mod, - post_tags_fragment, - }, - CreatorCommunityActionsAllColumnsTuple, - CreatorHomeInstanceActionsAllColumnsTuple, - CreatorLocalInstanceActionsAllColumnsTuple, + diesel::{Queryable, Selectable}, + lemmy_db_schema::utils::queries::{ + creator_banned_from_community, + creator_banned_within_community, + creator_is_moderator, }, + lemmy_db_schema::utils::queries::{creator_is_admin, local_user_can_mod, post_tags_fragment}, lemmy_db_views_local_user::LocalUserView, }; @@ -54,25 +46,10 @@ pub(crate) struct PersonSavedCombinedViewInternal { pub item_creator: Person, #[cfg_attr(feature = "full", diesel(embed))] pub community: Community, - #[cfg_attr(feature = "full", - diesel( - select_expression_type = Nullable, - select_expression = creator_community_actions_select().nullable() - ) - )] - pub creator_community_actions: Option, #[cfg_attr(feature = "full", diesel(embed))] pub community_actions: Option, #[cfg_attr(feature = "full", diesel(embed))] pub instance_actions: Option, - #[cfg_attr(feature = "full", diesel( - select_expression_type = Nullable, - select_expression = creator_home_instance_actions_select()))] - pub creator_home_instance_actions: Option, - #[cfg_attr(feature = "full", diesel( - select_expression_type = Nullable, - select_expression = creator_local_instance_actions_select()))] - pub creator_local_instance_actions: Option, #[cfg_attr(feature = "full", diesel(embed))] pub post_actions: Option, #[cfg_attr(feature = "full", diesel(embed))] @@ -101,10 +78,22 @@ pub(crate) struct PersonSavedCombinedViewInternal { pub can_mod: bool, #[cfg_attr(feature = "full", diesel( - select_expression = creator_banned() + select_expression = creator_banned_within_community() ) )] pub creator_banned: bool, + #[cfg_attr(feature = "full", + diesel( + select_expression = creator_is_moderator() + ) + )] + pub creator_is_moderator: bool, + #[cfg_attr(feature = "full", + diesel( + select_expression = creator_banned_from_community() + ) + )] + pub creator_banned_from_community: bool, } #[derive(Debug, PartialEq, Serialize, Deserialize, Clone)] diff --git a/crates/db_views/post/src/impls.rs b/crates/db_views/post/src/impls.rs index f54b9491b..b566a5658 100644 --- a/crates/db_views/post/src/impls.rs +++ b/crates/db_views/post/src/impls.rs @@ -33,6 +33,7 @@ use lemmy_db_schema::{ paginate, queries::{ creator_community_actions_join, + creator_community_instance_actions_join, creator_home_instance_actions_join, creator_local_instance_actions_join, filter_blocked, @@ -113,6 +114,7 @@ impl PostView { .left_join(my_instance_actions_community_join) .left_join(my_local_user_admin_join) .left_join(creator_home_instance_actions_join()) + .left_join(creator_community_instance_actions_join()) .left_join(creator_local_instance_actions_join) .left_join(creator_community_actions_join()) } @@ -774,18 +776,18 @@ mod tests { let tegan_local_user_view = LocalUserView { local_user: inserted_tegan_local_user, person: inserted_tegan_person, - instance_actions: None, + banned: false, }; let john_local_user_view = LocalUserView { local_user: inserted_john_local_user, person: inserted_john_person, - instance_actions: None, + banned: false, }; let bot_local_user_view = LocalUserView { local_user: inserted_bot_local_user, person: inserted_bot_person, - instance_actions: None, + banned: false, }; Ok(Data { @@ -1097,15 +1099,7 @@ mod tests { .list(&data.site, pool) .await? .into_iter() - .map(|p| { - ( - p.creator.name, - p.creator_community_actions - .map(|x| x.became_moderator_at.is_some()) - .unwrap_or(false), - p.can_mod, - ) - }) + .map(|p| (p.creator.name, p.creator_is_moderator, p.can_mod)) .collect::>(); // Tegan is an admin, so can_mod should be always true @@ -1133,15 +1127,7 @@ mod tests { .list(&data.site, pool) .await? .into_iter() - .map(|p| { - ( - p.creator.name, - p.creator_community_actions - .map(|x| x.became_moderator_at.is_some()) - .unwrap_or(false), - p.can_mod, - ) - }) + .map(|p| (p.creator.name, p.creator_is_moderator, p.can_mod)) .collect::>(); // John is a mod, so he can_mod the bots (and his own) posts, but not tegans. @@ -1162,15 +1148,7 @@ mod tests { .list(&data.site, pool) .await? .into_iter() - .map(|p| { - ( - p.creator.name, - p.creator_community_actions - .map(|x| x.became_moderator_at.is_some()) - .unwrap_or(false), - p.can_mod, - ) - }) + .map(|p| (p.creator.name, p.creator_is_moderator, p.can_mod)) .collect::>(); let expected_post_listing = vec![ @@ -1192,15 +1170,7 @@ mod tests { .list(&data.site, pool) .await? .into_iter() - .map(|p| { - ( - p.creator.name, - p.creator_community_actions - .map(|x| x.became_moderator_at.is_some()) - .unwrap_or(false), - p.can_mod, - ) - }) + .map(|p| (p.creator.name, p.creator_is_moderator, p.can_mod)) .collect::>(); let expected_post_listing = vec![ @@ -1223,15 +1193,7 @@ mod tests { .list(&data.site, pool) .await? .into_iter() - .map(|p| { - ( - p.creator.name, - p.creator_community_actions - .map(|x| x.became_moderator_at.is_some()) - .unwrap_or(false), - p.can_mod, - ) - }) + .map(|p| (p.creator.name, p.creator_is_moderator, p.can_mod)) .collect::>(); // John is a mod, so he still can_mod the bots (and his own) posts. Tegan is a lower mod and @@ -1892,13 +1854,9 @@ mod tests { ) .await?; - assert!(post_view - .creator_local_instance_actions - .is_some_and(|x| x.received_ban_at.is_some())); + assert!(post_view.creator_banned); - assert!(post_view - .creator_home_instance_actions - .is_some_and(|x| x.received_ban_at.is_some())); + assert!(post_view.creator_banned); // This should be none, since john wasn't banned, only the creator. assert!(post_view.instance_actions.is_none()); diff --git a/crates/db_views/post/src/lib.rs b/crates/db_views/post/src/lib.rs index eda566759..7439c7c97 100644 --- a/crates/db_views/post/src/lib.rs +++ b/crates/db_views/post/src/lib.rs @@ -12,20 +12,16 @@ pub mod db_perf; use serde_with::skip_serializing_none; #[cfg(feature = "full")] use { - diesel::{dsl::Nullable, NullableExpressionMethods, Queryable, Selectable}, - lemmy_db_schema::{ - utils::queries::{ - creator_banned, - creator_community_actions_select, - creator_home_instance_actions_select, - creator_local_instance_actions_select, - local_user_can_mod_post, - post_creator_is_admin, - post_tags_fragment, - }, - CreatorCommunityActionsAllColumnsTuple, - CreatorHomeInstanceActionsAllColumnsTuple, - CreatorLocalInstanceActionsAllColumnsTuple, + diesel::{Queryable, Selectable}, + lemmy_db_schema::utils::queries::{ + creator_banned_from_community, + creator_banned_within_community, + }, + lemmy_db_schema::utils::queries::{ + creator_is_moderator, + local_user_can_mod_post, + post_creator_is_admin, + post_tags_fragment, }, }; @@ -56,21 +52,6 @@ pub struct PostView { pub post_actions: Option, #[cfg_attr(feature = "full", diesel(embed))] pub instance_actions: Option, - #[cfg_attr(feature = "full", diesel( - select_expression_type = Nullable, - select_expression = creator_home_instance_actions_select()))] - pub creator_home_instance_actions: Option, - #[cfg_attr(feature = "full", diesel( - select_expression_type = Nullable, - select_expression = creator_local_instance_actions_select()))] - pub creator_local_instance_actions: Option, - #[cfg_attr(feature = "full", - diesel( - select_expression_type = Nullable, - select_expression = creator_community_actions_select().nullable() - ) - )] - pub creator_community_actions: Option, #[cfg_attr(feature = "full", diesel( select_expression = post_creator_is_admin() @@ -91,8 +72,20 @@ pub struct PostView { pub can_mod: bool, #[cfg_attr(feature = "full", diesel( - select_expression = creator_banned() + select_expression = creator_banned_within_community() ) )] pub creator_banned: bool, + #[cfg_attr(feature = "full", + diesel( + select_expression = creator_is_moderator() + ) + )] + pub creator_is_moderator: bool, + #[cfg_attr(feature = "full", + diesel( + select_expression = creator_banned_from_community() + ) + )] + pub creator_banned_from_community: bool, } diff --git a/crates/db_views/report_combined/src/impls.rs b/crates/db_views/report_combined/src/impls.rs index def3e03a5..d1bfad762 100644 --- a/crates/db_views/report_combined/src/impls.rs +++ b/crates/db_views/report_combined/src/impls.rs @@ -393,7 +393,6 @@ impl InternalToCombinedView for ReportCombinedViewInternal { post_creator, creator: v.report_creator, resolver: v.resolver, - creator_community_actions: v.creator_community_actions, community_actions: v.community_actions, post_actions: v.post_actions, person_actions: v.person_actions, @@ -420,7 +419,6 @@ impl InternalToCombinedView for ReportCombinedViewInternal { creator: v.report_creator, comment_creator, resolver: v.resolver, - creator_community_actions: v.creator_community_actions, community_actions: v.community_actions, comment_actions: v.comment_actions, person_actions: v.person_actions, @@ -517,7 +515,7 @@ mod tests { let timmy_view = LocalUserView { local_user: timmy_local_user, person: inserted_timmy.clone(), - instance_actions: None, + banned: false, }; // Make an admin, to be able to see private message reports. @@ -528,7 +526,7 @@ mod tests { let admin_view = LocalUserView { local_user: admin_local_user, person: inserted_admin.clone(), - instance_actions: None, + banned: false, }; let sara_form = PersonInsertForm::test_form(inserted_instance.id, "sara_rcv"); diff --git a/crates/db_views/report_combined/src/lib.rs b/crates/db_views/report_combined/src/lib.rs index 084285638..59d55531b 100644 --- a/crates/db_views/report_combined/src/lib.rs +++ b/crates/db_views/report_combined/src/lib.rs @@ -21,13 +21,7 @@ use serde::{Deserialize, Serialize}; use { diesel::{dsl::Nullable, NullableExpressionMethods, Queryable, Selectable}, lemmy_db_schema::{ - utils::queries::{ - creator_community_actions_select, - local_user_is_admin, - person1_select, - person2_select, - }, - CreatorCommunityActionsAllColumnsTuple, + utils::queries::{local_user_is_admin, person1_select, person2_select}, Person1AliasAllColumnsTuple, Person2AliasAllColumnsTuple, }, @@ -77,13 +71,6 @@ pub struct ReportCombinedViewInternal { pub resolver: Option, #[cfg_attr(feature = "full", diesel(embed))] pub community: Option, - #[cfg_attr(feature = "full", - diesel( - select_expression_type = Nullable, - select_expression = creator_community_actions_select().nullable() - ) - )] - pub creator_community_actions: Option, #[cfg_attr(feature = "full", diesel(embed))] pub community_actions: Option, #[cfg_attr(feature = "full", diesel(embed))] diff --git a/crates/db_views/reports/src/lib.rs b/crates/db_views/reports/src/lib.rs index b5d2796de..0aa889c7c 100644 --- a/crates/db_views/reports/src/lib.rs +++ b/crates/db_views/reports/src/lib.rs @@ -17,12 +17,10 @@ use { lemmy_db_schema::{ utils::queries::{ comment_creator_is_admin, - creator_community_actions_select, person1_select, person2_select, post_creator_is_admin, }, - CreatorCommunityActionsAllColumnsTuple, Person1AliasAllColumnsTuple, Person2AliasAllColumnsTuple, }, @@ -106,14 +104,6 @@ pub struct CommentReportView { )] pub resolver: Option, #[cfg_attr(feature = "full", diesel(embed))] - #[cfg_attr(feature = "full", - diesel( - select_expression_type = Nullable, - select_expression = creator_community_actions_select().nullable() - ) - )] - pub creator_community_actions: Option, - #[cfg_attr(feature = "full", diesel(embed))] pub person_actions: Option, #[cfg_attr(feature = "full", diesel(embed))] pub community_actions: Option, @@ -171,13 +161,6 @@ pub struct PostReportView { ) )] pub post_creator: Person, - #[cfg_attr(feature = "full", - diesel( - select_expression_type = Nullable, - select_expression = creator_community_actions_select().nullable() - ) - )] - pub creator_community_actions: Option, #[cfg_attr(feature = "full", diesel(embed))] pub community_actions: Option, #[cfg_attr(feature = "full", diesel(embed))] diff --git a/crates/db_views/search_combined/src/impls.rs b/crates/db_views/search_combined/src/impls.rs index 889159148..e8838916f 100644 --- a/crates/db_views/search_combined/src/impls.rs +++ b/crates/db_views/search_combined/src/impls.rs @@ -433,15 +433,14 @@ impl InternalToCombinedView for SearchCombinedViewInternal { creator, community_actions: v.community_actions, instance_actions: v.instance_actions, - creator_home_instance_actions: v.creator_home_instance_actions, - creator_local_instance_actions: v.creator_local_instance_actions, - creator_community_actions: v.creator_community_actions, person_actions: v.person_actions, comment_actions: v.comment_actions, creator_is_admin: v.item_creator_is_admin, post_tags: v.post_tags, can_mod: v.can_mod, creator_banned: v.creator_banned, + creator_is_moderator: v.creator_is_moderator, + creator_banned_from_community: v.creator_banned_from_community, })) } else if let (Some(post), Some(creator), Some(community)) = (v.post, v.item_creator.clone(), v.community.clone()) @@ -454,14 +453,13 @@ impl InternalToCombinedView for SearchCombinedViewInternal { image_details: v.image_details, community_actions: v.community_actions, instance_actions: v.instance_actions, - creator_home_instance_actions: v.creator_home_instance_actions, - creator_local_instance_actions: v.creator_local_instance_actions, - creator_community_actions: v.creator_community_actions, person_actions: v.person_actions, post_actions: v.post_actions, tags: v.post_tags, can_mod: v.can_mod, creator_banned: v.creator_banned, + creator_is_moderator: v.creator_is_moderator, + creator_banned_from_community: v.creator_banned_from_community, })) } else if let Some(community) = v.community { Some(SearchCombinedView::Community(CommunityView { @@ -481,8 +479,6 @@ impl InternalToCombinedView for SearchCombinedViewInternal { person, is_admin: v.item_creator_is_admin, person_actions: v.person_actions, - home_instance_actions: v.creator_home_instance_actions, - local_instance_actions: v.creator_local_instance_actions, creator_banned: v.creator_banned, })) } else { @@ -550,7 +546,7 @@ mod tests { let timmy_view = LocalUserView { local_user: timmy_local_user, person: timmy.clone(), - instance_actions: None, + banned: false, }; let community_form = CommunityInsertForm { diff --git a/crates/db_views/search_combined/src/lib.rs b/crates/db_views/search_combined/src/lib.rs index 6267b3abc..7347a1a63 100644 --- a/crates/db_views/search_combined/src/lib.rs +++ b/crates/db_views/search_combined/src/lib.rs @@ -23,22 +23,15 @@ use serde::{Deserialize, Serialize}; use serde_with::skip_serializing_none; #[cfg(feature = "full")] use { - diesel::{dsl::Nullable, NullableExpressionMethods, Queryable, Selectable}, - lemmy_db_schema::{ - utils::queries::{ - community_post_tags_fragment, - creator_banned, - creator_community_actions_select, - creator_home_instance_actions_select, - creator_is_admin, - creator_local_instance_actions_select, - local_user_can_mod, - post_tags_fragment, - }, - CreatorCommunityActionsAllColumnsTuple, - CreatorHomeInstanceActionsAllColumnsTuple, - CreatorLocalInstanceActionsAllColumnsTuple, + diesel::{Queryable, Selectable}, + lemmy_db_schema::utils::queries::{ + community_post_tags_fragment, + creator_banned, + creator_is_admin, + local_user_can_mod, + post_tags_fragment, }, + lemmy_db_schema::utils::queries::{creator_banned_from_community, creator_is_moderator}, lemmy_db_views_local_user::LocalUserView, }; @@ -62,25 +55,10 @@ pub(crate) struct SearchCombinedViewInternal { pub community: Option, #[cfg_attr(feature = "full", diesel(embed))] pub multi_community: Option, - #[cfg_attr(feature = "full", - diesel( - select_expression_type = Nullable, - select_expression = creator_community_actions_select().nullable() - ) - )] - pub creator_community_actions: Option, #[cfg_attr(feature = "full", diesel(embed))] pub community_actions: Option, #[cfg_attr(feature = "full", diesel(embed))] pub instance_actions: Option, - #[cfg_attr(feature = "full", diesel( - select_expression_type = Nullable, - select_expression = creator_home_instance_actions_select()))] - pub creator_home_instance_actions: Option, - #[cfg_attr(feature = "full", diesel( - select_expression_type = Nullable, - select_expression = creator_local_instance_actions_select()))] - pub creator_local_instance_actions: Option, #[cfg_attr(feature = "full", diesel(embed))] pub post_actions: Option, #[cfg_attr(feature = "full", diesel(embed))] @@ -121,6 +99,18 @@ pub(crate) struct SearchCombinedViewInternal { ) )] pub creator_banned: bool, + #[cfg_attr(feature = "full", + diesel( + select_expression = creator_is_moderator() + ) + )] + pub creator_is_moderator: bool, + #[cfg_attr(feature = "full", + diesel( + select_expression = creator_banned_from_community() + ) + )] + pub creator_banned_from_community: bool, } #[derive(Debug, PartialEq, Serialize, Deserialize, Clone)] diff --git a/crates/email/src/notifications.rs b/crates/email/src/notifications.rs index 1b3424414..50bb30b0f 100644 --- a/crates/email/src/notifications.rs +++ b/crates/email/src/notifications.rs @@ -109,12 +109,7 @@ async fn send_email_to_user( body: &str, settings: &Settings, ) { - let banned = local_user_view - .instance_actions - .as_ref() - .and_then(|i| i.received_ban_at) - .is_some(); - if banned || !local_user_view.local_user.send_notifications_to_email { + if local_user_view.banned || !local_user_view.local_user.send_notifications_to_email { return; }