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

Next steps toward implementation of admin users search and group display

parent 5691dc77
Pipeline #594 failed with stage
in 3 minutes and 40 seconds
...@@ -1045,7 +1045,7 @@ pub fn admin_search_users<T: MedalConnection>(conn: &T, session_token: &str, ...@@ -1045,7 +1045,7 @@ 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("results".to_string(), to_json(&conn.get_search_users(s_data))); data.insert("result".to_string(), to_json(&conn.get_search_users(s_data)));
Ok(("admin_search_results".to_string(), data)) Ok(("admin_search_results".to_string(), data))
} }
...@@ -1058,15 +1058,24 @@ pub fn admin_show_user<T: MedalConnection>(conn: &T, user_id: i32, session_token ...@@ -1058,15 +1058,24 @@ pub fn admin_show_user<T: MedalConnection>(conn: &T, user_id: i32, session_token
let mut data = json_val::Map::new(); let mut data = json_val::Map::new();
let (user, opt_group) = conn.get_user_and_group_by_id(user_id).ok_or(MedalError::AccessDenied)?; let (user, opt_group) = conn.get_user_and_group_by_id(user_id).ok_or(MedalError::AccessDenied)?;
fill_user_data(&user, &mut data);
data.insert("firstname".to_string(), to_json(&session.firstname));
data.insert("lastname".to_string(), to_json(&session.lastname));
if let Some(group) = opt_group { if let Some(group) = opt_group {
data.insert("group_id".to_string(), to_json(&group.id)); data.insert("group_id".to_string(), to_json(&group.id));
data.insert("group_name".to_string(), to_json(&group.name)); data.insert("group_name".to_string(), to_json(&group.name));
} }
let v: Vec<GroupInfo> =
conn.get_groups(user_id)
.iter()
.map(|g| GroupInfo { id: g.id.unwrap(),
name: g.name.clone(),
tag: g.tag.clone(),
code: g.groupcode.clone() })
.collect();
data.insert("group".to_string(), to_json(&v));
data.insert("csrf_token".to_string(), to_json(&session.csrf_token));
Ok(("admin_user".to_string(), data)) Ok(("admin_user".to_string(), data))
} }
pub fn admin_delete_user<T: MedalConnection>(conn: &T, user_id: i32, session_token: &str, csrf_token: &str) pub fn admin_delete_user<T: MedalConnection>(conn: &T, user_id: i32, session_token: &str, csrf_token: &str)
...@@ -1074,11 +1083,39 @@ pub fn admin_delete_user<T: MedalConnection>(conn: &T, user_id: i32, session_tok ...@@ -1074,11 +1083,39 @@ pub fn admin_delete_user<T: MedalConnection>(conn: &T, user_id: i32, session_tok
let mut data = json_val::Map::new(); let mut data = json_val::Map::new();
Ok(("profile".to_string(), data)) Ok(("profile".to_string(), data))
} }
pub fn admin_show_group<T: MedalConnection>(conn: &T, participation_id: i32, session_token: &str) -> MedalValueResult { pub fn admin_show_group<T: MedalConnection>(conn: &T, group_id: i32, session_token: &str) -> MedalValueResult {
let mut session = conn.get_session(&session_token).ensure_logged_in().ok_or(MedalError::NotLoggedIn)?;
if session.id != 35 {
return Err(MedalError::AccessDenied);
}
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();
Ok(("profile".to_string(), data))
let gi = GroupInfo { id: group.id.unwrap(),
name: group.name.clone(),
tag: group.tag.clone(),
code: group.groupcode.clone() };
let v: Vec<MemberInfo> =
group.members
.iter()
.map(|m| MemberInfo { id: m.id,
firstname: m.firstname.clone().unwrap_or_else(|| "".to_string()),
lastname: m.lastname.clone().unwrap_or_else(|| "".to_string()),
grade: grade_to_string(m.grade),
logincode: m.logincode.clone().unwrap_or_else(|| "".to_string()) })
.collect();
data.insert("group".to_string(), to_json(&gi));
data.insert("member".to_string(), to_json(&v));
data.insert("groupname".to_string(), to_json(&gi.name));
data.insert("group_admin_id".to_string(), to_json(&group.admin));
Ok(("admin_group".to_string(), data))
} }
pub fn admin_delete_group<T: MedalConnection>(conn: &T, participation_id: i32, session_token: &str, csrf_token: &str) pub fn admin_delete_group<T: MedalConnection>(conn: &T, group_id: i32, session_token: &str, csrf_token: &str)
-> MedalValueResult { -> MedalValueResult {
let mut data = json_val::Map::new(); let mut data = json_val::Map::new();
Ok(("profile".to_string(), data)) Ok(("profile".to_string(), data))
......
...@@ -930,7 +930,7 @@ fn admin_user<C>(req: &mut Request) -> IronResult<Response> ...@@ -930,7 +930,7 @@ fn admin_user<C>(req: &mut Request) -> IronResult<Response>
fn admin_group<C>(req: &mut Request) -> IronResult<Response> fn admin_group<C>(req: &mut Request) -> IronResult<Response>
where C: MedalConnection + std::marker::Send + 'static { where C: MedalConnection + std::marker::Send + 'static {
let group_id = req.expect_int::<i32>("userid")?; let group_id = req.expect_int::<i32>("groupid")?;
let session_token = req.expect_session_token()?; let session_token = req.expect_session_token()?;
let csrf_token = if let Ok(formdata) = req.get_ref::<UrlEncodedBody>() { let csrf_token = if let Ok(formdata) = req.get_ref::<UrlEncodedBody>() {
...@@ -952,7 +952,7 @@ fn admin_group<C>(req: &mut Request) -> IronResult<Response> ...@@ -952,7 +952,7 @@ fn admin_group<C>(req: &mut Request) -> IronResult<Response>
fn admin_participation<C>(req: &mut Request) -> IronResult<Response> fn admin_participation<C>(req: &mut Request) -> IronResult<Response>
where C: MedalConnection + std::marker::Send + 'static { where C: MedalConnection + std::marker::Send + 'static {
let group_id = req.expect_int::<i32>("userid")?; let group_id = req.expect_int::<i32>("participationid")?;
let session_token = req.expect_session_token()?; let session_token = req.expect_session_token()?;
let csrf_token = if let Ok(formdata) = req.get_ref::<UrlEncodedBody>() { let csrf_token = if let Ok(formdata) = req.get_ref::<UrlEncodedBody>() {
......
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