mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-25 07:36:01 +00:00
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:
parent
9dfd819691
commit
76e0ab934f
|
@ -6,7 +6,10 @@ use lemmy_api_common::{
|
||||||
utils::{check_community_ban, check_community_deleted_or_removed, get_local_user_view_from_jwt},
|
utils::{check_community_ban, check_community_deleted_or_removed, get_local_user_view_from_jwt},
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::community::{Community, CommunityFollower, CommunityFollowerForm},
|
source::{
|
||||||
|
actor_language::CommunityLanguage,
|
||||||
|
community::{Community, CommunityFollower, CommunityFollowerForm},
|
||||||
|
},
|
||||||
traits::{Crud, Followable},
|
traits::{Crud, Followable},
|
||||||
};
|
};
|
||||||
use lemmy_db_views_actor::structs::CommunityView;
|
use lemmy_db_views_actor::structs::CommunityView;
|
||||||
|
@ -51,7 +54,11 @@ impl Perform for FollowCommunity {
|
||||||
let community_id = data.community_id;
|
let community_id = data.community_id;
|
||||||
let person_id = local_user_view.person.id;
|
let person_id = local_user_view.person.id;
|
||||||
let community_view = CommunityView::read(context.pool(), community_id, Some(person_id)).await?;
|
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,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,12 +37,14 @@ pub struct CreateCommunity {
|
||||||
pub banner: Option<String>,
|
pub banner: Option<String>,
|
||||||
pub nsfw: Option<bool>,
|
pub nsfw: Option<bool>,
|
||||||
pub posting_restricted_to_mods: Option<bool>,
|
pub posting_restricted_to_mods: Option<bool>,
|
||||||
|
pub discussion_languages: Option<Vec<LanguageId>>,
|
||||||
pub auth: Sensitive<String>,
|
pub auth: Sensitive<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
pub struct CommunityResponse {
|
pub struct CommunityResponse {
|
||||||
pub community_view: CommunityView,
|
pub community_view: CommunityView,
|
||||||
|
pub discussion_languages: Vec<LanguageId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
|
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
|
||||||
|
|
|
@ -150,6 +150,7 @@ pub struct CreateSite {
|
||||||
pub captcha_difficulty: Option<String>,
|
pub captcha_difficulty: Option<String>,
|
||||||
pub allowed_instances: Option<Vec<String>>,
|
pub allowed_instances: Option<Vec<String>>,
|
||||||
pub blocked_instances: Option<Vec<String>>,
|
pub blocked_instances: Option<Vec<String>>,
|
||||||
|
pub taglines: Option<Vec<String>>,
|
||||||
pub auth: Sensitive<String>,
|
pub auth: Sensitive<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -229,7 +230,7 @@ pub struct MyUserInfo {
|
||||||
pub moderates: Vec<CommunityModeratorView>,
|
pub moderates: Vec<CommunityModeratorView>,
|
||||||
pub community_blocks: Vec<CommunityBlockView>,
|
pub community_blocks: Vec<CommunityBlockView>,
|
||||||
pub person_blocks: Vec<PersonBlockView>,
|
pub person_blocks: Vec<PersonBlockView>,
|
||||||
pub discussion_languages: Vec<Language>,
|
pub discussion_languages: Vec<LanguageId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
|
|
|
@ -10,6 +10,7 @@ use crate::{
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
newtypes::{CommentId, CommunityId, LocalUserId, PersonId, PostId, PrivateMessageId},
|
newtypes::{CommentId, CommunityId, LocalUserId, PersonId, PostId, PrivateMessageId},
|
||||||
source::{
|
source::{
|
||||||
|
actor_language::CommunityLanguage,
|
||||||
comment::Comment,
|
comment::Comment,
|
||||||
comment_reply::{CommentReply, CommentReplyInsertForm},
|
comment_reply::{CommentReply, CommentReplyInsertForm},
|
||||||
person::Person,
|
person::Person,
|
||||||
|
@ -98,8 +99,12 @@ pub async fn send_community_ws_message<OP: ToString + Send + OperationType + 'st
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
) -> Result<CommunityResponse, LemmyError> {
|
) -> Result<CommunityResponse, LemmyError> {
|
||||||
let community_view = CommunityView::read(context.pool(), community_id, person_id).await?;
|
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
|
// Strip out the person id and subscribed when sending to others
|
||||||
res.community_view.subscribed = SubscribedType::NotSubscribed;
|
res.community_view.subscribed = SubscribedType::NotSubscribed;
|
||||||
|
|
|
@ -16,13 +16,16 @@ use lemmy_api_common::{
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use lemmy_db_schema::{
|
use lemmy_db_schema::{
|
||||||
source::community::{
|
source::{
|
||||||
Community,
|
actor_language::{CommunityLanguage, SiteLanguage},
|
||||||
CommunityFollower,
|
community::{
|
||||||
CommunityFollowerForm,
|
Community,
|
||||||
CommunityInsertForm,
|
CommunityFollower,
|
||||||
CommunityModerator,
|
CommunityFollowerForm,
|
||||||
CommunityModeratorForm,
|
CommunityInsertForm,
|
||||||
|
CommunityModerator,
|
||||||
|
CommunityModeratorForm,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
traits::{ApubActor, Crud, Followable, Joinable},
|
traits::{ApubActor, Crud, Followable, Joinable},
|
||||||
utils::diesel_option_overwrite_to_url_create,
|
utils::diesel_option_overwrite_to_url_create,
|
||||||
|
@ -126,10 +129,28 @@ impl PerformCrud for CreateCommunity {
|
||||||
.await
|
.await
|
||||||
.map_err(|e| LemmyError::from_error_message(e, "community_follower_already_exists"))?;
|
.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 person_id = local_user_view.person.id;
|
||||||
let community_view =
|
let community_view =
|
||||||
CommunityView::read(context.pool(), inserted_community.id, Some(person_id)).await?;
|
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,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,8 +5,12 @@ use lemmy_api_common::{
|
||||||
site::{GetSite, GetSiteResponse, MyUserInfo},
|
site::{GetSite, GetSiteResponse, MyUserInfo},
|
||||||
utils::{build_federated_instances, get_local_user_settings_view_from_jwt_opt},
|
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_schema::source::{
|
||||||
use lemmy_db_views::structs::{LocalUserDiscussionLanguageView, SiteView};
|
actor_language::{LocalUserLanguage, SiteLanguage},
|
||||||
|
language::Language,
|
||||||
|
tagline::Tagline,
|
||||||
|
};
|
||||||
|
use lemmy_db_views::structs::SiteView;
|
||||||
use lemmy_db_views_actor::structs::{
|
use lemmy_db_views_actor::structs::{
|
||||||
CommunityBlockView,
|
CommunityBlockView,
|
||||||
CommunityFollowerView,
|
CommunityFollowerView,
|
||||||
|
@ -63,10 +67,9 @@ impl PerformCrud for GetSite {
|
||||||
.await
|
.await
|
||||||
.map_err(|e| LemmyError::from_error_message(e, "system_err_login"))?;
|
.map_err(|e| LemmyError::from_error_message(e, "system_err_login"))?;
|
||||||
|
|
||||||
let discussion_languages =
|
let discussion_languages = LocalUserLanguage::read(context.pool(), local_user_id)
|
||||||
LocalUserDiscussionLanguageView::read_languages(context.pool(), local_user_id)
|
.await
|
||||||
.await
|
.map_err(|e| LemmyError::from_error_message(e, "system_err_login"))?;
|
||||||
.map_err(|e| LemmyError::from_error_message(e, "system_err_login"))?;
|
|
||||||
|
|
||||||
Some(MyUserInfo {
|
Some(MyUserInfo {
|
||||||
local_user_view,
|
local_user_view,
|
||||||
|
|
|
@ -16,7 +16,10 @@ use lemmy_api_common::{
|
||||||
context::LemmyContext,
|
context::LemmyContext,
|
||||||
websocket::UserOperation,
|
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::structs::LocalUserView;
|
||||||
use lemmy_db_views_actor::structs::CommunityView;
|
use lemmy_db_views_actor::structs::CommunityView;
|
||||||
use lemmy_utils::error::LemmyError;
|
use lemmy_utils::error::LemmyError;
|
||||||
|
@ -103,8 +106,12 @@ impl ActivityHandler for AcceptFollow {
|
||||||
.await?
|
.await?
|
||||||
.local_user
|
.local_user
|
||||||
.id;
|
.id;
|
||||||
|
let discussion_languages = CommunityLanguage::read(context.pool(), community_id).await?;
|
||||||
|
|
||||||
let response = CommunityResponse { community_view };
|
let response = CommunityResponse {
|
||||||
|
community_view,
|
||||||
|
discussion_languages,
|
||||||
|
};
|
||||||
|
|
||||||
context
|
context
|
||||||
.chat_server()
|
.chat_server()
|
||||||
|
|
|
@ -6,15 +6,12 @@ pub mod comment_report_view;
|
||||||
#[cfg(feature = "full")]
|
#[cfg(feature = "full")]
|
||||||
pub mod comment_view;
|
pub mod comment_view;
|
||||||
#[cfg(feature = "full")]
|
#[cfg(feature = "full")]
|
||||||
pub mod local_user_discussion_language_view;
|
|
||||||
#[cfg(feature = "full")]
|
|
||||||
pub mod local_user_view;
|
pub mod local_user_view;
|
||||||
#[cfg(feature = "full")]
|
#[cfg(feature = "full")]
|
||||||
pub mod post_report_view;
|
pub mod post_report_view;
|
||||||
#[cfg(feature = "full")]
|
#[cfg(feature = "full")]
|
||||||
pub mod post_view;
|
pub mod post_view;
|
||||||
#[cfg(feature = "full")]
|
#[cfg(feature = "full")]
|
||||||
#[cfg(feature = "full")]
|
|
||||||
pub mod private_message_report_view;
|
pub mod private_message_report_view;
|
||||||
#[cfg(feature = "full")]
|
#[cfg(feature = "full")]
|
||||||
pub mod private_message_view;
|
pub mod private_message_view;
|
||||||
|
|
|
@ -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>>())
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -4,7 +4,6 @@ use lemmy_db_schema::{
|
||||||
comment::Comment,
|
comment::Comment,
|
||||||
comment_report::CommentReport,
|
comment_report::CommentReport,
|
||||||
community::CommunitySafe,
|
community::CommunitySafe,
|
||||||
language::Language,
|
|
||||||
local_site::LocalSite,
|
local_site::LocalSite,
|
||||||
local_site_rate_limit::LocalSiteRateLimit,
|
local_site_rate_limit::LocalSiteRateLimit,
|
||||||
local_user::{LocalUser, LocalUserSettings},
|
local_user::{LocalUser, LocalUserSettings},
|
||||||
|
@ -121,9 +120,3 @@ pub struct SiteView {
|
||||||
pub local_site_rate_limit: LocalSiteRateLimit,
|
pub local_site_rate_limit: LocalSiteRateLimit,
|
||||||
pub counts: SiteAggregates,
|
pub counts: SiteAggregates,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
|
||||||
pub struct LocalUserDiscussionLanguageView {
|
|
||||||
pub local_user: LocalUserSettings,
|
|
||||||
pub language: Language,
|
|
||||||
}
|
|
||||||
|
|
|
@ -17,6 +17,7 @@ services:
|
||||||
ports:
|
ports:
|
||||||
# actual and only port facing any connection from outside
|
# actual and only port facing any connection from outside
|
||||||
- "1236:1236"
|
- "1236:1236"
|
||||||
|
- "8536:8536"
|
||||||
volumes:
|
volumes:
|
||||||
- ./nginx.conf:/etc/nginx/nginx.conf:ro
|
- ./nginx.conf:/etc/nginx/nginx.conf:ro
|
||||||
restart: always
|
restart: always
|
||||||
|
@ -46,13 +47,13 @@ services:
|
||||||
- pictrs
|
- pictrs
|
||||||
|
|
||||||
lemmy-ui:
|
lemmy-ui:
|
||||||
# image: dessalines/lemmy-ui:dev
|
image: dessalines/lemmy-ui:dev
|
||||||
# use this to build your local lemmy ui image for development
|
# use this to build your local lemmy ui image for development
|
||||||
# run docker compose up --build
|
# run docker compose up --build
|
||||||
# assuming lemmy-ui is cloned besides lemmy directory
|
# assuming lemmy-ui is cloned besides lemmy directory
|
||||||
build:
|
# build:
|
||||||
context: ../../../lemmy-ui
|
# context: ../../../lemmy-ui
|
||||||
dockerfile: dev.dockerfile
|
# dockerfile: dev.dockerfile
|
||||||
networks:
|
networks:
|
||||||
- lemmyinternal
|
- lemmyinternal
|
||||||
environment:
|
environment:
|
||||||
|
|
|
@ -15,6 +15,7 @@ http {
|
||||||
server {
|
server {
|
||||||
# this is the port inside docker, not the public one yet
|
# this is the port inside docker, not the public one yet
|
||||||
listen 1236;
|
listen 1236;
|
||||||
|
listen 8536;
|
||||||
# change if needed, this is facing the public web
|
# change if needed, this is facing the public web
|
||||||
server_name localhost;
|
server_name localhost;
|
||||||
server_tokens off;
|
server_tokens off;
|
||||||
|
|
Loading…
Reference in a new issue