Skip to content

Commit

Permalink
Fix CSV export category substring matching.
Browse files Browse the repository at this point in the history
  • Loading branch information
dracos committed Aug 16, 2024
1 parent 090c9cd commit 5340ad0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
15 changes: 6 additions & 9 deletions perllib/FixMyStreet/Reporting.pm
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,10 @@ sub filter_premade_csv {
formatter => FixMyStreet::DB->schema->storage->datetime_parser,
);

my $all_states = $self->cobrand->call_hook('dashboard_export_include_all_states');
my $wards_re = join ('|', @{$self->wards});
my $category_re = join('|', map { quotemeta } @{$self->category});

my $csv = Text::CSV->new({ binary => 1, eol => "\n" });
open my $fh, "<:encoding(utf8)", $self->premade_csv_filename;
my $arr = $csv->getline($fh);
Expand All @@ -477,24 +481,17 @@ sub filter_premade_csv {
# Perform the same filtering as what construct_rs_filter does
# by skipping rows from the CSV file that do not match

if (@{$self->wards}) {
my $match = 0;
foreach (@{$self->wards}) {
$match = 1 if $row->{Areas} =~ /,$_,/;
}
next unless $match;
}
next if $wards_re && $row->{Areas} !~ /,($wards_re),/;

my $category = $row->{Subcategory} || $row->{Category};
next if @{$self->category} && !grep { /\Q$category\E/ } @{$self->category};
next if @{$self->category} && $category !~ /^($category_re)$/;

if ( $self->state && $fixed_states->{$self->state} ) { # Probably fixed - council
next unless $fixed_states->{$row->{$state_column}};
} elsif ( $self->state ) {
next if $row->{$state_column} ne $self->state;
}

my $all_states = $self->cobrand->call_hook('dashboard_export_include_all_states');
if ($all_states) {
# Has to use created, because unconfirmed ones won't have a confirmed timestamp
next if $row->{Created} lt $range->start_formatted;
Expand Down
4 changes: 3 additions & 1 deletion t/cobrand/brent.t
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,11 @@ my $staff_user = $mech->create_user_ok('[email protected]', from_body => $brent,
$staff_user->user_roles->find_or_create({ role_id => $role->id });

subtest 'role report shows staff problem when staff logged in during problem reporting process' => sub {
my $UPLOAD_DIR = tempdir( CLEANUP => 1 );
FixMyStreet::override_config {
ALLOWED_COBRANDS => ['brent'],
ALLOWED_COBRANDS => 'brent',
MAPIT_URL => 'http://mapit.uk/',
PHOTO_STORAGE_OPTIONS => { UPLOAD_DIR => $UPLOAD_DIR },
}, sub {
$mech->get_ok("/report/new?longitude=-0.28168&latitude=51.55904");
$mech->submit_form_ok( { with_fields => { category => 'Graffiti', title => 'Spraypaint on wall', detail => 'Some kind of picture', name => 'Staff User', username_register => $mech->uniquify_email('[email protected]') } }, 'Staff user logs in whilst making report' );
Expand Down

0 comments on commit 5340ad0

Please sign in to comment.