mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-22 20:31:19 +00:00
Always assign default language before checking if language is allowed
This commit is contained in:
parent
859dfb3f81
commit
5a6685f5bb
5 changed files with 48 additions and 40 deletions
|
@ -89,17 +89,13 @@ pub async fn create_comment(
|
|||
}
|
||||
|
||||
// attempt to set default language if none was provided
|
||||
let language_id = match data.language_id {
|
||||
Some(lid) => lid,
|
||||
None => {
|
||||
default_post_language(
|
||||
let language_id = default_post_language(
|
||||
&mut context.pool(),
|
||||
data.language_id,
|
||||
community_id,
|
||||
local_user_view.local_user.id,
|
||||
)
|
||||
.await?
|
||||
}
|
||||
};
|
||||
.await?;
|
||||
|
||||
CommunityLanguage::is_allowed_community_language(&mut context.pool(), language_id, community_id)
|
||||
.await?;
|
||||
|
|
|
@ -55,14 +55,19 @@ pub async fn update_comment(
|
|||
Err(LemmyErrorType::NoCommentEditAllowed)?
|
||||
}
|
||||
|
||||
if let Some(language_id) = data.language_id {
|
||||
let language_id = default_post_language(
|
||||
&mut context.pool(),
|
||||
data.language_id,
|
||||
community_id,
|
||||
local_user_view.local_user.id,
|
||||
)
|
||||
.await?;
|
||||
CommunityLanguage::is_allowed_community_language(
|
||||
&mut context.pool(),
|
||||
language_id,
|
||||
orig_comment.community.id,
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
|
||||
let slur_regex = local_site_to_slur_regex(&local_site);
|
||||
let url_blocklist = get_url_blocklist(&context).await?;
|
||||
|
|
|
@ -105,17 +105,13 @@ pub async fn create_post(
|
|||
}
|
||||
|
||||
// attempt to set default language if none was provided
|
||||
let language_id = match data.language_id {
|
||||
Some(lid) => lid,
|
||||
None => {
|
||||
default_post_language(
|
||||
let language_id = default_post_language(
|
||||
&mut context.pool(),
|
||||
data.language_id,
|
||||
community_id,
|
||||
local_user_view.local_user.id,
|
||||
)
|
||||
.await?
|
||||
}
|
||||
};
|
||||
.await?;
|
||||
|
||||
// Only need to check if language is allowed in case user set it explicitly. When using default
|
||||
// language, it already only returns allowed languages.
|
||||
|
|
|
@ -101,14 +101,19 @@ pub async fn update_post(
|
|||
Err(LemmyErrorType::NoPostEditAllowed)?
|
||||
}
|
||||
|
||||
if let Some(language_id) = data.language_id {
|
||||
let language_id = default_post_language(
|
||||
&mut context.pool(),
|
||||
data.language_id,
|
||||
community_id,
|
||||
local_user_view.local_user.id,
|
||||
)
|
||||
.await?;
|
||||
CommunityLanguage::is_allowed_community_language(
|
||||
&mut context.pool(),
|
||||
language_id,
|
||||
orig_post.community_id,
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
|
||||
// handle changes to scheduled_publish_time
|
||||
let scheduled_publish_time = match (
|
||||
|
|
|
@ -321,11 +321,14 @@ impl CommunityLanguage {
|
|||
|
||||
pub async fn default_post_language(
|
||||
pool: &mut DbPool<'_>,
|
||||
language_id: Option<LanguageId>,
|
||||
community_id: CommunityId,
|
||||
local_user_id: LocalUserId,
|
||||
) -> Result<LanguageId, Error> {
|
||||
use crate::schema::{community_language::dsl as cl, local_user_language::dsl as ul};
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
match language_id {
|
||||
None | Some(LanguageId(0)) => {
|
||||
let mut intersection = ul::local_user_language
|
||||
.inner_join(cl::community_language.on(ul::language_id.eq(cl::language_id)))
|
||||
.filter(ul::local_user_id.eq(local_user_id))
|
||||
|
@ -343,6 +346,9 @@ pub async fn default_post_language(
|
|||
Ok(UNDETERMINED_ID)
|
||||
}
|
||||
}
|
||||
Some(lid) => Ok(lid),
|
||||
}
|
||||
}
|
||||
|
||||
/// If no language is given, set all languages
|
||||
async fn convert_update_languages(
|
||||
|
|
Loading…
Reference in a new issue