diff options
author | Felix Ableitner <me@nutomic.com> | 2020-04-07 17:33:50 +0200 |
---|---|---|
committer | Felix Ableitner <me@nutomic.com> | 2020-04-07 17:33:50 +0200 |
commit | 095ccae616e40a93d59a14ee9e36840c0816aef4 (patch) | |
tree | 171d5dbf452d6a452518bc6108796a816f47befb | |
parent | 17bf6baa25a7b98718f209710d8a8ed908d125bd (diff) | |
parent | 56947e771046117cc58c78023ba1c8f3a2486bdd (diff) |
Merge branch 'federation_add_fed_columns' of https://yerbamate.dev/dessalines/lemmy into federation
-rw-r--r-- | server/migrations/2020-04-07-135912_add_user_community_apub_constraints/down.sql | 36 | ||||
-rw-r--r-- | server/migrations/2020-04-07-135912_add_user_community_apub_constraints/up.sql | 38 | ||||
-rw-r--r-- | server/src/api/user.rs | 2 | ||||
-rw-r--r-- | server/src/apub/mod.rs | 8 | ||||
-rw-r--r-- | server/src/db/code_migrations.rs | 1 | ||||
-rw-r--r-- | server/src/db/comment.rs | 1 | ||||
-rw-r--r-- | server/src/db/comment_view.rs | 1 | ||||
-rw-r--r-- | server/src/db/community.rs | 1 | ||||
-rw-r--r-- | server/src/db/moderator.rs | 2 | ||||
-rw-r--r-- | server/src/db/password_reset_request.rs | 1 | ||||
-rw-r--r-- | server/src/db/post.rs | 1 | ||||
-rw-r--r-- | server/src/db/post_view.rs | 1 | ||||
-rw-r--r-- | server/src/db/private_message.rs | 2 | ||||
-rw-r--r-- | server/src/db/user.rs | 6 | ||||
-rw-r--r-- | server/src/db/user_mention.rs | 2 | ||||
-rw-r--r-- | server/src/db/user_view.rs | 3 | ||||
-rw-r--r-- | server/src/schema.rs | 1 | ||||
-rw-r--r-- | ui/src/interfaces.ts | 1 |
18 files changed, 79 insertions, 29 deletions
diff --git a/server/migrations/2020-04-07-135912_add_user_community_apub_constraints/down.sql b/server/migrations/2020-04-07-135912_add_user_community_apub_constraints/down.sql new file mode 100644 index 00000000..faf24fdc --- /dev/null +++ b/server/migrations/2020-04-07-135912_add_user_community_apub_constraints/down.sql @@ -0,0 +1,36 @@ +-- User table +drop view user_view cascade; + +alter table user_ +add column fedi_name varchar(40) not null default 'changeme'; + +alter table user_ +add constraint user__name_fedi_name_key unique (name, fedi_name); + +-- Community +alter table community +add constraint community_name_key unique (name); + + +create view user_view as +select +u.id, +u.name, +u.avatar, +u.email, +u.matrix_user_id, +u.fedi_name, +u.admin, +u.banned, +u.show_avatars, +u.send_notifications_to_email, +u.published, +(select count(*) from post p where p.creator_id = u.id) as number_of_posts, +(select coalesce(sum(score), 0) from post p, post_like pl where u.id = p.creator_id and p.id = pl.post_id) as post_score, +(select count(*) from comment c where c.creator_id = u.id) as number_of_comments, +(select coalesce(sum(score), 0) from comment c, comment_like cl where u.id = c.creator_id and c.id = cl.comment_id) as comment_score +from user_ u; + +create materialized view user_mview as select * from user_view; + +create unique index idx_user_mview_id on user_mview (id); diff --git a/server/migrations/2020-04-07-135912_add_user_community_apub_constraints/up.sql b/server/migrations/2020-04-07-135912_add_user_community_apub_constraints/up.sql new file mode 100644 index 00000000..de65191d --- /dev/null +++ b/server/migrations/2020-04-07-135912_add_user_community_apub_constraints/up.sql @@ -0,0 +1,38 @@ +-- User table + +-- Need to regenerate user_view, user_mview +drop view user_view cascade; + +-- Remove the fedi_name constraint, drop that useless column +alter table user_ +drop constraint user__name_fedi_name_key; + +alter table user_ +drop column fedi_name; + +-- Community +alter table community +drop constraint community_name_key; + +create view user_view as +select +u.id, +u.name, +u.avatar, +u.email, +u.matrix_user_id, +u.admin, +u.banned, +u.show_avatars, +u.send_notifications_to_email, +u.published, +(select count(*) from post p where p.creator_id = u.id) as number_of_posts, +(select coalesce(sum(score), 0) from post p, post_like pl where u.id = p.creator_id and p.id = pl.post_id) as post_score, +(select count(*) from comment c where c.creator_id = u.id) as number_of_comments, +(select coalesce(sum(score), 0) from comment c, comment_like cl where u.id = c.creator_id and c.id = cl.comment_id) as comment_score +from user_ u; + +create materialized view user_mview as select * from user_view; + +create unique index idx_user_mview_id on user_mview (id); + diff --git a/server/src/api/user.rs b/server/src/api/user.rs index 629ce8e5..dda1d9ad 100644 --- a/server/src/api/user.rs +++ b/server/src/api/user.rs @@ -256,7 +256,6 @@ impl Perform<LoginResponse> for Oper<Register> { // Register the new user let user_form = UserForm { name: data.username.to_owned(), - fedi_name: Settings::get().hostname.to_owned(), email: data.email.to_owned(), matrix_user_id: None, avatar: None, @@ -404,7 +403,6 @@ impl Perform<LoginResponse> for Oper<SaveUserSettings> { let user_form = UserForm { name: read_user.name, - fedi_name: read_user.fedi_name, email, matrix_user_id: data.matrix_user_id.to_owned(), avatar: data.avatar.to_owned(), diff --git a/server/src/apub/mod.rs b/server/src/apub/mod.rs index 1669ee89..b9ed615b 100644 --- a/server/src/apub/mod.rs +++ b/server/src/apub/mod.rs @@ -36,10 +36,10 @@ pub enum EndpointType { // and have it fetch the object. pub fn make_apub_endpoint(endpoint_type: EndpointType, name: &str) -> Url { let point = match endpoint_type { - EndpointType::Community => "c", - EndpointType::User => "u", - EndpointType::Post => "p", - EndpointType::Comment => todo!(), + EndpointType::Community => "community", + EndpointType::User => "user", + EndpointType::Post => "post", + EndpointType::Comment => "comment", }; Url::parse(&format!( diff --git a/server/src/db/code_migrations.rs b/server/src/db/code_migrations.rs index 2fdf03d5..3575462e 100644 --- a/server/src/db/code_migrations.rs +++ b/server/src/db/code_migrations.rs @@ -33,7 +33,6 @@ fn user_updates_2020_04_02(conn: &PgConnection) -> Result<(), Error> { let form = UserForm { name: cuser.name.to_owned(), - fedi_name: cuser.fedi_name.to_owned(), email: cuser.email.to_owned(), matrix_user_id: cuser.matrix_user_id.to_owned(), avatar: cuser.avatar.to_owned(), diff --git a/server/src/db/comment.rs b/server/src/db/comment.rs index 7550f072..4925aabc 100644 --- a/server/src/db/comment.rs +++ b/server/src/db/comment.rs @@ -207,7 +207,6 @@ mod tests { let new_user = UserForm { name: "terry".into(), - fedi_name: "rrf".into(), preferred_username: None, password_encrypted: "nope".into(), email: None, diff --git a/server/src/db/comment_view.rs b/server/src/db/comment_view.rs index f0ca7231..bbeeecde 100644 --- a/server/src/db/comment_view.rs +++ b/server/src/db/comment_view.rs @@ -434,7 +434,6 @@ mod tests { let new_user = UserForm { name: "timmy".into(), - fedi_name: "rrf".into(), preferred_username: None, password_encrypted: "nope".into(), email: None, diff --git a/server/src/db/community.rs b/server/src/db/community.rs index 08354d42..15915715 100644 --- a/server/src/db/community.rs +++ b/server/src/db/community.rs @@ -231,7 +231,6 @@ mod tests { let new_user = UserForm { name: "bobbee".into(), - fedi_name: "rrf".into(), preferred_username: None, password_encrypted: "nope".into(), email: None, diff --git a/server/src/db/moderator.rs b/server/src/db/moderator.rs index 01acc25e..88262112 100644 --- a/server/src/db/moderator.rs +++ b/server/src/db/moderator.rs @@ -438,7 +438,6 @@ mod tests { let new_mod = UserForm { name: "the mod".into(), - fedi_name: "rrf".into(), preferred_username: None, password_encrypted: "nope".into(), email: None, @@ -466,7 +465,6 @@ mod tests { let new_user = UserForm { name: "jim2".into(), - fedi_name: "rrf".into(), preferred_username: None, password_encrypted: "nope".into(), email: None, diff --git a/server/src/db/password_reset_request.rs b/server/src/db/password_reset_request.rs index c9d18e1c..ea8b2964 100644 --- a/server/src/db/password_reset_request.rs +++ b/server/src/db/password_reset_request.rs @@ -88,7 +88,6 @@ mod tests { let new_user = UserForm { name: "thommy prw".into(), - fedi_name: "rrf".into(), preferred_username: None, password_encrypted: "nope".into(), email: None, diff --git a/server/src/db/post.rs b/server/src/db/post.rs index b0b9bddc..469fa819 100644 --- a/server/src/db/post.rs +++ b/server/src/db/post.rs @@ -240,7 +240,6 @@ mod tests { let new_user = UserForm { name: "jim".into(), - fedi_name: "rrf".into(), preferred_username: None, password_encrypted: "nope".into(), email: None, diff --git a/server/src/db/post_view.rs b/server/src/db/post_view.rs index 29ff2f1b..420e46df 100644 --- a/server/src/db/post_view.rs +++ b/server/src/db/post_view.rs @@ -359,7 +359,6 @@ mod tests { let new_user = UserForm { name: user_name.to_owned(), - fedi_name: "rrf".into(), preferred_username: None, password_encrypted: "nope".into(), email: None, diff --git a/server/src/db/private_message.rs b/server/src/db/private_message.rs index 18ec4963..63607547 100644 --- a/server/src/db/private_message.rs +++ b/server/src/db/private_message.rs @@ -65,7 +65,6 @@ mod tests { let creator_form = UserForm { name: "creator_pm".into(), - fedi_name: "rrf".into(), preferred_username: None, password_encrypted: "nope".into(), email: None, @@ -93,7 +92,6 @@ mod tests { let recipient_form = UserForm { name: "recipient_pm".into(), - fedi_name: "rrf".into(), preferred_username: None, password_encrypted: "nope".into(), email: None, diff --git a/server/src/db/user.rs b/server/src/db/user.rs index 1669d722..7b10d874 100644 --- a/server/src/db/user.rs +++ b/server/src/db/user.rs @@ -10,7 +10,6 @@ use jsonwebtoken::{decode, encode, DecodingKey, EncodingKey, Header, TokenData, pub struct User_ { pub id: i32, pub name: String, - pub fedi_name: String, pub preferred_username: Option<String>, pub password_encrypted: String, pub email: Option<String>, @@ -39,7 +38,6 @@ pub struct User_ { #[table_name = "user_"] pub struct UserForm { pub name: String, - pub fedi_name: String, pub preferred_username: Option<String>, pub password_encrypted: String, pub admin: bool, @@ -157,7 +155,7 @@ impl User_ { let my_claims = Claims { id: self.id, username: self.name.to_owned(), - iss: self.fedi_name.to_owned(), + iss: Settings::get().hostname.to_owned(), show_nsfw: self.show_nsfw, theme: self.theme.to_owned(), default_sort_type: self.default_sort_type, @@ -214,7 +212,6 @@ mod tests { let new_user = UserForm { name: "thommy".into(), - fedi_name: "rrf".into(), preferred_username: None, password_encrypted: "nope".into(), email: None, @@ -243,7 +240,6 @@ mod tests { let expected_user = User_ { id: inserted_user.id, name: "thommy".into(), - fedi_name: "rrf".into(), preferred_username: None, password_encrypted: "nope".into(), email: None, diff --git a/server/src/db/user_mention.rs b/server/src/db/user_mention.rs index 801df6fe..20eed23e 100644 --- a/server/src/db/user_mention.rs +++ b/server/src/db/user_mention.rs @@ -64,7 +64,6 @@ mod tests { let new_user = UserForm { name: "terrylake".into(), - fedi_name: "rrf".into(), preferred_username: None, password_encrypted: "nope".into(), email: None, @@ -92,7 +91,6 @@ mod tests { let recipient_form = UserForm { name: "terrylakes recipient".into(), - fedi_name: "rrf".into(), preferred_username: None, password_encrypted: "nope".into(), email: None, diff --git a/server/src/db/user_view.rs b/server/src/db/user_view.rs index 2274ecbd..efd84468 100644 --- a/server/src/db/user_view.rs +++ b/server/src/db/user_view.rs @@ -9,7 +9,6 @@ table! { avatar -> Nullable<Text>, email -> Nullable<Text>, matrix_user_id -> Nullable<Text>, - fedi_name -> Varchar, admin -> Bool, banned -> Bool, show_avatars -> Bool, @@ -29,7 +28,6 @@ table! { avatar -> Nullable<Text>, email -> Nullable<Text>, matrix_user_id -> Nullable<Text>, - fedi_name -> Varchar, admin -> Bool, banned -> Bool, show_avatars -> Bool, @@ -52,7 +50,6 @@ pub struct UserView { pub avatar: Option<String>, pub email: Option<String>, pub matrix_user_id: Option<String>, - pub fedi_name: String, pub admin: bool, pub banned: bool, pub show_avatars: bool, diff --git a/server/src/schema.rs b/server/src/schema.rs index 819fcd1c..01c526c6 100644 --- a/server/src/schema.rs +++ b/server/src/schema.rs @@ -293,7 +293,6 @@ table! { user_ (id) { id -> Int4, name -> Varchar, - fedi_name -> Varchar, preferred_username -> Nullable<Varchar>, password_encrypted -> Text, email -> Nullable<Text>, diff --git a/ui/src/interfaces.ts b/ui/src/interfaces.ts index 0eeeac06..283e1944 100644 --- a/ui/src/interfaces.ts +++ b/ui/src/interfaces.ts @@ -102,7 +102,6 @@ export interface UserView { avatar?: string; email?: string; matrix_user_id?: string; - fedi_name: string; published: string; number_of_posts: number; post_score: number; |