diff --git a/migrations/postgres/2019-03-16-143637_summary-md/down.sql b/migrations/postgres/2019-03-16-143637_summary-md/down.sql new file mode 100644 index 00000000..982805e0 --- /dev/null +++ b/migrations/postgres/2019-03-16-143637_summary-md/down.sql @@ -0,0 +1,2 @@ +-- This file should undo anything in `up.sql` +ALTER TABLE users DROP COLUMN summary_html; diff --git a/migrations/postgres/2019-03-16-143637_summary-md/up.sql b/migrations/postgres/2019-03-16-143637_summary-md/up.sql new file mode 100644 index 00000000..bc7d7c89 --- /dev/null +++ b/migrations/postgres/2019-03-16-143637_summary-md/up.sql @@ -0,0 +1,3 @@ +-- Your SQL goes here +ALTER TABLE users ADD COLUMN summary_html TEXT NOT NULL DEFAULT ''; +UPDATE users SET summary_html = summary; diff --git a/migrations/sqlite/2019-03-16-143637_summary-md/down.sql b/migrations/sqlite/2019-03-16-143637_summary-md/down.sql new file mode 100644 index 00000000..8b0fd636 --- /dev/null +++ b/migrations/sqlite/2019-03-16-143637_summary-md/down.sql @@ -0,0 +1,47 @@ +-- This file should undo anything in `up.sql` +CREATE TABLE users2 ( + id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + username VARCHAR NOT NULL, + display_name VARCHAR NOT NULL DEFAULT '', + outbox_url VARCHAR NOT NULL UNIQUE, + inbox_url VARCHAR NOT NULL UNIQUE, + is_admin BOOLEAN NOT NULL DEFAULT 'f', + summary TEXT NOT NULL DEFAULT '', + email TEXT, + hashed_password TEXT, + instance_id INTEGER REFERENCES instances(id) ON DELETE CASCADE NOT NULL, + creation_date DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + ap_url TEXT NOT NULL default '' UNIQUE, + private_key TEXT, + public_key TEXT NOT NULL DEFAULT '', + shared_inbox_url VARCHAR, + followers_endpoint VARCHAR NOT NULL DEFAULT '' UNIQUE, + avatar_id INTEGER REFERENCES medias(id) ON DELETE SET NULL, + last_fetched_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + fqn TEXT NOT NULL DEFAULT '', + CONSTRAINT blog_authors_unique UNIQUE (username, instance_id) +); + +INSERT INTO users2 SELECT + id, + username, + display_name, + outbox_url, + inbox_url, + is_admin, + summary, + email, + hashed_password, + instance_id, + creation_date, + ap_url, + private_key, + public_key, + shared_inbox_url, + followers_endpoint, + avatar_id, + last_fetched_date, + fqn +FROM users; +DROP TABLE users; +ALTER TABLE users2 RENAME TO users; diff --git a/migrations/sqlite/2019-03-16-143637_summary-md/up.sql b/migrations/sqlite/2019-03-16-143637_summary-md/up.sql new file mode 100644 index 00000000..bc7d7c89 --- /dev/null +++ b/migrations/sqlite/2019-03-16-143637_summary-md/up.sql @@ -0,0 +1,3 @@ +-- Your SQL goes here +ALTER TABLE users ADD COLUMN summary_html TEXT NOT NULL DEFAULT ''; +UPDATE users SET summary_html = summary; diff --git a/plume-models/src/schema.rs b/plume-models/src/schema.rs index c953f2a2..47357ac9 100644 --- a/plume-models/src/schema.rs +++ b/plume-models/src/schema.rs @@ -203,6 +203,7 @@ table! { avatar_id -> Nullable, last_fetched_date -> Timestamp, fqn -> Text, + summary_html -> Text, } } diff --git a/plume-models/src/users.rs b/plume-models/src/users.rs index 7ace4c38..1778182a 100644 --- a/plume-models/src/users.rs +++ b/plume-models/src/users.rs @@ -17,6 +17,7 @@ use plume_common::activity_pub::{ sign::{gen_keypair, Signer}, ActivityStream, ApSignature, Id, IntoId, PublicKey, }; +use plume_common::utils; use reqwest::{ header::{HeaderValue, ACCEPT}, Client, @@ -52,7 +53,7 @@ pub struct User { pub outbox_url: String, pub inbox_url: String, pub is_admin: bool, - pub summary: SafeString, + pub summary: String, pub email: Option, pub hashed_password: Option, pub instance_id: i32, @@ -65,6 +66,7 @@ pub struct User { pub avatar_id: Option, pub last_fetched_date: NaiveDateTime, pub fqn: String, + pub summary_html: SafeString, } #[derive(Default, Insertable)] @@ -75,7 +77,7 @@ pub struct NewUser { pub outbox_url: String, pub inbox_url: String, pub is_admin: bool, - pub summary: SafeString, + pub summary: String, pub email: Option, pub hashed_password: Option, pub instance_id: i32, @@ -85,6 +87,7 @@ pub struct NewUser { pub shared_inbox_url: Option, pub followers_endpoint: String, pub avatar_id: Option, + pub summary_html: SafeString, } pub const AUTH_COOKIE: &str = "user_id"; @@ -212,6 +215,7 @@ impl User { .set(( users::display_name.eq(name), users::email.eq(email), + users::summary_html.eq(utils::md_to_html(&summary,"").0), users::summary.eq(summary), )) .execute(conn)?; @@ -320,7 +324,12 @@ impl User { .ap_actor_props .inbox_string()?, is_admin: false, - summary: SafeString::new( + summary:acct + .object + .object_props + .summary_string() + .unwrap_or_default(), + summary_html: SafeString::new( &acct .object .object_props @@ -684,7 +693,7 @@ impl User { .set_name_string(self.display_name.clone())?; actor .object_props - .set_summary_string(self.summary.get().clone())?; + .set_summary_string(self.summary_html.get().clone())?; actor .object_props .set_url_string(self.ap_url.clone())?; @@ -902,7 +911,8 @@ impl NewUser { username, display_name, is_admin, - summary: SafeString::new(summary), + summary: summary.to_owned(), + summary_html: SafeString::new(&utils::md_to_html(&summary,"").0), email: Some(email), hashed_password: Some(password), instance_id: Instance::get_local(conn)?.id, @@ -1050,7 +1060,7 @@ pub(crate) mod tests { ).unwrap(); assert_eq!(updated.display_name, "new name"); assert_eq!(updated.email.unwrap(), "em@il"); - assert_eq!(updated.summary.get(), "

summary

"); + assert_eq!(updated.summary_html.get(), "

summary

"); Ok(()) }); diff --git a/src/routes/user.rs b/src/routes/user.rs index 398f6f80..023446de 100644 --- a/src/routes/user.rs +++ b/src/routes/user.rs @@ -225,7 +225,7 @@ pub fn edit(name: String, user: User, conn: DbConn, intl: I18n) -> Result@author.name() -

@Html(&author.summary) +

@Html(&author.summary_html) @if !ctx.2.as_ref().map(|u| u.id == author.id).unwrap_or(false) {

diff --git a/templates/users/edit.rs.html b/templates/users/edit.rs.html index 592f2901..885efb26 100644 --- a/templates/users/edit.rs.html +++ b/templates/users/edit.rs.html @@ -19,7 +19,8 @@ @input!(ctx.1, display_name (text), "Display name", form, errors.clone()) @input!(ctx.1, email (text), "Email", form, errors.clone()) - @input!(ctx.1, summary (text), "Summary", form, errors) + +
diff --git a/templates/users/followed.rs.html b/templates/users/followed.rs.html index 84573374..48954339 100644 --- a/templates/users/followed.rs.html +++ b/templates/users/followed.rs.html @@ -18,7 +18,7 @@ @for follow in followed {

@follow.name() @format!("@{}", &follow.fqn)

-

@Html(follow.summary)

+

@Html(follow.summary_html)

} diff --git a/templates/users/followers.rs.html b/templates/users/followers.rs.html index 70f2bdad..744adf02 100644 --- a/templates/users/followers.rs.html +++ b/templates/users/followers.rs.html @@ -18,7 +18,7 @@ @for follower in followers {

@follower.name() @format!("@{}", &follower.fqn)

-

@Html(follower.summary)

+

@Html(follower.summary_html)

} diff --git a/templates/users/header.rs.html b/templates/users/header.rs.html index 1637cbbf..26aaa362 100644 --- a/templates/users/header.rs.html +++ b/templates/users/header.rs.html @@ -43,6 +43,6 @@ }
- @Html(user.summary.clone()) + @Html(user.summary_html.clone())