aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin.pm46
-rw-r--r--t/app/controller/admin.t42
-rw-r--r--templates/web/default/admin/report_blocks.html4
-rw-r--r--templates/web/default/admin/report_edit.html2
-rw-r--r--templates/web/default/admin/update_edit.html2
5 files changed, 89 insertions, 7 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm
index 3854e27aa..dc85b909a 100644
--- a/perllib/FixMyStreet/App/Controller/Admin.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin.pm
@@ -499,6 +499,7 @@ sub report_edit : Path('report_edit') : Args(1) {
$c->forward('get_token');
$c->forward('check_page_allowed');
+ $c->forward('check_email_for_abuse', [ $problem->user->email ] );
$c->stash->{updates} =
[ $c->model('DB::Comment')
@@ -515,6 +516,9 @@ sub report_edit : Path('report_edit') : Args(1) {
$c->forward( 'log_edit', [ $id, 'problem', 'resend' ] );
}
+ elsif ( $c->req->param('banuser') ) {
+ $c->forward('ban_user');
+ }
elsif ( $c->req->param('submit') ) {
$c->forward('check_token');
@@ -688,6 +692,25 @@ sub log_edit : Private {
)->insert();
}
+sub ban_user : Private {
+ my ( $self, $c ) = @_;
+
+ my $email = $c->req->param('email');
+
+ my $abuse = $c->model('DB::Abuse')->find_or_new({ email => $email });
+
+ if ( $abuse->in_storage ) {
+ $c->stash->{status_message} = _('Email already in abuse list');
+ } else {
+ $abuse->insert;
+ $c->stash->{status_message} = _('Email added to abuse list');
+ }
+
+ $c->stash->{email_in_abuse} = 1;
+
+ return 1;
+}
+
sub update_edit : Path('update_edit') : Args(1) {
my ( $self, $c, $id ) = @_;
@@ -709,8 +732,12 @@ sub update_edit : Path('update_edit') : Args(1) {
$c->stash->{update} = $update;
- my $status_message = '';
- if ( $c->req->param('submit') ) {
+ $c->forward('check_email_for_abuse', [ $update->user->email ] );
+
+ if ( $c->req->param('banuser') ) {
+ $c->forward('ban_user');
+ }
+ elsif ( $c->req->param('submit') ) {
$c->forward('check_token');
my $old_state = $update->state;
@@ -752,7 +779,7 @@ sub update_edit : Path('update_edit') : Args(1) {
$update->update;
- $status_message = '<p><em>' . _('Updated!') . '</em></p>';
+ $c->stash->{status_message} = '<p><em>' . _('Updated!') . '</em></p>';
# If we're hiding an update, see if it marked as fixed and unfix if so
if ( $new_state eq 'hidden' && $update->mark_fixed ) {
@@ -761,7 +788,7 @@ sub update_edit : Path('update_edit') : Args(1) {
$update->problem->update;
}
- $status_message .=
+ $c->stash->{status_message} .=
'<p><em>' . _('Problem marked as open.') . '</em></p>';
}
@@ -775,7 +802,16 @@ sub update_edit : Path('update_edit') : Args(1) {
}
}
- $c->stash->{status_message} = $status_message;
+
+ return 1;
+}
+
+sub check_email_for_abuse : Private {
+ my ( $self, $c, $email ) =@_;
+
+ my $is_abuse = $c->model('DB::Abuse')->find({ email => $email });
+
+ $c->stash->{email_in_abuse} = 1 if $is_abuse;
return 1;
}
diff --git a/t/app/controller/admin.t b/t/app/controller/admin.t
index 4e2ec82fe..0acaffc8d 100644
--- a/t/app/controller/admin.t
+++ b/t/app/controller/admin.t
@@ -488,6 +488,27 @@ subtest 'change email to new user' => sub {
is $report->user_id, $user3->id, 'user changed to new user';
};
+subtest 'adding email to abuse list from report page' => sub {
+ my $email = $report->user->email;
+
+ my $abuse = FixMyStreet::App->model('DB::Abuse')->find( { email => $email } );
+ $abuse->delete if $abuse;
+
+ $mech->get_ok( '/admin/report_edit/' . $report->id );
+ $mech->content_contains('Ban email address');
+
+ $mech->click_ok('banuser');
+
+ $mech->content_contains('Email added to abuse list');
+ $mech->content_contains('<small>(Email in abuse table)</small>');
+
+ $abuse = FixMyStreet::App->model('DB::Abuse')->find( { email => $email } );
+ ok $abuse, 'entry created in abuse table';
+
+ $mech->get_ok( '/admin/report_edit/' . $report->id );
+ $mech->content_contains('<small>(Email in abuse table)</small>');
+};
+
$log_entries->delete;
my $update = FixMyStreet::App->model('DB::Comment')->create(
@@ -668,6 +689,27 @@ subtest 'editing update email creates new user if required' => sub {
is $update->user->id, $user->id, 'update set to new user';
};
+subtest 'adding email to abuse list from update page' => sub {
+ my $email = $update->user->email;
+
+ my $abuse = FixMyStreet::App->model('DB::Abuse')->find( { email => $email } );
+ $abuse->delete if $abuse;
+
+ $mech->get_ok( '/admin/update_edit/' . $update->id );
+ $mech->content_contains('Ban email address');
+
+ $mech->click_ok('banuser');
+
+ $mech->content_contains('Email added to abuse list');
+ $mech->content_contains('<small>(Email in abuse table)</small>');
+
+ $abuse = FixMyStreet::App->model('DB::Abuse')->find( { email => $email } );
+ ok $abuse, 'entry created in abuse table';
+
+ $mech->get_ok( '/admin/update_edit/' . $update->id );
+ $mech->content_contains('<small>(Email in abuse table)</small>');
+};
+
subtest 'hiding comment marked as fixed reopens report' => sub {
$update->mark_fixed( 1 );
$update->update;
diff --git a/templates/web/default/admin/report_blocks.html b/templates/web/default/admin/report_blocks.html
index 1fe650f15..6eaa03634 100644
--- a/templates/web/default/admin/report_blocks.html
+++ b/templates/web/default/admin/report_blocks.html
@@ -5,3 +5,7 @@
[% BLOCK format_time -%]
[%- IF time %][% time.ymd %]&nbsp;[% time.hms %][% ELSE %][% no_time || '&nbsp;' %][% END %][% no_time = '' %]
[%- END %]
+
+[% BLOCK abuse_button -%]
+[% IF email_in_abuse %]<small>[% loc('(Email in abuse table)') %]</small>[% ELSE %]<input type="submit" name="banuser" value="[% loc('Ban email address') %]" />[% END %]
+[%- END %]
diff --git a/templates/web/default/admin/report_edit.html b/templates/web/default/admin/report_edit.html
index 9c38b014e..d59885681 100644
--- a/templates/web/default/admin/report_edit.html
+++ b/templates/web/default/admin/report_edit.html
@@ -25,7 +25,7 @@
</select></li>
<li>[% loc('Category:') %] [% problem.category | html %] </li>
<li>[% loc('Name:') %] <input type='text' name='name' id='name' value='[% problem.name | html %]'></li>
-<li>[% loc('Email:') %] <input type='text' id='email' name='email' value='[% problem.user.email | html %]'></li>
+<li>[% loc('Email:') %] <input type='text' id='email' name='email' value='[% problem.user.email | html %]'> [% PROCESS abuse_button %]</li>
<li>[% loc('Phone:') %] [% problem.user.phone | html %]</li>
<li>[% loc('Created:') %] [% PROCESS format_time time=problem.created %]</li>
<li>[% loc('Confirmed:') %] [% PROCESS format_time time=problem.confirmed no_time='-' %]</li>
diff --git a/templates/web/default/admin/update_edit.html b/templates/web/default/admin/update_edit.html
index d7f212052..8e1ee935b 100644
--- a/templates/web/default/admin/update_edit.html
+++ b/templates/web/default/admin/update_edit.html
@@ -21,7 +21,7 @@
[% END %]
</select></li>
<li>[% loc('Name:') %] <input type='text' name='name' id='name' value='[% update.name | html %]'></li>
-<li>[% loc('Email:') %] <input type='text' id='email' name='email' value='[% update.user.email | html %]'></li>
+<li>[% loc('Email:') %] <input type='text' id='email' name='email' value='[% update.user.email | html %]'> [% PROCESS abuse_button %]</li>
<li>[% loc('Cobrand:') %] [% update.cobrand %]</li>
<li>[% loc('Cobrand data:') %] [% update.cobrand_data %]</li>
<li>[% loc('Created:') %] [% PROCESS format_time time=update.created %]</li>