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 db_conn::DbConn;
use models::{ use models::{
blogs::Blog,
blog_authors::BlogAuthor,
comments::Comment, comments::Comment,
follows::Follow, follows::Follow,
instance::Instance, instance::Instance,
@ -297,6 +299,15 @@ impl User {
.len() > 0 .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> { pub fn get_keypair(&self) -> PKey<Private> {
PKey::from_rsa(Rsa::private_key_from_pem(self.private_key.clone().unwrap().as_ref()).unwrap()).unwrap() 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!({ Template::render("blogs/details", json!({
"blog": blog, "blog": blog,
"account": user, "account": user,
"is_author": user.map(|x| x.is_author_in(&*conn, blog)),
"recents": recents.into_iter().map(|p| { "recents": recents.into_iter().map(|p| {
json!({ json!({
"post": p, "post": p,

View file

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