diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb index a803016f0..c9813c286 100644 --- a/app/controllers/registrations_controller.rb +++ b/app/controllers/registrations_controller.rb @@ -56,6 +56,16 @@ def account_update_params :avatar) end + def after_update_path_for(resource) + if User.staff.include?(resource) && resource.organization_id == Current.organization.id + return root_path unless allowed_to?(:index?, with: Organizations::DashboardPolicy, context: {organization: Current.organization}) + staff_dashboard_index_path + else + return root_path unless allowed_to?(:index?, with: Organizations::AdopterFosterDashboardPolicy, context: {organization: Current.organization}) + adopter_fosterer_dashboard_index_path + end + end + def after_sign_up_path_for(resource) return root_path unless allowed_to?(:index?, with: Organizations::AdopterFosterDashboardPolicy, context: {organization: Current.organization}) diff --git a/test/controllers/registrations_controller_test.rb b/test/controllers/registrations_controller_test.rb index 100d24c85..1b3ad0dc3 100644 --- a/test/controllers/registrations_controller_test.rb +++ b/test/controllers/registrations_controller_test.rb @@ -37,4 +37,27 @@ class RegistrationsControllerTest < ActionDispatch::IntegrationTest get edit_user_registration_url(script_name: "/#{organization.slug}") assert_select "nav.navbar-vertical", 0 end + + test "should redirect to adopter foster dashboard when updated" do + user = create(:adopter_fosterer, password: "123456") + sign_in user + + updated_params = {user: {first_name: "not the same name", current_password: "123456"}} + + put user_registration_url, params: updated_params + + assert_redirected_to adopter_fosterer_dashboard_index_url + end + + test "should redirect to staff dashboard when updated" do + user = create(:admin, password: "123456") + organization = user.organization + sign_in user + + updated_params = {user: {first_name: "Sean", current_password: "123456"}} + + put user_registration_url(script_name: "/#{organization.slug}"), params: updated_params + + assert_redirected_to staff_dashboard_index_url + end end