From fe6e69d7c4408a12733d2150309c92811691ee12 Mon Sep 17 00:00:00 2001 From: Baptiste Gelez Date: Wed, 6 Mar 2019 18:28:10 +0100 Subject: [PATCH] Add a fqn field to blogs and users (#457) Fixes #319 --- .../2019-03-05-082814_add_fqn/down.sql | 3 + .../postgres/2019-03-05-082814_add_fqn/up.sql | 18 +++++ .../sqlite/2019-03-05-082846_add_fqn/down.sql | 77 +++++++++++++++++++ .../sqlite/2019-03-05-082846_add_fqn/up.sql | 18 +++++ plume-models/src/blogs.rs | 48 ++++++------ plume-models/src/mentions.rs | 2 +- plume-models/src/notifications.rs | 2 +- plume-models/src/posts.rs | 4 +- plume-models/src/schema.rs | 2 + plume-models/src/search/searcher.rs | 2 +- plume-models/src/users.rs | 52 ++++++------- po/plume/ar.po | 3 +- po/plume/es.po | 3 +- po/plume/fr.po | 3 +- po/plume/gl.po | 3 +- po/plume/it.po | 3 +- po/plume/ja.po | 3 +- po/plume/nb.po | 3 +- po/plume/pl.po | 3 +- po/plume/plume.pot | 4 +- po/plume/pt.po | 3 +- po/plume/ru.po | 3 +- src/api/mod.rs | 2 +- src/routes/blogs.rs | 9 +-- src/routes/posts.rs | 4 +- src/routes/session.rs | 2 +- src/routes/user.rs | 8 +- src/routes/well_known.rs | 4 +- src/template_utils.rs | 4 +- templates/blogs/details.rs.html | 16 ++-- templates/instance/about.rs.html | 2 +- templates/instance/users.rs.html | 8 +- templates/partials/comment.rs.html | 6 +- templates/partials/post_card.rs.html | 12 +-- templates/posts/details.rs.html | 24 +++--- templates/users/details.rs.html | 10 +-- templates/users/followed.rs.html | 10 +-- templates/users/followers.rs.html | 10 +-- templates/users/header.rs.html | 6 +- 39 files changed, 258 insertions(+), 141 deletions(-) create mode 100644 migrations/postgres/2019-03-05-082814_add_fqn/down.sql create mode 100644 migrations/postgres/2019-03-05-082814_add_fqn/up.sql create mode 100644 migrations/sqlite/2019-03-05-082846_add_fqn/down.sql create mode 100644 migrations/sqlite/2019-03-05-082846_add_fqn/up.sql diff --git a/migrations/postgres/2019-03-05-082814_add_fqn/down.sql b/migrations/postgres/2019-03-05-082814_add_fqn/down.sql new file mode 100644 index 00000000..796c55ed --- /dev/null +++ b/migrations/postgres/2019-03-05-082814_add_fqn/down.sql @@ -0,0 +1,3 @@ +-- This file should undo anything in `up.sql` +ALTER TABLE blogs DROP COLUMN fqn; +ALTER TABLE users DROP COLUMN fqn; \ No newline at end of file diff --git a/migrations/postgres/2019-03-05-082814_add_fqn/up.sql b/migrations/postgres/2019-03-05-082814_add_fqn/up.sql new file mode 100644 index 00000000..f28231de --- /dev/null +++ b/migrations/postgres/2019-03-05-082814_add_fqn/up.sql @@ -0,0 +1,18 @@ +-- Your SQL goes here +ALTER TABLE blogs ADD COLUMN fqn TEXT NOT NULL DEFAULT ''; +UPDATE blogs SET fqn = + (CASE WHEN (SELECT local FROM instances WHERE id = instance_id) THEN + actor_id + ELSE + (actor_id || '@' || (SELECT public_domain FROM instances WHERE id = instance_id LIMIT 1)) + END) +WHERE fqn = ''; + +ALTER TABLE users ADD COLUMN fqn TEXT NOT NULL DEFAULT ''; +UPDATE users SET fqn = + (CASE WHEN (SELECT local FROM instances WHERE id = instance_id) THEN + username + ELSE + (username || '@' || (SELECT public_domain FROM instances WHERE id = instance_id LIMIT 1)) + END) +WHERE fqn = ''; \ No newline at end of file diff --git a/migrations/sqlite/2019-03-05-082846_add_fqn/down.sql b/migrations/sqlite/2019-03-05-082846_add_fqn/down.sql new file mode 100644 index 00000000..2767f409 --- /dev/null +++ b/migrations/sqlite/2019-03-05-082846_add_fqn/down.sql @@ -0,0 +1,77 @@ +-- This file should undo anything in `up.sql` +CREATE TABLE blogs_no_fqn ( + id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + actor_id VARCHAR NOT NULL, + title VARCHAR NOT NULL, + summary TEXT NOT NULL DEFAULT '', + outbox_url VARCHAR NOT NULL UNIQUE, + inbox_url VARCHAR NOT NULL UNIQUE, + 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 '', + CONSTRAINT blog_unique UNIQUE (actor_id, instance_id) +); + +INSERT INTO blogs_no_fqn SELECT + id, + actor_id, + title, + summary, + outbox_url, + inbox_url, + instance_id, + creation_date, + ap_url, + private_key, + public_key +FROM blogs; +DROP TABLE blogs; +ALTER TABLE blogs_no_fqn RENAME TO blogs; + + +CREATE TABLE users_no_fqn ( + 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, + CONSTRAINT blog_authors_unique UNIQUE (username, instance_id) +); + +INSERT INTO users_no_fqn 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 +FROM users; +DROP TABLE users; +ALTER TABLE users_no_fqn RENAME TO users; \ No newline at end of file diff --git a/migrations/sqlite/2019-03-05-082846_add_fqn/up.sql b/migrations/sqlite/2019-03-05-082846_add_fqn/up.sql new file mode 100644 index 00000000..f28231de --- /dev/null +++ b/migrations/sqlite/2019-03-05-082846_add_fqn/up.sql @@ -0,0 +1,18 @@ +-- Your SQL goes here +ALTER TABLE blogs ADD COLUMN fqn TEXT NOT NULL DEFAULT ''; +UPDATE blogs SET fqn = + (CASE WHEN (SELECT local FROM instances WHERE id = instance_id) THEN + actor_id + ELSE + (actor_id || '@' || (SELECT public_domain FROM instances WHERE id = instance_id LIMIT 1)) + END) +WHERE fqn = ''; + +ALTER TABLE users ADD COLUMN fqn TEXT NOT NULL DEFAULT ''; +UPDATE users SET fqn = + (CASE WHEN (SELECT local FROM instances WHERE id = instance_id) THEN + username + ELSE + (username || '@' || (SELECT public_domain FROM instances WHERE id = instance_id LIMIT 1)) + END) +WHERE fqn = ''; \ No newline at end of file diff --git a/plume-models/src/blogs.rs b/plume-models/src/blogs.rs index 67d9b70d..e5bcd3a5 100644 --- a/plume-models/src/blogs.rs +++ b/plume-models/src/blogs.rs @@ -43,6 +43,7 @@ pub struct Blog { pub ap_url: String, pub private_key: Option, pub public_key: String, + pub fqn: String, } #[derive(Default, Insertable)] @@ -87,6 +88,15 @@ impl Blog { "", ); } + + if inserted.fqn.is_empty() { + if instance.local { + inserted.fqn = inserted.actor_id.clone(); + } else { + inserted.fqn = format!("{}@{}", inserted.actor_id, instance.public_domain); + } + } + inserted.save_changes(conn).map_err(Error::from) }); get!(blogs); @@ -129,19 +139,17 @@ impl Blog { .map_err(Error::from) } - pub fn find_local(conn: &Connection, name: &str) -> Result { - Blog::find_by_name(conn, name, Instance::get_local(conn)?.id) - } - pub fn find_by_fqn(conn: &Connection, fqn: &str) -> Result { - let mut split_fqn = fqn.split('@'); - let actor = split_fqn.next().ok_or(Error::InvalidValue)?; - if let Some(domain) = split_fqn.next() { // remote blog - Instance::find_by_domain(conn, domain) - .and_then(|instance| Blog::find_by_name(conn, actor, instance.id)) - .or_else(|_| Blog::fetch_from_webfinger(conn, fqn)) - } else { // local blog - Blog::find_local(conn, actor) + let from_db = blogs::table + .filter(blogs::fqn.eq(fqn)) + .limit(1) + .load::(conn)? + .into_iter() + .next(); + if let Some(from_db) = from_db { + Ok(from_db) + } else { + Blog::fetch_from_webfinger(conn, fqn) } } @@ -338,18 +346,6 @@ impl Blog { }) } - pub fn get_fqn(&self, conn: &Connection) -> String { - if self.instance_id == Instance::get_local(conn).ok().expect("Blog::get_fqn: local instance error").id { - self.actor_id.clone() - } else { - format!( - "{}@{}", - self.actor_id, - self.get_instance(conn).ok().expect("Blog::get_fqn: instance error").public_domain - ) - } - } - pub fn delete(&self, conn: &Connection, searcher: &Searcher) -> Result<()> { for post in Post::get_for_blog(conn, &self)? { post.delete(&(conn, searcher))?; @@ -649,7 +645,7 @@ pub(crate) mod tests { ).unwrap(); assert_eq!( - Blog::find_local(conn, "SomeName").unwrap().id, + Blog::find_by_fqn(conn, "SomeName").unwrap().id, blog.id ); @@ -673,7 +669,7 @@ pub(crate) mod tests { ).unwrap(), ).unwrap(); - assert_eq!(blog.get_fqn(conn), "SomeName"); + assert_eq!(blog.fqn, "SomeName"); Ok(()) }); diff --git a/plume-models/src/mentions.rs b/plume-models/src/mentions.rs index e126d384..b9a06ef2 100644 --- a/plume-models/src/mentions.rs +++ b/plume-models/src/mentions.rs @@ -71,7 +71,7 @@ impl Mention { .set_href_string(user.ap_url.clone())?; mention .link_props - .set_name_string(format!("@{}", user.get_fqn(conn)))?; + .set_name_string(format!("@{}", user.fqn))?; Ok(mention) } diff --git a/plume-models/src/notifications.rs b/plume-models/src/notifications.rs index 7e29b5e7..b916c16f 100644 --- a/plume-models/src/notifications.rs +++ b/plume-models/src/notifications.rs @@ -81,7 +81,7 @@ impl Notification { pub fn get_url(&self, conn: &Connection) -> Option { match self.kind.as_ref() { notification_kind::COMMENT => self.get_post(conn).and_then(|p| Some(format!("{}#comment-{}", p.url(conn).ok()?, self.object_id))), - notification_kind::FOLLOW => Some(format!("/@/{}/", self.get_actor(conn).ok()?.get_fqn(conn))), + notification_kind::FOLLOW => Some(format!("/@/{}/", self.get_actor(conn).ok()?.fqn)), notification_kind::MENTION => Mention::get(conn, self.object_id).and_then(|mention| mention.get_post(conn).and_then(|p| p.url(conn)) .or_else(|_| { diff --git a/plume-models/src/posts.rs b/plume-models/src/posts.rs index dc3a026d..39f6f5bb 100644 --- a/plume-models/src/posts.rs +++ b/plume-models/src/posts.rs @@ -269,7 +269,7 @@ impl Post { post.ap_url = ap_url(&format!( "{}/~/{}/{}/", *BASE_URL, - post.get_blog(conn)?.get_fqn(conn), + post.get_blog(conn)?.fqn, post.slug )); let _: Post = post.save_changes(conn)?; @@ -850,7 +850,7 @@ impl Post { pub fn url(&self, conn: &Connection) -> Result { let blog = self.get_blog(conn)?; - Ok(format!("/~/{}/{}", blog.get_fqn(conn), self.slug)) + Ok(format!("/~/{}/{}", blog.fqn, self.slug)) } pub fn cover_url(&self, conn: &Connection) -> Option { diff --git a/plume-models/src/schema.rs b/plume-models/src/schema.rs index 5cce86c5..c953f2a2 100644 --- a/plume-models/src/schema.rs +++ b/plume-models/src/schema.rs @@ -43,6 +43,7 @@ table! { ap_url -> Text, private_key -> Nullable, public_key -> Text, + fqn -> Text, } } @@ -201,6 +202,7 @@ table! { followers_endpoint -> Varchar, avatar_id -> Nullable, last_fetched_date -> Timestamp, + fqn -> Text, } } diff --git a/plume-models/src/search/searcher.rs b/plume-models/src/search/searcher.rs index a18fcd9e..fa67eecf 100644 --- a/plume-models/src/search/searcher.rs +++ b/plume-models/src/search/searcher.rs @@ -144,7 +144,7 @@ impl Searcher { let writer = writer.as_mut().unwrap(); writer.add_document(doc!( post_id => i64::from(post.id), - author => post.get_authors(conn)?.into_iter().map(|u| u.get_fqn(conn)).join(" "), + author => post.get_authors(conn)?.into_iter().map(|u| u.fqn).join(" "), creation_date => i64::from(post.creation_date.num_days_from_ce()), instance => Instance::get(conn, post.get_blog(conn)?.instance_id)?.public_domain.clone(), tag => Tag::for_post(conn, post.id)?.into_iter().map(|t| t.tag).join(" "), diff --git a/plume-models/src/users.rs b/plume-models/src/users.rs index 4558c19a..0e394815 100644 --- a/plume-models/src/users.rs +++ b/plume-models/src/users.rs @@ -64,6 +64,7 @@ pub struct User { pub followers_endpoint: String, pub avatar_id: Option, pub last_fetched_date: NaiveDateTime, + pub fqn: String, } #[derive(Default, Insertable)] @@ -119,8 +120,7 @@ impl User { if inserted.shared_inbox_url.is_none() { inserted.shared_inbox_url = Some(ap_url(&format!( "{}/inbox", - Instance::get_local(conn)? - .public_domain + instance.public_domain ))); } @@ -132,6 +132,14 @@ impl User { ); } + if inserted.fqn.is_empty() { + if instance.local { + inserted.fqn = inserted.username.clone(); + } else { + inserted.fqn = format!("{}@{}", inserted.username, instance.public_domain); + } + } + inserted.save_changes(conn).map_err(Error::from) }); get!(users); @@ -218,19 +226,17 @@ impl User { .map_err(Error::from) } - pub fn find_local(conn: &Connection, username: &str) -> Result { - User::find_by_name(conn, username, Instance::get_local(conn)?.id) - } - pub fn find_by_fqn(conn: &Connection, fqn: &str) -> Result { - let mut split_fqn = fqn.split('@'); - let username = split_fqn.next().ok_or(Error::InvalidValue)?; - if let Some(domain) = split_fqn.next() { // remote user - Instance::find_by_domain(conn, domain) - .and_then(|instance| User::find_by_name(conn, username, instance.id)) - .or_else(|_| User::fetch_from_webfinger(conn, fqn)) - } else { // local user - User::find_local(conn, username) + let from_db = users::table + .filter(users::fqn.eq(fqn)) + .limit(1) + .load::(conn)? + .into_iter() + .next(); + if let Some(from_db) = from_db { + Ok(from_db) + } else { + User::fetch_from_webfinger(conn, fqn) } } @@ -518,18 +524,6 @@ impl User { .collect::>()) } - pub fn get_fqn(&self, conn: &Connection) -> String { - if self.instance_id == Instance::get_local(conn).ok().expect("User::get_fqn: instance error").id { - self.username.clone() - } else { - format!( - "{}@{}", - self.username, - self.get_instance(conn).ok().expect("User::get_fqn: instance error").public_domain - ) - } - } - pub fn get_followers(&self, conn: &Connection) -> Result> { use schema::follows; let follows = Follow::belonging_to(self).select(follows::follower_id); @@ -805,11 +799,11 @@ impl User { (Utc::now().naive_utc() - self.last_fetched_date).num_days() > 1 } - pub fn name(&self, conn: &Connection) -> String { + pub fn name(&self) -> String { if !self.display_name.is_empty() { self.display_name.clone() } else { - self.get_fqn(conn) + self.fqn.clone() } } } @@ -987,7 +981,7 @@ pub(crate) mod tests { ); assert_eq!( test_user.id, - User::find_by_fqn(conn, &test_user.get_fqn(conn)).unwrap().id + User::find_by_fqn(conn, &test_user.fqn).unwrap().id ); assert_eq!( test_user.id, diff --git a/po/plume/ar.po b/po/plume/ar.po index 6e8c1b78..0dd994a9 100644 --- a/po/plume/ar.po +++ b/po/plume/ar.po @@ -317,8 +317,9 @@ msgstr "" msgid "Articles" msgstr "المقالات" +#, fuzzy msgid "Subscribers" -msgstr "" +msgstr "الوصف" #, fuzzy msgid "Subscriptions" diff --git a/po/plume/es.po b/po/plume/es.po index 9c79ec7c..2da53ffe 100644 --- a/po/plume/es.po +++ b/po/plume/es.po @@ -302,8 +302,9 @@ msgid "" "can, however, find a different one." msgstr "" +#, fuzzy msgid "Articles" -msgstr "" +msgstr "Nueva publicación" msgid "Subscribers" msgstr "" diff --git a/po/plume/fr.po b/po/plume/fr.po index bc7a3a25..9d41b56b 100644 --- a/po/plume/fr.po +++ b/po/plume/fr.po @@ -336,8 +336,9 @@ msgstr "" msgid "Articles" msgstr "Articles" +#, fuzzy msgid "Subscribers" -msgstr "" +msgstr "Description" #, fuzzy msgid "Subscriptions" diff --git a/po/plume/gl.po b/po/plume/gl.po index a5f8d88c..f6fa3693 100644 --- a/po/plume/gl.po +++ b/po/plume/gl.po @@ -332,8 +332,9 @@ msgstr "" msgid "Articles" msgstr "Artigos" +#, fuzzy msgid "Subscribers" -msgstr "" +msgstr "Descrición" #, fuzzy msgid "Subscriptions" diff --git a/po/plume/it.po b/po/plume/it.po index 4f5ad9e5..08d36819 100644 --- a/po/plume/it.po +++ b/po/plume/it.po @@ -335,8 +335,9 @@ msgstr "" msgid "Articles" msgstr "Articoli" +#, fuzzy msgid "Subscribers" -msgstr "" +msgstr "Descrizione" #, fuzzy msgid "Subscriptions" diff --git a/po/plume/ja.po b/po/plume/ja.po index a0348536..3451d531 100644 --- a/po/plume/ja.po +++ b/po/plume/ja.po @@ -323,8 +323,9 @@ msgstr "" msgid "Articles" msgstr "記事" +#, fuzzy msgid "Subscribers" -msgstr "" +msgstr "説明" #, fuzzy msgid "Subscriptions" diff --git a/po/plume/nb.po b/po/plume/nb.po index fcbb2f45..24877dae 100644 --- a/po/plume/nb.po +++ b/po/plume/nb.po @@ -336,8 +336,9 @@ msgstr "" msgid "Articles" msgstr "artikler" +#, fuzzy msgid "Subscribers" -msgstr "" +msgstr "Lang beskrivelse" #, fuzzy msgid "Subscriptions" diff --git a/po/plume/pl.po b/po/plume/pl.po index 8dfc44ff..93f23f7c 100644 --- a/po/plume/pl.po +++ b/po/plume/pl.po @@ -301,8 +301,9 @@ msgstr "" msgid "Articles" msgstr "Artykuły" +#, fuzzy msgid "Subscribers" -msgstr "" +msgstr "Opis" #, fuzzy msgid "Subscriptions" diff --git a/po/plume/plume.pot b/po/plume/plume.pot index 65864ca2..730fadbb 100644 --- a/po/plume/plume.pot +++ b/po/plume/plume.pot @@ -36,11 +36,11 @@ msgstr "" msgid "{0}'s avatar" msgstr "" -# src/routes/blogs.rs:65 +# src/routes/blogs.rs:64 msgid "You need to be logged in order to create a new blog" msgstr "" -# src/routes/blogs.rs:135 +# src/routes/blogs.rs:134 msgid "You are not allowed to delete this blog." msgstr "" diff --git a/po/plume/pt.po b/po/plume/pt.po index 9b19d301..503ec614 100644 --- a/po/plume/pt.po +++ b/po/plume/pt.po @@ -317,8 +317,9 @@ msgstr "" msgid "Articles" msgstr "Artigos" +#, fuzzy msgid "Subscribers" -msgstr "" +msgstr "Descrição" #, fuzzy msgid "Subscriptions" diff --git a/po/plume/ru.po b/po/plume/ru.po index b5aaa3b6..a4769479 100644 --- a/po/plume/ru.po +++ b/po/plume/ru.po @@ -339,8 +339,9 @@ msgstr "" msgid "Articles" msgstr "Статьи" +#, fuzzy msgid "Subscribers" -msgstr "" +msgstr "Описание" #, fuzzy msgid "Subscriptions" diff --git a/src/api/mod.rs b/src/api/mod.rs index f4417eaf..c1583186 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -49,7 +49,7 @@ pub struct OAuthRequest { pub fn oauth(query: Form, conn: DbConn) -> Result, ApiError> { let app = App::find_by_client_id(&*conn, &query.client_id)?; if app.client_secret == query.client_secret { - if let Ok(user) = User::find_local(&*conn, &query.username) { + if let Ok(user) = User::find_by_fqn(&*conn, &query.username) { if user.auth(&query.password) { let token = ApiToken::insert(&*conn, NewApiToken { app_id: app.id, diff --git a/src/routes/blogs.rs b/src/routes/blogs.rs index a943214b..4a70a7e1 100644 --- a/src/routes/blogs.rs +++ b/src/routes/blogs.rs @@ -34,7 +34,6 @@ pub fn details(intl: I18n, name: String, conn: DbConn, user: Option, page: Ok(render!(blogs::details( &(&*conn, &intl.catalog, user.clone()), blog.clone(), - blog.get_fqn(&*conn), authors, articles_count, page.0, @@ -46,7 +45,7 @@ pub fn details(intl: I18n, name: String, conn: DbConn, user: Option, page: #[get("/~/", rank = 1)] pub fn activity_details(name: String, conn: DbConn, _ap: ApRequest) -> Option> { - let blog = Blog::find_local(&*conn, &name).ok()?; + let blog = Blog::find_by_fqn(&*conn, &name).ok()?; Some(ActivityStream::new(blog.to_activity(&*conn).ok()?)) } @@ -90,7 +89,7 @@ pub fn create(conn: DbConn, form: LenientForm, user: User, intl: I1 Ok(_) => ValidationErrors::new(), Err(e) => e }; - if Blog::find_local(&*conn, &slug).is_ok() { + if Blog::find_by_fqn(&*conn, &slug).is_ok() { errors.add("title", ValidationError { code: Cow::from("existing_slug"), message: Some(Cow::from("A blog with the same name already exists.")), @@ -124,7 +123,7 @@ pub fn create(conn: DbConn, form: LenientForm, user: User, intl: I1 #[post("/~//delete")] pub fn delete(conn: DbConn, name: String, user: Option, intl: I18n, searcher: Searcher) -> Result{ - let blog = Blog::find_local(&*conn, &name).expect("blog::delete: blog not found"); + let blog = Blog::find_by_fqn(&*conn, &name).expect("blog::delete: blog not found"); if user.clone().and_then(|u| u.is_author_in(&*conn, &blog).ok()).unwrap_or(false) { blog.delete(&conn, &searcher).expect("blog::expect: deletion error"); Ok(Redirect::to(uri!(super::instance::index))) @@ -139,7 +138,7 @@ pub fn delete(conn: DbConn, name: String, user: Option, intl: I18n, search #[get("/~//outbox")] pub fn outbox(name: String, conn: DbConn) -> Option> { - let blog = Blog::find_local(&*conn, &name).ok()?; + let blog = Blog::find_by_fqn(&*conn, &name).ok()?; Some(blog.outbox(&*conn).ok()?) } diff --git a/src/routes/posts.rs b/src/routes/posts.rs index 2391544d..46bb1ab1 100644 --- a/src/routes/posts.rs +++ b/src/routes/posts.rs @@ -46,14 +46,14 @@ pub fn details(blog: String, slug: String, conn: DbConn, user: Option, res warning: previous.clone().map(|p| p.spoiler_text).unwrap_or_default(), content: previous.clone().and_then(|p| Some(format!( "@{} {}", - p.get_author(&*conn).ok()?.get_fqn(&*conn), + p.get_author(&*conn).ok()?.fqn, Mention::list_for_comment(&*conn, p.id).ok()? .into_iter() .filter_map(|m| { let user = user.clone(); if let Ok(mentioned) = m.get_mentioned(&*conn) { if user.is_none() || mentioned.id != user.expect("posts::details_response: user error while listing mentions").id { - Some(format!("@{}", mentioned.get_fqn(&*conn))) + Some(format!("@{}", mentioned.fqn)) } else { None } diff --git a/src/routes/session.rs b/src/routes/session.rs index 998ffd3b..0128507b 100644 --- a/src/routes/session.rs +++ b/src/routes/session.rs @@ -40,7 +40,7 @@ pub struct LoginForm { #[post("/login", data = "
")] pub fn create(conn: DbConn, form: LenientForm, flash: Option, mut cookies: Cookies, intl: I18n) -> Result { let user = User::find_by_email(&*conn, &form.email_or_name) - .or_else(|_| User::find_local(&*conn, &form.email_or_name)); + .or_else(|_| User::find_by_fqn(&*conn, &form.email_or_name)); let mut errors = match form.validate() { Ok(_) => ValidationErrors::new(), Err(e) => e diff --git a/src/routes/user.rs b/src/routes/user.rs index 6783080d..35dbe813 100644 --- a/src/routes/user.rs +++ b/src/routes/user.rs @@ -203,7 +203,7 @@ pub fn activity_details( conn: DbConn, _ap: ApRequest, ) -> Option> { - let user = User::find_local(&*conn, &name).ok()?; + let user = User::find_by_fqn(&*conn, &name).ok()?; Some(ActivityStream::new(user.to_activity(&*conn).ok()?)) } @@ -369,7 +369,7 @@ pub fn create(conn: DbConn, form: LenientForm, intl: I18n) -> Resul #[get("/@//outbox")] pub fn outbox(name: String, conn: DbConn) -> Option> { - let user = User::find_local(&*conn, &name).ok()?; + let user = User::find_by_fqn(&*conn, &name).ok()?; user.outbox(&*conn).ok() } @@ -381,7 +381,7 @@ pub fn inbox( headers: Headers, searcher: Searcher, ) -> Result>> { - let user = User::find_local(&*conn, &name).map_err(|_| None)?; + let user = User::find_by_fqn(&*conn, &name).map_err(|_| None)?; let act = data.1.into_inner(); let sig = data.0; @@ -429,7 +429,7 @@ pub fn ap_followers( conn: DbConn, _ap: ApRequest, ) -> Option> { - let user = User::find_local(&*conn, &name).ok()?; + let user = User::find_by_fqn(&*conn, &name).ok()?; let followers = user .get_followers(&*conn).ok()? .into_iter() diff --git a/src/routes/well_known.rs b/src/routes/well_known.rs index 332032a2..89b0c895 100644 --- a/src/routes/well_known.rs +++ b/src/routes/well_known.rs @@ -39,9 +39,9 @@ impl Resolver for WebfingerResolver { } fn find(acct: String, conn: DbConn) -> Result { - User::find_local(&*conn, &acct) + User::find_by_fqn(&*conn, &acct) .and_then(|usr| usr.webfinger(&*conn)) - .or_else(|_| Blog::find_local(&*conn, &acct) + .or_else(|_| Blog::find_by_fqn(&*conn, &acct) .and_then(|blog| blog.webfinger(&*conn)) .or(Err(ResolverError::NotFound))) } diff --git a/src/template_utils.rs b/src/template_utils.rs index 9ea0e68b..39c31b52 100644 --- a/src/template_utils.rs +++ b/src/template_utils.rs @@ -29,7 +29,7 @@ macro_rules! render { } pub fn translate_notification(ctx: BaseContext, notif: Notification) -> String { - let name = notif.get_actor(ctx.0).unwrap().name(ctx.0); + let name = notif.get_actor(ctx.0).unwrap().name(); match notif.kind.as_ref() { notification_kind::COMMENT => i18n!(ctx.1, "{0} commented your article."; &name), notification_kind::FOLLOW => i18n!(ctx.1, "{0} is subscribed to you."; &name), @@ -55,7 +55,7 @@ impl Size { } pub fn avatar(conn: &Connection, user: &User, size: Size, pad: bool, catalog: &Catalog) -> Html { - let name = escape(&user.name(conn)).to_string(); + let name = escape(&user.name()).to_string(); Html(format!( r#"
, total_articles: i64, page: i32, n_pages: i32, is_author: bool, posts: Vec) +@(ctx: BaseContext, blog: Blog, authors: &Vec, total_articles: i64, page: i32, n_pages: i32, is_author: bool, posts: Vec) @:base(ctx, blog.title.clone(), {}, { - @blog.title + @blog.title }, {
-

@blog.title ~@fqn

+

@blog.title ~@blog.fqn

@blog.summary

@i18n!(ctx.1, "There's one author on this blog: ", "There are {0} authors on this blog: "; authors.len()) @for author in authors { - @author.name(ctx.0) + @author.name() }

@@ -34,13 +34,13 @@

@i18n!(ctx.1, "Latest articles") - @icon!("rss") + @icon!("rss")

@if posts.len() < 1 {

@i18n!(ctx.1, "No posts to see here yet.")

} @if is_author { - @i18n!(ctx.1, "New article") + @i18n!(ctx.1, "New article") }
@for article in posts { @@ -53,7 +53,7 @@ @if is_author {

@i18n!(ctx.1, "Danger zone")

@i18n!(ctx.1, "Be very careful, any action taken here can't be reversed.")

- + } diff --git a/templates/instance/about.rs.html b/templates/instance/about.rs.html index 0df32065..27166a45 100644 --- a/templates/instance/about.rs.html +++ b/templates/instance/about.rs.html @@ -24,7 +24,7 @@

@i18n!(ctx.1, "Administred by")

@avatar(ctx.0, &admin, Size::Small, false, ctx.1) -

@admin.name(ctx.0)@@@admin.get_fqn(ctx.0)

+

@admin.name()@@@admin.fqn

@i18n!(ctx.1, "Runs Plume {0}"; env!("CARGO_PKG_VERSION"))

diff --git a/templates/instance/users.rs.html b/templates/instance/users.rs.html index bde749e4..6f3208aa 100644 --- a/templates/instance/users.rs.html +++ b/templates/instance/users.rs.html @@ -9,9 +9,9 @@

@i18n!(ctx.1, "Users")

@tabs(&[ - (&uri!(instance::admin).to_string(), i18n!(ctx.1, "Configuration"), false), - (&uri!(instance::admin_instances: page = _).to_string(), i18n!(ctx.1, "Instances"), false), - (&uri!(instance::admin_users: page = _).to_string(), i18n!(ctx.1, "Users"), true), + (&uri!(instance::admin).to_string(), i18n!(ctx.1, "Configuration"), false), + (&uri!(instance::admin_instances: page = _).to_string(), i18n!(ctx.1, "Instances"), false), + (&uri!(instance::admin_users: page = _).to_string(), i18n!(ctx.1, "Users"), true), ])
@@ -19,7 +19,7 @@
@avatar(ctx.0, &user, Size::Small, false, ctx.1)

- @user.name(ctx.0) + @user.name() @format!("@{}", user.username)

@if !user.is_admin { diff --git a/templates/partials/comment.rs.html b/templates/partials/comment.rs.html index 646e9506..fba02d39 100644 --- a/templates/partials/comment.rs.html +++ b/templates/partials/comment.rs.html @@ -7,10 +7,10 @@ @if let Some(ref comm) = Some(&comment_tree.comment) { @if let Some(author) = comm.get_author(ctx.0).ok() {
- + @avatar(ctx.0, &author, Size::Small, true, ctx.1) - @author.name(ctx.0) - @author.get_fqn(ctx.0) + @author.name() + @&author.fqn @if let Some(ref ap_url) = comm.ap_url { diff --git a/templates/partials/post_card.rs.html b/templates/partials/post_card.rs.html index 13d31830..9f6d50d9 100644 --- a/templates/partials/post_card.rs.html +++ b/templates/partials/post_card.rs.html @@ -9,7 +9,7 @@
}

- + @article.title

@@ -19,15 +19,15 @@
@Html(i18n!(ctx.1, "By {0}"; format!( "{}", - uri!(user::details: name = article.get_authors(ctx.0).unwrap_or_default()[0].get_fqn(ctx.0)), - escape(&article.get_authors(ctx.0).unwrap_or_default()[0].name(ctx.0)) + uri!(user::details: name = &article.get_authors(ctx.0).unwrap_or_default()[0].fqn), + escape(&article.get_authors(ctx.0).unwrap_or_default()[0].name()) ))) @if article.published { - ⋅ @article.creation_date.format("%B %e, %Y") + ⋅ @article.creation_date.format("%B %e, %Y") } - ⋅ @article.get_blog(ctx.0).unwrap().title + ⋅ @article.get_blog(ctx.0).unwrap().title @if !article.published { - ⋅ @i18n!(ctx.1, "Draft") + ⋅ @i18n!(ctx.1, "Draft") }
diff --git a/templates/posts/details.rs.html b/templates/posts/details.rs.html index c69d3780..41efbac1 100644 --- a/templates/posts/details.rs.html +++ b/templates/posts/details.rs.html @@ -17,10 +17,10 @@ @if article.cover_id.is_some() { } - + }, { - @blog.title + @blog.title }, {

@&article.title

@@ -28,16 +28,16 @@ @if ctx.2.is_some() {
- -
+

@n_reshares

@@ -131,7 +131,7 @@

@i18n!(ctx.1, "Comments")

@if ctx.2.is_some() { - + @input!(ctx.1, warning (optional text), "Content warning", comment_form, comment_errors, "") @@ -146,7 +146,7 @@ @if !comments.is_empty() {
@for comm in comments { - @:comment(ctx, &comm, Some(&article.ap_url), &blog.get_fqn(ctx.0), &article.slug) + @:comment(ctx, &comm, Some(&article.ap_url), &blog.fqn, &article.slug) }
} else { diff --git a/templates/users/details.rs.html b/templates/users/details.rs.html index 5c2052ba..fcc51029 100644 --- a/templates/users/details.rs.html +++ b/templates/users/details.rs.html @@ -6,20 +6,20 @@ @(ctx: BaseContext, user: User, follows: bool, is_remote: bool, remote_url: String, recents: Vec, reshares: Vec) -@:base(ctx, user.name(ctx.0), {}, {}, { +@:base(ctx, user.name(), {}, {}, { @:header(ctx, &user, follows, is_remote, remote_url) @tabs(&[ - (&uri!(user::details: name= user.get_fqn(ctx.0)).to_string(), i18n!(ctx.1, "Articles"), true), - (&uri!(user::followers: name = user.get_fqn(ctx.0), page = _).to_string(), i18n!(ctx.1, "Subscribers"), false), - (&uri!(user::followed: name = user.get_fqn(ctx.0), page = _).to_string(), i18n!(ctx.1, "Subscriptions"), false) + (&uri!(user::details: name = &user.fqn).to_string(), i18n!(ctx.1, "Articles"), true), + (&uri!(user::followers: name = &user.fqn, page = _).to_string(), i18n!(ctx.1, "Subscribers"), false), + (&uri!(user::followed: name = &user.fqn, page = _).to_string(), i18n!(ctx.1, "Subscriptions"), false) ]) @if !recents.is_empty() {

@i18n!(ctx.1, "Latest articles") - @icon!("rss") + @icon!("rss")

@for article in recents { diff --git a/templates/users/followed.rs.html b/templates/users/followed.rs.html index bf328c4b..84573374 100644 --- a/templates/users/followed.rs.html +++ b/templates/users/followed.rs.html @@ -5,19 +5,19 @@ @(ctx: BaseContext, user: User, follows: bool, is_remote: bool, remote_url: String, followed: Vec, page: i32, n_pages: i32) -@:base(ctx, i18n!(ctx.1, "{0}'s subscriptions'"; user.name(ctx.0)), {}, {}, { +@:base(ctx, i18n!(ctx.1, "{0}'s subscriptions'"; user.name()), {}, {}, { @:header(ctx, &user, follows, is_remote, remote_url) @tabs(&[ - (&uri!(user::details: name= user.get_fqn(ctx.0)).to_string(), i18n!(ctx.1, "Articles"), true), - (&uri!(user::followers: name = user.get_fqn(ctx.0), page = _).to_string(), i18n!(ctx.1, "Subscribers"), false), - (&uri!(user::followed: name = user.get_fqn(ctx.0), page = _).to_string(), i18n!(ctx.1, "Subscriptions"), false) + (&uri!(user::details: name = &user.fqn).to_string(), i18n!(ctx.1, "Articles"), true), + (&uri!(user::followers: name = &user.fqn, page = _).to_string(), i18n!(ctx.1, "Subscribers"), false), + (&uri!(user::followed: name = &user.fqn, page = _).to_string(), i18n!(ctx.1, "Subscriptions"), false) ])
@for follow in followed {
-

@follow.name(ctx.0) @format!("@{}", follow.get_fqn(ctx.0))

+

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

@Html(follow.summary)

} diff --git a/templates/users/followers.rs.html b/templates/users/followers.rs.html index 10b697e4..70f2bdad 100644 --- a/templates/users/followers.rs.html +++ b/templates/users/followers.rs.html @@ -5,19 +5,19 @@ @(ctx: BaseContext, user: User, follows: bool, is_remote: bool, remote_url: String, followers: Vec, page: i32, n_pages: i32) -@:base(ctx, i18n!(ctx.1, "{0}'s subscribers"; user.name(ctx.0)), {}, {}, { +@:base(ctx, i18n!(ctx.1, "{0}'s subscribers"; user.name()), {}, {}, { @:header(ctx, &user, follows, is_remote, remote_url) @tabs(&[ - (&uri!(user::details: name= user.get_fqn(ctx.0)).to_string(), i18n!(ctx.1, "Articles"), true), - (&uri!(user::followers: name = user.get_fqn(ctx.0), page = _).to_string(), i18n!(ctx.1, "Subscribers"), false), - (&uri!(user::followed: name = user.get_fqn(ctx.0), page = _).to_string(), i18n!(ctx.1, "Subscriptions"), false) + (&uri!(user::details: name = &user.fqn).to_string(), i18n!(ctx.1, "Articles"), true), + (&uri!(user::followers: name = &user.fqn, page = _).to_string(), i18n!(ctx.1, "Subscribers"), false), + (&uri!(user::followed: name = &user.fqn, page = _).to_string(), i18n!(ctx.1, "Subscriptions"), false) ])
@for follower in followers {
-

@follower.name(ctx.0) @format!("@{}", follower.get_fqn(ctx.0))

+

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

@Html(follower.summary)

} diff --git a/templates/users/header.rs.html b/templates/users/header.rs.html index de2971cf..1637cbbf 100644 --- a/templates/users/header.rs.html +++ b/templates/users/header.rs.html @@ -10,8 +10,8 @@ @avatar(ctx.0, &user, Size::Medium, false, ctx.1)

- @user.name(ctx.0) - @user.get_fqn(ctx.0) + @user.name() + @&user.fqn

@@ -33,7 +33,7 @@ } @if ctx.2.clone().map(|u| u.id != user.id).unwrap_or(false) { - + @if follows { } else {