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
This commit is contained in:
Dessalines 2022-12-19 06:40:22 -05:00 committed by GitHub
parent 9dfd819691
commit 76e0ab934f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 72 additions and 71 deletions

View 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,
})
}
}

View 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)]

View 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)]

View 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;

View file

@ -16,7 +16,9 @@ use lemmy_api_common::{
},
};
use lemmy_db_schema::{
source::community::{
source::{
actor_language::{CommunityLanguage, SiteLanguage},
community::{
Community,
CommunityFollower,
CommunityFollowerForm,
@ -24,6 +26,7 @@ use lemmy_db_schema::{
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,
})
}
}

View 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,8 +67,7 @@ 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)
let discussion_languages = LocalUserLanguage::read(context.pool(), local_user_id)
.await
.map_err(|e| LemmyError::from_error_message(e, "system_err_login"))?;

View 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()

View 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;

View file

@ -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>>())
}
}

View 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,
}

View 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:

View 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;