From: Dessalines Date: Mon, 19 Dec 2022 11:40:22 +0000 (-0500) Subject: Fixing missing forms, incorrect user discussion_languages (#2580) X-Git-Url: http://these/git/readmes/%24%7B%60data:application/static/README.ja.md?a=commitdiff_plain;h=76e0ab934f6b0b2c5193d14091efe15a6add91fc;p=lemmy.git Fixing missing forms, incorrect user discussion_languages (#2580) * Fixing missing forms, incorrect user discussion_languages * Add discussion_language to CommunityResponse * Adding discussion_languages to CommunityResponse * Adding discussion_language logic to community.create --- diff --git a/crates/api/src/community/follow.rs b/crates/api/src/community/follow.rs index dedfc971..b0729bdc 100644 --- a/crates/api/src/community/follow.rs +++ b/crates/api/src/community/follow.rs @@ -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, + }) } } diff --git a/crates/api_common/src/community.rs b/crates/api_common/src/community.rs index 71d7cf73..b0b2b0c6 100644 --- a/crates/api_common/src/community.rs +++ b/crates/api_common/src/community.rs @@ -37,12 +37,14 @@ pub struct CreateCommunity { pub banner: Option, pub nsfw: Option, pub posting_restricted_to_mods: Option, + pub discussion_languages: Option>, pub auth: Sensitive, } #[derive(Debug, Serialize, Deserialize, Clone)] pub struct CommunityResponse { pub community_view: CommunityView, + pub discussion_languages: Vec, } #[derive(Debug, Serialize, Deserialize, Clone, Default)] diff --git a/crates/api_common/src/site.rs b/crates/api_common/src/site.rs index c3f321ce..9e660136 100644 --- a/crates/api_common/src/site.rs +++ b/crates/api_common/src/site.rs @@ -150,6 +150,7 @@ pub struct CreateSite { pub captcha_difficulty: Option, pub allowed_instances: Option>, pub blocked_instances: Option>, + pub taglines: Option>, pub auth: Sensitive, } @@ -229,7 +230,7 @@ pub struct MyUserInfo { pub moderates: Vec, pub community_blocks: Vec, pub person_blocks: Vec, - pub discussion_languages: Vec, + pub discussion_languages: Vec, } #[derive(Debug, Serialize, Deserialize, Clone)] diff --git a/crates/api_common/src/websocket/send.rs b/crates/api_common/src/websocket/send.rs index 4f639452..e1d05202 100644 --- a/crates/api_common/src/websocket/send.rs +++ b/crates/api_common/src/websocket/send.rs @@ -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 Result { 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; diff --git a/crates/api_crud/src/community/create.rs b/crates/api_crud/src/community/create.rs index cf894edb..680d0c7c 100644 --- a/crates/api_crud/src/community/create.rs +++ b/crates/api_crud/src/community/create.rs @@ -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, + }) } } diff --git a/crates/api_crud/src/site/read.rs b/crates/api_crud/src/site/read.rs index 5b133c2c..db386921 100644 --- a/crates/api_crud/src/site/read.rs +++ b/crates/api_crud/src/site/read.rs @@ -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, diff --git a/crates/apub/src/activities/following/accept.rs b/crates/apub/src/activities/following/accept.rs index fbde090f..08853c50 100644 --- a/crates/apub/src/activities/following/accept.rs +++ b/crates/apub/src/activities/following/accept.rs @@ -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() diff --git a/crates/db_views/src/lib.rs b/crates/db_views/src/lib.rs index 8eeca692..9f150023 100644 --- a/crates/db_views/src/lib.rs +++ b/crates/db_views/src/lib.rs @@ -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 index 9ffa47ec..00000000 --- a/crates/db_views/src/local_user_discussion_language_view.rs +++ /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, 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::(conn) - .await?; - - Ok(res.into_iter().map(|a| a.1).collect::>()) - } -} diff --git a/crates/db_views/src/structs.rs b/crates/db_views/src/structs.rs index 1e4fe70a..9a5aa05b 100644 --- a/crates/db_views/src/structs.rs +++ b/crates/db_views/src/structs.rs @@ -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, -} diff --git a/docker/dev/docker-compose.yml b/docker/dev/docker-compose.yml index c7f3e1ab..56647a7a 100644 --- a/docker/dev/docker-compose.yml +++ b/docker/dev/docker-compose.yml @@ -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: diff --git a/docker/dev/nginx.conf b/docker/dev/nginx.conf index acdbdcf0..fd52ec84 100644 --- a/docker/dev/nginx.conf +++ b/docker/dev/nginx.conf @@ -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;