Skip to content

Commit

Permalink
Merge pull request #352 from goinvo/fermion/fix-redirects
Browse files Browse the repository at this point in the history
Fixing redirects
  • Loading branch information
fermion authored Oct 16, 2024
2 parents edd9681 + ce3e931 commit b496e34
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 13 deletions.
10 changes: 10 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,14 @@ def set_paper_trail_whodunnit
return unless current_user
PaperTrail.request.whodunnit = current_user.id
end

def my_staffplan_url
case Rails.env
when "production"
"https://ui.staffplan.com/people/#{current_user.id}"
else
"http://localhost:8080/people/#{current_user.id}"
end
end
helper_method :my_staffplan_url
end
1 change: 1 addition & 0 deletions app/controllers/dashboard_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ class DashboardController < ApplicationController
before_action :require_user!

def show
redirect_to my_staffplan_url, allow_other_host: true
end

def switch_account
Expand Down
10 changes: 10 additions & 0 deletions app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,14 @@ def require_params
redirect_to auth_sign_in_url, alert: "Sorry, please try that again."
end
end

def my_staffplan_url(current_user)
case Rails.env
when "production"
"https://ui.staffplan.com/people/#{current_user.id}"
else
"http://localhost:8080/people/#{current_user.id}"
end
end
helper_method :my_staffplan_url
end
3 changes: 2 additions & 1 deletion app/controllers/settings/subscriptions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def new
render json: { 'error': { message: e.message } }, status: 400 and return
end

redirect_to session.url, status: 303, allow_other_host: true
# allow_other_host will be true if redirecting to *stripe.com
redirect_to session.url, status: 303, allow_other_host: session.url.match(/https:\/\/.*stripe\.com/)
end
end
7 changes: 7 additions & 0 deletions app/controllers/settings_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class SettingsController < ApplicationController

before_action :require_user!
def show
redirect_to settings_profile_url
end
end
6 changes: 3 additions & 3 deletions config/initializers/passwordless.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
config.timeout_at = lambda { 10.minutes.from_now } # How long until a token/magic link times out.

config.redirect_back_after_sign_in = true # When enabled the user will be redirected to their previous page, or a page specified by the `destination_path` query parameter, if available.
config.redirect_to_response_options = {} # Additional options for redirects.
config.success_redirect_path = '/' # After a user successfully signs in
config.redirect_to_response_options = {}
config.success_redirect_path = "/"
config.failure_redirect_path = '/' # After a sign in fails
config.sign_out_redirect_path = '/' # After a user signs out
config.paranoid = true
end
end
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

resource :avatars, only: [:destroy]

resource :settings, only: [:show, :update], controller: "settings" do
resource :settings do
resource :company, only: [:show, :update], controller: "settings/company"
resource :billing_information, only: [:show, :edit, :update], controller: "settings/billing_information"
resource :subscription, only: [:new], controller: "settings/subscriptions"
Expand Down
6 changes: 3 additions & 3 deletions spec/system/authentications_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
click_button "Sign in"
fill_in "passwordless[token]", with: token
click_button "Confirm"
expect(page).to have_current_path(root_path)
expect(page).to have_current_path("/people/#{user.id}")
end

it "signs them in after clicking the link in the email" do
Expand All @@ -63,7 +63,7 @@

# click the link in the email
visit confirm_auth_sign_in_path(user.passwordless_sessions.last.identifier, token)
expect(page).to have_current_path(root_path)
expect(page).to have_current_path("/people/#{user.id}")
end
end

Expand All @@ -90,7 +90,7 @@
click_button "Sign in"
fill_in "passwordless[token]", with: token
click_button "Confirm"
expect(page).to have_current_path(root_path)
expect(page).to have_current_path("/people/#{user.id}")

# sign yourself out
visit auth_sign_out_path
Expand Down
5 changes: 2 additions & 3 deletions spec/system/signup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,8 @@
it "should confirm the registration and sign the user in" do
registration = create(:registration)
visit register_registration_path(registration.reload, token: registration.token)

expect(page).to have_current_path(root_path)
expect(page).to have_content("Thanks for registering! You're now signed in.")
user = User.find_by!(email: registration.email)
expect(page).to have_current_path("/people/#{user.id}")
end

it "should mark the registration as having registered?" do
Expand Down
4 changes: 2 additions & 2 deletions spec/system/user_management_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

visit settings_users_url

expect(page).to have_current_path(root_path)
expect(page).to have_current_path("/people/#{membership.user_id}")
end
end

Expand Down Expand Up @@ -69,4 +69,4 @@
expect(page).to have_text("Email is invalid")
end
end
end
end

0 comments on commit b496e34

Please sign in to comment.