diff --git a/README.md b/README.md index 41a4339..bb65cdd 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/lib/PostText.pm b/lib/PostText.pm index 5f75bc9..74ec558 100644 --- a/lib/PostText.pm +++ b/lib/PostText.pm @@ -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'); } diff --git a/lib/PostText/Controller/Moderator.pm b/lib/PostText/Controller/Moderator.pm index 7977cea..809f4fa 100644 --- a/lib/PostText/Controller/Moderator.pm +++ b/lib/PostText/Controller/Moderator.pm @@ -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); diff --git a/lib/PostText/Model/Moderator.pm b/lib/PostText/Model/Moderator.pm index a221a29..eaa6628 100644 --- a/lib/PostText/Model/Moderator.pm +++ b/lib/PostText/Model/Moderator.pm @@ -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 diff --git a/t/moderator.t b/t/moderator.t index 532c9f0..9abea0d 100644 --- a/t/moderator.t +++ b/t/moderator.t @@ -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') diff --git a/templates/thread/by_id.html.ep b/templates/thread/by_id.html.ep index 2b834b6..1775f54 100644 --- a/templates/thread/by_id.html.ep +++ b/templates/thread/by_id.html.ep @@ -14,6 +14,13 @@ <%= link_to Bump => bump_thread => {thread_id => $thread->{'id'}} %> <%= link_to Flag => flag_thread => {thread_id => $thread->{'id'}} %> +<% if (is_mod) { =%> + +<% } =%> <% if (my $first_remark = $remarks->[0]) { =%>

Remarks