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

Redirect to credentials tab when AO creates credential #2338

Merged
merged 5 commits into from
Dec 2, 2024
Merged
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div>
<div class="margin-bottom-5">&larr; <%= link_to organization.name, organization_path(organization.path_id) %></div>
<div class="margin-bottom-5">&larr; <%= link_to organization.name, organization_path(organization, credential_start: :true) %></div>
<h1>Client token created</h1>
<div>
<h2>"<%= client_token['label'] %>" created for <%= organization.name %></h2>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ module Page
module Organization
# Shows tabbed credential delegates and credentials
class CompoundShowComponent < ViewComponent::Base
def initialize(organization, cd_invitations, expired_cd_invitations, credential_delegates, show_cds)
def initialize(organization, delegate_information, credential_start)
super
@links = [['User Access', '#credential_delegates', true],
['Credentials', '#credentials', false]]
@links = [['User Access', '#credential_delegates', !credential_start],
['Credentials', '#credentials', credential_start]]
@organization = organization
@active_credential_delegates = credential_delegates
@pending_credential_delegates = cd_invitations
@expired_cd_invitations = expired_cd_invitations
@show_cds = show_cds
@active_credential_delegates = delegate_information[:active]
@pending_credential_delegates = delegate_information[:pending]
@expired_cd_invitations = delegate_information[:expired]
@show_cds = !delegate_information.empty?
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ module Organization
class CompoundShowComponentPreview < ViewComponent::Preview
def authorized_official
org = ProviderOrganization.new(name: 'Health Hut', npi: '1111111111', id: 2)
render(Page::Organization::CompoundShowComponent.new(org, [], [], [], true))
render(Page::Organization::CompoundShowComponent.new(org, { active: [], pending: [], expired: [] }))
end

def credential_delegate
org = ProviderOrganization.new(name: 'Health Hut', npi: '1111111111', id: 2)
render(Page::Organization::CompoundShowComponent.new(org, [], [], [], false))
render(Page::Organization::CompoundShowComponent.new(org, {}))
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions dpc-portal/app/controllers/ip_addresses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def create
if new_ip_address[:response]
log_credential_action(:ip_address, new_ip_address.dig(:message, 'id'), :add)
flash[:notice] = 'IP address successfully created.'
redirect_to organization_path(@organization)
redirect_to organization_path(@organization, credential_start: true)
else
@errors = new_ip_address[:errors] || {}
flash[:alert] = @errors[:root] || 'IP address invalid'
Expand All @@ -35,7 +35,7 @@ def destroy
else
flash[:alert] = manager.errors[:root] || 'IP address could not be deleted.'
end
redirect_to organization_path(@organization)
redirect_to organization_path(@organization, credential_start: true)
end
# rubocop:enable Metrics/AbcSize
end
20 changes: 10 additions & 10 deletions dpc-portal/app/controllers/organizations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ def index
end

def show
show_cds = current_user.ao?(@organization)
if show_cds
@delegate_information = {}
if current_user.ao?(@organization)
# Invitation expiration is determined in relation to the `created_at` field; the `status` field will
# never be `'expired'`. Therefore, we need to further filter out expired invitations from this query.
@pending_invitations = Invitation.where(provider_organization: @organization,
invited_by: current_user,
status: :pending).reject(&:expired?)
@expired_invitations = Invitation.where(provider_organization: @organization,
invited_by: current_user).select(&:expired?)
@cds = CdOrgLink.where(provider_organization: @organization, disabled_at: nil)
@delegate_information[:pending] = Invitation.where(provider_organization: @organization,
invited_by: current_user,
status: :pending).reject(&:expired?)
@delegate_information[:expired] = Invitation.where(provider_organization: @organization,
invited_by: current_user).select(&:expired?)
@delegate_information[:active] = CdOrgLink.where(provider_organization: @organization, disabled_at: nil)
end
render(Page::Organization::CompoundShowComponent.new(@organization, @pending_invitations, @expired_invitations,
@cds, show_cds))
render(Page::Organization::CompoundShowComponent.new(@organization, @delegate_information,
params[:credential_start]))
end

def new
Expand Down
4 changes: 2 additions & 2 deletions dpc-portal/app/controllers/public_keys_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def create
if new_public_key[:response]
log_credential_action(:public_key, new_public_key.dig(:message, 'id'), :add)
flash[:notice] = 'Public key successfully created.'
redirect_to organization_path(@organization)
redirect_to organization_path(@organization, credential_start: true)
else
@errors = new_public_key[:errors]
render_error @errors[:root] || 'Invalid encoding'
Expand All @@ -38,7 +38,7 @@ def destroy
if manager.delete_public_key(params)
log_credential_action(:public_key, params[:id], :remove)
flash[:notice] = 'Public key successfully deleted.'
redirect_to organization_path(@organization)
redirect_to organization_path(@organization, credential_start: true)
else
flash[:alert] = 'Public key could not be deleted.'
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
let(:expected_html) do
<<~HTML
<div>
<div class="margin-bottom-5">← <a href="/portal/organizations/#{org.path_id}">#{org.name}</a></div>
<div class="margin-bottom-5">← <a href="/portal/organizations/#{org.path_id}?credential_start=true">#{org.name}</a></div>
<h1>Client token created</h1>
<div>
<h2>"Your token" created for #{org.name}</h2>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,51 @@
normalize_space(rendered_content)
end
let(:org) { build(:provider_organization, name: 'Health Hut', npi: '11111111', id: 2) }
let(:component) { described_class.new(org, [], [], [], show_cds) }
let(:component) { described_class.new(org, delegate_info, credential_start) }

before do
render_inline(component)
end

context 'show cds' do
let(:show_cds) { true }
it 'Should have org name' do
is_expected.to include("<h1>#{org.name}</h1>")
end
it 'Should have npi' do
is_expected.to include(%(<div class="margin-bottom-5">NPI: #{org.npi}</div>))
context 'cd tab' do
let(:delegate_info) { { active: [], pending: [], expired: [] } }
context 'credential delegate start' do
let(:credential_start) { false }
it 'Should have org name' do
is_expected.to include("<h1>#{org.name}</h1>")
end
it 'Should have npi' do
is_expected.to include(%(<div class="margin-bottom-5">NPI: #{org.npi}</div>))
end
it 'Should have script tag' do
is_expected.to include('<script')
end
it 'Should have header tag' do
is_expected.to include('<header')
end
it 'Should have credential delegates' do
is_expected.to include('<div id="credential_delegates">')
end
it 'Should have credentials' do
is_expected.to include('<div id="credentials">')
end
it 'Should start on credential delegate page' do
is_expected.to include('}make_current(0);')
is_expected.to_not include('}make_current(1);')
end
end
it 'Should have script tag' do
is_expected.to include('<script')
end
it 'Should have header tag' do
is_expected.to include('<header')
end
it 'Should have credential delegates' do
is_expected.to include('<div id="credential_delegates">')
end
it 'Should have credentials' do
is_expected.to include('<div id="credentials">')
context 'credential start' do
let(:credential_start) { true }
it 'Should start on credential page' do
is_expected.to_not include('}make_current(0);')
is_expected.to include('}make_current(1);')
end
end
end

context 'not show cds' do
let(:show_cds) { false }
context 'credentials tab' do
let(:delegate_info) { {} }
let(:credential_start) { true }
it 'Should have org name' do
is_expected.to include("<h1>#{org.name}</h1>")
end
Expand Down
5 changes: 3 additions & 2 deletions dpc-portal/spec/requests/ip_addresses_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@
response: default_get_ip_addresses['entities'].first,
api_client:)
post "/organizations/#{org.id}/ip_addresses", params: { label: 'Public IP 1', ip_address: '136.226.19.87' }
expect(response).to redirect_to(organization_path(org, credential_start: true))
expect(assigns(:organization)).to eq org
end

Expand Down Expand Up @@ -258,7 +259,7 @@
api_client:)
delete "/organizations/#{org.id}/ip_addresses/#{addr_guid}"
expect(flash[:notice]).to eq('IP address successfully deleted.')
expect(response).to redirect_to(organization_path(org))
expect(response).to redirect_to(organization_path(org, credential_start: true))
end

it 'renders error if error' do
Expand All @@ -272,7 +273,7 @@
api_client:)
delete "/organizations/#{org.id}/ip_addresses/#{addr_guid}"
expect(flash[:alert]).to eq('IP address could not be deleted.')
expect(response).to redirect_to(organization_path(org))
expect(response).to redirect_to(organization_path(org, credential_start: true))
end
end
end
Expand Down
34 changes: 24 additions & 10 deletions dpc-portal/spec/requests/organizations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,20 @@
expect(assigns(:organization)).to eq org
end

it 'should start on cd tab by default' do
get "/organizations/#{org.id}"
expect(response).to be_ok
expect(response.body).to include(' make_current(0);')
expect(response.body).to_not include(' make_current(1);')
end

it 'should start on credentials tab if credential_start param' do
get "/organizations/#{org.id}", params: { credential_start: true }
expect(response).to be_ok
expect(response.body).to_not include(' make_current(0);')
expect(response.body).to include(' make_current(1);')
end

it 'shows CD list page' do
get "/organizations/#{org.id}"
expect(response.body).to include('<h2>Credential delegates</h2>')
Expand All @@ -267,62 +281,62 @@
it 'assigns if exist' do
create(:invitation, :cd, provider_organization: org, invited_by: user)
get "/organizations/#{org.id}"
expect(assigns(:pending_invitations).size).to eq 1
expect(assigns(:delegate_information)[:pending].size).to eq 1
end

it 'does not assign if not exist' do
get "/organizations/#{org.id}"
expect(assigns(:pending_invitations).size).to eq 0
expect(assigns(:delegate_information)[:pending].size).to eq 0
end

it 'does not assign if only accepted exists' do
create(:invitation, :cd, provider_organization: org, invited_by: user, status: :accepted)
get "/organizations/#{org.id}"
expect(assigns(:pending_invitations).size).to eq 0
expect(assigns(:delegate_information)[:pending].size).to eq 0
end

it 'does not assign if expired' do
create(:invitation, :cd, provider_organization: org, invited_by: user, created_at: 3.days.ago)
get "/organizations/#{org.id}"
expect(assigns(:pending_invitations).size).to eq 0
expect(assigns(:delegate_information)[:pending].size).to eq 0
end
end

context :expired_invitations do
it 'assigns if exist' do
create(:invitation, :cd, provider_organization: org, invited_by: user, created_at: 3.days.ago)
get "/organizations/#{org.id}"
expect(assigns(:expired_invitations).size).to eq 1
expect(assigns(:delegate_information)[:expired].size).to eq 1
end

it 'does not assign if not exist' do
get "/organizations/#{org.id}"
expect(assigns(:pending_invitations).size).to eq 0
expect(assigns(:delegate_information)[:pending].size).to eq 0
end

it 'does not assign if invitation is not expired' do
create(:invitation, :cd, provider_organization: org, invited_by: user)
get "/organizations/#{org.id}"
expect(assigns(:expired_invitations).size).to eq 0
expect(assigns(:delegate_information)[:expired].size).to eq 0
end
end

context :credential_delegates do
it 'assigns if exist' do
create(:cd_org_link, provider_organization: org)
get "/organizations/#{org.id}"
expect(assigns(:cds).size).to eq 1
expect(assigns(:delegate_information)[:active].size).to eq 1
end

it 'does not assign if not exist' do
get "/organizations/#{org.id}"
expect(assigns(:cds).size).to eq 0
expect(assigns(:delegate_information)[:active].size).to eq 0
end

it 'does not assign if link disabled' do
create(:cd_org_link, provider_organization: org, disabled_at: 1.day.ago)
get "/organizations/#{org.id}"
expect(assigns(:cds).size).to eq 0
expect(assigns(:delegate_information)[:active].size).to eq 0
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions dpc-portal/spec/requests/public_keys_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@
}
expect(flash[:notice]).to eq('Public key successfully created.')
expect(assigns(:organization)).to eq org
expect(response).to redirect_to(organization_path(org))
expect(response).to redirect_to(organization_path(org, credential_start: true))
end

it 'fails if missing params' do
Expand Down Expand Up @@ -257,7 +257,7 @@
api_client:)
delete "/organizations/#{org.id}/public_keys/#{key_guid}"
expect(flash[:notice]).to eq('Public key successfully deleted.')
expect(response).to redirect_to(organization_path(org))
expect(response).to redirect_to(organization_path(org, credential_start: true))
end

it 'renders error if error' do
Expand Down
Loading