From 80f1ddbe1e80682edd2d85b797a4d90ae4fc6f10 Mon Sep 17 00:00:00 2001 From: Kjetil Orbekk Date: Mon, 10 Jul 2017 11:29:20 -0400 Subject: add: Quote approval. --- src/data/templates/approve.hbs | 77 ++++++++++++++++++++++++++++++++++++++++++ src/server.rs | 37 ++++++++++++++++++++ 2 files changed, 114 insertions(+) create mode 100644 src/data/templates/approve.hbs 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 @@ + + + + + + Quotes fra #linux.no på freenode + + + + +
+                     _ _  
+                    | (_)_ __  _   ___  __  _ __   ___  
+              _|_|_ | | | '_ \| | | \ \/ / | '_ \ / _ \ 
+              _|_|_ | | | | | | |_| |)  ( _| | | | (_) | 
+               | |  |_|_|_| |_|\__,_/_/\_(_)_| |_|\___/ 
+             -=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=- GAMMA -=-
+                   Quotes fra #linux.no på freenode
+                  Klikk her for å legge til en quote
+
+              Sortér etter dato | score
+
+
+ +{{#each quotes}} + +
+#{{id}}, lagt til av {{author}}
+Dato: {{date}}, +godkjenn, +slett +

+ +{{content}} +
+
+{{/each}} + + +
+
+

linoquotes v.3 © 2004-2017 Kjetil Ørbekk, Erlend Hamberg, Vidar Holen, John H. Anthony. +

Source code at https://git.orbekk.com/linoquotes-gamma.git. +

The quotes on this page are copyright their respective owners and submitters.

+
+ + + + + + 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 { ))) } +fn approve(r: &mut Request) -> IronResult { + let mut result = Map::new(); + let quote_id = get_param(r, "id").ok().and_then( + |id| id.parse::().ok(), + ); + let action = get_param(r, "action").unwrap_or("".to_string()); + + let quotes = { + let mu = r.get::>().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("es)); + 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()); -- cgit v1.2.3