diff options
author | Dave Arter <davea@mysociety.org> | 2019-11-06 11:46:56 +0000 |
---|---|---|
committer | Dave Arter <davea@mysociety.org> | 2019-12-09 12:50:07 +0000 |
commit | 9efd2981c85b3fae48118071e12058413f46a73c (patch) | |
tree | 9377238eeac76bd7853a851db44521f3f8c674eb /perllib/FixMyStreet/Cobrand/TfL.pm | |
parent | 64d09262cabeac85704067d03a358b86265ef27b (diff) |
[TfL] Set safety critical flag on reports
Adds a cobrand feature that can mark entire categories or just specific
answers to extra questions as safety critical. When reports are made
in those categories or with those answers, marks the report as
safety critical.
Diffstat (limited to 'perllib/FixMyStreet/Cobrand/TfL.pm')
-rw-r--r-- | perllib/FixMyStreet/Cobrand/TfL.pm | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/Cobrand/TfL.pm b/perllib/FixMyStreet/Cobrand/TfL.pm index ececa1184..846e1e776 100644 --- a/perllib/FixMyStreet/Cobrand/TfL.pm +++ b/perllib/FixMyStreet/Cobrand/TfL.pm @@ -160,4 +160,32 @@ sub update_email_shortlisted_user { } } +sub report_new_munge_before_insert { + my ($self, $report) = @_; + + # Sets the safety critical flag on this report according to category/extra + # fields selected. + + my $safety_critical = 0; + my $categories = $self->feature('safety_critical_categories'); + my $category = $categories->{$report->category}; + if ( ref $category eq 'HASH' ) { + # report is safety critical if any of its field values match + # the critical values from the config + for my $code (keys %$category) { + my $value = $report->get_extra_field_value($code); + my %critical_values = map { $_ => 1 } @{ $category->{$code} }; + $safety_critical ||= $critical_values{$value}; + } + } elsif ($category) { + # the entire category is safety critical + $safety_critical = 1; + } + + my $extra = $report->get_extra_fields; + @$extra = grep { $_->{name} ne 'safety_critical' } @$extra; + push @$extra, { name => 'safety_critical', value => $safety_critical ? 'yes' : 'no' }; + $report->set_extra_fields(@$extra); +} + 1; |