mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-05 20:15:01 +00:00
Merge branch 'federation_add_fed_columns' of https://yerbamate.dev/dessalines/lemmy into federation
This commit is contained in:
commit
77fbecf930
18 changed files with 79 additions and 29 deletions
36
server/migrations/2020-04-07-135912_add_user_community_apub_constraints/down.sql
vendored
Normal file
36
server/migrations/2020-04-07-135912_add_user_community_apub_constraints/down.sql
vendored
Normal file
|
@ -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);
|
38
server/migrations/2020-04-07-135912_add_user_community_apub_constraints/up.sql
vendored
Normal file
38
server/migrations/2020-04-07-135912_add_user_community_apub_constraints/up.sql
vendored
Normal file
|
@ -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);
|
||||
|
|
@ -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(),
|
||||
|
|
|
@ -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!(
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -293,7 +293,6 @@ table! {
|
|||
user_ (id) {
|
||||
id -> Int4,
|
||||
name -> Varchar,
|
||||
fedi_name -> Varchar,
|
||||
preferred_username -> Nullable<Varchar>,
|
||||
password_encrypted -> Text,
|
||||
email -> Nullable<Text>,
|
||||
|
|
1
ui/src/interfaces.ts
vendored
1
ui/src/interfaces.ts
vendored
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue