Verify that the user attempts to create a new article
This commit is contained in:
parent
700cf42eb0
commit
a42010a1f8
1 changed files with 6 additions and 6 deletions
|
@ -12,7 +12,7 @@ use site::Layout;
|
||||||
use state::State;
|
use state::State;
|
||||||
use web::{Resource, ResponseFuture};
|
use web::{Resource, ResponseFuture};
|
||||||
|
|
||||||
const NDASH: &str = "\u{2013}";
|
const NEW: &str = "NEW";
|
||||||
|
|
||||||
const EMPTY_ARTICLE_MESSAGE: &str = "
|
const EMPTY_ARTICLE_MESSAGE: &str = "
|
||||||
<p>Not found</p>
|
<p>Not found</p>
|
||||||
|
@ -74,7 +74,7 @@ impl Resource for NewArticleResource {
|
||||||
base: None, // Hmm, should perhaps accept `base` as argument
|
base: None, // Hmm, should perhaps accept `base` as argument
|
||||||
title: &title,
|
title: &title,
|
||||||
body: &Template {
|
body: &Template {
|
||||||
revision: NDASH,
|
revision: NEW,
|
||||||
last_updated: None,
|
last_updated: None,
|
||||||
|
|
||||||
// Implicitly start in edit-mode when no slug is given. This
|
// Implicitly start in edit-mode when no slug is given. This
|
||||||
|
@ -94,7 +94,7 @@ impl Resource for NewArticleResource {
|
||||||
|
|
||||||
fn put(self: Box<Self>, body: hyper::Body, identity: Option<String>) -> ResponseFuture {
|
fn put(self: Box<Self>, body: hyper::Body, identity: Option<String>) -> ResponseFuture {
|
||||||
// TODO Check incoming Content-Type
|
// TODO Check incoming Content-Type
|
||||||
// TODO Refactor. Reduce duplication with ArticleResource::put
|
// TODO Refactor? Reduce duplication with ArticleResource::put?
|
||||||
|
|
||||||
use chrono::{TimeZone, Local};
|
use chrono::{TimeZone, Local};
|
||||||
use futures::Stream;
|
use futures::Stream;
|
||||||
|
@ -131,9 +131,9 @@ impl Resource for NewArticleResource {
|
||||||
.map_err(Into::into)
|
.map_err(Into::into)
|
||||||
})
|
})
|
||||||
.and_then(move |arg: CreateArticle| {
|
.and_then(move |arg: CreateArticle| {
|
||||||
// TODO Check that update.base_revision == NDASH
|
if arg.base_revision != NEW {
|
||||||
// ... which seems silly. But there should be a mechanism to indicate that
|
unimplemented!("Version update conflict");
|
||||||
// the client is actually trying to create a new article
|
}
|
||||||
self.state.create_article(self.slug.clone(), arg.title, arg.body, identity)
|
self.state.create_article(self.slug.clone(), arg.title, arg.body, identity)
|
||||||
})
|
})
|
||||||
.and_then(|updated| {
|
.and_then(|updated| {
|
||||||
|
|
Loading…
Reference in a new issue