Commit 5e8a02e2 authored by Robert Czechowski's avatar Robert Czechowski

Admin page: Show participations on user page

parent 3da8ac81
......@@ -1162,6 +1162,12 @@ pub fn admin_show_user<T: MedalConnection>(conn: &T, user_id: i32, session_token
data.insert("group".to_string(), to_json(&v));
data.insert("csrf_token".to_string(), to_json(&session.csrf_token));
let parts = conn.get_all_participations_complete(user_id);
let pi: Vec<(i32, String)> = parts.into_iter().map(|(_, c)| (c.id.unwrap(), c.name)).collect();
data.insert("participations".to_string(), to_json(&pi));
Ok(("admin_user".to_string(), data))
}
......@@ -1218,14 +1224,14 @@ pub fn admin_delete_group<T: MedalConnection>(conn: &T, group_id: i32, session_t
}
#[allow(unused_variables)]
pub fn admin_show_participation<T: MedalConnection>(conn: &T, participation_id: i32, session_token: &str)
pub fn admin_show_participation<T: MedalConnection>(conn: &T, user_id: i32, contest_id: i32, session_token: &str)
-> MedalValueResult {
let data = json_val::Map::new();
Ok(("profile".to_string(), data))
}
#[allow(unused_variables)]
pub fn admin_delete_participation<T: MedalConnection>(conn: &T, participation_id: i32, session_token: &str,
pub fn admin_delete_participation<T: MedalConnection>(conn: &T, user_id: i32, contest_id: i32, session_token: &str,
csrf_token: &str)
-> MedalValueResult
{
......
......@@ -924,6 +924,37 @@ impl MedalConnection for Connection {
start: row.get(1) })
.ok()?
}
fn get_all_participations_complete(&self, session_id: i32) -> Vec<(Participation, Contest)> {
let query = "SELECT participation.start_date, contest.id, location, filename, name, duration, public,
contest.start_date, end_date, min_grade, max_grade, requires_login, secret
FROM participation
JOIN contest ON participation.contest = contest.id
WHERE participation.session = $1";
self.query_map_many(query, &[&session_id], |row| {
( Participation { contest: row.get(1),
user: session_id,
start: row.get(0) },
Contest { id: Some(row.get(1)),
location: row.get(2),
filename: row.get(3),
name: row.get(4),
duration: row.get(5),
public: row.get(6),
start: row.get(7),
end: row.get(8),
min_grade: row.get(9),
max_grade: row.get(10),
positionalnumber: None,
requires_login: row.get(11),
secret: row.get(12),
taskgroups: Vec::new() },
)
})
.unwrap()
}
fn new_participation(&self, session: &str, contest_id: i32) -> Result<Participation, ()> {
let query = "SELECT session, start_date
FROM participation
......
......@@ -52,6 +52,7 @@ pub trait MedalConnection {
fn get_contest_by_id_partial(&self, contest_id: i32) -> Contest;
fn get_contest_by_id_complete(&self, contest_id: i32) -> Contest;
fn get_participation(&self, session: &str, contest_id: i32) -> Option<Participation>;
fn get_all_participations_complete(&self, session_id: i32) -> Vec<(Participation, Contest)>;
fn new_participation(&self, session: &str, contest_id: i32) -> Result<Participation, ()>;
fn get_task_by_id(&self, task_id: i32) -> Task;
fn get_task_by_id_complete(&self, task_id: i32) -> (Task, Taskgroup, Contest);
......
......@@ -1044,6 +1044,33 @@ impl MedalConnection for Connection {
start: row.get(1) })
.ok()?
}
fn get_all_participations_complete(&self, session_id: i32) -> Vec<(Participation, Contest)> {
let query = "SELECT participation.start_date, contest.id, location, filename, name, duration, public,
contest.start_date, end_date, min_grade, max_grade, requires_login, secret
FROM participation
JOIN contest ON participation.contest = contest.id
WHERE participation.session = $1";
self.query_map_many(query, &[&session_id], |row| {
(Participation { contest: row.get(1), user: session_id, start: row.get(0) },
Contest { id: Some(row.get(1)),
location: row.get(2),
filename: row.get(3),
name: row.get(4),
duration: row.get(5),
public: row.get(6),
start: row.get(7),
end: row.get(8),
min_grade: row.get(9),
max_grade: row.get(10),
positionalnumber: None,
requires_login: row.get(11),
secret: row.get(12),
taskgroups: Vec::new() })
})
.unwrap()
}
fn new_participation(&self, session: &str, contest_id: i32) -> Result<Participation, ()> {
let query = "SELECT session, start_date
FROM participation
......
......@@ -1044,6 +1044,33 @@ impl MedalConnection for Connection {
start: row.get(1) })
.ok()?
}
fn get_all_participations_complete(&self, session_id: i32) -> Vec<(Participation, Contest)> {
let query = "SELECT participation.start_date, contest.id, location, filename, name, duration, public,
contest.start_date, end_date, min_grade, max_grade, requires_login, secret
FROM participation
JOIN contest ON participation.contest = contest.id
WHERE participation.session = ?1";
self.query_map_many(query, &[&session_id], |row| {
(Participation { contest: row.get(1), user: session_id, start: row.get(0) },
Contest { id: Some(row.get(1)),
location: row.get(2),
filename: row.get(3),
name: row.get(4),
duration: row.get(5),
public: row.get(6),
start: row.get(7),
end: row.get(8),
min_grade: row.get(9),
max_grade: row.get(10),
positionalnumber: None,
requires_login: row.get(11),
secret: row.get(12),
taskgroups: Vec::new() })
})
.unwrap()
}
fn new_participation(&self, session: &str, contest_id: i32) -> Result<Participation, ()> {
let query = "SELECT session, start_date
FROM participation
......
......@@ -983,7 +983,8 @@ fn admin_group<C>(req: &mut Request) -> IronResult<Response>
fn admin_participation<C>(req: &mut Request) -> IronResult<Response>
where C: MedalConnection + std::marker::Send + 'static {
let group_id = req.expect_int::<i32>("participationid")?;
let user_id = req.expect_int::<i32>("userid")?;
let contest_id = req.expect_int::<i32>("contestid")?;
let session_token = req.expect_session_token()?;
let csrf_token = if let Ok(formdata) = req.get_ref::<UrlEncodedBody>() {
......@@ -993,9 +994,9 @@ fn admin_participation<C>(req: &mut Request) -> IronResult<Response>
};
let (template, data) = if let Some(csrf_token) = csrf_token {
with_conn![core::admin_delete_participation, C, req, group_id, &session_token, &csrf_token].aug(req)?
with_conn![core::admin_delete_participation, C, req, user_id, contest_id, &session_token, &csrf_token].aug(req)?
} else {
with_conn![core::admin_show_participation, C, req, group_id, &session_token].aug(req)?
with_conn![core::admin_show_participation, C, req, user_id, contest_id, &session_token].aug(req)?
};
let mut resp = Response::new();
......@@ -1236,8 +1237,8 @@ pub fn start_server<C>(conn: C, config: Config) -> iron::error::HttpResult<iron:
admin_user_post: post "/admin/user/:userid" => admin_user::<C>,
admin_group: get "/admin/group/:groupid" => admin_group::<C>,
admin_group_post: post "/admin/group/:groupid" => admin_group::<C>,
admin_participation: get "/admin/participation/:participationid" => admin_participation::<C>,
admin_participation_post: post "/admin/participation/:participationid" => admin_participation::<C>,
admin_participation: get "/admin/user/:userid/:contestid" => admin_participation::<C>,
admin_participation_post: post "/admin/user/:userid/:contestid" => admin_participation::<C>,
oauth: get "/oauth/:oauthid" => oauth::<C>,
check_cookie: get "/cookie" => cookie_warning,
dbstatus: get "/dbstatus" => dbstatus::<C>,
......
......@@ -32,9 +32,15 @@ Nachname: {{lastname}}<br>
{{/if}}
{{#if group_id }}
<h3>Mitglied von</h3>
<h3>Mitglied von</h3>
<ul>
<li><a href="/admin/group/{{group_id}}">{{group_id}}: {{group_name}}</a></li>
</ul>
{{/if}}
<h2>Teilnahmen</h2>
<ul>
{{#each participations}}
<li><a href="/admin/user/{{ ../userid }}/{{ this.0 }}">{{this.0}}: {{this.1}}</a></li>
{{/each}}
</ul>
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