Added buttons for the mod stuff; had to restructure things to make room for mod remark stuff

This commit is contained in:
swagg boi 2022-12-08 00:13:59 -06:00
parent 088daa120d
commit d01acbcde2
6 changed files with 54 additions and 22 deletions

View file

@ -32,8 +32,7 @@ Run the tests locally (against development environment):
## TODOs
1. Add buttons in single thread and single remark views for mods to
hide flagged posts; something like
1. Something like
[this](https://paste.lgts.xyz/?575618a432427bd1#DogvKr3pq6LUdezx5MrzccaANybAr6TjUV31iShdxfjB)
for the flagged list which will link to the single remark|thread
views

View file

@ -147,16 +147,18 @@ sub startup($self) {
->to('moderator#flagged')
->name('flagged_list');
$moderator->get('/unflag/:thread_id', [thread_id => qr/\d+/])
->to('moderator#unflag')
my $mod_thread = $moderator->under('/thread');
$mod_thread->get('/unflag/:thread_id', [thread_id => qr/\d+/])
->to('moderator#unflag_thread')
->name('unflag_thread');
$moderator->get('/hide/:thread_id', [thread_id => qr/\d+/])
->to('moderator#hide')
$mod_thread->get('/hide/:thread_id', [thread_id => qr/\d+/])
->to('moderator#hide_thread')
->name('hide_thread');
$moderator->get('/unhide/:thread_id', [thread_id => qr/\d+/])
->to('moderator#unhide')
$mod_thread->get('/unhide/:thread_id', [thread_id => qr/\d+/])
->to('moderator#unhide_thread')
->name('unhide_thread');
}

View file

@ -57,32 +57,32 @@ sub logout($self) {
$self->redirect_to('threads_list');
}
sub unflag($self) {
sub unflag_thread($self) {
my $thread_id = $self->param('thread_id');
my $redirect_url = $self->url_for('threads_list')->fragment('info')->to_abs;
$self->moderator->unflag($thread_id);
$self->moderator->unflag_thread($thread_id);
$self->flash(info => "Thread #$thread_id has been unflagged. ◀️");
$self->redirect_to($redirect_url);
}
sub hide($self) {
sub hide_thread($self) {
my $thread_id = $self->param('thread_id');
my $redirect_url = $self->url_for(single_thread => thread_id => $thread_id)
->fragment('info')->to_abs;
$self->moderator->hide($thread_id);
$self->moderator->hide_thread($thread_id);
$self->flash(info => "Thread #$thread_id has been hidden. 🫥");
$self->redirect_to($redirect_url);
}
sub unhide($self) {
sub unhide_thread($self) {
my $thread_id = $self->param('thread_id');
my $redirect_url = $self->url_for('threads_list')->fragment('info')->to_abs;
$self->moderator->unhide($thread_id);
$self->moderator->unhide_thread($thread_id);
$self->flash(info => "Thread #$thread_id has been unhidden. ⏪");
$self->redirect_to($redirect_url);

View file

@ -35,7 +35,7 @@ sub get_name($self, $mod_id) {
END_SQL
}
sub unflag($self, $thread_id) {
sub unflag_thread($self, $thread_id) {
$self->pg->db->query(<<~'END_SQL', $thread_id)
UPDATE threads
SET flagged_status = FALSE
@ -43,7 +43,7 @@ sub unflag($self, $thread_id) {
END_SQL
}
sub hide($self, $thread_id) {
sub hide_thread($self, $thread_id) {
$self->pg->db->query(<<~'END_SQL', $thread_id)
UPDATE threads
SET hidden_status = TRUE,
@ -52,7 +52,7 @@ sub hide($self, $thread_id) {
END_SQL
}
sub unhide($self, $thread_id) {
sub unhide_thread($self, $thread_id) {
$self->pg->db->query(<<~'END_SQL', $thread_id)
UPDATE threads
SET hidden_status = FALSE

View file

@ -41,19 +41,43 @@ subtest Login => sub {
# Do these subs while logged in
subtest Flag => sub {
$t->get_ok('/moderator/unflag/1')
$t->get_ok('/moderator/thread/unflag/1')
->status_is(302)
->header_like(Location => qr{thread/list});
#$t->get_ok('/moderator/remark/unflag/1')
# ->status_is(302)
# ->header_like(Location => qr{thread/single});
};
subtest Hide => sub {
$t->get_ok('/moderator/hide/1')
$t->get_ok('/moderator/thread/hide/1')
->status_is(302)
->header_like(Location => qr{thread/single/1});
$t->get_ok('/moderator/unhide/1')
->header_like(Location => qr{thread/single});
$t->get_ok('/moderator/thread/unhide/1')
->status_is(302)
->header_like(Location => qr{thread/list});
#$t->get_ok('/moderator/remark/hide/1')
# ->status_is(302)
# ->header_like(Location => qr{thread/single});
#$t->get_ok('/moderator/remark/unhide/1')
# ->status_is(302)
# ->header_like(Location => qr{thread/single});
};
subtest 'Buttons for mods', sub {
$t->get_ok('/thread/single/1')
->status_is(200)
->element_exists('a[href*="/hide/1"]' )
->element_exists('a[href*="/unhide/1"]')
->element_exists('a[href*="/unflag/1"]');
#$t->get_ok('/remark/single/1')
# ->status_is(200)
# ->element_exists('a[href*="/hide/1"]' )
# ->element_exists('a[href*="/unhide/1"]')
# ->element_exists('a[href*="/unflag/1"]');
};
$t->get_ok('/logout')

View file

@ -14,6 +14,13 @@
<%= link_to Bump => bump_thread => {thread_id => $thread->{'id'}} %>
<%= link_to Flag => flag_thread => {thread_id => $thread->{'id'}} %>
</nav>
<% if (is_mod) { =%>
<nav>
<%= link_to Hide => hide_thread => {thread_id => $thread->{'id'}} %>
<%= link_to Unhide => unhide_thread => {thread_id => $thread->{'id'}} %>
<%= link_to Unflag => unflag_thread => {thread_id => $thread->{'id'}} %>
</nav>
<% } =%>
<% if (my $first_remark = $remarks->[0]) { =%>
<div class="remarks" id="remarks">
<h3>Remarks</h3>