Commit 74721993 authored by Robert Czechowski's avatar Robert Czechowski
Browse files

Admin pages add search by group code

parent 86b69d04
Pipeline #617 passed with stage
in 15 minutes and 49 seconds
...@@ -1030,8 +1030,7 @@ pub fn edit_profile<T: MedalConnection>(conn: &T, session_token: &str, user_id: ...@@ -1030,8 +1030,7 @@ pub fn edit_profile<T: MedalConnection>(conn: &T, session_token: &str, user_id:
Ok(result) Ok(result)
} }
pub fn admin_index<T: MedalConnection>(conn: &T, session_token: &str) pub fn admin_index<T: MedalConnection>(conn: &T, session_token: &str) -> MedalValueResult {
-> MedalValueResult {
let session = conn.get_session(&session_token).ensure_logged_in().ok_or(MedalError::NotLoggedIn)?; let session = conn.get_session(&session_token).ensure_logged_in().ok_or(MedalError::NotLoggedIn)?;
if session.id != 1 { if session.id != 1 {
return Err(MedalError::AccessDenied); return Err(MedalError::AccessDenied);
...@@ -1041,14 +1040,12 @@ pub fn admin_index<T: MedalConnection>(conn: &T, session_token: &str) ...@@ -1041,14 +1040,12 @@ pub fn admin_index<T: MedalConnection>(conn: &T, session_token: &str)
Ok(("admin".to_string(), data)) Ok(("admin".to_string(), data))
} }
pub fn admin_search_users<T: MedalConnection>(conn: &T, session_token: &str, pub fn admin_search_users<T: MedalConnection>(conn: &T, session_token: &str,
s_data: (Option<i32>, s_data: (Option<i32>,
Option<String>, Option<String>,
Option<String>, Option<String>,
Option<String>, Option<String>,
Option<String>,
Option<String>)) Option<String>))
-> MedalValueResult -> MedalValueResult
{ {
...@@ -1059,7 +1056,10 @@ pub fn admin_search_users<T: MedalConnection>(conn: &T, session_token: &str, ...@@ -1059,7 +1056,10 @@ pub fn admin_search_users<T: MedalConnection>(conn: &T, session_token: &str,
let mut data = json_val::Map::new(); let mut data = json_val::Map::new();
data.insert("result".to_string(), to_json(&conn.get_search_users(s_data))); match conn.get_search_users(s_data) {
Ok(users) => data.insert("users".to_string(), to_json(&users)),
Err(groups) => data.insert("groups".to_string(), to_json(&groups)),
};
Ok(("admin_search_results".to_string(), data)) Ok(("admin_search_results".to_string(), data))
} }
...@@ -1112,7 +1112,7 @@ pub fn admin_show_group<T: MedalConnection>(conn: &T, group_id: i32, session_tok ...@@ -1112,7 +1112,7 @@ pub fn admin_show_group<T: MedalConnection>(conn: &T, group_id: i32, session_tok
} }
let group = conn.get_group_complete(group_id).unwrap(); // TODO handle error let group = conn.get_group_complete(group_id).unwrap(); // TODO handle error
let mut data = json_val::Map::new(); let mut data = json_val::Map::new();
let gi = GroupInfo { id: group.id.unwrap(), let gi = GroupInfo { id: group.id.unwrap(),
......
...@@ -1081,42 +1081,54 @@ impl MedalConnection for Connection { ...@@ -1081,42 +1081,54 @@ impl MedalConnection for Connection {
.unwrap(); .unwrap();
Some(group) Some(group)
} }
fn get_search_users(&self, fn get_search_users(&self,
(s_id, s_firstname, s_lastname, s_logincode, s_pms_id): (Option<i32>, (s_id, s_firstname, s_lastname, s_logincode, s_groupcode, s_pms_id): (Option<i32>,
Option<String>,
Option<String>, Option<String>,
Option<String>, Option<String>,
Option<String>, Option<String>,
Option<String>)) Option<String>))
-> Vec<(i32, String, String)> -> Result<Vec<(i32, String, String)>, Vec<(i32, String, String)>>
{ {
if let Some(id) = s_id { if let Some(id) = s_id {
let query = "SELECT id, firstname, lastname let query = "SELECT id, firstname, lastname
FROM session FROM session
WHERE id = $1 WHERE id = $1
LIMIT 30"; LIMIT 30";
self.query_map_many(query, &[&id], |row| (row.get(0), row.get(1), row.get(2))).unwrap() Ok(self.query_map_many(query, &[&id], |row| (row.get(0), row.get(1), row.get(2))).unwrap())
} else if let Some(logincode) = s_logincode { } else if let Some(logincode) = s_logincode {
let query = "SELECT id, firstname, lastname let query = "SELECT id, firstname, lastname
FROM session FROM session
WHERE logincode = $1 WHERE logincode = $1
LIMIT 30"; LIMIT 30";
self.query_map_many(query, &[&logincode], |row| (row.get(0), row.get(1), row.get(2))).unwrap() Ok(self.query_map_many(query, &[&logincode], |row| (row.get(0), row.get(1), row.get(2))).unwrap())
} else if let Some(groupcode) = s_groupcode {
let query = "SELECT id, name, tag
FROM usergroup
WHERE groupcode = $1
LIMIT 30";
Err(self.query_map_many(query, &[&groupcode], |row| {
(row.get(0),
format!("Gruppe: {}", row.get::<_, String>(1)),
format!("(Marker: {})", row.get::<_, String>(2)))
})
.unwrap())
} else if let Some(pms_id) = s_pms_id { } else if let Some(pms_id) = s_pms_id {
let query = "SELECT id, firstname, lastname let query = "SELECT id, firstname, lastname
FROM session FROM session
WHERE oauth_foreign_id = $1 WHERE oauth_foreign_id = $1
LIMIT 30"; LIMIT 30";
self.query_map_many(query, &[&pms_id], |row| (row.get(0), row.get(1), row.get(2))).unwrap() Ok(self.query_map_many(query, &[&pms_id], |row| (row.get(0), row.get(1), row.get(2))).unwrap())
} else if let (Some(firstname), Some(lastname)) = (s_firstname, s_lastname) { } else if let (Some(firstname), Some(lastname)) = (s_firstname, s_lastname) {
let query = "SELECT id, firstname, lastname let query = "SELECT id, firstname, lastname
FROM session FROM session
WHERE firstname LIKE $1 WHERE firstname LIKE $1
AND lastname LIKE $2 AND lastname LIKE $2
LIMIT 30"; LIMIT 30";
self.query_map_many(query, &[&firstname, &lastname], |row| (row.get(0), row.get(1), row.get(2))).unwrap() Ok(self.query_map_many(query, &[&firstname, &lastname], |row| (row.get(0), row.get(1), row.get(2)))
.unwrap())
} else { } else {
Vec::new() Ok(Vec::new())
} }
} }
......
...@@ -50,8 +50,14 @@ pub trait MedalConnection { ...@@ -50,8 +50,14 @@ pub trait MedalConnection {
fn get_groups_complete(&self, session_id: i32) -> Vec<Group>; fn get_groups_complete(&self, session_id: i32) -> Vec<Group>;
fn get_group_complete(&self, group_id: i32) -> Option<Group>; fn get_group_complete(&self, group_id: i32) -> Option<Group>;
fn get_search_users(&self, _: (Option<i32>, Option<String>, Option<String>, Option<String>, Option<String>)) fn get_search_users(&self,
-> Vec<(i32, String, String)>; _: (Option<i32>,
Option<String>,
Option<String>,
Option<String>,
Option<String>,
Option<String>))
-> Result<Vec<(i32, String, String)>, Vec<(i32, String, String)>>;
fn get_debug_information(&self) -> String; fn get_debug_information(&self) -> String;
......
...@@ -1177,42 +1177,54 @@ impl MedalConnection for Connection { ...@@ -1177,42 +1177,54 @@ impl MedalConnection for Connection {
.unwrap(); .unwrap();
Some(group) Some(group)
} }
fn get_search_users(&self, fn get_search_users(&self,
(s_id, s_firstname, s_lastname, s_logincode, s_pms_id): (Option<i32>, (s_id, s_firstname, s_lastname, s_logincode, s_groupcode, s_pms_id): (Option<i32>,
Option<String>,
Option<String>, Option<String>,
Option<String>, Option<String>,
Option<String>, Option<String>,
Option<String>)) Option<String>))
-> Vec<(i32, String, String)> -> Result<Vec<(i32, String, String)>, Vec<(i32, String, String)>>
{ {
if let Some(id) = s_id { if let Some(id) = s_id {
let query = "SELECT id, firstname, lastname let query = "SELECT id, firstname, lastname
FROM session FROM session
WHERE id = $1 WHERE id = $1
LIMIT 30"; LIMIT 30";
self.query_map_many(query, &[&id], |row| (row.get(0), row.get(1), row.get(2))).unwrap() Ok(self.query_map_many(query, &[&id], |row| (row.get(0), row.get(1), row.get(2))).unwrap())
} else if let Some(logincode) = s_logincode { } else if let Some(logincode) = s_logincode {
let query = "SELECT id, firstname, lastname let query = "SELECT id, firstname, lastname
FROM session FROM session
WHERE logincode = $1 WHERE logincode = $1
LIMIT 30"; LIMIT 30";
self.query_map_many(query, &[&logincode], |row| (row.get(0), row.get(1), row.get(2))).unwrap() Ok(self.query_map_many(query, &[&logincode], |row| (row.get(0), row.get(1), row.get(2))).unwrap())
} else if let Some(groupcode) = s_groupcode {
let query = "SELECT id, name, tag
FROM usergroup
WHERE groupcode = $1
LIMIT 30";
Err(self.query_map_many(query, &[&groupcode], |row| {
(row.get(0),
format!("Gruppe: {}", row.get::<_, String>(1)),
format!("(Marker: {})", row.get::<_, String>(2)))
})
.unwrap())
} else if let Some(pms_id) = s_pms_id { } else if let Some(pms_id) = s_pms_id {
let query = "SELECT id, firstname, lastname let query = "SELECT id, firstname, lastname
FROM session FROM session
WHERE oauth_foreign_id = $1 WHERE oauth_foreign_id = $1
LIMIT 30"; LIMIT 30";
self.query_map_many(query, &[&pms_id], |row| (row.get(0), row.get(1), row.get(2))).unwrap() Ok(self.query_map_many(query, &[&pms_id], |row| (row.get(0), row.get(1), row.get(2))).unwrap())
} else if let (Some(firstname), Some(lastname)) = (s_firstname, s_lastname) { } else if let (Some(firstname), Some(lastname)) = (s_firstname, s_lastname) {
let query = "SELECT id, firstname, lastname let query = "SELECT id, firstname, lastname
FROM session FROM session
WHERE firstname LIKE $1 WHERE firstname LIKE $1
AND lastname LIKE $2 AND lastname LIKE $2
LIMIT 30"; LIMIT 30";
self.query_map_many(query, &[&firstname, &lastname], |row| (row.get(0), row.get(1), row.get(2))).unwrap() Ok(self.query_map_many(query, &[&firstname, &lastname], |row| (row.get(0), row.get(1), row.get(2)))
.unwrap())
} else { } else {
Vec::new() Ok(Vec::new())
} }
} }
......
...@@ -1177,42 +1177,54 @@ impl MedalConnection for Connection { ...@@ -1177,42 +1177,54 @@ impl MedalConnection for Connection {
.unwrap(); .unwrap();
Some(group) Some(group)
} }
fn get_search_users(&self, fn get_search_users(&self,
(s_id, s_firstname, s_lastname, s_logincode, s_pms_id): (Option<i32>, (s_id, s_firstname, s_lastname, s_logincode, s_groupcode, s_pms_id): (Option<i32>,
Option<String>,
Option<String>, Option<String>,
Option<String>, Option<String>,
Option<String>, Option<String>,
Option<String>)) Option<String>))
-> Vec<(i32, String, String)> -> Result<Vec<(i32, String, String)>, Vec<(i32, String, String)>>
{ {
if let Some(id) = s_id { if let Some(id) = s_id {
let query = "SELECT id, firstname, lastname let query = "SELECT id, firstname, lastname
FROM session FROM session
WHERE id = ?1 WHERE id = ?1
LIMIT 30"; LIMIT 30";
self.query_map_many(query, &[&id], |row| (row.get(0), row.get(1), row.get(2))).unwrap() Ok(self.query_map_many(query, &[&id], |row| (row.get(0), row.get(1), row.get(2))).unwrap())
} else if let Some(logincode) = s_logincode { } else if let Some(logincode) = s_logincode {
let query = "SELECT id, firstname, lastname let query = "SELECT id, firstname, lastname
FROM session FROM session
WHERE logincode = ?1 WHERE logincode = ?1
LIMIT 30"; LIMIT 30";
self.query_map_many(query, &[&logincode], |row| (row.get(0), row.get(1), row.get(2))).unwrap() Ok(self.query_map_many(query, &[&logincode], |row| (row.get(0), row.get(1), row.get(2))).unwrap())
} else if let Some(groupcode) = s_groupcode {
let query = "SELECT id, name, tag
FROM usergroup
WHERE groupcode = ?1
LIMIT 30";
Err(self.query_map_many(query, &[&groupcode], |row| {
(row.get(0),
format!("Gruppe: {}", row.get::<_, String>(1)),
format!("(Marker: {})", row.get::<_, String>(2)))
})
.unwrap())
} else if let Some(pms_id) = s_pms_id { } else if let Some(pms_id) = s_pms_id {
let query = "SELECT id, firstname, lastname let query = "SELECT id, firstname, lastname
FROM session FROM session
WHERE oauth_foreign_id = ?1 WHERE oauth_foreign_id = ?1
LIMIT 30"; LIMIT 30";
self.query_map_many(query, &[&pms_id], |row| (row.get(0), row.get(1), row.get(2))).unwrap() Ok(self.query_map_many(query, &[&pms_id], |row| (row.get(0), row.get(1), row.get(2))).unwrap())
} else if let (Some(firstname), Some(lastname)) = (s_firstname, s_lastname) { } else if let (Some(firstname), Some(lastname)) = (s_firstname, s_lastname) {
let query = "SELECT id, firstname, lastname let query = "SELECT id, firstname, lastname
FROM session FROM session
WHERE firstname LIKE ?1 WHERE firstname LIKE ?1
AND lastname LIKE ?2 AND lastname LIKE ?2
LIMIT 30"; LIMIT 30";
self.query_map_many(query, &[&firstname, &lastname], |row| (row.get(0), row.get(1), row.get(2))).unwrap() Ok(self.query_map_many(query, &[&firstname, &lastname], |row| (row.get(0), row.get(1), row.get(2)))
.unwrap())
} else { } else {
Vec::new() Ok(Vec::new())
} }
} }
......
...@@ -875,10 +875,7 @@ fn admin<C>(req: &mut Request) -> IronResult<Response> ...@@ -875,10 +875,7 @@ fn admin<C>(req: &mut Request) -> IronResult<Response>
where C: MedalConnection + std::marker::Send + 'static { where C: MedalConnection + std::marker::Send + 'static {
let session_token = req.expect_session_token()?; let session_token = req.expect_session_token()?;
let (template, data) = with_conn![core::admin_index, let (template, data) = with_conn![core::admin_index, C, req, &session_token].aug(req)?;
C,
req,
&session_token].aug(req)?;
let mut resp = Response::new(); let mut resp = Response::new();
resp.set_mut(Template::new(&template, data)).set_mut(status::Ok); resp.set_mut(Template::new(&template, data)).set_mut(status::Ok);
...@@ -889,12 +886,13 @@ fn admin_users<C>(req: &mut Request) -> IronResult<Response> ...@@ -889,12 +886,13 @@ fn admin_users<C>(req: &mut Request) -> IronResult<Response>
where C: MedalConnection + std::marker::Send + 'static { where C: MedalConnection + std::marker::Send + 'static {
let session_token = req.expect_session_token()?; let session_token = req.expect_session_token()?;
let (s_id, s_firstname, s_lastname, s_logincode, s_pms_id) = { let (s_id, s_firstname, s_lastname, s_logincode, s_groupcode, s_pms_id) = {
let formdata = itry!(req.get_ref::<UrlEncodedBody>()); let formdata = itry!(req.get_ref::<UrlEncodedBody>());
(formdata.get("id").map(|x| x[0].parse::<i32>().unwrap_or(0)), (formdata.get("id").map(|x| x[0].parse::<i32>().unwrap_or(0)),
formdata.get("firstname").map(|x| x[0].to_owned()), formdata.get("firstname").map(|x| x[0].to_owned()),
formdata.get("lastname").map(|x| x[0].to_owned()), formdata.get("lastname").map(|x| x[0].to_owned()),
formdata.get("logincode").map(|x| x[0].to_owned()), formdata.get("logincode").map(|x| x[0].to_owned()),
formdata.get("groupcode").map(|x| x[0].to_owned()),
formdata.get("pmsid").map(|x| x[0].to_owned())) formdata.get("pmsid").map(|x| x[0].to_owned()))
}; };
...@@ -902,7 +900,7 @@ fn admin_users<C>(req: &mut Request) -> IronResult<Response> ...@@ -902,7 +900,7 @@ fn admin_users<C>(req: &mut Request) -> IronResult<Response>
C, C,
req, req,
&session_token, &session_token,
(s_id, s_firstname, s_lastname, s_logincode, s_pms_id)].aug(req)?; (s_id, s_firstname, s_lastname, s_logincode, s_groupcode, s_pms_id)].aug(req)?;
let mut resp = Response::new(); let mut resp = Response::new();
resp.set_mut(Template::new(&template, data)).set_mut(status::Ok); resp.set_mut(Template::new(&template, data)).set_mut(status::Ok);
......
<h1>Admin-Suche</h1> <h1>Admin-Suche</h1>
<p>Suche beachtet Groß-/Kleinschreibung. Das Prozentzeichen % ist ein Wildcart in der Namenssuche. Die Suche gibt nur bis zu 30 Ergebnisse aus, auch wenn es mehr gibt!</p> <p>Suche beachtet Groß-/Kleinschreibung. Das Prozentzeichen % ist ein Wildcart in der Namenssuche. Die Suche gibt nur bis zu 30 Ergebnisse aus, auch wenn es mehr gibt!</p>
<p>
<form action="/admin/user/" method="post">
ID:<br>
<input type="text" name="id">
<br><br>
<input type="submit" value="search">
</form>
</p>
<p> <p>
<form action="/admin/user/" method="post"> <form action="/admin/user/" method="post">
Vorname:<br> Vorname:<br>
...@@ -31,6 +22,24 @@ ...@@ -31,6 +22,24 @@
</form> </form>
</p> </p>
<p>
<form action="/admin/user/" method="post">
Gruppencode:<br>
<input type="text" name="groupcode">
<br><br>
<input type="submit" value="search">
</form>
</p>
<p>
<form action="/admin/user/" method="post">
ID:<br>
<input type="text" name="id">
<br><br>
<input type="submit" value="search">
</form>
</p>
<p> <p>
<form action="/admin/user/" method="post"> <form action="/admin/user/" method="post">
PMS-ID:<br> PMS-ID:<br>
......
<h1>Ergebnisse</h1> <h1>Ergebnisse</h1>
<ul> {{#if users}}
{{#each result}} <h2>Benutzer</h2>
<li><a href="{{this.0}}">{{this.0}}: {{this.1}} {{this.2}}</li> <ul>
{{/each}} {{#each users}}
</ul> <li><a href="{{this.0}}">{{this.0}}: {{this.1}} {{this.2}}</li>
{{/each}}
</ul>
{{/if}}
{{#if groups}}
<h2>Gruppen</h2>
<ul>
{{#each groups}}
<li><a href="/admin/group/{{this.0}}">{{this.0}}: {{this.1}} {{this.2}}</li>
{{/each}}
</ul>
{{/if}}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment