Skip to content

Commit

Permalink
Merge branch 'surrey-cobrand' into commercial-staging
Browse files Browse the repository at this point in the history
  • Loading branch information
davea committed Sep 16, 2024
2 parents 2a46c93 + 05af01f commit 4342066
Show file tree
Hide file tree
Showing 13 changed files with 101 additions and 77 deletions.
51 changes: 0 additions & 51 deletions bin/fixmystreet.com/buckinghamshire-flytipping

This file was deleted.

28 changes: 15 additions & 13 deletions perllib/FixMyStreet/Cobrand/Surrey.pm
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,21 @@ sub dashboard_export_problems_add_columns {
});
}

=back
=head2 Open311
=over 1
=item * Fetched reports via Open311 use the service name as their title
=cut

sub open311_title_fetched_report {
my ($self, $request) = @_;
return $request->{service_name};
}

sub get_geocoder { 'OSM'}


Expand Down Expand Up @@ -273,19 +288,6 @@ sub open311_pre_send {
$row->set_extra_fields( @$extra ) if @$extra;
}

=head2 Open311
=over 1
=item * Fetched reports via Open311 use the service name as their title
=cut

sub open311_title_fetched_report {
my ($self, $request) = @_;
return $request->{service_name};
}

1;

=back
2 changes: 2 additions & 0 deletions perllib/FixMyStreet/Cobrand/UK.pm
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,8 @@ sub _updates_disallowed_check {
return $cfg unless !$body_comment_user && $open;
} elsif ($cfg eq 'reporter-not-open/staff-open') {
return $cfg unless ( $reporter && !$open ) || ( $staff && $open );
} elsif ($cfg eq 'reporter/staff/notopen311-open') {
return $cfg unless ($reporter || $staff) && !$body_comment_user && $open;
}
return '';
}
Expand Down
12 changes: 12 additions & 0 deletions perllib/FixMyStreet/DB/Result/Problem.pm
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,18 @@ __PACKAGE__->has_many(
{ cascade_copy => 0, cascade_delete => 0 },
);

__PACKAGE__->has_many(
answered_questionnaires => "FixMyStreet::DB::Result::Questionnaire",
sub {
my $args = shift;
return {
"$args->{foreign_alias}.problem_id" => { -ident => "$args->{self_alias}.id" },
"$args->{foreign_alias}.whenanswered" => { '!=' => undef },
};
},
{ cascade_copy => 0, cascade_delete => 0 },
);

__PACKAGE__->might_have(
contributed_by => "FixMyStreet::DB::Result::User",
sub {
Expand Down
17 changes: 14 additions & 3 deletions perllib/FixMyStreet/Reporting.pm
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,9 @@ sub _csv_parameters_problems {
my $self = shift;

my $groups = $self->cobrand->enable_category_groups ? 1 : 0;
my $join = ['confirmed_comments'];
my $columns = ['confirmed_comments.id', 'confirmed_comments.problem_state', 'confirmed_comments.confirmed', 'confirmed_comments.mark_fixed'];
my $join = ['confirmed_comments', 'answered_questionnaires'];
my $columns = ['confirmed_comments.id', 'confirmed_comments.problem_state', 'confirmed_comments.confirmed', 'confirmed_comments.mark_fixed',
'answered_questionnaires.id', 'answered_questionnaires.whenanswered', 'answered_questionnaires.new_state'];
if ($groups) {
push @$join, 'contact';
push @$columns, 'contact.id', 'contact.extra';
Expand Down Expand Up @@ -288,7 +289,7 @@ sub generate_csv {
? '(anonymous)' : $obj->name;

if ($asked_for{acknowledged}) {
my @updates = $obj->comments->all;
my @updates = $obj->confirmed_comments->all;
@updates = sort { $a->confirmed <=> $b->confirmed || $a->id <=> $b->id } @updates;
for my $comment (@updates) {
next unless $comment->problem_state || $comment->mark_fixed;
Expand All @@ -303,6 +304,16 @@ sub generate_csv {
last;
}
}
my @questionnaires = $obj->answered_questionnaires->all;
@questionnaires = sort { $a->whenanswered <=> $b->whenanswered || $a->id <=> $b->id } @questionnaires;
for my $questionnaire (@questionnaires) {
my $problem_state = $questionnaire->new_state || '';
if ($fixed_states->{ $problem_state }) {
if (!$hashref->{fixed} || $questionnaire->whenanswered lt $hashref->{fixed}) {
$hashref->{fixed} = $questionnaire->whenanswered;
}
}
}
}

if ($asked_for{wards}) {
Expand Down
30 changes: 28 additions & 2 deletions perllib/FixMyStreet/Script/CSVExport.pm
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ sub process_body {
$hashref = initial_hashref($obj, $cobrand, $children);
}
process_comment($hashref, $obj);
process_questionnaire($hashref, $obj);
if (my $fn = $reporting->csv_extra_data) {
my $extra = $fn->($obj, $hashref);
$hashref = { %$hashref, %$extra };
Expand Down Expand Up @@ -176,8 +177,10 @@ sub generate_sql {
"to_json(date_trunc('second', me.created))#>>'{}' as created",
"to_json(date_trunc('second', me.confirmed))#>>'{}' as confirmed",
"to_json(date_trunc('second', me.whensent))#>>'{}' as whensent",
# Fetch the relevant bits of comments we need for timestamps
# Fetch the relevant bits of comments and questionnaires we need for timestamps
"comments.id as comment_id, comments.problem_state, to_json(date_trunc('second', comments.confirmed))#>>'{}' as comment_confirmed, comments.mark_fixed",
"questionnaire.id as questionnaire_id, questionnaire.new_state as questionnaire_new_state",
"to_json(date_trunc('second', questionnaire.whenanswered))#>>'{}' as questionnaire_whenanswered",
# Older reports did not store the group on the report, so fetch it from contacts
"contact.extra->'group' AS group",
# Fetch any relevant staff user and their roles
Expand All @@ -200,6 +203,7 @@ EOF
'"comment" "comments" ON "comments"."problem_id" = "me"."id" AND "comments"."state" = \'confirmed\'',
'"users" "contributed_by_user" ON "contributed_by_user"."id" = ("me"."extra"->>\'contributed_by\')::integer',
'staff_roles ON contributed_by_user.id = staff_roles.user_id',
'questionnaire ON questionnaire.problem_id = me.id AND questionnaire.whenanswered IS NOT NULL',
);

if ($EXTRAS->{reassigned}{$cobrand->moniker}) {
Expand Down Expand Up @@ -311,10 +315,32 @@ sub process_comment {
return if $problem_state eq 'confirmed';
$hashref->{acknowledged} //= $obj->{comment_confirmed};
$hashref->{action_scheduled} //= $problem_state eq 'action scheduled' ? $obj->{comment_confirmed} : undef;
$hashref->{fixed} //= $fixed_states->{ $problem_state } || $obj->{mark_fixed} ? $obj->{comment_confirmed} : undef;
if ($fixed_states->{ $problem_state } || $obj->{mark_fixed}) {
if (!$hashref->{fixed} || $obj->{comment_confirmed} lt $hashref->{fixed}) {
$hashref->{fixed} = $obj->{comment_confirmed};
}
}
if ($closed_states->{ $problem_state }) {
$hashref->{closed} = $obj->{comment_confirmed};
}
}


=head2 process_questionnaire
Given a result row, look at the questionnaire entry to see if we need to set any
row timestamps.
=cut

sub process_questionnaire {
my ($hashref, $obj) = @_;
my $new_state = $obj->{questionnaire_new_state} || '';
if ($fixed_states->{$new_state}) {
if (!$hashref->{fixed} || $obj->{comment_confirmed} lt $hashref->{fixed}) {
$hashref->{fixed} = $obj->{questionnaire_whenanswered};
}
}
}

1;
26 changes: 23 additions & 3 deletions t/cobrand/bexley.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use Test::MockTime qw(:all);
use Test::Output;
use File::Temp 'tempdir';
use FixMyStreet::TestMech;
use FixMyStreet::Script::CSVExport;
use FixMyStreet::Script::Reports;
use FixMyStreet::SendReport::Open311;
use Catalyst::Test 'FixMyStreet::App';
Expand Down Expand Up @@ -266,17 +267,36 @@ FixMyStreet::override_config {
is $c->param('service_code'), 'StreetLightingLAMP', 'Report resent';
};

subtest 'extra CSV columns present' => sub {
subtest 'extra CSV columns present, and questionnaire answers work' => sub {
my $report = FixMyStreet::DB->resultset("Problem")->first;
my $fly = FixMyStreet::DB->resultset("Problem")->search({ category => 'Flytipping' })->single;
$fly->update({ confirmed => $fly->confirmed->clone->subtract(days => 2), state => 'fixed - user' });

FixMyStreet::DB->resultset("Questionnaire")->create({
problem => $fly,
whensent => $fly->confirmed,
whenanswered => $fly->confirmed->clone->add(hours => 1),
old_state => 'confirmed',
new_state => 'fixed - user',
});

$mech->get_ok('/dashboard?export=1');
$mech->content_contains(',Category,Subcategory,');
$mech->content_contains('"Danger things","Something dangerous"');
$mech->content_contains(',"User Email"');
$mech->content_contains(',' . $report->user->email);
$mech->content_like(qr/Flytipping,,[^,]*,2019-10-14T17:00:00,,2019-10-14T18:00:00,,"fixed - user"/);

my $report = FixMyStreet::DB->resultset("Problem")->first;
FixMyStreet::Script::CSVExport::process(dbh => FixMyStreet::DB->schema->storage->dbh);

$mech->get_ok('/dashboard?export=1');
$mech->content_contains(',Category,Subcategory,');
$mech->content_contains('"Danger things","Something dangerous"');
$mech->content_contains(',"User Email"');
$mech->content_contains(',' . $report->user->email);
$mech->content_like(qr/Flytipping,,[^,]*,2019-10-14T17:00:00,,2019-10-14T18:00:00,,"fixed - user"/);
};


subtest 'testing special Open311 behaviour', sub {
my @reports = $mech->create_problems_for_body( 1, $body->id, 'Test', {
category => 'Flooding in the road', cobrand => 'bexley',
Expand Down
2 changes: 2 additions & 0 deletions templates/web/base/report/_council_sent_info.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
[%- ELSIF c.cobrand.moniker == 'surrey' %]
[% # don't display anything - problem.can_display_external_id not set so external id will not show either %]
[%- ELSIF c.cobrand.moniker == 'nottinghamshirepolice' %]
[%- ELSIF c.cobrand.moniker == 'surrey' %]
[% # don't display anything - problem.can_display_external_id not set so external id will not show either %]
[%- ELSIF problem.cobrand_data == 'waste' %]
[%- tprintf('WasteWorks ref:&nbsp;%s', problem.id) %].
[%- ELSE %]
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 5 additions & 5 deletions web/cobrands/surrey/base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ input {
input[type="text"],
textarea {
color: #222; // requested by Surrey
font-size: 1.175rem;
// workaround for Edge bug where autocomplete text is white
// https://stackoverflow.com/questions/78490541/how-do-i-override-the-being-autocompleted-input-color-in-microsoft-edge
-webkit-text-fill-color: #222;
font-size: 1.175rem;
}


Expand Down Expand Up @@ -110,8 +110,8 @@ input.form-error, textarea.form-error {
}

/* BUTTONS */
.btn-primary,
.btn--primary,
.btn-primary,
.btn--primary,
.postcode-form-box input#sub,
.mappage .btn{
@include button-variant($bg-top: $button-primary-bg-top, $bg-bottom: $button-primary-bg-bottom, $border: $button-primary-border, $text: $button-primary-text, $hover-bg-bottom: $button-primary-hover-bg-bottom, $hover-bg-top: $button-primary-hover-bg-top, $hover-border: $button-primary-hover-border, $hover-text: $button-primary-hover-text,$focus-bg-bottom: $button-primary-focus-bg-bottom, $focus-bg-top: $button-primary-focus-bg-top, $focus-border: $button-primary-focus-border, $focus-text: $button-primary-focus-text);
Expand All @@ -126,8 +126,8 @@ input.form-error, textarea.form-error {
}
}

.btn--secondary,
.btn-secondary,
.btn--secondary,
.btn-secondary,
.nav-menu a.btn-secondary,
a#geolocate_link,
.my-account-buttons a{
Expand Down

0 comments on commit 4342066

Please sign in to comment.