summaryrefslogtreecommitdiffstats
path: root/server/src
diff options
context:
space:
mode:
authorFelix Ableitner <me@nutomic.com>2020-04-03 07:22:39 +0200
committerFelix Ableitner <me@nutomic.com>2020-04-03 07:24:46 +0200
commit6a7a262912dbf0ef725261eb6fc2aaaa7a01c84d (patch)
tree59d7dfa6856427acdd66ec142a236c92a8ac403f /server/src
parent96c3621a801d96a8d2bffc849d871c297683e387 (diff)
parent9197b39ed6f19b536510318b5446ec2ebb303396 (diff)
Merge branch 'federation_add_fed_columns' of https://yerbamate.dev/dessalines/lemmy into federation
Diffstat (limited to 'server/src')
-rw-r--r--server/src/api/community.rs20
-rw-r--r--server/src/api/site.rs48
-rw-r--r--server/src/api/user.rs51
-rw-r--r--server/src/apub/mod.rs27
-rw-r--r--server/src/apub/puller.rs4
-rw-r--r--server/src/db/code_migrations.rs101
-rw-r--r--server/src/db/comment.rs11
-rw-r--r--server/src/db/comment_view.rs11
-rw-r--r--server/src/db/community.rs26
-rw-r--r--server/src/db/mod.rs2
-rw-r--r--server/src/db/moderator.rs17
-rw-r--r--server/src/db/password_reset_request.rs6
-rw-r--r--server/src/db/post.rs11
-rw-r--r--server/src/db/post_view.rs11
-rw-r--r--server/src/db/private_message.rs12
-rw-r--r--server/src/db/user.rs25
-rw-r--r--server/src/db/user_mention.rs17
-rw-r--r--server/src/lib.rs13
-rw-r--r--server/src/main.rs2
-rw-r--r--server/src/routes/feeds.rs205
-rw-r--r--server/src/routes/nodeinfo.rs1
-rw-r--r--server/src/schema.rs488
-rw-r--r--server/src/settings.rs10
-rw-r--r--server/src/version.rs2
24 files changed, 745 insertions, 376 deletions
diff --git a/server/src/api/community.rs b/server/src/api/community.rs
index 2bc6e357..d0c4b8d3 100644
--- a/server/src/api/community.rs
+++ b/server/src/api/community.rs
@@ -1,5 +1,6 @@
use super::*;
use crate::apub::puller::{get_all_communities, get_remote_community};
+use crate::apub::{gen_keypair_str, make_apub_endpoint, EndpointType};
use crate::settings::Settings;
use diesel::PgConnection;
use std::str::FromStr;
@@ -208,6 +209,8 @@ impl Perform<CommunityResponse> for Oper<CreateCommunity> {
}
// When you create a community, make sure the user becomes a moderator and a follower
+ let (community_public_key, community_private_key) = gen_keypair_str();
+
let community_form = CommunityForm {
name: data.name.to_owned(),
title: data.title.to_owned(),
@@ -218,6 +221,11 @@ impl Perform<CommunityResponse> for Oper<CreateCommunity> {
deleted: None,
nsfw: data.nsfw,
updated: None,
+ actor_id: make_apub_endpoint(EndpointType::Community, &data.name).to_string(),
+ local: true,
+ private_key: Some(community_private_key),
+ public_key: Some(community_public_key),
+ last_refreshed_at: None,
};
let inserted_community = match Community::create(&conn, &community_form) {
@@ -298,6 +306,8 @@ impl Perform<CommunityResponse> for Oper<EditCommunity> {
return Err(APIError::err("no_community_edit_allowed").into());
}
+ let read_community = Community::read(&conn, data.edit_id)?;
+
let community_form = CommunityForm {
name: data.name.to_owned(),
title: data.title.to_owned(),
@@ -308,6 +318,11 @@ impl Perform<CommunityResponse> for Oper<EditCommunity> {
deleted: data.deleted.to_owned(),
nsfw: data.nsfw,
updated: Some(naive_now()),
+ actor_id: read_community.actor_id,
+ local: read_community.local,
+ private_key: read_community.private_key,
+ public_key: read_community.public_key,
+ last_refreshed_at: None,
};
let _updated_community = match Community::update(&conn, data.edit_id, &community_form) {
@@ -571,6 +586,11 @@ impl Perform<GetCommunityResponse> for Oper<TransferCommunity> {
deleted: None,
nsfw: read_community.nsfw,
updated: Some(naive_now()),
+ actor_id: read_community.actor_id,
+ local: read_community.local,
+ private_key: read_community.private_key,
+ public_key: read_community.public_key,
+ last_refreshed_at: None,
};
let _updated_community = match Community::update(&conn, data.community_id, &community_form) {
diff --git a/server/src/api/site.rs b/server/src/api/site.rs
index ef1a2828..6bd90149 100644
--- a/server/src/api/site.rs
+++ b/server/src/api/site.rs
@@ -1,5 +1,9 @@
use super::*;
+use crate::api::user::Register;
+use crate::api::{Oper, Perform};
+use crate::settings::Settings;
use diesel::PgConnection;
+use log::info;
use std::str::FromStr;
#[derive(Serialize, Deserialize)]
@@ -53,12 +57,12 @@ pub struct GetModlogResponse {
#[derive(Serialize, Deserialize)]
pub struct CreateSite {
- name: String,
- description: Option<String>,
- enable_downvotes: bool,
- open_registration: bool,
- enable_nsfw: bool,
- auth: String,
+ pub name: String,
+ pub description: Option<String>,
+ pub enable_downvotes: bool,
+ pub open_registration: bool,
+ pub enable_nsfw: bool,
+ pub auth: String,
}
#[derive(Serialize, Deserialize)]
@@ -277,10 +281,34 @@ impl Perform<GetSiteResponse> for Oper<GetSite> {
fn perform(&self, conn: &PgConnection) -> Result<GetSiteResponse, Error> {
let _data: &GetSite = &self.data;
- // It can return a null site in order to redirect
- let site_view = match Site::read(&conn, 1) {
- Ok(_site) => Some(SiteView::read(&conn)?),
- Err(_e) => None,
+ let site = Site::read(&conn, 1);
+ let site_view = if site.is_ok() {
+ Some(SiteView::read(&conn)?)
+ } else if let Some(setup) = Settings::get().setup.as_ref() {
+ let register = Register {
+ username: setup.admin_username.to_owned(),
+ email: setup.admin_email.to_owned(),
+ password: setup.admin_password.to_owned(),
+ password_verify: setup.admin_password.to_owned(),
+ admin: true,
+ show_nsfw: true,
+ };
+ let login_response = Oper::new(register).perform(&conn)?;
+ info!("Admin {} created", setup.admin_username);
+
+ let create_site = CreateSite {
+ name: setup.site_name.to_owned(),
+ description: None,
+ enable_downvotes: false,
+ open_registration: false,
+ enable_nsfw: false,
+ auth: login_response.jwt,
+ };
+ Oper::new(create_site).perform(&conn)?;
+ info!("Site {} created", setup.site_name);
+ Some(SiteView::read(&conn)?)
+ } else {
+ None
};
let mut admins = UserView::admins(&conn)?;
diff --git a/server/src/api/user.rs b/server/src/api/user.rs
index 333fd949..59a3d623 100644
--- a/server/src/api/user.rs
+++ b/server/src/api/user.rs
@@ -1,4 +1,5 @@
use super::*;
+use crate::apub::{gen_keypair_str, make_apub_endpoint, EndpointType};
use crate::settings::Settings;
use crate::{generate_random_string, send_email};
use bcrypt::verify;
@@ -14,12 +15,12 @@ pub struct Login {
#[derive(Serialize, Deserialize)]
pub struct Register {
- username: String,
- email: Option<String>,
- password: String,
- password_verify: String,
- admin: bool,
- show_nsfw: bool,
+ pub username: String,
+ pub email: Option<String>,
+ pub password: String,
+ pub password_verify: String,
+ pub admin: bool,
+ pub show_nsfw: bool,
}
#[derive(Serialize, Deserialize)]
@@ -42,7 +43,7 @@ pub struct SaveUserSettings {
#[derive(Serialize, Deserialize)]
pub struct LoginResponse {
- jwt: String,
+ pub jwt: String,
}
#[derive(Serialize, Deserialize)]
@@ -250,6 +251,8 @@ impl Perform<LoginResponse> for Oper<Register> {
return Err(APIError::err("admin_already_created").into());
}
+ let (user_public_key, user_private_key) = gen_keypair_str();
+
// Register the new user
let user_form = UserForm {
name: data.username.to_owned(),
@@ -269,6 +272,12 @@ impl Perform<LoginResponse> for Oper<Register> {
lang: "browser".into(),
show_avatars: true,
send_notifications_to_email: false,
+ actor_id: make_apub_endpoint(EndpointType::User, &data.username).to_string(),
+ bio: None,
+ local: true,
+ private_key: Some(user_private_key),
+ public_key: Some(user_public_key),
+ last_refreshed_at: None,
};
// Create the user
@@ -287,12 +296,15 @@ impl Perform<LoginResponse> for Oper<Register> {
}
};
+ let (community_public_key, community_private_key) = gen_keypair_str();
+
// Create the main community if it doesn't exist
let main_community: Community = match Community::read(&conn, 2) {
Ok(c) => c,
Err(_e) => {
+ let default_community_name = "main";
let community_form = CommunityForm {
- name: "main".to_string(),
+ name: default_community_name.to_string(),
title: "The Default Community".to_string(),
description: Some("The Default Community".to_string()),
category_id: 1,
@@ -301,6 +313,11 @@ impl Perform<LoginResponse> for Oper<Register> {
removed: None,
deleted: None,
updated: None,
+ actor_id: make_apub_endpoint(EndpointType::Community, default_community_name).to_string(),
+ local: true,
+ private_key: Some(community_private_key),
+ public_key: Some(community_public_key),
+ last_refreshed_at: None,
};
Community::create(&conn, &community_form).unwrap()
}
@@ -403,6 +420,12 @@ impl Perform<LoginResponse> for Oper<SaveUserSettings> {
lang: data.lang.to_owned(),
show_avatars: data.show_avatars,
send_notifications_to_email: data.send_notifications_to_email,
+ actor_id: read_user.actor_id,
+ bio: read_user.bio,
+ local: read_user.local,
+ private_key: read_user.private_key,
+ public_key: read_user.public_key,
+ last_refreshed_at: None,
};
let updated_user = match User_::update(&conn, user_id, &user_form) {
@@ -561,6 +584,12 @@ impl Perform<AddAdminResponse> for Oper<AddAdmin> {
lang: read_user.lang,
show_avatars: read_user.show_avatars,
send_notifications_to_email: read_user.send_notifications_to_email,
+ actor_id: read_user.actor_id,
+ bio: read_user.bio,
+ local: read_user.local,
+ private_key: read_user.private_key,
+ public_key: read_user.public_key,
+ last_refreshed_at: None,
};
match User_::update(&conn, data.user_id, &user_form) {
@@ -624,6 +653,12 @@ impl Perform<BanUserResponse> for Oper<BanUser> {
lang: read_user.lang,
show_avatars: read_user.show_avatars,
send_notifications_to_email: read_user.send_notifications_to_email,
+ actor_id: read_user.actor_id,
+ bio: read_user.bio,
+ local: read_user.local,
+ private_key: read_user.private_key,
+ public_key: read_user.public_key,
+ last_refreshed_at: None,
};
match User_::update(&conn, data.user_id, &user_form) {
diff --git a/server/src/apub/mod.rs b/server/src/apub/mod.rs
index 8e725805..8c915f71 100644
--- a/server/src/apub/mod.rs
+++ b/server/src/apub/mod.rs
@@ -3,6 +3,7 @@ pub mod post;
pub mod puller;
pub mod user;
use crate::Settings;
+use openssl::{pkey::PKey, rsa::Rsa};
use activitystreams::actor::{properties::ApActorProperties, Group};
use activitystreams::ext::Ext;
@@ -21,13 +22,13 @@ where
.json(json)
}
-enum EndpointType {
+pub enum EndpointType {
Community,
User,
Post,
}
-fn make_apub_endpoint(endpoint_type: EndpointType, name: &str) -> Url {
+pub fn make_apub_endpoint(endpoint_type: EndpointType, name: &str) -> Url {
let point = match endpoint_type {
EndpointType::Community => "c",
EndpointType::User => "u",
@@ -51,3 +52,25 @@ pub fn get_apub_protocol_string() -> &'static str {
"http"
}
}
+
+pub fn gen_keypair() -> (Vec<u8>, Vec<u8>) {
+ let rsa = Rsa::generate(2048).expect("sign::gen_keypair: key generation error");
+ let pkey = PKey::from_rsa(rsa).expect("sign::gen_keypair: parsing error");
+ (
+ pkey
+ .public_key_to_pem()
+ .expect("sign::gen_keypair: public key encoding error"),
+ pkey
+ .private_key_to_pem_pkcs8()
+ .expect("sign::gen_keypair: private key encoding error"),
+ )
+}
+
+pub fn gen_keypair_str() -> (String, String) {
+ let (public_key, private_key) = gen_keypair();
+ (vec_bytes_to_str(public_key), vec_bytes_to_str(private_key))
+}
+
+fn vec_bytes_to_str(bytes: Vec<u8>) -> String {
+ String::from_utf8_lossy(&bytes).into_owned()
+}
diff --git a/server/src/apub/puller.rs b/server/src/apub/puller.rs
index c92023ec..6a81b8d0 100644
--- a/server/src/apub/puller.rs
+++ b/server/src/apub/puller.rs
@@ -8,8 +8,8 @@ use crate::settings::Settings;
use activitystreams::collection::{OrderedCollection, UnorderedCollection};
use activitystreams::object::Page;
use activitystreams::BaseBox;
-use chttp::prelude::*;
use failure::Error;
+use isahc::prelude::*;
use log::warn;
use serde::Deserialize;
@@ -67,7 +67,7 @@ where
}
// TODO: should cache responses here when we are in production
// TODO: this function should return a future
- let text = chttp::get(uri)?.text()?;
+ let text = isahc::get(uri)?.text()?;
let res: Response = serde_json::from_str(&text)?;
Ok(res)
}
diff --git a/server/src/db/code_migrations.rs b/server/src/db/code_migrations.rs
new file mode 100644
index 00000000..e0c736e1
--- /dev/null
+++ b/server/src/db/code_migrations.rs
@@ -0,0 +1,101 @@
+// This is for db migrations that require code
+use super::community::{Community, CommunityForm};
+use super::user::{UserForm, User_};
+use super::*;
+use crate::apub::{gen_keypair_str, make_apub_endpoint, EndpointType};
+use crate::naive_now;
+use log::info;
+
+pub fn run_advanced_migrations(conn: &PgConnection) -> Result<(), Error> {
+ user_updates_2020_04_02(conn)?;
+ community_updates_2020_04_02(conn)?;
+
+ Ok(())
+}
+
+fn user_updates_2020_04_02(conn: &PgConnection) -> Result<(), Error> {
+ use crate::schema::user_::dsl::*;
+
+ info!("Running user_updates_2020_04_02");
+
+ // Update the actor_id, private_key, and public_key, last_refreshed_at
+ let incorrect_users = user_
+ .filter(actor_id.eq("changeme"))
+ .filter(local.eq(true))
+ .load::<User_>(conn)?;
+
+ for cuser in &incorrect_users {
+ let (user_public_key, user_private_key) = gen_keypair_str();
+
+ 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(),
+ password_encrypted: cuser.password_encrypted.to_owned(),
+ preferred_username: cuser.preferred_username.to_owned(),
+ updated: None,
+ admin: cuser.admin,
+ banned: cuser.banned,
+ show_nsfw: cuser.show_nsfw,
+ theme: cuser.theme.to_owned(),
+ default_sort_type: cuser.default_sort_type,
+ default_listing_type: cuser.default_listing_type,
+ lang: cuser.lang.to_owned(),
+ show_avatars: cuser.show_avatars,
+ send_notifications_to_email: cuser.send_notifications_to_email,
+ actor_id: make_apub_endpoint(EndpointType::User, &cuser.name).to_string(),
+ bio: cuser.bio.to_owned(),
+ local: cuser.local,
+ private_key: Some(user_private_key),
+ public_key: Some(user_public_key),
+ last_refreshed_at: Some(naive_now()),
+ };
+
+ User_::update(&conn, cuser.id, &form)?;
+ }
+
+ info!("{} user rows updated.", incorrect_users.len());
+
+ Ok(())
+}
+
+fn community_updates_2020_04_02(conn: &PgConnection) -> Result<(), Error> {
+ use crate::schema::community::dsl::*;
+
+ info!("Running community_updates_2020_04_02");
+
+ // Update the actor_id, private_key, and public_key, last_refreshed_at
+ let incorrect_communities = community
+ .filter(actor_id.eq("changeme"))
+ .filter(local.eq(true))
+ .load::<Community>(conn)?;
+
+ for ccommunity in &incorrect_communities {
+ let (community_public_key, community_private_key) = gen_keypair_str();
+
+ let form = CommunityForm {
+ name: ccommunity.name.to_owned(),
+ title: ccommunity.title.to_owned(),
+ description: ccommunity.description.to_owned(),
+ category_id: ccommunity.category_id,
+ creator_id: ccommunity.creator_id,
+ removed: None,
+ deleted: None,
+ nsfw: ccommunity.nsfw,
+ updated: None,
+ actor_id: make_apub_endpoint(EndpointType::Community, &ccommunity.name).to_string(),
+ local: ccommunity.local,
+ private_key: Some(community_private_key),
+ public_key: Some(community_public_key),
+ last_refreshed_at: Some(naive_now()),
+ };
+
+ Community::update(&conn, ccommunity.id, &form)?;
+ }
+
+ info!("{} community rows updated.", incorrect_communities.len());
+
+ Ok(())
+}
diff --git a/server/src/db/comment.rs b/server/src/db/comment.rs
index c9bfbac6..8110fc5b 100644
--- a/server/src/db/comment.rs
+++ b/server/src/db/comment.rs
@@ -186,6 +186,12 @@ mod tests {
lang: "browser".into(),
show_avatars: true,
send_notifications_to_email: false,
+ actor_id: "changeme".into(),
+ bio: None,
+ local: true,
+ private_key: None,
+ public_key: None,
+ last_refreshed_at: None,
};
let inserted_user = User_::create(&conn, &new_user).unwrap();
@@ -200,6 +206,11 @@ mod tests {
deleted: None,
updated: None,
nsfw: false,
+ actor_id: "changeme".into(),
+ local: true,
+ private_key: None,
+ public_key: None,
+ last_refreshed_at: None,
};
let inserted_community = Community::create(&conn, &new_community).unwrap();
diff --git a/server/src/db/comment_view.rs b/server/src/db/comment_view.rs
index 85b41d82..97c03c53 100644
--- a/server/src/db/comment_view.rs
+++ b/server/src/db/comment_view.rs
@@ -450,6 +450,12 @@ mod tests {
lang: "browser".into(),
show_avatars: true,
send_notifications_to_email: false,
+ actor_id: "changeme".into(),
+ bio: None,
+ local: true,
+ private_key: None,
+ public_key: None,
+ last_refreshed_at: None,
};
let inserted_user = User_::create(&conn, &new_user).unwrap();
@@ -464,6 +470,11 @@ mod tests {
deleted: None,
updated: None,
nsfw: false,
+ actor_id: "changeme".into(),
+ local: true,
+ private_key: None,
+ public_key: None,
+ last_refreshed_at: None,
};
let inserted_community = Community::create(&conn, &new_community).unwrap();
diff --git a/server/src/db/community.rs b/server/src/db/community.rs
index 63500963..ff578224 100644
--- a/server/src/db/community.rs
+++ b/server/src/db/community.rs
@@ -15,6 +15,11 @@ pub struct Community {
pub updated: Option<chrono::NaiveDateTime>,
pub deleted: bool,
pub nsfw: bool,
+ pub actor_id: String,
+ pub local: bool,
+ pub private_key: Option<String>,
+ pub public_key: Option<String>,
+ pub last_refreshed_at: chrono::NaiveDateTime,
}
#[derive(Insertable, AsChangeset, Clone, Serialize, Deserialize)]
@@ -29,6 +34,11 @@ pub struct CommunityForm {
pub updated: Option<chrono::NaiveDateTime>,
pub deleted: Option<bool>,
pub nsfw: bool,
+ pub actor_id: String,
+ pub local: bool,
+ pub private_key: Option<String>,
+ pub public_key: Option<String>,
+ pub last_refreshed_at: Option<chrono::NaiveDateTime>,
}
impl Crud<CommunityForm> for Community {
@@ -232,6 +242,12 @@ mod tests {
lang: "browser".into(),
show_avatars: true,
send_notifications_to_email: false,
+ actor_id: "changeme".into(),
+ bio: None,
+ local: true,
+ private_key: None,
+ public_key: None,
+ last_refreshed_at: None,
};
let inserted_user = User_::create(&conn, &new_user).unwrap();
@@ -246,6 +262,11 @@ mod tests {
removed: None,
deleted: None,
updated: None,
+ actor_id: "changeme".into(),
+ local: true,
+ private_key: None,
+ public_key: None,
+ last_refreshed_at: None,
};
let inserted_community = Community::create(&conn, &new_community).unwrap();
@@ -262,6 +283,11 @@ mod tests {
deleted: false,
published: inserted_community.published,
updated: None,
+ actor_id: "changeme".into(),
+ local: true,
+ private_key: None,
+ public_key: None,
+ last_refreshed_at: inserted_community.published,
};
let community_follower_form = CommunityFollowerForm {
diff --git a/server/src/db/mod.rs b/server/src/db/mod.rs
index dacdb6f6..f434f728 100644
--- a/server/src/db/mod.rs
+++ b/server/src/db/mod.rs
@@ -1,4 +1,3 @@
-extern crate lazy_static;
use crate::settings::Settings;
use diesel::dsl::*;
use diesel::result::Error;
@@ -6,6 +5,7 @@ use diesel::*;
use serde::{Deserialize, Serialize};
pub mod category;
+pub mod code_migrations;
pub mod comment;
pub mod comment_view;
pub mod community;
diff --git a/server/src/db/moderator.rs b/server/src/db/moderator.rs
index a8c3df4f..b01dc5cc 100644
--- a/server/src/db/moderator.rs
+++ b/server/src/db/moderator.rs
@@ -454,6 +454,12 @@ mod tests {
lang: "browser".into(),
show_avatars: true,
send_notifications_to_email: false,
+ actor_id: "changeme".into(),
+ bio: None,
+ local: true,
+ private_key: None,
+ public_key: None,
+ last_refreshed_at: None,
};
let inserted_mod = User_::create(&conn, &new_mod).unwrap();
@@ -476,6 +482,12 @@ mod tests {
lang: "browser".into(),
show_avatars: true,
send_notifications_to_email: false,
+ actor_id: "changeme".into(),
+ bio: None,
+ local: true,
+ private_key: None,
+ public_key: None,
+ last_refreshed_at: None,
};
let inserted_user = User_::create(&conn, &new_user).unwrap();
@@ -490,6 +502,11 @@ mod tests {
deleted: None,
updated: None,
nsfw: false,
+ actor_id: "changeme".into(),
+ local: true,
+ private_key: None,
+ public_key: None,
+ last_refreshed_at: None,
};
let inserted_community = Community::create(&conn, &new_community).unwrap();
diff --git a/server/src/db/password_reset_request.rs b/server/src/db/password_reset_request.rs
index 6951fd39..c9d18e1c 100644
--- a/server/src/db/password_reset_request.rs
+++ b/server/src/db/password_reset_request.rs
@@ -104,6 +104,12 @@ mod tests {
lang: "browser".into(),
show_avatars: true,
send_notifications_to_email: false,
+ actor_id: "changeme".into(),
+ bio: None,
+ local: true,
+ private_key: None,
+ public_key: None,
+ last_refreshed_at: None,
};
let inserted_user = User_::create(&conn, &new_user).unwrap();
diff --git a/server/src/db/post.rs b/server/src/db/post.rs
index ffde14d3..bf9a9ad7 100644
--- a/server/src/db/post.rs
+++ b/server/src/db/post.rs
@@ -207,6 +207,12 @@ mod tests {
lang: "browser".into(),
show_avatars: true,
send_notifications_to_email: false,
+ actor_id: "changeme".into(),
+ bio: None,
+ local: true,
+ private_key: None,
+ public_key: None,
+ last_refreshed_at: None,
};
let inserted_user = User_::create(&conn, &new_user).unwrap();
@@ -221,6 +227,11 @@ mod tests {
deleted: None,
updated: None,
nsfw: false,
+ actor_id: "changeme".into(),
+ local: true,
+ private_key: None,
+ public_key: None,
+ last_refreshed_at: None,
};
let inserted_community = Community::create(&conn, &new_community).unwrap();
diff --git a/server/src/db/post_view.rs b/server/src/db/post_view.rs
index f48f4f68..587ae52b 100644
--- a/server/src/db/post_view.rs
+++ b/server/src/db/post_view.rs
@@ -375,6 +375,12 @@ mod tests {
lang: "browser".into(),
show_avatars: true,
send_notifications_to_email: false,
+ actor_id: "changeme".into(),
+ bio: None,
+ local: true,
+ private_key: None,
+ public_key: None,
+ last_refreshed_at: None,
};
let inserted_user = User_::create(&conn, &new_user).unwrap();
@@ -389,6 +395,11 @@ mod tests {
deleted: None,
updated: None,
nsfw: false,
+ actor_id: "changeme".into(),
+ local: true,
+ private_key: None,
+ public_key: None,
+ last_refreshed_at: None,
};
let inserted_community = Community::create(&conn, &new_community).unwrap();
diff --git a/server/src/db/private_message.rs b/server/src/db/private_message.rs
index cc073b59..18ec4963 100644
--- a/server/src/db/private_message.rs
+++ b/server/src/db/private_message.rs
@@ -81,6 +81,12 @@ mod tests {
lang: "browser".into(),
show_avatars: true,
send_notifications_to_email: false,
+ actor_id: "changeme".into(),
+ bio: None,
+ local: true,
+ private_key: None,
+ public_key: None,
+ last_refreshed_at: None,
};
let inserted_creator = User_::create(&conn, &creator_form).unwrap();
@@ -103,6 +109,12 @@ mod tests {
lang: "browser".into(),
show_avatars: true,
send_notifications_to_email: false,
+ actor_id: "changeme".into(),
+ bio: None,
+ local: true,
+ private_key: None,
+ public_key: None,
+ last_refreshed_at: None,
};
let inserted_recipient = User_::create(&conn, &recipient_form).unwrap();
diff --git a/server/src/db/user.rs b/server/src/db/user.rs
index e7c76965..32596c27 100644
--- a/server/src/db/user.rs
+++ b/server/src/db/user.rs
@@ -27,6 +27,12 @@ pub struct User_ {
pub show_avatars: bool,
pub send_notifications_to_email: bool,
pub matrix_user_id: Option<String>,
+ pub actor_id: String,
+ pub bio: Option<String>,
+ pub local: bool,
+ pub private_key: Option<String>,
+ pub public_key: Option<String>,
+ pub last_refreshed_at: chrono::NaiveDateTime,
}
#[derive(Insertable, AsChangeset, Clone)]
@@ -49,6 +55,12 @@ pub struct UserForm {
pub show_avatars: bool,
pub send_notifications_to_email: bool,
pub matrix_user_id: Option<String>,
+ pub actor_id: String,
+ pub bio: Option<String>,
+ pub local: bool,
+ pub private_key: Option<String>,
+ pub public_key: Option<String>,
+ pub last_refreshed_at: Option<chrono::NaiveDateTime>,
}
impl Crud<UserForm> for User_ {
@@ -78,6 +90,7 @@ impl User_ {
Self::create(&conn, &edited_user)
}
+ // TODO do more individual updates like these
pub fn update_password(
conn: &PgConnection,
user_id: i32,
@@ -202,6 +215,12 @@ mod tests {
lang: "browser".into(),
show_avatars: true,
send_notifications_to_email: false,
+ actor_id: "changeme".into(),
+ bio: None,
+ local: true,
+ private_key: None,
+ public_key: None,
+ last_refreshed_at: None,
};
let inserted_user = User_::create(&conn, &new_user).unwrap();
@@ -226,6 +245,12 @@ mod tests {
lang: "browser".into(),
show_avatars: true,
send_notifications_to_email: false,
+ actor_id: "changeme".into(),
+ bio: None,
+ local: true,
+ private_key: None,
+ public_key: None,
+ last_refreshed_at: inserted_user.published,
};
let read_user = User_::read(&conn, inserted_user.id).unwrap();
diff --git a/server/src/db/user_mention.rs b/server/src/db/user_mention.rs
index 0cf25795..48814c89 100644
--- a/server/src/db/user_mention.rs
+++ b/server/src/db/user_mention.rs
@@ -80,6 +80,12 @@ mod tests {
lang: "browser".into(),
show_avatars: true,
send_notifications_to_email: false,
+ actor_id: "changeme".into(),
+ bio: None,
+ local: true,
+ private_key: None,
+ public_key: None,
+ last_refreshed_at: None,
};
let inserted_user = User_::create(&conn, &new_user).unwrap();
@@ -102,6 +108,12 @@ mod tests {
lang: "browser".into(),
show_avatars: true,
send_notifications_to_email: false,
+ actor_id: "changeme".into(),
+ bio: None,
+ local: true,
+ private_key: None,
+ public_key: None,
+ last_refreshed_at: None,
};
let inserted_recipient = User_::create(&conn, &recipient_form).unwrap();
@@ -116,6 +128,11 @@ mod tests {
deleted: None,
updated: None,
nsfw: false,
+ actor_id: "changeme".into(),
+ local: true,
+ private_key: None,
+ public_key: None,
+ last_refreshed_at: None,
};
let inserted_community = Community::create(&conn, &new_community).unwrap();
diff --git a/server/src/lib.rs b/server/src/lib.rs
index 2507819d..e45311ee 100644
--- a/server/src/lib.rs
+++ b/server/src/lib.rs
@@ -11,13 +11,16 @@ pub extern crate actix;
pub extern crate actix_web;
pub extern crate bcrypt;
pub extern crate chrono;
+pub extern crate comrak;
pub extern crate dotenv;
pub extern crate jsonwebtoken;
pub extern crate lettre;
pub extern crate lettre_email;
extern crate log;
+pub extern crate openssl;
pub extern crate rand;
pub extern crate regex;