From acf3c69537e867d9277f82d6b94858ee414281f3 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Fri, 24 May 2024 12:45:45 +0100 Subject: [PATCH] [FMS] Make sure contributed_by recorded if not logged in contributed_by is now set if a user logs in during report making process. Results in dashboard report now showing roles filter correctly when staff user logs in as part of report making process. https://github.com/mysociety/societyworks/issues/4234 --- .../FixMyStreet/App/Controller/Report/New.pm | 8 +++++++ t/cobrand/brent.t | 21 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index d5dab75882c..7c1ae8c1ea7 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -1633,7 +1633,15 @@ sub process_confirmation : Private { } } } + + if ($problem->user->is_superuser || $problem->user->from_body) { + if (!$problem->get_extra_metadata('contributed_by')) { + $problem->set_extra_metadata( contributed_by => $problem->user->id ); + $problem->update; + } + } } + # log the problem creation user in to the site if ($problem->user->email_verified) { $c->authenticate( { email => $problem->user->email, email_verified => 1 }, 'no_password' ); diff --git a/t/cobrand/brent.t b/t/cobrand/brent.t index 18f0cd60f3d..b110370510d 100644 --- a/t/cobrand/brent.t +++ b/t/cobrand/brent.t @@ -125,7 +125,28 @@ my $parks_contact2 = $mech->create_contact_ok(body_id => $brent->id, category => my $parks_contact3 = $mech->create_contact_ok(body_id => $brent->id, category => 'Ponds', email => 'ponds@example.org', group => 'Parks and open spaces'); my $user1 = $mech->create_user_ok('user1@example.org', email_verified => 1, name => 'User 1'); +my $role = FixMyStreet::DB->resultset("Role")->create({ + body => $brent, + name => 'Role', + permissions => ['moderate', 'user_edit'], +}); my $staff_user = $mech->create_user_ok('staff@example.org', from_body => $brent, name => 'Staff User'); +$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 { + FixMyStreet::override_config { + ALLOWED_COBRANDS => ['brent'], + MAPIT_URL => 'http://mapit.uk/', + }, 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('staff@example.org') } }, 'Staff user logs in whilst making report' ); + $mech->get_ok($mech->get_link_from_email($mech->get_email)); + $mech->get_ok('/dashboard?body=' . $brent->id . '&state=&role=' . $role->id . '&start_date=&end_date=&group_by=category+state&export=1'); + $mech->content_contains('"Spraypaint on wall","Some kind of picture"', 'Report has contributed_by set and so shows in roles report'); + $mech->clear_emails_ok; + $mech->log_out_ok; + }; +}; # Add location_name field to parks categories for my $contact ($parks_contact, $parks_contact2, $parks_contact3) {