diff --git a/lib/PostText.pm b/lib/PostText.pm index 74ec558..141982f 100644 --- a/lib/PostText.pm +++ b/lib/PostText.pm @@ -71,6 +71,11 @@ sub startup($self) { $self->remark->per_page($remarks_per_page) } + if (my $date_format = $self->config->{'date_format'}) { + $self->thread->date_format($date_format); + $self->remark->date_format($date_format); + } + $self->asset->process('main.css', 'css/PostText.css'); push @{$self->commands->namespaces}, 'PostText::Command'; @@ -160,6 +165,20 @@ sub startup($self) { $mod_thread->get('/unhide/:thread_id', [thread_id => qr/\d+/]) ->to('moderator#unhide_thread') ->name('unhide_thread'); + + my $mod_remark = $moderator->under('/remark'); + + $mod_remark->get('/unflag/:remark_id', [remark_id => qr/\d+/]) + ->to('moderator#unflag_remark') + ->name('unflag_remark'); + + $mod_remark->get('/hide/:remark_id', [remark_id => qr/\d+/]) + ->to('moderator#hide_remark') + ->name('hide_remark'); + + $mod_remark->get('/unhide/:remark_id', [remark_id => qr/\d+/]) + ->to('moderator#unhide_remark') + ->name('unhide_remark'); } 1; diff --git a/lib/PostText/Controller/Moderator.pm b/lib/PostText/Controller/Moderator.pm index 809f4fa..d4be1fd 100644 --- a/lib/PostText/Controller/Moderator.pm +++ b/lib/PostText/Controller/Moderator.pm @@ -88,4 +88,39 @@ sub unhide_thread($self) { $self->redirect_to($redirect_url); } +sub unflag_remark($self) { + my $remark_id = $self->param('remark_id'); + my $thread_id = $self->remark->thread_id_for($remark_id); + my $redirect_url = $self->url_for(single_thread => thread_id => $thread_id) + ->fragment('info')->to_abs; + + $self->moderator->unflag_remark($remark_id); + $self->flash(info => "Remark #$remark_id has been unflagged. ◀️"); + + $self->redirect_to($redirect_url); +} + +sub hide_remark($self) { + my $remark_id = $self->param('remark_id'); + my $redirect_url = $self->url_for(single_remark => remark_id => $remark_id) + ->fragment('info')->to_abs; + + $self->moderator->hide_remark($remark_id); + $self->flash(info => "Remark #$remark_id has been hidden. 🫥"); + + $self->redirect_to($redirect_url); +} + +sub unhide_remark($self) { + my $remark_id = $self->param('remark_id'); + my $thread_id = $self->remark->thread_id_for($remark_id); + my $redirect_url = $self->url_for(single_thread => thread_id => $thread_id) + ->fragment('info')->to_abs; + + $self->moderator->unhide_remark($remark_id); + $self->flash(info => "Remark #$remark_id has been unhidden. ⏪"); + + $self->redirect_to($redirect_url); +} + 1; diff --git a/lib/PostText/Model/Moderator.pm b/lib/PostText/Model/Moderator.pm index eaa6628..bdbe5c0 100644 --- a/lib/PostText/Model/Moderator.pm +++ b/lib/PostText/Model/Moderator.pm @@ -60,4 +60,29 @@ sub unhide_thread($self, $thread_id) { END_SQL } +sub unflag_remark($self, $remark_id) { + $self->pg->db->query(<<~'END_SQL', $remark_id) + UPDATE remarks + SET flagged_status = FALSE + WHERE remark_id = ?; + END_SQL +} + +sub hide_remark($self, $remark_id) { + $self->pg->db->query(<<~'END_SQL', $remark_id) + UPDATE remarks + SET hidden_status = TRUE, + flagged_status = FALSE + WHERE remark_id = ?; + END_SQL +} + +sub unhide_remark($self, $remark_id) { + $self->pg->db->query(<<~'END_SQL', $remark_id) + UPDATE remarks + SET hidden_status = FALSE + WHERE remark_id = ?; + END_SQL +} + 1; diff --git a/lib/PostText/Model/Remark.pm b/lib/PostText/Model/Remark.pm index 0f3d095..4018db5 100644 --- a/lib/PostText/Model/Remark.pm +++ b/lib/PostText/Model/Remark.pm @@ -6,8 +6,10 @@ has 'pg'; has per_page => 5; +has date_format => 'Dy Mon FMDD HH24:MI TZ YYYY'; + sub by_page_for($self, $thread_id, $this_page = 1) { - my $date_format = $self->{'date_format'}; + my $date_format = $self->date_format; my $row_count = $self->per_page; my $offset = ($this_page - 1) * $row_count; my @data = ($date_format, $thread_id, $row_count, $offset); @@ -60,7 +62,7 @@ sub last_page_for($self, $thread_id) { } sub last_for($self, $thread_id) { - my $date_format = $self->{'date_format'}; + my $date_format = $self->date_format; $self->pg->db->query(<<~'END_SQL', $date_format, $thread_id)->hash; SELECT remark_id AS id, @@ -75,7 +77,7 @@ sub last_for($self, $thread_id) { } sub by_id($self, $remark_id) { - my $date_format = $self->{'date_format'}; + my $date_format = $self->date_format; $self->pg->db->query(<<~'END_SQL', $date_format, $remark_id)->hash; SELECT remark_id AS id, diff --git a/lib/PostText/Model/Thread.pm b/lib/PostText/Model/Thread.pm index d8b6598..48bee97 100644 --- a/lib/PostText/Model/Thread.pm +++ b/lib/PostText/Model/Thread.pm @@ -6,6 +6,8 @@ has 'pg'; has per_page => 5; +has date_format => 'Dy Mon FMDD HH24:MI TZ YYYY'; + sub create($self, $author, $title, $body, $hidden = 0, $flagged = 0) { my @data = ($author, $title, $body, $hidden, $flagged); @@ -23,7 +25,7 @@ sub create($self, $author, $title, $body, $hidden = 0, $flagged = 0) { } sub by_page($self, $this_page = 1) { - my $date_format = $self->{'date_format'}; + my $date_format = $self->date_format; my $row_count = $self->per_page; my $offset = ($this_page - 1) * $row_count; @@ -65,7 +67,7 @@ sub count($self) { } sub by_id($self, $thread_id) { - my $date_format = $self->{'date_format'}; + my $date_format = $self->date_format; $self->pg->db->query(<<~'END_SQL', $date_format, $thread_id)->hash; SELECT thread_id AS id, diff --git a/t/moderator.t b/t/moderator.t index 9abea0d..b2b54b7 100644 --- a/t/moderator.t +++ b/t/moderator.t @@ -45,9 +45,9 @@ subtest Login => sub { ->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}); + $t->get_ok('/moderator/remark/unflag/1') + ->status_is(302) + ->header_like(Location => qr{thread/single}); }; subtest Hide => sub { @@ -58,12 +58,12 @@ subtest Login => sub { ->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}); + $t->get_ok('/moderator/remark/hide/1') + ->status_is(302) + ->header_like(Location => qr{remark/single}); + $t->get_ok('/moderator/remark/unhide/1') + ->status_is(302) + ->header_like(Location => qr{thread/single}); }; subtest 'Buttons for mods', sub { @@ -83,6 +83,20 @@ subtest Login => sub { $t->get_ok('/logout') ->status_is(302) ->header_like(Location => qr{thread/list}); + + subtest 'No mod, no buttons', sub { + $t->get_ok('/thread/single/1') + ->status_is(200) + ->element_exists_not('a[href*="/hide/1"]' ) + ->element_exists_not('a[href*="/unhide/1"]') + ->element_exists_not('a[href*="/unflag/1"]'); + + $t->get_ok('/remark/single/1') + ->status_is(200) + ->element_exists_not('a[href*="/hide/1"]' ) + ->element_exists_not('a[href*="/unhide/1"]') + ->element_exists_not('a[href*="/unflag/1"]'); + }; }; done_testing(); diff --git a/templates/layouts/default.html.ep b/templates/layouts/default.html.ep index 5a0eeab..2cd8787 100644 --- a/templates/layouts/default.html.ep +++ b/templates/layouts/default.html.ep @@ -9,14 +9,14 @@ -<% if (is_mod) { =%> - <% } =%> +
<%= flash 'error' %>