aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--db/schema.sql17
-rwxr-xr-xweb-admin/index.cgi29
2 files changed, 43 insertions, 3 deletions
diff --git a/db/schema.sql b/db/schema.sql
index 4da21a212..18b3282ed 100644
--- a/db/schema.sql
+++ b/db/schema.sql
@@ -324,3 +324,20 @@ create table textmystreet (
postcode text not null,
mobile text not null
);
+
+-- Record basic information about edits made through the admin interface
+
+create table admin_log (
+ id serial not null primary key,
+ admin_user text not null,
+ object_type text not null check (
+ object_type = 'problem'
+ or object_type = 'update'
+ ),
+ object_id integer not null,
+ action text not null check (
+ action = 'edit'
+ or action = 'state_change'
+ or action = 'resend'),
+ whenedited timestamp not null default ms_current_timestamp()
+);
diff --git a/web-admin/index.cgi b/web-admin/index.cgi
index dfe18d097..fe49341c3 100755
--- a/web-admin/index.cgi
+++ b/web-admin/index.cgi
@@ -525,11 +525,11 @@ sub admin_edit_report {
my $cobrand = Page::get_cobrand($q);
return not_found($q) if ! $row->[0];
my %row = %{$row->[0]};
- my %row_h = map { $_ => $row{$_} ? ent($row{$_}) : '' } keys %row;
my $status_message = '';
if ($q->param('resend')) {
return not_found($q) if $q->param('token') ne get_token($q);
dbh()->do('update problem set whensent=null where id=?', {}, $id);
+ admin_log_edit($q, $id, 'problem', 'resend');
dbh()->commit();
$status_message = '<p><em>That problem will now be resent.</em></p>';
} elsif ($q->param('submit')) {
@@ -554,12 +554,22 @@ sub admin_edit_report {
unless ($done) {
dbh()->do($query, {}, $q->param('anonymous') ? 't' : 'f', $new_state,
$q->param('name'), $q->param('email'), $q->param('title'), $q->param('detail'), $id);
+ if ($new_state ne $row{state}) {
+ admin_log_edit($q, $id, 'problem', 'state_change');
+ }
+ if ($q->param('anonymous') ne $row{anonymous} ||
+ $q->param('name') ne $row{name} ||
+ $q->param('email') ne $row{email} ||
+ $q->param('title') ne $row{title} ||
+ $q->param('detail') ne $row{detail}) {
+ admin_log_edit($q, $id, 'problem', 'edit');
+ }
dbh()->commit();
map { $row{$_} = $q->param($_) } qw(anonymous state name email title detail);
$status_message = '<p><em>Updated!</em></p>';
}
}
-
+ my %row_h = map { $_ => $row{$_} ? ent($row{$_}) : '' } keys %row;
my $title = "Editing problem $id";
print html_head($q, $title);
print $q->h1($title);
@@ -665,7 +675,6 @@ sub admin_edit_update {
my $cobrand = Page::get_cobrand($q);
my %row = %{$row->[0]};
- my %row_h = map { $_ => $row{$_} ? ent($row{$_}) : '' } keys %row;
my $status_message;
if ($q->param('submit')) {
return not_found($q) if $q->param('token') ne get_token($q);
@@ -675,10 +684,17 @@ sub admin_edit_update {
}
$query .= ' where id=?';
dbh()->do($query, {}, $q->param('state'), $q->param('name'), $q->param('email'), $q->param('text'), $id);
+ if ($q->param('state') ne $row{state}) {
+ admin_log_edit($q, $id, 'update', 'state_change');
+ }
+ if ($q->param('name') ne $row{name} || $q->param('email') ne $row{email} || $q->param('text') ne $row{text}) {
+ admin_log_edit($q, $id, 'update', 'edit');
+ }
dbh()->commit();
map { $row{$_} = $q->param($_) } qw(state name email text);
$status_message = '<p><em>Updated!</em></p>';
}
+ my %row_h = map { $_ => $row{$_} ? ent($row{$_}) : '' } keys %row;
my $title = "Editing update $id";
print html_head($q, $title);
print $q->h1($title);
@@ -734,6 +750,13 @@ sub get_cobrand_data_from_hash {
return $cobrand_data;
}
+sub admin_log_edit {
+ my ($q, $id, $object_type, $action) = @_;
+ my $query = "insert into admin_log (admin_user, object_type, object_id, action)
+ values (?, ?, ?, ?);";
+ dbh()->do($query, {}, $q->remote_user(), $object_type, $id, $action);
+}
+
sub admin_timeline {
my $q = shift;
my $cobrand = Page::get_cobrand($q);