Add routes for mods to view hidden posts
This commit is contained in:
parent
83d9034fde
commit
7357b9c791
|
@ -206,6 +206,10 @@ sub startup($self) {
|
||||||
->to('moderator#unhide_thread')
|
->to('moderator#unhide_thread')
|
||||||
->name('unhide_thread');
|
->name('unhide_thread');
|
||||||
|
|
||||||
|
$mod_thread->get('/single/:thread_id', [thread_id => qr/\d+/])
|
||||||
|
->to('moderator#thread_by_id')
|
||||||
|
->name('hidden_thread');
|
||||||
|
|
||||||
my $mod_remark = $moderator->any('/remark');
|
my $mod_remark = $moderator->any('/remark');
|
||||||
|
|
||||||
$mod_remark->get('/unflag/:remark_id', [remark_id => qr/\d+/])
|
$mod_remark->get('/unflag/:remark_id', [remark_id => qr/\d+/])
|
||||||
|
@ -220,6 +224,10 @@ sub startup($self) {
|
||||||
->to('moderator#unhide_remark')
|
->to('moderator#unhide_remark')
|
||||||
->name('unhide_remark');
|
->name('unhide_remark');
|
||||||
|
|
||||||
|
$mod_remark->get('/single/:remark_id', [remark_id => qr/\d+/])
|
||||||
|
->to('moderator#remark_by_id')
|
||||||
|
->name('hidden_remark');
|
||||||
|
|
||||||
# Admin
|
# Admin
|
||||||
my $mod_admin = $moderator->under('/admin')->to('moderator#admin_check');
|
my $mod_admin = $moderator->under('/admin')->to('moderator#admin_check');
|
||||||
|
|
||||||
|
|
|
@ -330,4 +330,28 @@ sub admin_check($self) {
|
||||||
return $self->redirect_to('mod_login'), undef;
|
return $self->redirect_to('mod_login'), undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub thread_by_id($self) {
|
||||||
|
my $thread_id = $self->param('thread_id');
|
||||||
|
my $thread = $self->thread->by_id($thread_id);
|
||||||
|
|
||||||
|
$self->stash(thread => $thread);
|
||||||
|
|
||||||
|
$self->stash(status => 404, error => 'Thread not found 🤷')
|
||||||
|
unless keys %{$thread};
|
||||||
|
|
||||||
|
$self->render;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub remark_by_id($self) {
|
||||||
|
my $remark_id = $self->param('remark_id');
|
||||||
|
my $remark = $self->remark->by_id($remark_id);
|
||||||
|
|
||||||
|
$self->stash(remark => $remark);
|
||||||
|
|
||||||
|
$self->stash(error => 'Remark not found 🤷')
|
||||||
|
unless keys %{$remark};
|
||||||
|
|
||||||
|
$self->render;
|
||||||
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
|
@ -4,6 +4,8 @@ use Mojo::Base -base, -signatures;
|
||||||
|
|
||||||
has [qw{pg authenticator}];
|
has [qw{pg authenticator}];
|
||||||
|
|
||||||
|
has date_format => 'Dy, FMDD Mon YYYY HH24:MI:SS TZHTZM';
|
||||||
|
|
||||||
sub create($self, $name, $email, $password) {
|
sub create($self, $name, $email, $password) {
|
||||||
my $password_hash = $self->authenticator->hash_password($password);
|
my $password_hash = $self->authenticator->hash_password($password);
|
||||||
|
|
||||||
|
@ -224,4 +226,37 @@ sub demote($self, $email) {
|
||||||
END_SQL
|
END_SQL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub thread_by_id($self, $thread_id) {
|
||||||
|
my $date_format = $self->date_format;
|
||||||
|
|
||||||
|
$self->pg->db->query(<<~'END_SQL', $date_format, $thread_id)->hash;
|
||||||
|
SELECT t.thread_id AS id,
|
||||||
|
TO_CHAR(t.thread_date, ?) AS date,
|
||||||
|
t.thread_author AS author,
|
||||||
|
t.thread_title AS title,
|
||||||
|
t.thread_body AS body,
|
||||||
|
COUNT(r.*) AS remark_tally,
|
||||||
|
t.bump_tally AS bump_tally
|
||||||
|
FROM threads AS t
|
||||||
|
LEFT JOIN remarks AS r
|
||||||
|
ON t.thread_id = r.thread_id
|
||||||
|
WHERE t.thread_id = ?
|
||||||
|
GROUP BY t.thread_id;
|
||||||
|
END_SQL
|
||||||
|
}
|
||||||
|
|
||||||
|
sub remark_by_id($self, $remark_id) {
|
||||||
|
my $date_format = $self->date_format;
|
||||||
|
|
||||||
|
$self->pg->db->query(<<~'END_SQL', $date_format, $remark_id)->hash;
|
||||||
|
SELECT remark_id AS id,
|
||||||
|
TO_CHAR(remark_date, ?) AS date,
|
||||||
|
remark_author AS author,
|
||||||
|
remark_body AS body,
|
||||||
|
thread_id
|
||||||
|
FROM remarks
|
||||||
|
WHERE remark_id = ?;
|
||||||
|
END_SQL
|
||||||
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
35
templates/moderator/remark_by_id.html.ep
Normal file
35
templates/moderator/remark_by_id.html.ep
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
% layout 'default';
|
||||||
|
% title my $remark_id = $remark->{'id'} ? "Remark #$remark_id" : '?';
|
||||||
|
<h2 class="page-title"><%= title %></h2>
|
||||||
|
<% if (keys %{$remark}) { =%>
|
||||||
|
<main class="pager">
|
||||||
|
<article class="post">
|
||||||
|
<h4 class="post__title">
|
||||||
|
<%= $remark->{'date'} %>
|
||||||
|
<span class="post__id">#<%= $remark->{'id'} %></span>
|
||||||
|
</h4>
|
||||||
|
<h5 class="post__author"><%= $remark->{'author'} %></h5>
|
||||||
|
<div class="post__body">
|
||||||
|
<%== markdown $remark->{'body'} =%>
|
||||||
|
</div>
|
||||||
|
<nav class="post__nav">
|
||||||
|
<%= link_to Thread => single_thread =>
|
||||||
|
{thread_id => $remark->{'thread_id'}}, (class => 'click') %>
|
||||||
|
<%= link_to Remark => post_remark =>
|
||||||
|
{thread_id => $remark->{'thread_id'}}, (class => 'click') %>
|
||||||
|
<%= link_to Flag => flag_remark => {remark_id => $remark->{'id'}},
|
||||||
|
(class => 'click') %>
|
||||||
|
</nav>
|
||||||
|
<% if (is_mod) { =%>
|
||||||
|
<nav class="post__nav">
|
||||||
|
<%= link_to Hide => hide_remark => {remark_id => $remark->{'id'}},
|
||||||
|
(class => 'click') %>
|
||||||
|
<%= link_to Unhide => unhide_remark => {remark_id => $remark->{'id'}},
|
||||||
|
(class => 'click') %>
|
||||||
|
<%= link_to Unflag => unflag_remark => {remark_id => $remark->{'id'}},
|
||||||
|
(class => 'click') %>
|
||||||
|
</nav>
|
||||||
|
<% } =%>
|
||||||
|
</article>
|
||||||
|
</main>
|
||||||
|
<% } =%>
|
40
templates/moderator/thread_by_id.html.ep
Normal file
40
templates/moderator/thread_by_id.html.ep
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
% layout 'default';
|
||||||
|
% title my $thread_id = $thread->{'id'} ? "Thread #$thread_id" : '?';
|
||||||
|
<h2 class="page-title"><%= title %></h2>
|
||||||
|
<% if (keys %{$thread}) { =%>
|
||||||
|
<main class="pager">
|
||||||
|
<article class="post">
|
||||||
|
<h3 class="post__title">
|
||||||
|
<%= $thread->{'title'} %>
|
||||||
|
<span class="post__id">#<%= $thread->{'id'} %></span>
|
||||||
|
</h3>
|
||||||
|
<h4 class="post__date"><%= $thread->{'date'} %></h4>
|
||||||
|
<h5 class="post__author"><%= $thread->{'author'} %></h5>
|
||||||
|
<div class="post__body">
|
||||||
|
<%== markdown $thread->{'body'} =%>
|
||||||
|
</div>
|
||||||
|
<nav class="post__nav">
|
||||||
|
<%= link_to post_remark => {thread_id => $thread->{'id'}},
|
||||||
|
(class => 'click'), begin %>
|
||||||
|
Remark (<%= $thread->{'remark_tally'} %>)
|
||||||
|
<% end %>
|
||||||
|
<%= link_to bump_thread => {thread_id => $thread->{'id'}},
|
||||||
|
(class => 'click'), begin %>
|
||||||
|
Bump (<%= $thread->{'bump_tally'} %>)
|
||||||
|
<% end %>
|
||||||
|
<%= link_to Flag => flag_thread => {thread_id => $thread->{'id'}},
|
||||||
|
(class => 'click') %>
|
||||||
|
</nav>
|
||||||
|
<% if (is_mod) { =%>
|
||||||
|
<nav class="post__nav">
|
||||||
|
<%= link_to Hide => hide_thread => {thread_id => $thread->{'id'}},
|
||||||
|
(class => 'click') %>
|
||||||
|
<%= link_to Unhide => unhide_thread => {thread_id => $thread->{'id'}},
|
||||||
|
(class => 'click') %>
|
||||||
|
<%= link_to Unflag => unflag_thread => {thread_id => $thread->{'id'}},
|
||||||
|
(class => 'click') %>
|
||||||
|
</nav>
|
||||||
|
<% } =%>
|
||||||
|
</article>
|
||||||
|
</main>
|
||||||
|
<% } =%>
|
Loading…
Reference in New Issue
Block a user