fixmystreet icon indicating copy to clipboard operation
fixmystreet copied to clipboard

Wrong user displayed in assignment dropdown when actual user is anonymised

Open jonkri opened this issue 1 year ago • 1 comments

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:

  1. Make sure there are at least two body users
  2. Assign one of the users to a report
  3. Remove the assigned user's account
  4. Visit the report from Step 1
  5. 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.

jonkri avatar Feb 21 '24 11:02 jonkri

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.

davea avatar Jun 25 '24 10:06 davea

Option 2 would work for us!

jonkri avatar Jul 07 '24 09:07 jonkri

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).

dracos avatar Jul 09 '24 17:07 dracos