mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-10-01 01:36:12 -04:00
* Fix limit_languages to operate on correct instance (fixes #2496) * cargo fmt
This commit is contained in:
parent
3b0be52e67
commit
6aa9bdebae
@ -76,7 +76,8 @@ impl PerformCrud for EditSite {
|
||||
let site_id = local_site.site_id;
|
||||
if let Some(discussion_languages) = data.discussion_languages.clone() {
|
||||
blocking(context.pool(), move |conn| {
|
||||
SiteLanguage::update(conn, discussion_languages.clone(), site_id)
|
||||
let site = Site::read(conn, site_id)?;
|
||||
SiteLanguage::update(conn, discussion_languages, &site)
|
||||
})
|
||||
.await??;
|
||||
}
|
||||
@ -92,7 +93,7 @@ impl PerformCrud for EditSite {
|
||||
.build();
|
||||
|
||||
blocking(context.pool(), move |conn| {
|
||||
Site::update(conn, site_id, &site_form)
|
||||
Site::update(conn, local_site.site_id, &site_form)
|
||||
})
|
||||
.await
|
||||
// Ignore errors for all these, so as to not throw errors if no update occurs
|
||||
|
@ -159,7 +159,7 @@ impl ApubObject for ApubSite {
|
||||
|
||||
let site = blocking(data.pool(), move |conn| {
|
||||
let site = Site::create(conn, &site_form)?;
|
||||
SiteLanguage::update(conn, languages, site.id)?;
|
||||
SiteLanguage::update(conn, languages, &site)?;
|
||||
Ok::<Site, diesel::result::Error>(site)
|
||||
})
|
||||
.await??;
|
||||
|
@ -1,7 +1,7 @@
|
||||
use crate::{
|
||||
diesel::JoinOnDsl,
|
||||
newtypes::{CommunityId, LanguageId, LocalUserId, SiteId},
|
||||
source::{actor_language::*, language::Language},
|
||||
newtypes::{CommunityId, InstanceId, LanguageId, LocalUserId, SiteId},
|
||||
source::{actor_language::*, language::Language, site::Site},
|
||||
};
|
||||
use diesel::{
|
||||
delete,
|
||||
@ -81,17 +81,17 @@ impl SiteLanguage {
|
||||
pub fn update(
|
||||
conn: &mut PgConnection,
|
||||
language_ids: Vec<LanguageId>,
|
||||
for_site_id: SiteId,
|
||||
site: &Site,
|
||||
) -> Result<(), Error> {
|
||||
conn.build_transaction().read_write().run(|conn| {
|
||||
use crate::schema::site_language::dsl::*;
|
||||
// Clear the current languages
|
||||
delete(site_language.filter(site_id.eq(for_site_id))).execute(conn)?;
|
||||
delete(site_language.filter(site_id.eq(site.id))).execute(conn)?;
|
||||
|
||||
let lang_ids = convert_update_languages(conn, language_ids)?;
|
||||
for l in lang_ids {
|
||||
let form = SiteLanguageForm {
|
||||
site_id: for_site_id,
|
||||
site_id: site.id,
|
||||
language_id: l,
|
||||
};
|
||||
insert_into(site_language)
|
||||
@ -99,7 +99,7 @@ impl SiteLanguage {
|
||||
.get_result::<Self>(conn)?;
|
||||
}
|
||||
|
||||
CommunityLanguage::limit_languages(conn)?;
|
||||
CommunityLanguage::limit_languages(conn, site.instance_id)?;
|
||||
|
||||
Ok(())
|
||||
})
|
||||
@ -136,7 +136,7 @@ impl CommunityLanguage {
|
||||
/// also part of site languages. This is because post/comment language is only checked against
|
||||
/// community language, and it shouldnt be possible to post content in languages which are not
|
||||
/// allowed by local site.
|
||||
fn limit_languages(conn: &mut PgConnection) -> Result<(), Error> {
|
||||
fn limit_languages(conn: &mut PgConnection, for_instance_id: InstanceId) -> Result<(), Error> {
|
||||
use crate::schema::{
|
||||
community::dsl as c,
|
||||
community_language::dsl as cl,
|
||||
@ -145,7 +145,7 @@ impl CommunityLanguage {
|
||||
let community_languages: Vec<LanguageId> = cl::community_language
|
||||
.left_outer_join(sl::site_language.on(cl::language_id.eq(sl::language_id)))
|
||||
.inner_join(c::community)
|
||||
.filter(c::local)
|
||||
.filter(c::instance_id.eq(for_instance_id))
|
||||
.filter(sl::language_id.is_null())
|
||||
.select(cl::language_id)
|
||||
.get_results(conn)?;
|
||||
@ -343,7 +343,7 @@ mod tests {
|
||||
assert_eq!(184, site_languages1.len());
|
||||
|
||||
let test_langs = test_langs1(conn);
|
||||
SiteLanguage::update(conn, test_langs.clone(), site.id).unwrap();
|
||||
SiteLanguage::update(conn, test_langs.clone(), &site).unwrap();
|
||||
|
||||
let site_languages2 = SiteLanguage::read_local(conn).unwrap();
|
||||
// after update, site only has new languages
|
||||
@ -361,7 +361,7 @@ mod tests {
|
||||
|
||||
let (site, instance) = create_test_site(conn);
|
||||
let test_langs = test_langs1(conn);
|
||||
SiteLanguage::update(conn, test_langs.clone(), site.id).unwrap();
|
||||
SiteLanguage::update(conn, test_langs.clone(), &site).unwrap();
|
||||
|
||||
let person_form = PersonInsertForm::builder()
|
||||
.name("my test person".to_string())
|
||||
@ -399,7 +399,7 @@ mod tests {
|
||||
let conn = &mut establish_unpooled_connection();
|
||||
let (site, instance) = create_test_site(conn);
|
||||
let test_langs = test_langs1(conn);
|
||||
SiteLanguage::update(conn, test_langs.clone(), site.id).unwrap();
|
||||
SiteLanguage::update(conn, test_langs.clone(), &site).unwrap();
|
||||
|
||||
let read_site_langs = SiteLanguage::read(conn, site.id).unwrap();
|
||||
assert_eq!(test_langs, read_site_langs);
|
||||
@ -431,7 +431,7 @@ mod tests {
|
||||
|
||||
// limit site languages to en, fi. after this, community languages should be updated to
|
||||
// intersection of old languages (en, fr, ru) and (en, fi), which is only fi.
|
||||
SiteLanguage::update(conn, vec![test_langs[0], test_langs2[0]], site.id).unwrap();
|
||||
SiteLanguage::update(conn, vec![test_langs[0], test_langs2[0]], &site).unwrap();
|
||||
let community_langs2 = CommunityLanguage::read(conn, community.id).unwrap();
|
||||
assert_eq!(vec![test_langs[0]], community_langs2);
|
||||
|
||||
|
@ -26,7 +26,7 @@ impl Crud for Site {
|
||||
.get_result::<Self>(conn)?;
|
||||
|
||||
// initialize with all languages
|
||||
SiteLanguage::update(conn, vec![], site_.id)?;
|
||||
SiteLanguage::update(conn, vec![], &site_)?;
|
||||
Ok(site_)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user