Added under() behavior for admin users
This commit is contained in:
parent
0fbe7dc184
commit
86a7d92156
|
@ -32,7 +32,6 @@ Run the tests locally (against development environment):
|
|||
|
||||
## TODOs
|
||||
|
||||
1. Need to actually protect the admin paths with `under()`
|
||||
1. Action for resetting passwords
|
||||
1. Action for locking/unlocking accounts
|
||||
1. CSS
|
||||
|
|
|
@ -160,10 +160,6 @@ sub startup($self) {
|
|||
->to('moderator#hidden')
|
||||
->name('hidden_list');
|
||||
|
||||
$moderator->any([qw{GET POST}], '/create')
|
||||
->to('moderator#create')
|
||||
->name('create_mod');
|
||||
|
||||
my $mod_thread = $moderator->under('/thread');
|
||||
|
||||
$mod_thread->get('/unflag/:thread_id', [thread_id => qr/\d+/])
|
||||
|
@ -192,6 +188,16 @@ sub startup($self) {
|
|||
->to('moderator#unhide_remark')
|
||||
->name('unhide_remark');
|
||||
|
||||
my $mod_admin = $moderator->under('/admin', sub ($c) {
|
||||
return 1 if $c->is_admin;
|
||||
|
||||
# Return undef otherwise a body is rendered with the redirect...
|
||||
return $c->redirect_to('mod_login'), undef;
|
||||
});
|
||||
|
||||
$mod_admin->any([qw{GET POST}], '/create')
|
||||
->to('moderator#create')
|
||||
->name('create_mod');
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
@ -80,30 +80,30 @@ subtest Login => sub {
|
|||
$t->get_ok('/moderator/flagged')
|
||||
->status_is(200)
|
||||
->text_like(h2 => qr/Flagged Posts/)
|
||||
->element_exists('a[href*="/moderator/flagged"]')
|
||||
->element_exists('a[href*="/moderator/flagged"]' )
|
||||
->element_exists('a[href*="/moderator/hidden"]' )
|
||||
->element_exists('a[href*="/logout"]' )
|
||||
->element_exists('a[href*="/moderator/create"]' )
|
||||
->element_exists('a[href*="/moderator/admin/create"]' )
|
||||
};
|
||||
|
||||
subtest Hidden => sub {
|
||||
$t->get_ok('/moderator/hidden')
|
||||
->status_is(200)
|
||||
->text_like(h2 => qr/Hidden Posts/)
|
||||
->element_exists('a[href*="/moderator/flagged"]')
|
||||
->element_exists('a[href*="/moderator/flagged"]' )
|
||||
->element_exists('a[href*="/moderator/hidden"]' )
|
||||
->element_exists('a[href*="/logout"]' )
|
||||
->element_exists('a[href*="/moderator/create"]' )
|
||||
->element_exists('a[href*="/moderator/admin/create"]' )
|
||||
};
|
||||
|
||||
subtest Create => sub {
|
||||
$t->get_ok('/moderator/create')
|
||||
$t->get_ok('/moderator/admin/create')
|
||||
->status_is(200)
|
||||
->text_like(h2 => qr/Create Moderator/)
|
||||
->element_exists('a[href*="/moderator/flagged"]')
|
||||
->element_exists('a[href*="/moderator/flagged"]' )
|
||||
->element_exists('a[href*="/moderator/hidden"]' )
|
||||
->element_exists('a[href*="/logout"]' )
|
||||
->element_exists('a[href*="/moderator/create"]' )
|
||||
->element_exists('a[href*="/moderator/admin/create"]' )
|
||||
};
|
||||
|
||||
# Mod session ends
|
||||
|
@ -138,7 +138,7 @@ subtest Login => sub {
|
|||
->status_is(302)
|
||||
->header_like(Location => qr/login/);
|
||||
|
||||
$t->get_ok('/moderator/create')
|
||||
$t->get_ok('/moderator/admin/create')
|
||||
->status_is(302)
|
||||
->header_like(Location => qr/login/);
|
||||
};
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
<% } =%>
|
||||
</div>
|
||||
<div>
|
||||
<% if (is_mod && is_admin) { =%>
|
||||
<% if (is_admin) { =%>
|
||||
<span>Admin:</span>
|
||||
<%= link_to Create => 'create_mod' %>
|
||||
<% } =%>
|
||||
|
|
Loading…
Reference in a new issue