From 7fd152e270790ad3f0a836e203b479d46c354647 Mon Sep 17 00:00:00 2001 From: Bat Date: Sun, 10 Jun 2018 19:16:25 +0100 Subject: [PATCH] Add a button to write a new article --- src/models/users.rs | 11 +++++++++++ src/routes/blogs.rs | 1 + templates/blogs/details.tera | 20 ++++++++++++++------ 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/models/users.rs b/src/models/users.rs index 89698ab..64a1e6d 100644 --- a/src/models/users.rs +++ b/src/models/users.rs @@ -35,6 +35,8 @@ use activity_pub::{ }; use db_conn::DbConn; use models::{ + blogs::Blog, + blog_authors::BlogAuthor, comments::Comment, follows::Follow, instance::Instance, @@ -297,6 +299,15 @@ impl User { .len() > 0 } + pub fn is_author_in(&self, conn: &PgConnection, blog: Blog) -> bool { + use schema::blog_authors; + blog_authors::table.filter(blog_authors::author_id.eq(self.id)) + .filter(blog_authors::blog_id.eq(blog.id)) + .load::(conn) + .expect("Couldn't load blog/author relationship") + .len() > 0 + } + pub fn get_keypair(&self) -> PKey { PKey::from_rsa(Rsa::private_key_from_pem(self.private_key.clone().unwrap().as_ref()).unwrap()).unwrap() } diff --git a/src/routes/blogs.rs b/src/routes/blogs.rs index ab42d49..1131a06 100644 --- a/src/routes/blogs.rs +++ b/src/routes/blogs.rs @@ -24,6 +24,7 @@ fn details(name: String, conn: DbConn, user: Option) -> Template { Template::render("blogs/details", json!({ "blog": blog, "account": user, + "is_author": user.map(|x| x.is_author_in(&*conn, blog)), "recents": recents.into_iter().map(|p| { json!({ "post": p, diff --git a/templates/blogs/details.tera b/templates/blogs/details.tera index 663c9d8..f976a61 100644 --- a/templates/blogs/details.tera +++ b/templates/blogs/details.tera @@ -9,10 +9,18 @@

{{ blog.title }} (~{{ blog.actor_id }})

{{ blog.summary }}

-

Latest articles

-
- {% for article in recents %} - {{ macros::post_card(article=article) }} - {% endfor %} -
+
+

Latest articles

+ {% if recents | length < 1 %} +

No posts to see here yet.

+ {% endif %} + {% if is_author %} + New article + {% endif %} +
+ {% for article in recents %} + {{ macros::post_card(article=article) }} + {% endfor %} +
+
{% endblock content %}