Add routes + tests for the unflag, hide and unhide actions
This commit is contained in:
parent
34f2ec7033
commit
452229780e
|
@ -145,14 +145,25 @@ sub startup($self) {
|
|||
my $moderator = $r->under('/moderator', sub ($c) {
|
||||
return 1 if $c->is_mod;
|
||||
|
||||
$c->redirect_to('mod_login');
|
||||
# Return false otherwise a body is rendered with the redirect...
|
||||
return undef;
|
||||
return $c->redirect_to('mod_login'), undef;
|
||||
});
|
||||
|
||||
$moderator->get('/flagged')
|
||||
->to('moderator#flagged')
|
||||
->name('flagged_list');
|
||||
|
||||
$moderator->get('/unflag/:thread_id', [thread_id => qr/\d+/])
|
||||
->to('moderator#unflag')
|
||||
->name('unflag_thread');
|
||||
|
||||
$moderator->get('/hide/:thread_id', [thread_id => qr/\d+/])
|
||||
->to('moderator#hide')
|
||||
->name('hide_thread');
|
||||
|
||||
$moderator->get('/unhide/:thread_id', [thread_id => qr/\d+/])
|
||||
->to('moderator#unhide')
|
||||
->name('unhide_thread');
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
@ -57,4 +57,35 @@ sub logout($self) {
|
|||
$self->redirect_to('threads_list');
|
||||
}
|
||||
|
||||
sub unflag($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->flash(info => "Thread #$thread_id has been unflagged. ◀️");
|
||||
|
||||
$self->redirect_to($redirect_url);
|
||||
}
|
||||
|
||||
sub hide($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->flash(info => "Thread #$thread_id has been hidden. 🫥");
|
||||
|
||||
$self->redirect_to($redirect_url);
|
||||
}
|
||||
|
||||
sub unhide($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->flash(info => "Thread #$thread_id has been unhidden. ⏪");
|
||||
|
||||
$self->redirect_to($redirect_url);
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
@ -35,4 +35,29 @@ sub get_name($self, $mod_id) {
|
|||
END_SQL
|
||||
}
|
||||
|
||||
sub unflag($self, $thread_id) {
|
||||
$self->pg->db->query(<<~'END_SQL', $thread_id)
|
||||
UPDATE threads
|
||||
SET flagged_status = FALSE
|
||||
WHERE thread_id = ?;
|
||||
END_SQL
|
||||
}
|
||||
|
||||
sub hide($self, $thread_id) {
|
||||
$self->pg->db->query(<<~'END_SQL', $thread_id)
|
||||
UPDATE threads
|
||||
SET hidden_status = TRUE,
|
||||
flagged_status = FALSE
|
||||
WHERE thread_id = ?;
|
||||
END_SQL
|
||||
}
|
||||
|
||||
sub unhide($self, $thread_id) {
|
||||
$self->pg->db->query(<<~'END_SQL', $thread_id)
|
||||
UPDATE threads
|
||||
SET hidden_status = FALSE
|
||||
WHERE thread_id = ?;
|
||||
END_SQL
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
@ -95,12 +95,4 @@ sub flag($self, $thread_id) {
|
|||
END_SQL
|
||||
}
|
||||
|
||||
sub unflag($self, $thread_id) {
|
||||
$self->pg->db->query(<<~'END_SQL', $thread_id)
|
||||
UPDATE threads
|
||||
SET flagged_status = FALSE
|
||||
WHERE thread_id = ?;
|
||||
END_SQL
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
@ -39,6 +39,23 @@ subtest Login => sub {
|
|||
->status_is(302)
|
||||
->header_like(Location => qr{moderator/flagged});
|
||||
|
||||
# Do these subs while logged in
|
||||
subtest Flag => sub {
|
||||
$t->get_ok('/moderator/unflag/1')
|
||||
->status_is(302)
|
||||
->header_like(Location => qr{thread/list});
|
||||
};
|
||||
|
||||
subtest Hide => sub {
|
||||
$t->get_ok('/moderator/hide/1')
|
||||
->status_is(302)
|
||||
->header_like(Location => qr{thread/single/1});
|
||||
|
||||
$t->get_ok('/moderator/unhide/1')
|
||||
->status_is(302)
|
||||
->header_like(Location => qr{thread/list});
|
||||
};
|
||||
|
||||
$t->get_ok('/logout')
|
||||
->status_is(302)
|
||||
->header_like(Location => qr{thread/list});
|
||||
|
|
Loading…
Reference in a new issue