Optionally show authors in _changes based on --trust-identity command line argument.

This fixes #19
This commit is contained in:
Magnus Hoff 2017-10-30 11:44:36 +01:00
parent ef4a3e689b
commit 4ca748f180
5 changed files with 20 additions and 13 deletions

View file

@ -76,7 +76,7 @@ fn core_main() -> Result<(), Box<std::error::Error>> {
let cpu_pool = futures_cpupool::CpuPool::new_num_cpus();
let state = state::State::new(db_pool, cpu_pool);
let lookup = wiki_lookup::WikiLookup::new(state);
let lookup = wiki_lookup::WikiLookup::new(state, trust_identity);
let server =
hyper::server::Http::new()

View file

@ -22,6 +22,7 @@ type BoxResource = Box<Resource + Sync + Send>;
#[derive(Clone)]
pub struct ChangesLookup {
state: State,
show_authors: bool,
}
#[derive(Serialize, Deserialize, Default)]
@ -91,14 +92,15 @@ fn apply_query_config<'a>(
}
impl ChangesLookup {
pub fn new(state: State) -> ChangesLookup {
Self { state }
pub fn new(state: State, show_authors: bool) -> ChangesLookup {
Self { state, show_authors }
}
pub fn lookup(&self, query: Option<&str>) -> Box<Future<Item=Option<BoxResource>, Error=::web::Error>> {
use super::pagination;
let state = self.state.clone();
let show_authors = self.show_authors;
Box::new(
done((|| {
@ -153,8 +155,8 @@ impl ChangesLookup {
}))
})) as Box<Future<Item=Option<BoxResource>, Error=::web::Error>>
},
Pagination::Before(x) => Box::new(finished(Some(Box::new(ChangesResource::new(state, Some(x), article_id, author, limit)) as BoxResource))),
Pagination::None => Box::new(finished(Some(Box::new(ChangesResource::new(state, None, article_id, author, limit)) as BoxResource))),
Pagination::Before(x) => Box::new(finished(Some(Box::new(ChangesResource::new(state, show_authors, Some(x), article_id, author, limit)) as BoxResource))),
Pagination::None => Box::new(finished(Some(Box::new(ChangesResource::new(state, show_authors, None, article_id, author, limit)) as BoxResource))),
})
)
}
@ -162,6 +164,7 @@ impl ChangesLookup {
pub struct ChangesResource {
state: State,
show_authors: bool,
before: Option<i32>,
article_id: Option<i32>,
author: Option<String>,
@ -169,8 +172,8 @@ pub struct ChangesResource {
}
impl ChangesResource {
pub fn new(state: State, before: Option<i32>, article_id: Option<i32>, author: Option<String>, limit: i32) -> Self {
Self { state, before, article_id, author, limit }
pub fn new(state: State, show_authors: bool, before: Option<i32>, article_id: Option<i32>, author: Option<String>, limit: i32) -> Self {
Self { state, show_authors, before, article_id, author, limit }
}
fn query_args(&self) -> QueryParameters {
@ -235,6 +238,7 @@ impl Resource for ChangesResource {
struct Template<'a> {
resource: &'a ChangesResource,
show_authors: bool,
newer: Option<NavLinks>,
older: Option<NavLinks>,
changes: &'a [Row<'a>],
@ -339,6 +343,7 @@ impl Resource for ChangesResource {
title: "Changes",
body: &Template {
resource: &self,
show_authors: self.show_authors,
newer,
older,
changes

View file

@ -57,9 +57,11 @@ fn decide_slug(conn: &SqliteConnection, article_id: i32, prev_title: &str, title
}
}
let base_slug = if base_slug.is_empty() { "article" } else { &base_slug };
use schema::article_revisions;
let mut slug = base_slug.clone();
let mut slug = base_slug.to_owned();
let mut disambiguator = 1;
loop {

View file

@ -76,8 +76,8 @@ fn asset_lookup(path: &str) -> FutureResult<Option<BoxResource>, Box<::std::erro
}
impl WikiLookup {
pub fn new(state: State) -> WikiLookup {
let changes_lookup = ChangesLookup::new(state.clone());
pub fn new(state: State, show_authors: bool) -> WikiLookup {
let changes_lookup = ChangesLookup::new(state.clone(), show_authors);
let search_lookup = SearchLookup::new(state.clone());
WikiLookup { state, changes_lookup, search_lookup }

View file

@ -5,7 +5,7 @@
<article>
<p>
These are the {{^newer}}most recent{{/newer}} changes that have been
These are the {{^newer}}most recent{{/newer}} changes
made to{{{subject_clause()}}}{{#author()}} by {{.}}{{/author()}}.
</p>
@ -23,14 +23,14 @@
<tr>
<th>Article</th>
<th>Updated</th>
<th>Author</th>
{{#show_authors?}}<th>Author</th>{{/show_authors}}
</tr>
{{/changes}}
{{#changes}}
<tr>
<td><a href="_revisions/{{.article_id}}/{{.revision}}">{{.title}}</a></td>
<td>{{.created}}</td>
<td>{{#.author}}<a href="{{..author_link()}}">{{.}}</a>{{/.author}}{{^.author}}<i>Anonymous</i>{{/.author}}</td>
{{#show_authors?}}<td>{{#..author}}<a href="{{...author_link()}}">{{.}}</a>{{/..author}}{{^..author}}<i>Anonymous</i>{{/..author}}</td>{{/show_authors}}
</tr>
{{/changes}}
</table>