Add a button to write a new article

This commit is contained in:
Bat 2018-06-10 19:16:25 +01:00
parent edbeeef640
commit 7fd152e270
3 changed files with 26 additions and 6 deletions

View file

@ -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::<BlogAuthor>(conn)
.expect("Couldn't load blog/author relationship")
.len() > 0
}
pub fn get_keypair(&self) -> PKey<Private> {
PKey::from_rsa(Rsa::private_key_from_pem(self.private_key.clone().unwrap().as_ref()).unwrap()).unwrap()
}

View file

@ -24,6 +24,7 @@ fn details(name: String, conn: DbConn, user: Option<User>) -> 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,

View file

@ -9,10 +9,18 @@
<h1>{{ blog.title }} (~{{ blog.actor_id }})</h1>
<p>{{ blog.summary }}</p>
<h2>Latest articles</h2>
<div class="cards">
{% for article in recents %}
{{ macros::post_card(article=article) }}
{% endfor %}
</div>
<section>
<h2>Latest articles</h2>
{% if recents | length < 1 %}
<p>No posts to see here yet.</p>
{% endif %}
{% if is_author %}
<a href="new" class="button inline-block">New article</a>
{% endif %}
<div class="cards">
{% for article in recents %}
{{ macros::post_card(article=article) }}
{% endfor %}
</div>
</section>
{% endblock content %}