parent
9ae401f86d
commit
11d2f80524
|
@ -151,28 +151,14 @@ sub bump($self) {
|
||||||
|
|
||||||
sub flag($self) {
|
sub flag($self) {
|
||||||
my $thread_id = $self->param('thread_id');
|
my $thread_id = $self->param('thread_id');
|
||||||
my $v = $self->validation;
|
my $redirect_url = $self->url_for('threads_list')->fragment('info')->to_abs;
|
||||||
|
|
||||||
$v->optional(captcha => 'trim')->size(4, 4)->like(qr/flag/i);
|
|
||||||
|
|
||||||
if ($v->is_valid) {
|
|
||||||
my $redirect_url =
|
|
||||||
$self->url_for('threads_list')->fragment('info')->to_abs;
|
|
||||||
|
|
||||||
$self->thread->flag($thread_id);
|
$self->thread->flag($thread_id);
|
||||||
$self->flash(
|
$self->flash(
|
||||||
info => "Thread #$thread_id has been flagged for moderator. 🚩"
|
info => "Thread #$thread_id has been flagged for moderator. 🚩"
|
||||||
);
|
);
|
||||||
|
|
||||||
return $self->redirect_to($redirect_url);
|
$self->redirect_to($redirect_url);
|
||||||
}
|
|
||||||
elsif ($v->has_error) {
|
|
||||||
$self->stash(status => 400)
|
|
||||||
}
|
|
||||||
|
|
||||||
$self->stash(thread_id => $thread_id);
|
|
||||||
|
|
||||||
return $self->render;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
|
@ -98,8 +98,9 @@ subtest 'Flagging thread', sub {
|
||||||
->element_exists('a[href*="flag"]')
|
->element_exists('a[href*="flag"]')
|
||||||
->text_like(h2 => qr/Thread #1/);
|
->text_like(h2 => qr/Thread #1/);
|
||||||
|
|
||||||
$t->get_ok('/thread/flag/1' )->status_is(200);
|
$t->get_ok('/thread/flag/1')->status_is(200)
|
||||||
$t->get_ok('/thread/flag/65536')->status_is(404);
|
->element_exists('p[class="stash-with-info"]')
|
||||||
|
->text_like(p => qr/Thread #1 has been flagged/);
|
||||||
};
|
};
|
||||||
|
|
||||||
done_testing;
|
done_testing;
|
||||||
|
|
|
@ -1,17 +0,0 @@
|
||||||
% layout 'default';
|
|
||||||
% title $thread_id ? "Flag Thread #$thread_id" : '?';
|
|
||||||
<h2 class="page-title"><%= title %></h2>
|
|
||||||
<% if ($thread_id) { =%>
|
|
||||||
<form class="form-body">
|
|
||||||
<div class="form-field">
|
|
||||||
<% if (my $error = validation->error('captcha')) { =%>
|
|
||||||
<p class="field-with-error">Must be between <%= $error->[2] %>
|
|
||||||
and <%= $error->[3] %> characters.</p>
|
|
||||||
<% } =%>
|
|
||||||
<%= label_for captcha => "Enter the word 'flag' to confirm:" %>
|
|
||||||
<%= text_field captcha => id => 'captcha' %>
|
|
||||||
</div>
|
|
||||||
<button type="submit" class="form-button">Flag</button>
|
|
||||||
</fieldset>
|
|
||||||
</form>
|
|
||||||
<% } =%>
|
|
Loading…
Reference in a new issue