summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKjetil Orbekk <kjetil.orbekk@gmail.com>2017-07-10 11:29:20 -0400
committerKjetil Orbekk <kjetil.orbekk@gmail.com>2017-07-10 11:29:35 -0400
commit80f1ddbe1e80682edd2d85b797a4d90ae4fc6f10 (patch)
tree43c26e8503d182458c0ebf0e2b90a22cc12f6b01
parentee8b1d28744443535bbcc13bcb49e0b143691dd3 (diff)
add: Quote approval.
-rw-r--r--src/data/templates/approve.hbs77
-rw-r--r--src/server.rs37
2 files changed, 114 insertions, 0 deletions
diff --git a/src/data/templates/approve.hbs b/src/data/templates/approve.hbs
new file mode 100644
index 0000000..195bb0d
--- /dev/null
+++ b/src/data/templates/approve.hbs
@@ -0,0 +1,77 @@
+<!doctype html>
+<html lang="no">
+ <head>
+ <meta name="robots" content="noindex, nofollow" />
+ <link rel="shortcut icon" href="/favicon.ico" />
+ <title>Quotes fra #linux.no på freenode</title>
+ <style type="text/css">
+ body {
+ font-family: monospace;
+ background: #ffffff;
+ color: #000000;
+ }
+ a, a:visited {
+ color: #000000;
+ }
+ hr {
+ border-style: solid;
+ border-color: black;
+ border-width: 1px;
+ }
+ .ragebutton {
+ font-family: monospace;
+ text-align: left;
+ text-decoration: underline;
+ color: black;
+ background: none;
+ margin: 0;
+ padding: 0;
+ border: none;
+ cursor: pointer;
+ -moz-user-select: text;
+ }
+ </style>
+ </head>
+ <body>
+
+<pre>
+ _ _
+ | (_)_ __ _ ___ __ _ __ ___
+ _|_|_ | | | '_ \| | | \ \/ / | '_ \ / _ \
+ _|_|_ | | | | | | |_| |) ( _| | | | (_) |
+ | | |_|_|_| |_|\__,_/_/\_(_)_| |_|\___/
+ -=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=- GAMMA -=-
+ Quotes fra #linux.no på freenode
+ Klikk <a href="add.jsp">her</a> for å legge til en quote
+
+ Sortér etter <a href="quotes.jsp?order=date">dato</a> | <a href="quotes.jsp?order=score">score</a>
+</pre>
+<hr>
+
+{{#each quotes}}
+
+<br>
+#{{id}}, lagt til av {{author}}<br>
+Dato: {{date}},
+<a href="approve.jsp?id={{id}}&action=approve">godkjenn</a>,
+<a href="approve.jsp?id={{id}}&action=reject">slett</a>
+<br> <br>
+
+{{content}}
+<br>
+<hr>
+{{/each}}
+
+
+<center>
+<br>
+<p>linoquotes v.3 © 2004-2017 Kjetil Ørbekk, Erlend Hamberg, Vidar Holen, John H. Anthony.
+<p>Source code at <a href="https://git.orbekk.com/linoquotes-gamma.git">https://git.orbekk.com/linoquotes-gamma.git</a>.
+<p>The quotes on this page are copyright their respective owners and submitters.</p>
+</center>
+
+ </body>
+</html>
+
+
+
diff --git a/src/server.rs b/src/server.rs
index 7c1b3db..e20bb96 100644
--- a/src/server.rs
+++ b/src/server.rs
@@ -44,6 +44,10 @@ fn make_renderer() -> HandlebarsEngine {
"add_post".to_string(),
include_str!("data/templates/add_post.hbs").to_string(),
);
+ templates.insert(
+ "approve".to_string(),
+ include_str!("data/templates/approve.hbs").to_string(),
+ );
e.add(Box::new(MemorySource(templates)));
if let Err(r) = e.reload() {
@@ -113,6 +117,38 @@ fn add_post(r: &mut Request) -> IronResult<Response> {
)))
}
+fn approve(r: &mut Request) -> IronResult<Response> {
+ let mut result = Map::new();
+ let quote_id = get_param(r, "id").ok().and_then(
+ |id| id.parse::<i64>().ok(),
+ );
+ let action = get_param(r, "action").unwrap_or("".to_string());
+
+ let quotes = {
+ let mu = r.get::<Write<State>>().unwrap();
+ let state = mu.lock().unwrap();
+ if let Some(quote_id) = quote_id {
+ info!("Approval for quote({}): {}", quote_id, action);
+ if action == "approve" {
+ data::approve_quote(&state.connection, quote_id)?;
+ } else if action == "reject" {
+ data::delete_quote(&state.connection, quote_id)?;
+ } else {
+ return Err(From::from(
+ LinoError::BadRequest(format!("invalid action: {}", action)),
+ ));
+ }
+ }
+ data::get_pending_quotes(&state.connection)?
+ };
+ result.insert("quotes".to_string(), to_json(&quotes));
+ Ok(Response::with((
+ status::Ok,
+ Header(ContentType::html()),
+ Template::new("approve", result),
+ )))
+}
+
pub fn serve(state: State, port: u16) {
let router =
router!(
@@ -121,6 +157,7 @@ pub fn serve(state: State, port: u16) {
add_post: post "/add.jsp" => add_post,
quotes_jsp: get "/quotes.jsp" => quotes,
view_quote: get "/view_quote" => quotes,
+ approve: get "/approve.jsp" => approve,
);
let mut chain = Chain::new(router);
chain.link_after(make_renderer());