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
8a358ae0
Commit
8a358ae0
authored
May 14, 2020
by
Robert Czechowski
Browse files
Merge branch 'teacher-page'
parents
ebb91bf0
72dbee11
Pipeline
#638
passed with stages
in 26 minutes and 29 seconds
Changes
7
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/config.rs
View file @
8a358ae0
...
...
@@ -18,6 +18,7 @@ pub struct Config {
pub
cookie_signing_secret
:
Option
<
String
>
,
pub
disable_results_page
:
Option
<
bool
>
,
pub
server_message
:
Option
<
String
>
,
pub
teacher_page
:
Option
<
String
>
,
}
#[derive(StructOpt,
Debug)]
...
...
@@ -58,6 +59,10 @@ pub struct Opt {
/// Disable results page to reduce load on the server
#[structopt(long
=
"disable-results-page"
)]
pub
disableresultspage
:
bool
,
/// Teacher page in task directory
#[structopt(short
=
"t"
,
long
=
"teacherpage"
)]
pub
teacherpage
:
Option
<
String
>
,
}
pub
fn
read_config_from_file
(
file
:
&
Path
)
->
Config
{
...
...
src/core.rs
View file @
8a358ae0
...
...
@@ -1030,6 +1030,22 @@ pub fn edit_profile<T: MedalConnection>(conn: &T, session_token: &str, user_id:
Ok
(
result
)
}
pub
fn
teacher_infos
<
T
:
MedalConnection
>
(
conn
:
&
T
,
session_token
:
&
str
,
teacher_page
:
Option
<&
str
>
)
->
MedalValueResult
{
let
session
=
conn
.get_session
(
&
session_token
)
.ensure_logged_in
()
.ok_or
(
MedalError
::
NotLoggedIn
)
?
;
if
!
session
.is_teacher
{
return
Err
(
MedalError
::
AccessDenied
);
}
let
mut
data
=
json_val
::
Map
::
new
();
fill_user_data
(
&
session
,
&
mut
data
);
if
let
Some
(
teacher_page
)
=
teacher_page
{
data
.insert
(
"teacher_page"
.to_string
(),
to_json
(
&
teacher_page
));
}
Ok
((
"teacher"
.to_string
(),
data
))
}
pub
fn
admin_index
<
T
:
MedalConnection
>
(
conn
:
&
T
,
session_token
:
&
str
)
->
MedalValueResult
{
let
session
=
conn
.get_session
(
&
session_token
)
.ensure_logged_in
()
.ok_or
(
MedalError
::
NotLoggedIn
)
?
;
if
session
.id
!=
1
{
...
...
src/main.rs
View file @
8a358ae0
...
...
@@ -202,6 +202,7 @@ fn main() {
// Let options override config values
opt
.databasefile
.map
(|
x
|
config
.database_file
=
Some
(
x
));
opt
.databaseurl
.map
(|
x
|
config
.database_url
=
Some
(
x
));
opt
.teacherpage
.map
(|
x
|
config
.teacher_page
=
Some
(
x
));
opt
.port
.map
(|
x
|
config
.port
=
Some
(
x
));
config
.no_contest_scan
=
if
opt
.nocontestscan
{
Some
(
true
)
}
else
{
config
.no_contest_scan
};
config
.open_browser
=
if
opt
.openbrowser
{
Some
(
true
)
}
else
{
config
.open_browser
};
...
...
src/webfw_iron.rs
View file @
8a358ae0
...
...
@@ -871,6 +871,20 @@ fn user_post<C>(req: &mut Request) -> IronResult<Response>
//old: Ok(Response::with((status::Found, Redirect(url_for!(req, "user", "userid" => format!("{}",user_id))))))
}
fn
teacherinfos
<
C
>
(
req
:
&
mut
Request
)
->
IronResult
<
Response
>
where
C
:
MedalConnection
+
std
::
marker
::
Send
+
'static
{
let
session_token
=
req
.expect_session_token
()
?
;
let
config
=
req
.get
::
<
Read
<
SharedConfiguration
>>
()
.unwrap
();
let
(
template
,
data
)
=
with_conn!
[
core
::
teacher_infos
,
C
,
req
,
&
session_token
,
config
.teacher_page
.as_ref
()
.map
(|
x
|
&**
x
)]
.aug
(
req
)
?
;
// .as_ref().map(|x| &**x) can be written as .as_deref() since rust 1.40
let
mut
resp
=
Response
::
new
();
resp
.set_mut
(
Template
::
new
(
&
template
,
data
))
.set_mut
(
status
::
Ok
);
Ok
(
resp
)
}
fn
admin
<
C
>
(
req
:
&
mut
Request
)
->
IronResult
<
Response
>
where
C
:
MedalConnection
+
std
::
marker
::
Send
+
'static
{
let
session_token
=
req
.expect_session_token
()
?
;
...
...
@@ -1200,6 +1214,7 @@ pub fn start_server<C>(conn: C, config: Config) -> iron::error::HttpResult<iron:
user
:
get
"/user/:userid"
=>
user
::
<
C
>
,
user_post
:
post
"/user/:userid"
=>
user_post
::
<
C
>
,
task
:
get
"/task/:taskid"
=>
task
::
<
C
>
,
teacher
:
get
"/teacher"
=>
teacherinfos
::
<
C
>
,
admin
:
get
"/admin"
=>
admin
::
<
C
>
,
admin_users
:
post
"/admin/user/"
=>
admin_users
::
<
C
>
,
admin_user
:
get
"/admin/user/:userid"
=>
admin_user
::
<
C
>
,
...
...
templates/default/teacher.hbs
0 → 100644
View file @
8a358ae0
<iframe
src=
"/tasks/teacher/index.html"
></iframe>
templates/jwinf/base.hbs
View file @
8a358ae0
...
...
@@ -34,7 +34,7 @@
{{#if
logged_in
}}
{{#if
firstlogin
}}{{else}}
<div
class=
"columns alogin"
>
<div
class=
"columns alogin"
style=
"margin-bottom: 0px;"
>
<div
class=
"column is-three-fifths"
>
Eingeloggt als
<em>
{{
username
}}
</em>
{{#if
firstname
}}{{#if
lastname
}}
...
...
@@ -42,17 +42,18 @@
{{/if}}{{/if}}
{{#if
teacher
}}
[Lehrer]
{{/if}}
<br>
{{/if}}
</div>
<div
class=
"column"
><a
href=
"/logout"
class=
"button is-small is-danger"
type=
"submit"
>
⨯
Logout
</a></div>
</div>
<div
class=
"columns alogin"
>
<div
class=
"column"
>
<a
href=
"/profile"
class=
"button is-info is-small"
>
👤
Profil
</a>
{{#if
teacher
}}
<a
href=
"/group/"
class=
"button is-warning is-small"
>
⚙
Gruppenverwaltung
</a>
<a
href=
"/teacher"
class=
"button is-primary is-small"
>
👨🏫
Lehrer-Informationen
</a>
{{/if}}
</div>
<div
class=
"column"
><a
href=
"/logout"
class=
"button is-small is-danger"
type=
"submit"
>
⨯
Logout
</a></div>
</div>
<div
class=
"columns alogin"
>
<div
class=
"column"
></div>
</div>
{{/if}}
{{else}}
...
...
templates/jwinf/teacher.hbs
0 → 100644
View file @
8a358ae0
{{#
*
inline
"page"
}}
<div
class=
"columns"
>
<div
class=
"column is-8 is-offset-2"
>
<h3
class=
"title is-4"
>
Lehrer-Informationen
</h3>
{{#if
teacher_page
}}
<iframe
src=
"/tasks/
{{
teacher_page
}}
"
style=
"height: calc(100vh - 550px); min-height:200px;"
></iframe>
{{else}}
<em>
Noch keine Informationen vorhanden
</em>
{{/if}}
</div>
</div>
{{/
inline
}}
{{~>
(
parent
)
~}}
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