diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 7610e7efb..e5952a80f 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -171,12 +171,21 @@ class UsersController < ApplicationController validate_log_reassignment if @user.errors.empty? - redirect_to user_confirm_organisation_change_path(@user, log_reassignment_params) + redirect_to user_organisation_change_confirmation_path(@user, log_reassignment_params) else render :log_reassignment, status: :unprocessable_entity end end + def organisation_change_confirmation + if params[:organisation_id].blank? || params[:log_reassignment].blank? || !Organisation.where(id: params[:organisation_id]).exists? + return redirect_to user_path(@user) + end + + @new_organisation = Organisation.find(params[:organisation_id]) + @log_reassignment = params[:log_reassignment] + end + private def validate_attributes diff --git a/app/helpers/user_helper.rb b/app/helpers/user_helper.rb index c80264203..6b11fc4d4 100644 --- a/app/helpers/user_helper.rb +++ b/app/helpers/user_helper.rb @@ -21,4 +21,24 @@ module UserHelper "You’re moving #{user.name} from #{user.organisation.name} to #{new_organisation.name}. There #{logs_count_text} assigned to them." end + + def organisation_change_confirmation_warning(user, new_organisation, log_reassignment) + log_reassignment_text = "There are no logs assigned to them." + + logs_count = user.assigned_to_lettings_logs.count + user.assigned_to_sales_logs.count + if logs_count.positive? + case log_reassignment + when "reassign_all" + log_reassignment_text = "The stock owner and managing agent on their logs will change to #{new_organisation.name}." + when "reassign_stock_owner" + log_reassignment_text = "The stock owner on their logs will change to #{new_organisation.name}." + when "reassign_managing_agent" + log_reassignment_text = "The managing agent on their logs will change to #{new_organisation.name}." + when "unassign" + log_reassignment_text = "Their logs will be unassigned." + end + end + + "You’re moving #{user.name} from #{user.organisation.name} to #{new_organisation.name}. #{log_reassignment_text}" + end end diff --git a/app/views/users/organisation_change_confirmation.html.erb b/app/views/users/organisation_change_confirmation.html.erb new file mode 100644 index 000000000..8dc56e17c --- /dev/null +++ b/app/views/users/organisation_change_confirmation.html.erb @@ -0,0 +1,24 @@ +<% content_for :before_content do %> + <% content_for :title, "Are you sure you want to move this user?" %> + <%= govuk_back_link(href: :back) %> +<% end %> + +