Mod only stuff finally plus a list mod view

This commit is contained in:
swagg boi 2024-06-25 19:23:34 -04:00
parent 04ff49c932
commit 43e9ccd887
7 changed files with 72 additions and 3 deletions

View file

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

View file

@ -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+/])

View file

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

View file

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

View file

@ -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/);
};
};

View file

@ -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') %>
</nav>
<% } =%>

View file

@ -0,0 +1,29 @@
% layout 'default';
% title 'Moderator List';
<h2 class="page-title"><%= title %></h2>
<main class="page-body">
<% if (scalar @{$moderators}) { =%>
<table>
<tr>
<th>Moderator ID</th>
<th>Moderator Name</th>
<th>Email Address</th>
<th>Creation Date</th>
<th>Last Login Date</th>
<th>Locked?</th>
<th>Admin?</th>
</tr>
<% for my $moderator (@{$moderators}) { %>
<tr>
<td><%= $moderator->{'id' } %></td>
<td><%= $moderator->{'name' } %></td>
<td><%= $moderator->{'email_addr' } %></td>
<td><%= $moderator->{'creation_date' } %></td>
<td><%= $moderator->{'last_login_date'} %></td>
<td><%= $moderator->{'lock_status' } %></td>
<td><%= $moderator->{'admin_status' } %></td>
</tr>
<% } %>
</table>
<% } =%>
</main>