List authors of a blog

Update french translation accordingly

Fixes #129
This commit is contained in:
Bat 2018-07-18 23:08:49 +02:00
parent 216f334d75
commit ce256d6e39
8 changed files with 59 additions and 5 deletions

View File

@ -23,6 +23,7 @@ use plume_common::activity_pub::{
sign sign
}; };
use instance::*; use instance::*;
use users::User;
use schema::blogs; use schema::blogs;
pub type CustomGroup = CustomObject<ApSignature, Group>; pub type CustomGroup = CustomObject<ApSignature, Group>;
@ -68,6 +69,15 @@ impl Blog {
Instance::get(conn, self.instance_id).expect("Couldn't find instance") Instance::get(conn, self.instance_id).expect("Couldn't find instance")
} }
pub fn list_authors(&self, conn: &PgConnection) -> Vec<User> {
use schema::blog_authors;
use schema::users;
let authors_ids = blog_authors::table.filter(blog_authors::blog_id.eq(self.id)).select(blog_authors::author_id);
users::table.filter(users::id.eq(any(authors_ids)))
.load::<User>(conn)
.expect("Couldn't load authors of a blog")
}
pub fn find_for_author(conn: &PgConnection, author_id: i32) -> Vec<Blog> { pub fn find_for_author(conn: &PgConnection, author_id: i32) -> Vec<Blog> {
use schema::blog_authors; use schema::blog_authors;
let author_ids = blog_authors::table.filter(blog_authors::author_id.eq(author_id)).select(blog_authors::blog_id); let author_ids = blog_authors::table.filter(blog_authors::author_id.eq(author_id)).select(blog_authors::blog_id);

View File

@ -327,3 +327,9 @@ msgstr ""
msgid "Password should be at least 8 characters long" msgid "Password should be at least 8 characters long"
msgstr "" msgstr ""
#, fuzzy
msgid "One author in this blog: "
msgid_plural "{{ count }} authors in this blog: "
msgstr[0] "Du bist kein Autor in diesem Blog."
msgstr[1] "Du bist kein Autor in diesem Blog."

View File

@ -321,3 +321,8 @@ msgstr ""
msgid "Password should be at least 8 characters long" msgid "Password should be at least 8 characters long"
msgstr "" msgstr ""
msgid "One author in this blog: "
msgid_plural "{{ count }} authors in this blog: "
msgstr[0] ""
msgstr[1] ""

View File

@ -70,7 +70,8 @@ msgstr "Notifications"
msgid "" msgid ""
"Written by {{ link_1 }}{{ url }}{{ link_2 }}{{ name | escape }}{{ link_3 }}" "Written by {{ link_1 }}{{ url }}{{ link_2 }}{{ name | escape }}{{ link_3 }}"
msgstr "Écrit par {{ link_1 }}{{ url }}{{ link_2 }}{{ name | escape }}{{ link_3 }}" msgstr ""
"Écrit par {{ link_1 }}{{ url }}{{ link_2 }}{{ name | escape }}{{ link_3 }}"
msgid "This article is under the {{ license }} license." msgid "This article is under the {{ license }} license."
msgstr "Cet article est placé sous la licence {{ license }}" msgstr "Cet article est placé sous la licence {{ license }}"
@ -303,7 +304,9 @@ msgid "A post with the same title already exists."
msgstr "Un article avec le même titre existe déjà." msgstr "Un article avec le même titre existe déjà."
msgid "We need an email or a username to identify you" msgid "We need an email or a username to identify you"
msgstr "Nous avons besoin d'une adresse mail ou d'un nom d'utilisateur pour vous identifier." msgstr ""
"Nous avons besoin d'une adresse mail ou d'un nom d'utilisateur pour vous "
"identifier."
msgid "Your password should be at least 8 characters long" msgid "Your password should be at least 8 characters long"
msgstr "Votre mot de passe doit faire au moins 8 caractères." msgstr "Votre mot de passe doit faire au moins 8 caractères."
@ -319,3 +322,8 @@ msgstr "Adresse mail invalide"
msgid "Password should be at least 8 characters long" msgid "Password should be at least 8 characters long"
msgstr "Le mot de passe doit faire au moins 8 caractères." msgstr "Le mot de passe doit faire au moins 8 caractères."
msgid "One author in this blog: "
msgid_plural "{{ count }} authors in this blog: "
msgstr[0] "{{ count }} aut⋅eur⋅rice dans ce blog : "
msgstr[1] "{{ count }} aut⋅eur⋅rice⋅s dans ce blog : "

View File

@ -329,5 +329,12 @@ msgstr "Nieprawidłowy adres e-mail"
msgid "Password should be at least 8 characters long" msgid "Password should be at least 8 characters long"
msgstr "Hasło musi składać się z przynajmniej 8 znaków" msgstr "Hasło musi składać się z przynajmniej 8 znaków"
#, fuzzy
msgid "One author in this blog: "
msgid_plural "{{ count }} authors in this blog: "
msgstr[0] "Nie jesteś autorem tego bloga."
msgstr[1] "Nie jesteś autorem tego bloga."
msgstr[2] "Nie jesteś autorem tego bloga."
#~ msgid "Logowanie" #~ msgid "Logowanie"
#~ msgstr "Zaloguj się" #~ msgstr "Zaloguj się"

View File

@ -315,3 +315,7 @@ msgstr ""
msgid "Password should be at least 8 characters long" msgid "Password should be at least 8 characters long"
msgstr "" msgstr ""
msgid "One author in this blog: "
msgid_plural "{{ count }} authors in this blog: "
msgstr[0] ""
msgstr[1] ""

View File

@ -23,12 +23,15 @@ use plume_models::{
fn details(name: String, conn: DbConn, user: Option<User>) -> Template { fn details(name: String, conn: DbConn, user: Option<User>) -> Template {
may_fail!(user, Blog::find_by_fqn(&*conn, name), "Requested blog couldn't be found", |blog| { may_fail!(user, Blog::find_by_fqn(&*conn, name), "Requested blog couldn't be found", |blog| {
let recents = Post::get_recents_for_blog(&*conn, &blog, 5); let recents = Post::get_recents_for_blog(&*conn, &blog, 5);
let authors = &blog.list_authors(&*conn);
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)), "is_author": user.map(|x| x.is_author_in(&*conn, blog.clone())),
"recents": recents.into_iter().map(|p| p.to_json(&*conn)).collect::<Vec<serde_json::Value>>() "recents": recents.into_iter().map(|p| p.to_json(&*conn)).collect::<Vec<serde_json::Value>>(),
"authors": authors.into_iter().map(|u| u.to_json(&*conn)).collect::<Vec<serde_json::Value>>(),
"n_authors": authors.len()
})) }))
}) })
} }

View File

@ -8,6 +8,17 @@
{% block content %} {% block content %}
<h1>{{ blog.title }} (~{{ blog.actor_id }})</h1> <h1>{{ blog.title }} (~{{ blog.actor_id }})</h1>
<p>{{ blog.summary }}</p> <p>{{ blog.summary }}</p>
<p>
{{ "{{ count }} authors in this blog: " | _n(singular="One author in this blog: ", count = n_authors) }}
{% for author in authors %}
{% if author.display_name %}
{% set name = author.display_name %}
{% else %}
{% set name = author.username %}
{% endif %}
<a class="author" href="/@/{{ author.fqn }}">{{ name }}</a>{% if not loop.last %},{% endif %}
{% endfor %}
</p>
<section> <section>
<h2>{{ "Latest articles" | _ }}</h2> <h2>{{ "Latest articles" | _ }}</h2>