From 4a4629763ed8a88d14bd24ab53b30d80228e1e2b Mon Sep 17 00:00:00 2001 From: Dessalines Date: Thu, 3 Sep 2020 08:48:26 -0500 Subject: [PATCH 1/2] Fixing user search leaking emails. --- server/lemmy_db/src/user_view.rs | 23 +++++++++++++++++++++++ ui/src/components/search.tsx | 3 +-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/server/lemmy_db/src/user_view.rs b/server/lemmy_db/src/user_view.rs index 08f4c79cf..09a17aee3 100644 --- a/server/lemmy_db/src/user_view.rs +++ b/server/lemmy_db/src/user_view.rs @@ -125,6 +125,7 @@ impl<'a> UserQueryBuilder<'a> { pub fn list(self) -> Result, Error> { use super::user_view::user_fast::dsl::*; + use diesel::sql_types::{Nullable, Text}; let mut query = self.query; @@ -154,6 +155,28 @@ impl<'a> UserQueryBuilder<'a> { let (limit, offset) = limit_and_offset(self.page, self.limit); query = query.limit(limit).offset(offset); + // The select is necessary here to not get back emails + query = query.select(( + id, + actor_id, + name, + preferred_username, + avatar, + banner, + "".into_sql::>(), + matrix_user_id, + bio, + local, + admin, + banned, + show_avatars, + send_notifications_to_email, + published, + number_of_posts, + post_score, + number_of_comments, + comment_score, + )); query.load::(self.conn) } } diff --git a/ui/src/components/search.tsx b/ui/src/components/search.tsx index a18cc2d8e..8ab7f599b 100644 --- a/ui/src/components/search.tsx +++ b/ui/src/components/search.tsx @@ -311,7 +311,6 @@ export class Search extends Component { {i.type_ == 'users' && (
- @ {
- @ From 2aaf4228ac958739abb0c9cb29d00fbb4f80b556 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Thu, 3 Sep 2020 09:58:33 -0400 Subject: [PATCH 2/2] Local timeline (#1111) * Adding a local filter. Fixes #1103 * Not showing local if there are no federated instances. --- server/lemmy_db/src/comment_view.rs | 8 +++++--- server/lemmy_db/src/lib.rs | 1 + server/lemmy_db/src/post_view.rs | 8 +++++--- ui/package.json | 2 +- ui/src/components/listing-type-select.tsx | 18 ++++++++++++++++++ ui/src/components/main.tsx | 4 ++++ ui/src/components/user.tsx | 4 ++++ ui/translations/en.json | 1 + ui/yarn.lock | 13 +++++++++---- 9 files changed, 48 insertions(+), 11 deletions(-) diff --git a/server/lemmy_db/src/comment_view.rs b/server/lemmy_db/src/comment_view.rs index 1dcdf1934..a1751ca67 100644 --- a/server/lemmy_db/src/comment_view.rs +++ b/server/lemmy_db/src/comment_view.rs @@ -241,9 +241,11 @@ impl<'a> CommentQueryBuilder<'a> { query = query.filter(content.ilike(fuzzy_search(&search_term))); }; - if let ListingType::Subscribed = self.listing_type { - query = query.filter(subscribed.eq(true)); - } + query = match self.listing_type { + ListingType::Subscribed => query.filter(subscribed.eq(true)), + ListingType::Local => query.filter(community_local.eq(true)), + _ => query, + }; if self.saved_only { query = query.filter(saved.eq(true)); diff --git a/server/lemmy_db/src/lib.rs b/server/lemmy_db/src/lib.rs index bf7d00cab..4a4748ce5 100644 --- a/server/lemmy_db/src/lib.rs +++ b/server/lemmy_db/src/lib.rs @@ -147,6 +147,7 @@ pub enum SortType { #[derive(EnumString, ToString, Debug, Serialize, Deserialize)] pub enum ListingType { All, + Local, Subscribed, Community, } diff --git a/server/lemmy_db/src/post_view.rs b/server/lemmy_db/src/post_view.rs index d79253836..eb2429c6f 100644 --- a/server/lemmy_db/src/post_view.rs +++ b/server/lemmy_db/src/post_view.rs @@ -267,9 +267,11 @@ impl<'a> PostQueryBuilder<'a> { let mut query = self.query; - if let ListingType::Subscribed = self.listing_type { - query = query.filter(subscribed.eq(true)); - } + query = match self.listing_type { + ListingType::Subscribed => query.filter(subscribed.eq(true)), + ListingType::Local => query.filter(community_local.eq(true)), + _ => query, + }; if let Some(for_community_id) = self.for_community_id { query = query.filter(community_id.eq(for_community_id)); diff --git a/ui/package.json b/ui/package.json index f50f061f1..76920d184 100644 --- a/ui/package.json +++ b/ui/package.json @@ -37,7 +37,7 @@ "inferno-router": "^7.4.2", "js-cookie": "^2.2.0", "jwt-decode": "^2.2.0", - "lemmy-js-client": "^1.0.8", + "lemmy-js-client": "^1.0.9", "markdown-it": "^11.0.0", "markdown-it-container": "^3.0.0", "markdown-it-emoji": "^1.4.0", diff --git a/ui/src/components/listing-type-select.tsx b/ui/src/components/listing-type-select.tsx index 3d12d4343..f7d8cc3b2 100644 --- a/ui/src/components/listing-type-select.tsx +++ b/ui/src/components/listing-type-select.tsx @@ -6,6 +6,7 @@ import { i18n } from '../i18next'; interface ListingTypeSelectProps { type_: ListingType; + showLocal?: boolean; onChange?(val: ListingType): any; } @@ -31,6 +32,7 @@ export class ListingTypeSelect extends Component< static getDerivedStateFromProps(props: any): ListingTypeSelectProps { return { type_: props.type_, + showLocal: props.showLocal, }; } @@ -53,6 +55,22 @@ export class ListingTypeSelect extends Component< /> {i18n.t('subscribed')} + {this.props.showLocal && ( + + )}