CLDC-3404 Allow support to update user organisation (#2596)
* Allow support to change user organisation
* Redirect to log-reassignment page when updating organisation
* Add log reassignment page
* Allow setting log reassignment choice
* Add organisation change confirmation page
* Update logs based on log reassignment selection
* Skip log reassignment question if user has no logs
* Send organisation update email
* Update routes in accessibility tests
* Allo moving deactivated users
* Move org field above role
* Only display banner if email has changed
* rescue StandardError
* Only reassign visible logs
* Clean user error messages
* Update pluralization in email
* Mark related bulk uploads as cancelled by user
* Add moved user banner
* Update routing for fix-choice page
* Update pluralization again
reassigned_logs_text="There #{assigned_logs_count} assigned to you. The stock owner and managing agent on #{logs_count==1?'this log':'these logs'} has been changed from #{current_organisation.name} to #{new_organisation.name}."
when"reassign_stock_owner"
reassigned_logs_text="There #{assigned_logs_count} assigned to you. The stock owner on #{logs_count==1?'this log':'these logs'} has been changed from #{current_organisation.name} to #{new_organisation.name}."
when"reassign_managing_agent"
reassigned_logs_text="There #{assigned_logs_count} assigned to you. The managing agent on #{logs_count==1?'this log':'these logs'} has been changed from #{current_organisation.name} to #{new_organisation.name}."
when"unassign"
reassigned_logs_text="There #{assigned_logs_count} assigned to you. #{logs_count==1?'This':'These'} have now been unassigned."
<% if current_user.id == @bulk_upload.moved_user_id %>
You moved to a different organisation since this file was uploaded. Reupload the file to get an accurate error report.
<% else %>
Some logs in this upload are assigned to <%= @bulk_upload.moved_user_name %>, who has moved to a different organisation since this file was uploaded. Reupload the file to get an accurate error report.
expected_text="You’re moving #{user.name} from #{user.organisation.name} to #{current_user.organisation.name}. The stock owner and managing agent on their logs will change to #{current_user.organisation.name}."
expected_text="You’re moving #{user.name} from #{user.organisation.name} to #{current_user.organisation.name}. The stock owner on their logs will change to #{current_user.organisation.name}."
expected_text="You’re moving #{user.name} from #{user.organisation.name} to #{current_user.organisation.name}. The managing agent on their logs will change to #{current_user.organisation.name}."
reassigned_logs_text:"There are 2 logs assigned to you. The stock owner and managing agent on these logs has been changed from #{user.organisation.name} to #{new_organisation.name}.",
reassigned_logs_text:"There are 2 logs assigned to you. The stock owner on these logs has been changed from #{user.organisation.name} to #{new_organisation.name}.",
reassigned_logs_text:"There are 2 logs assigned to you. The managing agent on these logs has been changed from #{user.organisation.name} to #{new_organisation.name}.",
expect(response.body).toinclude("This error report is out of date.")
expect(response.body).toinclude("Some logs in this upload are assigned to #{user.name}, who has moved to a different organisation since this file was uploaded. Reupload the file to get an accurate error report.")
end
end
context"and bulk upload has been cancelled by the current moved user"do
expect(response.body).toinclude("This error report is out of date.")
expect(response.body).toinclude("You moved to a different organisation since this file was uploaded. Reupload the file to get an accurate error report.")
end
end
end
end
@ -107,5 +129,28 @@ RSpec.describe BulkUploadLettingsResultsController, type: :request do
expect(response).tobe_not_found
end
end
context"and bulk upload has been cancelled by not the current moved user"do
expect(response.body).toinclude("This error report is out of date.")
expect(response.body).toinclude("Some logs in this upload are assigned to #{other_user.name}, who has moved to a different organisation since this file was uploaded. Reupload the file to get an accurate error report.")
end
end
context"and bulk upload has been cancelled by the current moved user"do
expect(response.body).toinclude("This error report is out of date.")
expect(response.body).toinclude("You moved to a different organisation since this file was uploaded. Reupload the file to get an accurate error report.")
expect(response.body).toinclude("This error report is out of date.")
expect(response.body).toinclude("Some logs in this upload are assigned to #{user.name}, who has moved to a different organisation since this file was uploaded. Reupload the file to get an accurate error report.")
end
end
context"and bulk upload has been cancelled by the current moved user"do
expect(response.body).toinclude("This error report is out of date.")
expect(response.body).toinclude("You moved to a different organisation since this file was uploaded. Reupload the file to get an accurate error report.")
expect(response.body).toinclude("This error report is out of date.")
expect(response.body).toinclude("Some logs in this upload are assigned to #{other_user.name}, who has moved to a different organisation since this file was uploaded. Reupload the file to get an accurate error report.")
end
end
context"and bulk upload has been cancelled by the current moved user"do
expect(response.body).toinclude("This error report is out of date.")
expect(response.body).toinclude("You moved to a different organisation since this file was uploaded. Reupload the file to get an accurate error report.")
expect(page).tohave_content("New org must be a stock owner of #{other_user.organisation_name}, #{new_organisation_2.name}, and #{new_organisation_3.name} to make this change.")
end
end
end
context"and log reassignment choice is to change managing agent"do
expect(page).tohave_content("New org must be a managing agent of #{other_user.organisation_name}, #{new_organisation_2.name}, and #{new_organisation_3.name} to make this change.")
end
end
end
end
@ -2194,6 +2423,151 @@ RSpec.describe UsersController, type: :request do
expect(page).tohave_content("Are you sure you want to move this user?")
expect(page).tohave_content("You’re moving #{other_user.name} from #{other_user.organisation_name} to #{new_organisation.name}. The stock owner and managing agent on their logs will change to #{new_organisation.name}.")