aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2019-11-05 16:33:51 +0000
committerMatthew Somerville <matthew@mysociety.org>2019-11-08 15:31:39 +0000
commit7a39608ab48c8fd3fa2c5a8061b42ee8f9869973 (patch)
treeaa51d01235cde53fd408348f2439121e22beab65
parenteb68c3fa83ce8796a69429c83adedddba64c7cdc (diff)
Add admin log entry for more objects and things.
Namely templates, roles, bodies, categories, various user edits, and when using the inspect form and changing category.
-rwxr-xr-xbin/update-schema1
-rw-r--r--db/schema.sql4
-rw-r--r--db/schema_0069-admin-log-types.sql17
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin/Bodies.pm7
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin/Reports.pm1
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin/Roles.pm3
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin/Templates.pm3
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin/Users.pm23
-rw-r--r--perllib/FixMyStreet/App/Controller/Report.pm1
-rw-r--r--t/app/controller/admin/report_edit.t2
10 files changed, 44 insertions, 18 deletions
diff --git a/bin/update-schema b/bin/update-schema
index 3f4b2bafe..4755142bb 100755
--- a/bin/update-schema
+++ b/bin/update-schema
@@ -212,6 +212,7 @@ else {
# (assuming schema change files are never half-applied, which should be the case)
sub get_db_version {
return 'EMPTY' if ! table_exists('problem');
+ return '0069' if constraint_contains('admin_log_object_type_check', 'template');
return '0068' if column_exists('users', 'oidc_ids');
return '0067' if table_exists('roles');
return '0066' if column_exists('users', 'area_ids');
diff --git a/db/schema.sql b/db/schema.sql
index a211ef50d..cf2914467 100644
--- a/db/schema.sql
+++ b/db/schema.sql
@@ -445,6 +445,10 @@ create table admin_log (
or object_type = 'update'
or object_type = 'user'
or object_type = 'moderation'
+ or object_type = 'template'
+ or object_type = 'body'
+ or object_type = 'category'
+ or object_type = 'role'
),
object_id integer not null,
action text not null,
diff --git a/db/schema_0069-admin-log-types.sql b/db/schema_0069-admin-log-types.sql
new file mode 100644
index 000000000..e4e9362ac
--- /dev/null
+++ b/db/schema_0069-admin-log-types.sql
@@ -0,0 +1,17 @@
+BEGIN;
+
+ALTER TABLE admin_log DROP CONSTRAINT admin_log_object_type_check;
+
+ALTER TABLE admin_log ADD CONSTRAINT admin_log_object_type_check CHECK (
+ object_type = 'problem'
+ OR object_type = 'update'
+ OR object_type = 'user'
+ OR object_type = 'moderation'
+ OR object_type = 'template'
+ OR object_type = 'body'
+ OR object_type = 'category'
+ OR object_type = 'role'
+);
+
+COMMIT;
+
diff --git a/perllib/FixMyStreet/App/Controller/Admin/Bodies.pm b/perllib/FixMyStreet/App/Controller/Admin/Bodies.pm
index 098c29ad4..ea03b146f 100644
--- a/perllib/FixMyStreet/App/Controller/Admin/Bodies.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin/Bodies.pm
@@ -280,7 +280,6 @@ sub update_contact : Private {
$contact->unset_extra_metadata( 'group' );
}
-
$c->forward('/admin/update_extra_fields', [ $contact ]);
$c->forward('contact_cobrand_extra_fields', [ $contact, \%errors ]);
@@ -306,12 +305,13 @@ sub update_contact : Private {
$c->stash->{errors} = \%errors;
} elsif ( $contact->in_storage ) {
$c->stash->{updated} = _('Values updated');
-
+ $c->forward('/admin/log_edit', [ $contact->id, 'category', 'edit' ]);
# NB: History is automatically stored by a trigger in the database
$contact->update;
} else {
$c->stash->{updated} = _('New category contact added');
$contact->insert;
+ $c->forward('/admin/log_edit', [ $contact->id, 'category', 'add' ]);
}
unless ( %errors ) {
@@ -346,6 +346,7 @@ sub confirm_contacts : Private {
}
);
+ $c->forward('/admin/log_edit', [ $c->stash->{body_id}, 'body', 'edit' ]);
$c->stash->{updated} = _('Values updated');
}
@@ -360,8 +361,10 @@ sub update_body : Private {
if ($body) {
$body->update( $values->{params} );
+ $c->forward('/admin/log_edit', [ $body->id, 'body', 'edit' ]);
} else {
$body = $c->model('DB::Body')->create( $values->{params} );
+ $c->forward('/admin/log_edit', [ $body->id, 'body', 'add' ]);
}
if ($values->{extras}) {
diff --git a/perllib/FixMyStreet/App/Controller/Admin/Reports.pm b/perllib/FixMyStreet/App/Controller/Admin/Reports.pm
index 60a02f8fd..895bc17a8 100644
--- a/perllib/FixMyStreet/App/Controller/Admin/Reports.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin/Reports.pm
@@ -405,6 +405,7 @@ sub edit_category : Private {
anonymous => 0,
});
}
+ $c->forward( '/admin/log_edit', [ $problem->id, 'problem', 'category_change' ] );
return 1;
}
return 0;
diff --git a/perllib/FixMyStreet/App/Controller/Admin/Roles.pm b/perllib/FixMyStreet/App/Controller/Admin/Roles.pm
index 902ed6255..279ee695c 100644
--- a/perllib/FixMyStreet/App/Controller/Admin/Roles.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin/Roles.pm
@@ -63,6 +63,7 @@ sub form {
if ($c->get_param('delete_role')) {
$role->delete;
+ $c->forward('/admin/log_edit', [ $role->id, 'role', 'delete' ]);
$c->response->redirect($c->uri_for($self->action_for('index')));
$c->detach;
}
@@ -88,11 +89,13 @@ sub form {
$opts->{body_id} = $c->user->from_body->id;
}
+ my $action = $role->in_storage ? 'edit' : 'add';
my $form = FixMyStreet::App::Form::Role->new(%$opts);
$c->stash(template => 'admin/roles/form.html', form => $form);
$form->process(item => $role, params => $c->req->params);
return unless $form->validated;
+ $c->forward('/admin/log_edit', [ $role->id, 'role', $action ]);
$c->response->redirect($c->uri_for($self->action_for('index')));
}
diff --git a/perllib/FixMyStreet/App/Controller/Admin/Templates.pm b/perllib/FixMyStreet/App/Controller/Admin/Templates.pm
index 1a7381c0b..97a62c2b8 100644
--- a/perllib/FixMyStreet/App/Controller/Admin/Templates.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin/Templates.pm
@@ -77,6 +77,7 @@ sub edit : Path : Args(2) {
if ($c->get_param('delete_template') && $c->get_param('delete_template') eq _("Delete template")) {
$template->contact_response_templates->delete_all;
$template->delete;
+ $c->forward('/admin/log_edit', [ $template->id, 'template', 'delete' ]);
} else {
my @live_contact_ids = map { $_->id } @live_contacts;
my @new_contact_ids = grep { $c->get_param("contacts[$_]") } @live_contact_ids;
@@ -144,6 +145,8 @@ sub edit : Path : Args(2) {
contact_id => $contact_id,
});
}
+ my $action = $template_id eq 'new' ? 'add' : 'edit';
+ $c->forward('/admin/log_edit', [ $template->id, 'template', $action ]);
}
$c->res->redirect( $c->uri_for_action( '/admin/templates/view', $c->stash->{body}->id ) );
diff --git a/perllib/FixMyStreet/App/Controller/Admin/Users.pm b/perllib/FixMyStreet/App/Controller/Admin/Users.pm
index 2137f1135..ac9353921 100644
--- a/perllib/FixMyStreet/App/Controller/Admin/Users.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin/Users.pm
@@ -171,7 +171,7 @@ sub add : Local : Args(0) {
$c->forward('user_cobrand_extra_fields');
$user->insert;
- $c->forward( '/admin/log_edit', [ $user->id, 'user', 'edit' ] );
+ $c->forward( '/admin/log_edit', [ $user->id, 'user', 'add' ] );
$c->flash->{status_message} = _("Updated!");
$c->detach('post_edit_redirect', [ $user ]);
@@ -243,8 +243,6 @@ sub edit : Chained('user') : PathPart('') : Args(0) {
$c->forward('update_alerts');
} elsif ( $c->get_param('submit') ) {
- my $edited = 0;
-
my $name = $c->get_param('name');
my $email = lc $c->get_param('email');
my $phone = $c->get_param('phone');
@@ -286,15 +284,6 @@ sub edit : Chained('user') : PathPart('') : Args(0) {
return if %{$c->stash->{field_errors}};
- if ( ($user->email || "") ne $email ||
- $user->name ne $name ||
- ($user->phone || "") ne $phone ||
- ($user->from_body && $c->get_param('body') && $user->from_body->id ne $c->get_param('body')) ||
- (!$user->from_body && $c->get_param('body'))
- ) {
- $edited = 1;
- }
-
if ($existing_user_cobrand) {
$existing_user->adopt($user);
$c->forward( '/admin/log_edit', [ $user->id, 'user', 'merge' ] );
@@ -387,9 +376,7 @@ sub edit : Chained('user') : PathPart('') : Args(0) {
}
$user->update;
- if ($edited) {
- $c->forward( '/admin/log_edit', [ $user->id, 'user', 'edit' ] );
- }
+ $c->forward( '/admin/log_edit', [ $user->id, 'user', 'edit' ] );
$c->flash->{status_message} = _("Updated!");
$c->detach('post_edit_redirect', [ $user ]);
@@ -610,6 +597,7 @@ sub user_remove_account : Private {
my ( $self, $c, $user ) = @_;
$c->forward('user_logout_everywhere', [ $user ]);
$user->anonymize_account;
+ $c->forward( '/admin/log_edit', [ $user->id, 'user', 'edit' ] );
$c->stash->{status_message} = _('That user’s personal details have been removed.');
}
@@ -637,6 +625,7 @@ sub ban : Private {
$c->stash->{status_message} = _('User already in abuse list');
} else {
$abuse->insert;
+ $c->forward( '/admin/log_edit', [ $user->id, 'user', 'edit' ] );
$c->stash->{status_message} = _('User added to abuse list');
}
$c->stash->{username_in_abuse} = 1;
@@ -647,6 +636,7 @@ sub ban : Private {
$c->stash->{status_message} = _('User already in abuse list');
} else {
$abuse->insert;
+ $c->forward( '/admin/log_edit', [ $user->id, 'user', 'edit' ] );
$c->stash->{status_message} = _('User added to abuse list');
}
$c->stash->{username_in_abuse} = 1;
@@ -668,6 +658,7 @@ sub unban : Private {
my $abuse = $c->model('DB::Abuse')->search({ email => \@username });
if ( $abuse ) {
$abuse->delete;
+ $c->forward( '/admin/log_edit', [ $user->id, 'user', 'edit' ] );
$c->stash->{status_message} = _('user removed from abuse list');
} else {
$c->stash->{status_message} = _('user not in abuse list');
@@ -697,6 +688,7 @@ sub flag : Private {
} else {
$user->flagged(1);
$user->update;
+ $c->forward( '/admin/log_edit', [ $user->id, 'user', 'edit' ] );
$c->stash->{status_message} = _('User flagged');
}
@@ -726,6 +718,7 @@ sub flag_remove : Private {
} else {
$user->flagged(0);
$user->update;
+ $c->forward( '/admin/log_edit', [ $user->id, 'user', 'edit' ] );
$c->stash->{status_message} = _('User flag removed');
}
diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm
index 695832832..190687d41 100644
--- a/perllib/FixMyStreet/App/Controller/Report.pm
+++ b/perllib/FixMyStreet/App/Controller/Report.pm
@@ -516,6 +516,7 @@ sub inspect : Private {
if ($valid) {
$problem->lastupdate( \'current_timestamp' );
$problem->update;
+ $c->forward( '/admin/log_edit', [ $problem->id, 'problem', 'edit' ] );
if ($update_text || %update_params) {
my $timestamp = \'current_timestamp';
if (my $saved_at = $c->get_param('saved_at')) {
diff --git a/t/app/controller/admin/report_edit.t b/t/app/controller/admin/report_edit.t
index c6e03ff7e..1a2e8f1bf 100644
--- a/t/app/controller/admin/report_edit.t
+++ b/t/app/controller/admin/report_edit.t
@@ -353,7 +353,7 @@ foreach my $test (
user_body => $oxfordshire,
changes => { state => 'in progress', category => 'Potholes' },
log_entries => [
- qw/edit state_change edit state_change edit edit resend edit state_change edit state_change edit state_change edit state_change edit state_change edit edit edit edit edit/
+ qw/edit state_change category_change edit state_change edit edit resend edit state_change edit state_change edit state_change edit state_change edit state_change edit edit edit edit edit/
],
resend => 0,
},