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
ce621a4f
Commit
ce621a4f
authored
May 14, 2020
by
Robert Czechowski
Browse files
Add helper functions ensure_teacher() and ensure_admin() for sessions
parent
a56c1184
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/db_objects.rs
View file @
ce621a4f
...
@@ -285,6 +285,22 @@ impl SessionUser {
...
@@ -285,6 +285,22 @@ impl SessionUser {
None
None
}
}
}
}
pub
fn
ensure_teacher
(
self
)
->
Option
<
Self
>
{
if
self
.is_logged_in
()
&&
self
.is_teacher
()
{
Some
(
self
)
}
else
{
None
}
}
pub
fn
ensure_admin
(
self
)
->
Option
<
Self
>
{
if
self
.is_logged_in
()
&&
self
.is_admin
()
{
Some
(
self
)
}
else
{
None
}
}
}
}
impl
Taskgroup
{
impl
Taskgroup
{
...
@@ -307,9 +323,13 @@ impl Task {
...
@@ -307,9 +323,13 @@ impl Task {
pub
trait
OptionSession
{
pub
trait
OptionSession
{
fn
ensure_alive
(
self
)
->
Self
;
fn
ensure_alive
(
self
)
->
Self
;
fn
ensure_logged_in
(
self
)
->
Self
;
fn
ensure_logged_in
(
self
)
->
Self
;
fn
ensure_teacher
(
self
)
->
Self
;
fn
ensure_admin
(
self
)
->
Self
;
}
}
impl
OptionSession
for
Option
<
SessionUser
>
{
impl
OptionSession
for
Option
<
SessionUser
>
{
fn
ensure_alive
(
self
)
->
Self
{
self
?
.ensure_alive
()
}
fn
ensure_alive
(
self
)
->
Self
{
self
?
.ensure_alive
()
}
fn
ensure_logged_in
(
self
)
->
Self
{
self
?
.ensure_logged_in
()
}
fn
ensure_logged_in
(
self
)
->
Self
{
self
?
.ensure_logged_in
()
}
fn
ensure_teacher
(
self
)
->
Self
{
self
?
.ensure_teacher
()
}
fn
ensure_admin
(
self
)
->
Self
{
self
?
.ensure_admin
()
}
}
}
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