Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update: User Registration Redirect Path #1290

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions app/controllers/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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})

Expand Down
23 changes: 23 additions & 0 deletions test/controllers/registrations_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading