Skip to content

Commit

Permalink
Add requirement for PVB_REQUESTS role to application
Browse files Browse the repository at this point in the history
  • Loading branch information
starswan committed Jul 14, 2021
1 parent 771ac0c commit 0c36a51
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 7 deletions.
10 changes: 9 additions & 1 deletion app/models/signon_identity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class SignonIdentity
class InvalidSessionData < RuntimeError; end

ADMIN_ROLE = 'ROLE_PVB_ADMIN'
REQUEST_ROLE = 'ROLE_PVB_REQUESTS'

class << self
def from_omniauth(omniauth_auth)
Expand Down Expand Up @@ -92,7 +93,14 @@ def logout_url(redirect_to: nil)
end

def accessible_estates
@accessible_estates ||= estate_sso_mapper.accessible_estates.order(:nomis_id).to_a
@accessible_estates ||= begin
# Ensure that user has at least one valid role
if @roles.select { |role| [ADMIN_ROLE, REQUEST_ROLE].include?(role) }.empty?
[]
else
estate_sso_mapper.accessible_estates.order(:nomis_id).to_a
end
end
end

def accessible_estates?(estates)
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/sessions_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
{
'user_id' => user.id,
'full_name' => 'Joe Bloggs',
'roles' => [],
'roles' => [SignonIdentity::REQUEST_ROLE],
'logout_url' => 'http://example.com/logout',
'organisations' => [estate_nomis_id]
}
Expand Down
12 changes: 10 additions & 2 deletions spec/models/signon_identity_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
'organisations' => organisations,
'first_name' => 'Joe',
'last_name' => 'Bloggs',
'roles' => []
'roles' => [SignonIdentity::REQUEST_ROLE]
}
end

Expand Down Expand Up @@ -127,7 +127,7 @@
let!(:swansea_org_name) { 'swansea.noms' }
let!(:swansea_estate) { create(:estate, sso_organisation_name: swansea_org_name, nomis_id: 'SWI') }
let!(:orgs) { [swansea_estate, cardiff_estate] }
let!(:roles) { [] }
let!(:roles) { [SignonIdentity::REQUEST_ROLE] }
let!(:serialization) do
{
'user_id' => user.id,
Expand Down Expand Up @@ -168,6 +168,14 @@
expect(subject.accessible_estates).to include(pentonville_estate)
end
end

context 'without the role' do
let(:roles) { [] }

it 'has no estates' do
expect(subject.accessible_estates).to eq([])
end
end
end

it 'builds the logout url required for SSO' do
Expand Down
2 changes: 1 addition & 1 deletion spec/shared_process_setup_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def choose_date
'organisations' => [
vst.prison.estate.nomis_id
],
'roles' => [],
'roles' => [SignonIdentity::REQUEST_ROLE],
}
}
end
Expand Down
2 changes: 1 addition & 1 deletion spec/support/helpers/controller_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def login_user(user, current_estates:, available_estates: [current_estates.first
sso_identity = SignonIdentity.new(
user,
full_name: FFaker::Name.name,
roles: [],
roles: [SignonIdentity::REQUEST_ROLE],
logout_url: '',
organisations: orgs
)
Expand Down
2 changes: 1 addition & 1 deletion spec/support/helpers/service_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def simulate_api_error_for(api, exception_class = Nomis::APIError)
end

# allow feature tests to login for specific prisons
def prison_login(estates, email_address = 'joe@example.com', roles = [])
def prison_login(estates, email_address = 'joe@example.com', roles = [SignonIdentity::REQUEST_ROLE])
sso_response =
{
'uid' => '1234-1234-1234-1234',
Expand Down

0 comments on commit 0c36a51

Please sign in to comment.