make it compile, move user languages to separate table

feature/language-tags
Felix Ableitner 2021-04-22 14:53:34 +02:00
parent fb8c05d6ba
commit d3f3cbb8df
15 changed files with 129 additions and 101 deletions

View File

@ -178,12 +178,14 @@ pub(crate) fn captcha_as_wav_base64(captcha: &Captcha) -> String {
#[cfg(test)]
mod tests {
use language_tags::LanguageTag;
use lemmy_api_common::check_validator_time;
use lemmy_db_queries::{establish_unpooled_connection, source::local_user::LocalUser_, Crud};
use lemmy_db_schema::source::{
local_user::{LocalUser, LocalUserForm},
person::{Person, PersonForm},
use lemmy_db_schema::{
source::{
local_user::{LocalUser, LocalUserForm},
person::{Person, PersonForm},
},
PrimaryLanguageTag,
};
use lemmy_utils::claims::Claims;
@ -201,7 +203,7 @@ mod tests {
let local_user_form = LocalUserForm {
person_id: inserted_person.id,
password_encrypted: "123456".to_string(),
discussion_languages: Some(vec![LanguageTag::parse("en").unwrap().into()]),
discussion_languages: Some(vec![PrimaryLanguageTag("en".to_string())]),
..LocalUserForm::default()
};

View File

@ -29,12 +29,14 @@ mod tests {
Crud,
Likeable,
};
use language_tags::LanguageTag;
use lemmy_db_schema::source::{
comment::{Comment, CommentForm, CommentLike, CommentLikeForm},
community::{Community, CommunityForm},
person::{Person, PersonForm},
post::{Post, PostForm},
use lemmy_db_schema::{
source::{
comment::{Comment, CommentForm, CommentLike, CommentLikeForm},
community::{Community, CommunityForm},
person::{Person, PersonForm},
post::{Post, PostForm},
},
PrimaryLanguageTag,
};
use serial_test::serial;
@ -69,7 +71,7 @@ mod tests {
name: "A test post".into(),
creator_id: inserted_person.id,
community_id: inserted_community.id,
language: Some(LanguageTag::parse("en").unwrap().into()),
language: Some(PrimaryLanguageTag("en".to_string())),
..PostForm::default()
};
@ -79,7 +81,7 @@ mod tests {
content: "A test comment".into(),
creator_id: inserted_person.id,
post_id: inserted_post.id,
language: Some(LanguageTag::parse("en").unwrap().into()),
language: Some(PrimaryLanguageTag("en".to_string())),
..CommentForm::default()
};
@ -90,7 +92,7 @@ mod tests {
creator_id: inserted_person.id,
post_id: inserted_post.id,
parent_id: Some(inserted_comment.id),
language: Some(LanguageTag::parse("en").unwrap().into()),
language: Some(PrimaryLanguageTag("en".to_string())),
..CommentForm::default()
};

View File

@ -33,12 +33,14 @@ mod tests {
Crud,
Followable,
};
use language_tags::LanguageTag;
use lemmy_db_schema::source::{
comment::{Comment, CommentForm},
community::{Community, CommunityFollower, CommunityFollowerForm, CommunityForm},
person::{Person, PersonForm},
post::{Post, PostForm},
use lemmy_db_schema::{
source::{
comment::{Comment, CommentForm},
community::{Community, CommunityFollower, CommunityFollowerForm, CommunityForm},
person::{Person, PersonForm},
post::{Post, PostForm},
},
PrimaryLanguageTag,
};
use serial_test::serial;
@ -105,7 +107,7 @@ mod tests {
name: "A test post".into(),
creator_id: inserted_person.id,
community_id: inserted_community.id,
language: Some(LanguageTag::parse("en").unwrap().into()),
language: Some(PrimaryLanguageTag("en".to_string())),
..PostForm::default()
};
@ -115,7 +117,7 @@ mod tests {
content: "A test comment".into(),
creator_id: inserted_person.id,
post_id: inserted_post.id,
language: Some(LanguageTag::parse("en").unwrap().into()),
language: Some(PrimaryLanguageTag("en".to_string())),
..CommentForm::default()
};
@ -126,7 +128,7 @@ mod tests {
creator_id: inserted_person.id,
post_id: inserted_post.id,
parent_id: Some(inserted_comment.id),
language: Some(LanguageTag::parse("en").unwrap().into()),
language: Some(PrimaryLanguageTag("en".to_string())),
..CommentForm::default()
};

View File

@ -29,12 +29,14 @@ mod tests {
Crud,
Likeable,
};
use language_tags::LanguageTag;
use lemmy_db_schema::source::{
comment::{Comment, CommentForm, CommentLike, CommentLikeForm},
community::{Community, CommunityForm},
person::{Person, PersonForm},
post::{Post, PostForm, PostLike, PostLikeForm},
use lemmy_db_schema::{
source::{
comment::{Comment, CommentForm, CommentLike, CommentLikeForm},
community::{Community, CommunityForm},
person::{Person, PersonForm},
post::{Post, PostForm, PostLike, PostLikeForm},
},
PrimaryLanguageTag,
};
use serial_test::serial;
@ -69,7 +71,7 @@ mod tests {
name: "A test post".into(),
creator_id: inserted_person.id,
community_id: inserted_community.id,
language: Some(LanguageTag::parse("en").unwrap().into()),
language: Some(PrimaryLanguageTag("en".to_string())),
..PostForm::default()
};
@ -87,7 +89,7 @@ mod tests {
content: "A test comment".into(),
creator_id: inserted_person.id,
post_id: inserted_post.id,
language: Some(LanguageTag::parse("en").unwrap().into()),
language: Some(PrimaryLanguageTag("en".to_string())),
..CommentForm::default()
};
@ -107,7 +109,7 @@ mod tests {
creator_id: inserted_person.id,
post_id: inserted_post.id,
parent_id: Some(inserted_comment.id),
language: Some(LanguageTag::parse("en").unwrap().into()),
language: Some(PrimaryLanguageTag("en".to_string())),
..CommentForm::default()
};

View File

@ -33,12 +33,14 @@ mod tests {
Crud,
Likeable,
};
use language_tags::LanguageTag;
use lemmy_db_schema::source::{
comment::{Comment, CommentForm},
community::{Community, CommunityForm},
person::{Person, PersonForm},
post::{Post, PostForm, PostLike, PostLikeForm},
use lemmy_db_schema::{
source::{
comment::{Comment, CommentForm},
community::{Community, CommunityForm},
person::{Person, PersonForm},
post::{Post, PostForm, PostLike, PostLikeForm},
},
PrimaryLanguageTag,
};
use serial_test::serial;
@ -73,7 +75,7 @@ mod tests {
name: "A test post".into(),
creator_id: inserted_person.id,
community_id: inserted_community.id,
language: Some(LanguageTag::parse("en").unwrap().into()),
language: Some(PrimaryLanguageTag("en".to_string())),
..PostForm::default()
};
@ -83,7 +85,7 @@ mod tests {
content: "A test comment".into(),
creator_id: inserted_person.id,
post_id: inserted_post.id,
language: Some(LanguageTag::parse("en").unwrap().into()),
language: Some(PrimaryLanguageTag("en".to_string())),
..CommentForm::default()
};
@ -94,7 +96,7 @@ mod tests {
creator_id: inserted_person.id,
post_id: inserted_post.id,
parent_id: Some(inserted_comment.id),
language: Some(LanguageTag::parse("en").unwrap().into()),
language: Some(PrimaryLanguageTag("en".to_string())),
..CommentForm::default()
};

View File

@ -26,13 +26,15 @@ impl SiteAggregates {
#[cfg(test)]
mod tests {
use crate::{aggregates::site_aggregates::SiteAggregates, establish_unpooled_connection, Crud};
use language_tags::LanguageTag;
use lemmy_db_schema::source::{
comment::{Comment, CommentForm},
community::{Community, CommunityForm},
person::{Person, PersonForm},
post::{Post, PostForm},
site::{Site, SiteForm},
use lemmy_db_schema::{
source::{
comment::{Comment, CommentForm},
community::{Community, CommunityForm},
person::{Person, PersonForm},
post::{Post, PostForm},
site::{Site, SiteForm},
},
PrimaryLanguageTag,
};
use serial_test::serial;
@ -75,7 +77,7 @@ mod tests {
name: "A test post".into(),
creator_id: inserted_person.id,
community_id: inserted_community.id,
language: Some(LanguageTag::parse("en").unwrap().into()),
language: Some(PrimaryLanguageTag("en".to_string())),
..PostForm::default()
};
@ -87,7 +89,7 @@ mod tests {
content: "A test comment".into(),
creator_id: inserted_person.id,
post_id: inserted_post.id,
language: Some(LanguageTag::parse("en").unwrap().into()),
language: Some(PrimaryLanguageTag("en".to_string())),
..CommentForm::default()
};
@ -99,7 +101,7 @@ mod tests {
creator_id: inserted_person.id,
post_id: inserted_post.id,
parent_id: Some(inserted_comment.id),
language: Some(LanguageTag::parse("en").unwrap().into()),
language: Some(PrimaryLanguageTag("en".to_string())),
..CommentForm::default()
};

View File

@ -231,12 +231,14 @@ impl Saveable<CommentSavedForm> for CommentSaved {
#[cfg(test)]
mod tests {
use crate::{establish_unpooled_connection, Crud, Likeable, Saveable};
use language_tags::LanguageTag;
use lemmy_db_schema::source::{
comment::*,
community::{Community, CommunityForm},
person::{Person, PersonForm},
post::*,
use lemmy_db_schema::{
source::{
comment::*,
community::{Community, CommunityForm},
person::{Person, PersonForm},
post::*,
},
PrimaryLanguageTag,
};
use serial_test::serial;
@ -264,7 +266,7 @@ mod tests {
name: "A test post".into(),
creator_id: inserted_person.id,
community_id: inserted_community.id,
language: Some(LanguageTag::parse("en").unwrap().into()),
language: Some(PrimaryLanguageTag("en".to_string())),
..PostForm::default()
};
@ -274,7 +276,7 @@ mod tests {
content: "A test comment".into(),
creator_id: inserted_person.id,
post_id: inserted_post.id,
language: Some(LanguageTag::parse("en").unwrap().into()),
language: Some(PrimaryLanguageTag("en".to_string())),
..CommentForm::default()
};
@ -293,7 +295,7 @@ mod tests {
updated: None,
ap_id: inserted_comment.ap_id.to_owned(),
local: true,
language: LanguageTag::parse("en").unwrap().into(),
language: PrimaryLanguageTag("en".to_string()),
};
let child_comment_form = CommentForm {
@ -301,7 +303,7 @@ mod tests {
creator_id: inserted_person.id,
post_id: inserted_post.id,
parent_id: Some(inserted_comment.id),
language: Some(LanguageTag::parse("en").unwrap().into()),
language: Some(PrimaryLanguageTag("en".to_string())),
..CommentForm::default()
};

View File

@ -198,8 +198,10 @@ impl Crud<ModAddForm, i32> for ModAdd {
#[cfg(test)]
mod tests {
use crate::{establish_unpooled_connection, Crud};
use language_tags::LanguageTag;
use lemmy_db_schema::source::{comment::*, community::*, moderator::*, person::*, post::*};
use lemmy_db_schema::{
source::{comment::*, community::*, moderator::*, person::*, post::*},
PrimaryLanguageTag,
};
use serial_test::serial;
// use Crud;
@ -234,7 +236,7 @@ mod tests {
name: "A test post thweep".into(),
creator_id: inserted_person.id,
community_id: inserted_community.id,
language: Some(LanguageTag::parse("en").unwrap().into()),
language: Some(PrimaryLanguageTag("en".to_string())),
..PostForm::default()
};
@ -244,7 +246,7 @@ mod tests {
content: "A test comment".into(),
creator_id: inserted_person.id,
post_id: inserted_post.id,
language: Some(LanguageTag::parse("en").unwrap().into()),
language: Some(PrimaryLanguageTag("en".to_string())),
..CommentForm::default()
};

View File

@ -81,11 +81,13 @@ mod tests {
source::password_reset_request::PasswordResetRequest_,
Crud,
};
use language_tags::LanguageTag;
use lemmy_db_schema::source::{
local_user::{LocalUser, LocalUserForm},
password_reset_request::PasswordResetRequest,
person::*,
use lemmy_db_schema::{
source::{
local_user::{LocalUser, LocalUserForm},
password_reset_request::PasswordResetRequest,
person::*,
},
PrimaryLanguageTag,
};
use serial_test::serial;
@ -104,7 +106,7 @@ mod tests {
let new_local_user = LocalUserForm {
person_id: inserted_person.id,
password_encrypted: "pass".to_string(),
discussion_languages: Some(vec![LanguageTag::parse("en").unwrap().into()]),
discussion_languages: Some(vec![PrimaryLanguageTag("en".to_string())]),
..LocalUserForm::default()
};

View File

@ -74,13 +74,15 @@ impl PersonMention_ for PersonMention {
#[cfg(test)]
mod tests {
use crate::{establish_unpooled_connection, Crud};
use language_tags::LanguageTag;
use lemmy_db_schema::source::{
comment::*,
community::{Community, CommunityForm},
person::*,
person_mention::*,
post::*,
use lemmy_db_schema::{
source::{
comment::*,
community::{Community, CommunityForm},
person::*,
person_mention::*,
post::*,
},
PrimaryLanguageTag,
};
use serial_test::serial;
@ -115,7 +117,7 @@ mod tests {
name: "A test post".into(),
creator_id: inserted_person.id,
community_id: inserted_community.id,
language: Some(LanguageTag::parse("en").unwrap().into()),
language: Some(PrimaryLanguageTag("en".to_string())),
..PostForm::default()
};
@ -125,7 +127,7 @@ mod tests {
content: "A test comment".into(),
creator_id: inserted_person.id,
post_id: inserted_post.id,
language: Some(LanguageTag::parse("en").unwrap().into()),
language: Some(PrimaryLanguageTag("en".to_string())),
..CommentForm::default()
};

View File

@ -260,10 +260,12 @@ impl Readable<PostReadForm> for PostRead {
#[cfg(test)]
mod tests {
use crate::{establish_unpooled_connection, source::post::*};
use language_tags::LanguageTag;
use lemmy_db_schema::source::{
community::{Community, CommunityForm},
person::*,
use lemmy_db_schema::{
source::{
community::{Community, CommunityForm},
person::*,
},
PrimaryLanguageTag,
};
use serial_test::serial;
@ -291,7 +293,7 @@ mod tests {
name: "A test post".into(),
creator_id: inserted_person.id,
community_id: inserted_community.id,
language: Some(LanguageTag::parse("en").unwrap().into()),
language: Some(PrimaryLanguageTag("en".to_string())),
..PostForm::default()
};
@ -317,7 +319,7 @@ mod tests {
thumbnail_url: None,
ap_id: inserted_post.ap_id.to_owned(),
local: true,
language: LanguageTag::parse("en").unwrap().into(),
language: PrimaryLanguageTag("en".to_string()),
};
// Post Like

View File

@ -140,8 +140,10 @@ impl PrivateMessage_ for PrivateMessage {
#[cfg(test)]
mod tests {
use crate::{establish_unpooled_connection, source::private_message::PrivateMessage_, Crud};
use language_tags::LanguageTag;
use lemmy_db_schema::source::{person::*, private_message::*};
use lemmy_db_schema::{
source::{person::*, private_message::*},
PrimaryLanguageTag,
};
use serial_test::serial;
#[test]
@ -167,7 +169,7 @@ mod tests {
content: "A test private message".into(),
creator_id: inserted_creator.id,
recipient_id: inserted_recipient.id,
language: Some(LanguageTag::parse("en").unwrap().into()),
language: Some(PrimaryLanguageTag("en".to_string())),
..PrivateMessageForm::default()
};
@ -184,7 +186,7 @@ mod tests {
published: inserted_private_message.published,
ap_id: inserted_private_message.ap_id.to_owned(),
local: true,
language: LanguageTag::parse("en").unwrap().into(),
language: PrimaryLanguageTag("en".to_string()),
};
let read_private_message = PrivateMessage::read(&conn, inserted_private_message.id).unwrap();

View File

@ -124,7 +124,7 @@ pub fn naive_now() -> NaiveDateTime {
#[repr(transparent)]
#[derive(Debug, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, DieselNewType)]
pub struct PrimaryLanguageTag(String);
pub struct PrimaryLanguageTag(pub String);
impl TryFrom<LanguageTag> for PrimaryLanguageTag {
type Error = ValidationError;

View File

@ -438,14 +438,16 @@ impl ViewToVec for CommentView {
#[cfg(test)]
mod tests {
use crate::comment_view::*;
use language_tags::LanguageTag;
use lemmy_db_queries::{
aggregates::comment_aggregates::CommentAggregates,
establish_unpooled_connection,
Crud,
Likeable,
};
use lemmy_db_schema::source::{comment::*, community::*, person::*, post::*};
use lemmy_db_schema::{
source::{comment::*, community::*, person::*, post::*},
PrimaryLanguageTag,
};
use serial_test::serial;
#[test]
@ -472,7 +474,7 @@ mod tests {
name: "A test post 2".into(),
creator_id: inserted_person.id,
community_id: inserted_community.id,
language: Some(LanguageTag::parse("en").unwrap().into()),
language: Some(PrimaryLanguageTag("en".to_string())),
..PostForm::default()
};
@ -482,7 +484,7 @@ mod tests {
content: "A test comment 32".into(),
creator_id: inserted_person.id,
post_id: inserted_post.id,
language: Some(LanguageTag::parse("en").unwrap().into()),
language: Some(PrimaryLanguageTag("en".to_string())),
..CommentForm::default()
};
@ -517,7 +519,7 @@ mod tests {
ap_id: inserted_comment.ap_id,
updated: None,
local: true,
language: LanguageTag::parse("en").unwrap().into(),
language: PrimaryLanguageTag("en".to_string()),
},
creator: PersonSafe {
id: inserted_person.id,
@ -558,7 +560,7 @@ mod tests {
thumbnail_url: None,
ap_id: inserted_post.ap_id.to_owned(),
local: true,
language: LanguageTag::parse("en").unwrap().into(),
language: PrimaryLanguageTag("en".to_string()),
},
community: CommunitySafe {
id: inserted_community.id,

View File

@ -444,7 +444,6 @@ impl ViewToVec for PostView {
#[cfg(test)]
mod tests {
use crate::post_view::{PostQueryBuilder, PostView};
use language_tags::LanguageTag;
use lemmy_db_queries::{
aggregates::post_aggregates::PostAggregates,
establish_unpooled_connection,
@ -453,7 +452,10 @@ mod tests {
ListingType,
SortType,
};
use lemmy_db_schema::source::{community::*, person::*, post::*};
use lemmy_db_schema::{
source::{community::*, person::*, post::*},
PrimaryLanguageTag,
};
use serial_test::serial;
#[test]
@ -484,7 +486,7 @@ mod tests {
name: post_name.to_owned(),
creator_id: inserted_person.id,
community_id: inserted_community.id,
language: Some(LanguageTag::parse("en").unwrap().into()),
language: Some(PrimaryLanguageTag("en".to_string())),
..PostForm::default()
};
@ -549,7 +551,7 @@ mod tests {
thumbnail_url: None,
ap_id: inserted_post.ap_id.to_owned(),
local: true,
language: LanguageTag::parse("en").unwrap().into(),
language: PrimaryLanguageTag("en".to_string()),
},
my_vote: None,
creator: PersonSafe {