* Fix limit_languages to operate on correct instance (fixes #2496)
* cargo fmt
let site_id = local_site.site_id;
if let Some(discussion_languages) = data.discussion_languages.clone() {
blocking(context.pool(), move |conn| {
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)
.build();
blocking(context.pool(), move |conn| {
.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
})
.await
// Ignore errors for all these, so as to not throw errors if no update occurs
let site = blocking(data.pool(), move |conn| {
let site = Site::create(conn, &site_form)?;
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??;
Ok::<Site, diesel::result::Error>(site)
})
.await??;
use crate::{
diesel::JoinOnDsl,
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},
pub fn update(
conn: &mut PgConnection,
language_ids: Vec<LanguageId>,
pub fn update(
conn: &mut PgConnection,
language_ids: Vec<LanguageId>,
) -> Result<(), Error> {
conn.build_transaction().read_write().run(|conn| {
use crate::schema::site_language::dsl::*;
// Clear the current languages
) -> 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 {
let lang_ids = convert_update_languages(conn, language_ids)?;
for l in lang_ids {
let form = SiteLanguageForm {
language_id: l,
};
insert_into(site_language)
language_id: l,
};
insert_into(site_language)
.get_result::<Self>(conn)?;
}
.get_result::<Self>(conn)?;
}
- CommunityLanguage::limit_languages(conn)?;
+ CommunityLanguage::limit_languages(conn, site.instance_id)?;
/// 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.
/// 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,
use crate::schema::{
community::dsl as c,
community_language::dsl as cl,
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)
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::instance_id.eq(for_instance_id))
.filter(sl::language_id.is_null())
.select(cl::language_id)
.get_results(conn)?;
.filter(sl::language_id.is_null())
.select(cl::language_id)
.get_results(conn)?;
assert_eq!(184, site_languages1.len());
let test_langs = test_langs1(conn);
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
let site_languages2 = SiteLanguage::read_local(conn).unwrap();
// after update, site only has new languages
let (site, instance) = create_test_site(conn);
let test_langs = test_langs1(conn);
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())
let person_form = PersonInsertForm::builder()
.name("my test person".to_string())
let conn = &mut establish_unpooled_connection();
let (site, instance) = create_test_site(conn);
let test_langs = test_langs1(conn);
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);
let read_site_langs = SiteLanguage::read(conn, site.id).unwrap();
assert_eq!(test_langs, read_site_langs);
// 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.
// 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);
let community_langs2 = CommunityLanguage::read(conn, community.id).unwrap();
assert_eq!(vec![test_langs[0]], community_langs2);
.get_result::<Self>(conn)?;
// initialize with all languages
.get_result::<Self>(conn)?;
// initialize with all languages
- SiteLanguage::update(conn, vec![], site_.id)?;
+ SiteLanguage::update(conn, vec![], &site_)?;