Skip to content

Commit

Permalink
[FMS] Make sure contributed_by recorded if not logged in
Browse files Browse the repository at this point in the history
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.

mysociety/societyworks#4234
  • Loading branch information
dracos authored and MorayMySoc committed Jun 7, 2024
1 parent 818a840 commit acf3c69
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
8 changes: 8 additions & 0 deletions perllib/FixMyStreet/App/Controller/Report/New.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
Expand Down
21 changes: 21 additions & 0 deletions t/cobrand/brent.t
Original file line number Diff line number Diff line change
Expand Up @@ -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 => '[email protected]', group => 'Parks and open spaces');
my $user1 = $mech->create_user_ok('[email protected]', 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('[email protected]', 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('[email protected]') } }, '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) {
Expand Down

0 comments on commit acf3c69

Please sign in to comment.