Skip to content

Commit

Permalink
Cherrypicking files from Dan's PR (to squash)
Browse files Browse the repository at this point in the history
  • Loading branch information
elceebee committed Dec 19, 2023
1 parent 387afe7 commit a428792
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 3 deletions.
19 changes: 19 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class ApplicationController < ActionController::Base
include ApplicationHelper
include RoutesHelper

default_form_builder(GOVUKDesignSystemFormBuilder::FormBuilder)

Expand All @@ -19,4 +20,22 @@ def current_user
def support_user
@support_user ||= sign_in_user&.support_user
end

def after_sign_in_path
return support_root_path if support_user.present?

root_path
end

def after_sign_out_path
sign_in_path
end

def authenticate_user!
return if current_user

session[:requested_path] = request.fullpath

redirect_to sign_in_path
end
end
13 changes: 13 additions & 0 deletions app/controllers/placements/support/application_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Placements::Support::ApplicationController < ApplicationController
before_action :authenticate_support_user!

private

def authenticate_support_user!
authenticate_user!

if support_user.blank?
redirect_to placements_root_path, alert: "You cannot perform this action"
end
end
end
2 changes: 1 addition & 1 deletion app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def callback
if current_user
# DfESignInUsers::Update.call(user: current_user, sign_in_user: sign_in_user)

redirect_to(root_path)
redirect_to after_sign_in_path
else
# session.delete(:requested_path)
DfESignInUser.end_session!(session)
Expand Down
19 changes: 19 additions & 0 deletions app/helpers/routes_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module RoutesHelper
def root_path
case current_service
when :claims
claims_root_path
when :placements
placements_root_path
end
end

def support_root_path
case current_service
# when :claims
# claims_support_root_path # TODO: claims support path in another PR
when :placements
placements_support_root_path
end
end
end
1 change: 0 additions & 1 deletion app/models/dfe_sign_in_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,5 @@ def support_user_klass
when :placements
Placements::SupportUser
end

end
end
5 changes: 5 additions & 0 deletions config/routes/placements.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@
host: ENV["PLACEMENTS_HOST"]
} do
root to: "pages#index"

namespace :support do
root to: redirect("/support/organisations")
resources :organisations, only: :index
end
end
4 changes: 3 additions & 1 deletion spec/factories/users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
service { "placements" }
end

factory :placements_support_user, class: "Placements::SupportUser", parent: :user do
factory :placements_support_user,
class: "Placements::SupportUser",
parent: :user do
service { "placements" }
end
end

0 comments on commit a428792

Please sign in to comment.