diff --git a/README.md b/README.md index ef6e285..a3ef958 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,6 @@ tests locally: 1. Test JS with LibreJS or something like that (I don't like RMS I just want free JS!!) -1. Tests for mod-only user? ## Crazy future ideas @@ -71,6 +70,7 @@ tests locally: 1. Is `remark_tally` counting hidden remarks? Tried to add a `WHERE NOT hidden_status` but that returns null, probably need a different `JOIN` which may not be worth the trouble/processing +1. Nah it needs a subquery instead of just `COUNT(*)` (dude trust me) 1. Implement tripcodes (moving this down in priority due to complexity...) 1. Post thread via SMS (twil.io??) diff --git a/lib/PostText.pm b/lib/PostText.pm index 0ef3393..d7d5ed0 100644 --- a/lib/PostText.pm +++ b/lib/PostText.pm @@ -231,6 +231,10 @@ sub startup($self) { ->to('moderator#mod_reset') ->name('mod_reset'); + $moderator->get('/list') + ->to('moderator#list') + ->name('mod_list'); + my $mod_thread = $moderator->any('/thread'); $mod_thread->get('/unflag/:thread_id', [thread_id => qr/\d+/]) diff --git a/lib/PostText/Controller/Moderator.pm b/lib/PostText/Controller/Moderator.pm index 93e9f64..c5917d4 100644 --- a/lib/PostText/Controller/Moderator.pm +++ b/lib/PostText/Controller/Moderator.pm @@ -344,4 +344,12 @@ sub remark_by_id($self) { $self->render; } +sub list($self) { + my $moderators = $self->moderator->list; + + $self->stash(moderators => $moderators); + + $self->render; +} + 1; diff --git a/lib/PostText/Model/Moderator.pm b/lib/PostText/Model/Moderator.pm index ace354e..3e49d45 100644 --- a/lib/PostText/Model/Moderator.pm +++ b/lib/PostText/Model/Moderator.pm @@ -259,4 +259,19 @@ sub remark_by_id($self, $remark_id) { END_SQL } +sub list($self) { + my $date_format = $self->date_format; + + $self->pg->db->query(<<~'END_SQL', $date_format)->hashes; + SELECT moderator_id AS id, + moderator_name AS name, + email_addr, + TO_CHAR(creation_date, $1) AS creation_date, + TO_CHAR(last_login_date, $1) AS last_login_date, + lock_status, + admin_status + FROM moderators; + END_SQL +} + 1; diff --git a/t/moderator.t b/t/moderator.t index c9d7b24..9b79b2c 100644 --- a/t/moderator.t +++ b/t/moderator.t @@ -5,8 +5,8 @@ use Test::Mojo; my $t = Test::Mojo->new('PostText'); my %valid_login = ( - email => 'swaggboi@slackware.uk', - password => 'i like to party' + email => 'swaggboi@gangstalking.agency', + password => 'i also like to party' ); my %invalid_login = ( @@ -114,6 +114,12 @@ subtest Login => sub { ->element_exists('form input[name="password"]') }; + subtest List => sub { + $t->get_ok('/moderator/list') + ->status_is(200) + ->text_like(h2 => qr/Moderator List/) + }; + # Mod session ends $t->get_ok('/logout') ->status_is(302) @@ -127,6 +133,7 @@ subtest Login => sub { ->element_exists_not('a[href*="/unflag/1"]' ) ->element_exists_not('a[href*="/moderator/flagged"]') ->element_exists_not('a[href*="/moderator/hidden"]' ) + ->element_exists_not('a[href*="/moderator/list"]' ) ->element_exists_not('a[href*="/logout"]' ); $t->get_ok('/remark/single/1') @@ -136,6 +143,7 @@ subtest Login => sub { ->element_exists_not('a[href*="/unflag/1"]' ) ->element_exists_not('a[href*="/moderator/flagged"]') ->element_exists_not('a[href*="/moderator/hidden"]' ) + ->element_exists_not('a[href*="/moderator/list"]' ) ->element_exists_not('a[href*="/logout"]' ); $t->get_ok('/moderator/flagged') @@ -145,6 +153,10 @@ subtest Login => sub { $t->get_ok('/moderator/hidden') ->status_is(302) ->header_like(Location => qr/login/); + + $t->get_ok('/moderator/list') + ->status_is(302) + ->header_like(Location => qr/login/); }; }; diff --git a/templates/layouts/default.html.ep b/templates/layouts/default.html.ep index 99cb6f8..86617de 100644 --- a/templates/layouts/default.html.ep +++ b/templates/layouts/default.html.ep @@ -51,6 +51,7 @@ <%= link_to Flagged => flagged_list => (class => 'click') %> <%= link_to Hidden => hidden_list => (class => 'click') %> <%= link_to Reset => mod_reset => (class => 'click') %> + <%= link_to List => mod_list => (class => 'click') %> <%= link_to Logout => mod_logout => (class => 'click') %> <% } =%> diff --git a/templates/moderator/list.html.ep b/templates/moderator/list.html.ep new file mode 100644 index 0000000..26c7d8f --- /dev/null +++ b/templates/moderator/list.html.ep @@ -0,0 +1,29 @@ +% layout 'default'; +% title 'Moderator List'; +

<%= title %>

+
+ <% if (scalar @{$moderators}) { =%> + + + + + + + + + + + <% for my $moderator (@{$moderators}) { %> + + + + + + + + + + <% } %> +
Moderator IDModerator NameEmail AddressCreation DateLast Login DateLocked?Admin?
<%= $moderator->{'id' } %><%= $moderator->{'name' } %><%= $moderator->{'email_addr' } %><%= $moderator->{'creation_date' } %><%= $moderator->{'last_login_date'} %><%= $moderator->{'lock_status' } %><%= $moderator->{'admin_status' } %>
+ <% } =%> +