aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/App/Controller
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2020-07-10 14:38:17 +0100
committerMatthew Somerville <matthew@mysociety.org>2020-07-14 18:25:19 +0100
commit67823bc788ce744e1228a8602b9a5aa805771ced (patch)
tree0b1eddd4e071314573e52206d0061cab022e1cd0 /perllib/FixMyStreet/App/Controller
parenteed6158981240afce10824e82fa86f14b38f3167 (diff)
Centralise update creation to include fields.
Given the user, we can infer the name if not provided, and the extra data if a staff user. We can also provide defaults for various other fields. Always have superuser take precedence over from_body.
Diffstat (limited to 'perllib/FixMyStreet/App/Controller')
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin/Reports.pm24
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin/Triage.pm17
-rw-r--r--perllib/FixMyStreet/App/Controller/Moderate.pm9
-rwxr-xr-xperllib/FixMyStreet/App/Controller/Questionnaire.pm4
-rw-r--r--perllib/FixMyStreet/App/Controller/Report.pm7
5 files changed, 7 insertions, 54 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin/Reports.pm b/perllib/FixMyStreet/App/Controller/Admin/Reports.pm
index 4866a657e..48386cf3e 100644
--- a/perllib/FixMyStreet/App/Controller/Admin/Reports.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin/Reports.pm
@@ -368,24 +368,10 @@ sub edit : Path('/admin/report_edit') : Args(1) {
if ( $problem->state ne $old_state ) {
$c->forward( '/admin/log_edit', [ $id, 'problem', 'state_change' ] );
- my $name = $c->user->moderating_user_name;
- my $extra = { is_superuser => 1 };
- if ($c->user->from_body) {
- delete $extra->{is_superuser};
- $extra->{is_body_user} = $c->user->from_body->id;
- }
- my $timestamp = \'current_timestamp';
$problem->add_to_comments( {
text => $c->stash->{update_text} || '',
- created => $timestamp,
- confirmed => $timestamp,
- user_id => $c->user->id,
- name => $name,
- mark_fixed => 0,
- anonymous => 0,
- state => 'confirmed',
+ user => $c->user->obj,
problem_state => $problem->state,
- extra => $extra
} );
}
$c->forward( '/admin/log_edit', [ $id, 'problem', 'edit' ] );
@@ -444,13 +430,7 @@ sub edit_category : Private {
} else {
$problem->add_to_comments({
text => $update_text,
- created => \'current_timestamp',
- confirmed => \'current_timestamp',
- user_id => $c->user->id,
- name => $c->user->from_body ? $c->user->from_body->name : $c->user->name,
- state => 'confirmed',
- mark_fixed => 0,
- anonymous => 0,
+ user => $c->user->obj,
});
}
$c->forward( '/admin/log_edit', [ $problem->id, 'problem', 'category_change' ] );
diff --git a/perllib/FixMyStreet/App/Controller/Admin/Triage.pm b/perllib/FixMyStreet/App/Controller/Admin/Triage.pm
index 7cfcc93dd..c5bb6628d 100644
--- a/perllib/FixMyStreet/App/Controller/Admin/Triage.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin/Triage.pm
@@ -117,27 +117,14 @@ sub update : Private {
$c->stash->{problem}->update( { state => 'confirmed' } );
$c->forward( '/admin/log_edit', [ $problem->id, 'problem', 'triage' ] );
- my $name = $c->user->moderating_user_name;
- my $extra = { is_superuser => 1 };
- if ($c->user->from_body) {
- delete $extra->{is_superuser};
- $extra->{is_body_user} = $c->user->from_body->id;
- }
-
+ my $extra;
$extra->{triage_report} = 1;
$extra->{holding_category} = $current_category;
$extra->{new_category} = $new_category;
- my $timestamp = \'current_timestamp';
my $comment = $problem->add_to_comments( {
text => "Report triaged from $current_category to $new_category",
- created => $timestamp,
- confirmed => $timestamp,
- user_id => $c->user->id,
- name => $name,
- mark_fixed => 0,
- anonymous => 0,
- state => 'confirmed',
+ user => $c->user->obj,
problem_state => $problem->state,
extra => $extra,
whensent => \'current_timestamp',
diff --git a/perllib/FixMyStreet/App/Controller/Moderate.pm b/perllib/FixMyStreet/App/Controller/Moderate.pm
index f4143f0b4..c936f13c0 100644
--- a/perllib/FixMyStreet/App/Controller/Moderate.pm
+++ b/perllib/FixMyStreet/App/Controller/Moderate.pm
@@ -340,13 +340,8 @@ sub moderate_state : Private {
$problem->state($new_state);
$problem->add_to_comments( {
text => $c->stash->{moderation_reason},
- created => \'current_timestamp',
- confirmed => \'current_timestamp',
- user_id => $c->user->id,
- name => $c->user->from_body ? $c->user->from_body->name : $c->user->name,
- state => 'confirmed',
- mark_fixed => 0,
- anonymous => $c->user->from_body ? 0 : 1,
+ user => $c->user->obj,
+ anonymous => $c->user->is_superuser || $c->user->from_body ? 0 : 1,
problem_state => $new_state,
} );
return 'state';
diff --git a/perllib/FixMyStreet/App/Controller/Questionnaire.pm b/perllib/FixMyStreet/App/Controller/Questionnaire.pm
index ab6117ae4..ef6152c30 100755
--- a/perllib/FixMyStreet/App/Controller/Questionnaire.pm
+++ b/perllib/FixMyStreet/App/Controller/Questionnaire.pm
@@ -206,16 +206,12 @@ sub submit_standard : Private {
$update = $c->model('DB::Comment')->new(
{
problem => $problem,
- name => $problem->name,
user => $problem->user,
text => $update,
- state => 'confirmed',
mark_fixed => $c->stash->{new_state} eq 'fixed - user' ? 1 : 0,
mark_open => $c->stash->{new_state} eq 'confirmed' ? 1 : 0,
lang => $c->stash->{lang_code},
cobrand => $c->cobrand->moniker,
- cobrand_data => '',
- confirmed => \'current_timestamp',
anonymous => $problem->anonymous,
}
);
diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm
index 4f9825cae..dd7abc563 100644
--- a/perllib/FixMyStreet/App/Controller/Report.pm
+++ b/perllib/FixMyStreet/App/Controller/Report.pm
@@ -569,16 +569,11 @@ sub inspect : Private {
epoch => $saved_at
);
}
- my $name = $c->user->from_body ? $c->user->from_body->name : $c->user->name;
$problem->add_to_comments( {
text => $update_text,
created => $timestamp,
confirmed => $timestamp,
- user_id => $c->user->id,
- name => $name,
- state => 'confirmed',
- mark_fixed => 0,
- anonymous => 0,
+ user => $c->user->obj,
%update_params,
} );
}