fixmystreet
fixmystreet copied to clipboard
Wrong user displayed in assignment dropdown when actual user is anonymised
Describe the bug
We noticed that the wrong user was being displayed in the assignment dropdown in the inspector form.
Looking in the database, we figured out that the user_id
value in user_planned_reports
referenced a user that has been anonymized.
To Reproduce
Steps to reproduce the behavior:
- Make sure there are at least two body users
- Assign one of the users to a report
- Remove the assigned user's account
- Visit the report from Step 1
- Notice that the wrong user is displayed in the assignment dropdown
Expected behavior
That the assignment dropdown displays “unassigned”.
Screenshots
N/A
Desktop (please complete the following information):
- OS: N/A
- Browser: N/A
- Version: N/A
Smartphone (please complete the following information):
- Device: N/A
- OS: N/A
- Browser: N/A
- Version: N/A
Additional context
It seems to me that the dropdown should be able to handle anonymized users or that anonymized users should be unassigned.
The former option retains more information.
Option 2 ("anonymized users should be unassigned") is the simplest - just remove all of a user's assignments when their account is anonymised. 1-2 hours to add this to User::anonymize_account
and tests.
Option 2 would work for us!
So two issues here, for a report assigned to a removed user:
- The "Assign to" dropdown doesn't have a 'not one of these' option, so if the currently selected user isn't in the dropdown (ie because they're not associated with the body any more), it will be showing the first entry in the dropdown by default. It has not selected the wrong user, it's just no user is selected at all.
- The "Shortlisted by" section will be missing a name, saying "Shortlisted by. / Adding this report to your shortlist will remove it from ’s shortlist."
Removing a user's assignments when they're anonymized will partly fix this (as in this case the report won't be assigned to anyone any more), but won't fix the issue with the dropdown where a report is e.g. assigned to a user who is no longer staff but has not been anonymized. So I think we need to fix the dropdown regardless of whether we remove when anonymized, it should always include the 'current' user even if they're not assignable to any more (or have an extra 'unassignable user' entry that is selected).