Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
bwinf
medal
Commits
5e8a02e2
Commit
5e8a02e2
authored
Jun 22, 2020
by
Robert Czechowski
Browse files
Admin page: Show participations on user page
parent
3da8ac81
Changes
7
Hide whitespace changes
Inline
Side-by-side
src/core.rs
View file @
5e8a02e2
...
...
@@ -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
{
...
...
src/db_conn.base.rs
View file @
5e8a02e2
...
...
@@ -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
...
...
src/db_conn.rs
View file @
5e8a02e2
...
...
@@ -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
);
...
...
src/db_conn_postgres.rs
View file @
5e8a02e2
...
...
@@ -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
...
...
src/db_conn_sqlite_new.rs
View file @
5e8a02e2
...
...
@@ -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
...
...
src/webfw_iron.rs
View file @
5e8a02e2
...
...
@@ -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/:participation
id"
=>
admin_participation
::
<
C
>
,
admin_participation_post
:
post
"/admin/
participation/:participation
id"
=>
admin_participation
::
<
C
>
,
admin_participation
:
get
"/admin/
user/:userid/:contest
id"
=>
admin_participation
::
<
C
>
,
admin_participation_post
:
post
"/admin/
user/:userid/:contest
id"
=>
admin_participation
::
<
C
>
,
oauth
:
get
"/oauth/:oauthid"
=>
oauth
::
<
C
>
,
check_cookie
:
get
"/cookie"
=>
cookie_warning
,
dbstatus
:
get
"/dbstatus"
=>
dbstatus
::
<
C
>
,
...
...
templates/default/admin_user.hbs
View file @
5e8a02e2
...
...
@@ -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>
Robert Czechowski
@zgtm
mentioned in issue
#85 (closed)
·
Jun 22, 2020
mentioned in issue
#85 (closed)
mentioned in issue #85
Toggle commit list
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment