Added under() behavior for admin users

This commit is contained in:
swag 2023-04-21 17:32:16 -04:00
parent 0fbe7dc184
commit 86a7d92156
4 changed files with 25 additions and 20 deletions

View File

@ -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

View File

@ -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;

View File

@ -83,7 +83,7 @@ subtest Login => sub {
->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 {
@ -93,17 +93,17 @@ subtest Login => sub {
->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/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/);
};

View File

@ -23,7 +23,7 @@
<% } =%>
</div>
<div>
<% if (is_mod && is_admin) { =%>
<% if (is_admin) { =%>
<span>Admin:</span>
<%= link_to Create => 'create_mod' %>
<% } =%>