]> Untitled Git - lemmy.git/commitdiff
Fixing missing forms, incorrect user discussion_languages (#2580)
authorDessalines <dessalines@users.noreply.github.com>
Mon, 19 Dec 2022 11:40:22 +0000 (06:40 -0500)
committerGitHub <noreply@github.com>
Mon, 19 Dec 2022 11:40:22 +0000 (11:40 +0000)
* Fixing missing forms, incorrect user discussion_languages

* Add discussion_language to CommunityResponse

* Adding discussion_languages to CommunityResponse

* Adding discussion_language logic to community.create

12 files changed:
crates/api/src/community/follow.rs
crates/api_common/src/community.rs
crates/api_common/src/site.rs
crates/api_common/src/websocket/send.rs
crates/api_crud/src/community/create.rs
crates/api_crud/src/site/read.rs
crates/apub/src/activities/following/accept.rs
crates/db_views/src/lib.rs
crates/db_views/src/local_user_discussion_language_view.rs [deleted file]
crates/db_views/src/structs.rs
docker/dev/docker-compose.yml
docker/dev/nginx.conf

index dedfc97129f8570677702fcd64a0ce1e34edb698..b0729bdc6848132082a2b7ba91f7ba83d08c4f64 100644 (file)
@@ -6,7 +6,10 @@ use lemmy_api_common::{
   utils::{check_community_ban, check_community_deleted_or_removed, get_local_user_view_from_jwt},
 };
 use lemmy_db_schema::{
-  source::community::{Community, CommunityFollower, CommunityFollowerForm},
+  source::{
+    actor_language::CommunityLanguage,
+    community::{Community, CommunityFollower, CommunityFollowerForm},
+  },
   traits::{Crud, Followable},
 };
 use lemmy_db_views_actor::structs::CommunityView;
@@ -51,7 +54,11 @@ impl Perform for FollowCommunity {
     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 discussion_languages = CommunityLanguage::read(context.pool(), community_id).await?;
 
-    Ok(Self::Response { community_view })
+    Ok(Self::Response {
+      community_view,
+      discussion_languages,
+    })
   }
 }
index 71d7cf7349d558f0920200526645e555dcbe13e1..b0b2b0c65496bd659a6d697d0ddc14d72391f4c1 100644 (file)
@@ -37,12 +37,14 @@ pub struct CreateCommunity {
   pub banner: Option<String>,
   pub nsfw: Option<bool>,
   pub posting_restricted_to_mods: Option<bool>,
+  pub discussion_languages: Option<Vec<LanguageId>>,
   pub auth: Sensitive<String>,
 }
 
 #[derive(Debug, Serialize, Deserialize, Clone)]
 pub struct CommunityResponse {
   pub community_view: CommunityView,
+  pub discussion_languages: Vec<LanguageId>,
 }
 
 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
index c3f321ce704e606064001334a4446461b67381de..9e66013656daff9c4da23832dd2088689ea12b48 100644 (file)
@@ -150,6 +150,7 @@ pub struct CreateSite {
   pub captcha_difficulty: Option<String>,
   pub allowed_instances: Option<Vec<String>>,
   pub blocked_instances: Option<Vec<String>>,
+  pub taglines: Option<Vec<String>>,
   pub auth: Sensitive<String>,
 }
 
@@ -229,7 +230,7 @@ pub struct MyUserInfo {
   pub moderates: Vec<CommunityModeratorView>,
   pub community_blocks: Vec<CommunityBlockView>,
   pub person_blocks: Vec<PersonBlockView>,
-  pub discussion_languages: Vec<Language>,
+  pub discussion_languages: Vec<LanguageId>,
 }
 
 #[derive(Debug, Serialize, Deserialize, Clone)]
index 4f639452e94902b6bb4a8eee925646c01ef211a8..e1d05202c0c859c2e08b6eb23b18ad75ad3c2d8c 100644 (file)
@@ -10,6 +10,7 @@ use crate::{
 use lemmy_db_schema::{
   newtypes::{CommentId, CommunityId, LocalUserId, PersonId, PostId, PrivateMessageId},
   source::{
+    actor_language::CommunityLanguage,
     comment::Comment,
     comment_reply::{CommentReply, CommentReplyInsertForm},
     person::Person,
@@ -98,8 +99,12 @@ pub async fn send_community_ws_message<OP: ToString + Send + OperationType + 'st
   context: &LemmyContext,
 ) -> Result<CommunityResponse, LemmyError> {
   let community_view = CommunityView::read(context.pool(), community_id, person_id).await?;
+  let discussion_languages = CommunityLanguage::read(context.pool(), community_id).await?;
 
-  let mut res = CommunityResponse { community_view };
+  let mut res = CommunityResponse {
+    community_view,
+    discussion_languages,
+  };
 
   // Strip out the person id and subscribed when sending to others
   res.community_view.subscribed = SubscribedType::NotSubscribed;
index cf894edbd62abd0d00d8623f6ab4a809e9127b33..680d0c7c701aa658fdc2c99791ae202ec7912284 100644 (file)
@@ -16,13 +16,16 @@ use lemmy_api_common::{
   },
 };
 use lemmy_db_schema::{
-  source::community::{
-    Community,
-    CommunityFollower,
-    CommunityFollowerForm,
-    CommunityInsertForm,
-    CommunityModerator,
-    CommunityModeratorForm,
+  source::{
+    actor_language::{CommunityLanguage, SiteLanguage},
+    community::{
+      Community,
+      CommunityFollower,
+      CommunityFollowerForm,
+      CommunityInsertForm,
+      CommunityModerator,
+      CommunityModeratorForm,
+    },
   },
   traits::{ApubActor, Crud, Followable, Joinable},
   utils::diesel_option_overwrite_to_url_create,
@@ -126,10 +129,28 @@ impl PerformCrud for CreateCommunity {
       .await
       .map_err(|e| LemmyError::from_error_message(e, "community_follower_already_exists"))?;
 
+    // Update the discussion_languages if that's provided
+    let community_id = inserted_community.id;
+    if let Some(languages) = data.discussion_languages.clone() {
+      let site_languages = SiteLanguage::read_local(context.pool()).await?;
+      // check that community languages are a subset of site languages
+      // https://stackoverflow.com/a/64227550
+      let is_subset = languages.iter().all(|item| site_languages.contains(item));
+      if !is_subset {
+        return Err(LemmyError::from_message("language_not_allowed"));
+      }
+      CommunityLanguage::update(context.pool(), languages, community_id).await?;
+    }
+
     let person_id = local_user_view.person.id;
     let community_view =
       CommunityView::read(context.pool(), inserted_community.id, Some(person_id)).await?;
+    let discussion_languages =
+      CommunityLanguage::read(context.pool(), inserted_community.id).await?;
 
-    Ok(CommunityResponse { community_view })
+    Ok(CommunityResponse {
+      community_view,
+      discussion_languages,
+    })
   }
 }
index 5b133c2c7b6e0a25730cbb1de915db7e03615c37..db386921e961a7b81276f7e67300fb2c3df4eb53 100644 (file)
@@ -5,8 +5,12 @@ use lemmy_api_common::{
   site::{GetSite, GetSiteResponse, MyUserInfo},
   utils::{build_federated_instances, get_local_user_settings_view_from_jwt_opt},
 };
-use lemmy_db_schema::source::{actor_language::SiteLanguage, language::Language, tagline::Tagline};
-use lemmy_db_views::structs::{LocalUserDiscussionLanguageView, SiteView};
+use lemmy_db_schema::source::{
+  actor_language::{LocalUserLanguage, SiteLanguage},
+  language::Language,
+  tagline::Tagline,
+};
+use lemmy_db_views::structs::SiteView;
 use lemmy_db_views_actor::structs::{
   CommunityBlockView,
   CommunityFollowerView,
@@ -63,10 +67,9 @@ impl PerformCrud for GetSite {
         .await
         .map_err(|e| LemmyError::from_error_message(e, "system_err_login"))?;
 
-      let discussion_languages =
-        LocalUserDiscussionLanguageView::read_languages(context.pool(), local_user_id)
-          .await
-          .map_err(|e| LemmyError::from_error_message(e, "system_err_login"))?;
+      let discussion_languages = LocalUserLanguage::read(context.pool(), local_user_id)
+        .await
+        .map_err(|e| LemmyError::from_error_message(e, "system_err_login"))?;
 
       Some(MyUserInfo {
         local_user_view,
index fbde090f7b434c771e3f4d8ab0c4981e2e7a318c..08853c50df77e8c1bd6f897eb0593ee95971d59f 100644 (file)
@@ -16,7 +16,10 @@ use lemmy_api_common::{
   context::LemmyContext,
   websocket::UserOperation,
 };
-use lemmy_db_schema::{source::community::CommunityFollower, traits::Followable};
+use lemmy_db_schema::{
+  source::{actor_language::CommunityLanguage, community::CommunityFollower},
+  traits::Followable,
+};
 use lemmy_db_views::structs::LocalUserView;
 use lemmy_db_views_actor::structs::CommunityView;
 use lemmy_utils::error::LemmyError;
@@ -103,8 +106,12 @@ impl ActivityHandler for AcceptFollow {
       .await?
       .local_user
       .id;
+    let discussion_languages = CommunityLanguage::read(context.pool(), community_id).await?;
 
-    let response = CommunityResponse { community_view };
+    let response = CommunityResponse {
+      community_view,
+      discussion_languages,
+    };
 
     context
       .chat_server()
index 8eeca692e087cfc1db8fb07105110205a543a01c..9f15002376ee23c35b20420b8de5c51b49933783 100644 (file)
@@ -6,15 +6,12 @@ pub mod comment_report_view;
 #[cfg(feature = "full")]
 pub mod comment_view;
 #[cfg(feature = "full")]
-pub mod local_user_discussion_language_view;
-#[cfg(feature = "full")]
 pub mod local_user_view;
 #[cfg(feature = "full")]
 pub mod post_report_view;
 #[cfg(feature = "full")]
 pub mod post_view;
 #[cfg(feature = "full")]
-#[cfg(feature = "full")]
 pub mod private_message_report_view;
 #[cfg(feature = "full")]
 pub mod private_message_view;
diff --git a/crates/db_views/src/local_user_discussion_language_view.rs b/crates/db_views/src/local_user_discussion_language_view.rs
deleted file mode 100644 (file)
index 9ffa47e..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-use crate::structs::LocalUserDiscussionLanguageView;
-use diesel::{result::Error, ExpressionMethods, QueryDsl};
-use diesel_async::RunQueryDsl;
-use lemmy_db_schema::{
-  newtypes::LocalUserId,
-  schema::{language, local_user, local_user_language},
-  source::{
-    language::Language,
-    local_user::{LocalUser, LocalUserSettings},
-  },
-  traits::ToSafeSettings,
-  utils::{get_conn, DbPool},
-};
-
-type LocalUserDiscussionLanguageViewTuple = (LocalUserSettings, Language);
-
-impl LocalUserDiscussionLanguageView {
-  pub async fn read_languages(
-    pool: &DbPool,
-    local_user_id: LocalUserId,
-  ) -> Result<Vec<Language>, Error> {
-    let conn = &mut get_conn(pool).await?;
-
-    let res = local_user_language::table
-      .inner_join(local_user::table)
-      .inner_join(language::table)
-      .select((
-        LocalUser::safe_settings_columns_tuple(),
-        language::all_columns,
-      ))
-      .filter(local_user::id.eq(local_user_id))
-      .load::<LocalUserDiscussionLanguageViewTuple>(conn)
-      .await?;
-
-    Ok(res.into_iter().map(|a| a.1).collect::<Vec<Language>>())
-  }
-}
index 1e4fe70ae8450653d373a41558ec03afe1bd5c74..9a5aa05b9eafbecae959af931012c7f9cc3e4dad 100644 (file)
@@ -4,7 +4,6 @@ use lemmy_db_schema::{
     comment::Comment,
     comment_report::CommentReport,
     community::CommunitySafe,
-    language::Language,
     local_site::LocalSite,
     local_site_rate_limit::LocalSiteRateLimit,
     local_user::{LocalUser, LocalUserSettings},
@@ -121,9 +120,3 @@ pub struct SiteView {
   pub local_site_rate_limit: LocalSiteRateLimit,
   pub counts: SiteAggregates,
 }
-
-#[derive(Debug, Serialize, Deserialize, Clone)]
-pub struct LocalUserDiscussionLanguageView {
-  pub local_user: LocalUserSettings,
-  pub language: Language,
-}
index c7f3e1abaa46faa486fdc08e55bed689a7fba416..56647a7a57fc5149c167317e148100a03f0fe617 100644 (file)
@@ -17,6 +17,7 @@ services:
     ports:
     # actual and only port facing any connection from outside 
       - "1236:1236"
+      - "8536:8536"
     volumes:
       - ./nginx.conf:/etc/nginx/nginx.conf:ro
     restart: always
@@ -46,13 +47,13 @@ services:
       - pictrs
 
   lemmy-ui:
-    image: dessalines/lemmy-ui:dev
+    image: dessalines/lemmy-ui:dev
     # use this to build your local lemmy ui image for development
     # run docker compose up --build
     # assuming lemmy-ui is cloned besides lemmy directory
-    build: 
-     context: ../../../lemmy-ui
-     dockerfile: dev.dockerfile
+    build: 
+     context: ../../../lemmy-ui
+     dockerfile: dev.dockerfile
     networks:
       - lemmyinternal
     environment:
index acdbdcf01a250fdc3c454fefc79d720450567419..fd52ec84e2d7479fb536d22ebb08f82323b481c4 100644 (file)
@@ -15,6 +15,7 @@ http {
     server {
         # this is the port inside docker, not the public one yet
         listen 1236;
+        listen 8536;
         # change if needed, this is facing the public web
         server_name localhost;
         server_tokens off;