From abe8511b81a9b40cf104959a585b44029be37d0d Mon Sep 17 00:00:00 2001
From: jdettmannnava <145699825+jdettmannnava@users.noreply.github.com>
Date: Wed, 27 Nov 2024 15:45:49 -0500
Subject: [PATCH 1/4] refactor compound component
---
.../organization/compound_show_component.rb | 10 ++++-----
.../compound_show_component_preview.rb | 4 ++--
.../controllers/organizations_controller.rb | 19 ++++++++--------
.../compound_show_component_spec.rb | 8 +++----
.../spec/requests/client_tokens_spec.rb | 22 +++++++++++++++++++
.../spec/requests/organizations_spec.rb | 20 ++++++++---------
6 files changed, 52 insertions(+), 31 deletions(-)
diff --git a/dpc-portal/app/components/page/organization/compound_show_component.rb b/dpc-portal/app/components/page/organization/compound_show_component.rb
index 9e44bb1a4d..e6de7002bf 100644
--- a/dpc-portal/app/components/page/organization/compound_show_component.rb
+++ b/dpc-portal/app/components/page/organization/compound_show_component.rb
@@ -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)
super
@links = [['User Access', '#credential_delegates', true],
['Credentials', '#credentials', false]]
@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
diff --git a/dpc-portal/app/components/page/organization/compound_show_component_preview.rb b/dpc-portal/app/components/page/organization/compound_show_component_preview.rb
index 81b37a7dc1..997daf04fe 100644
--- a/dpc-portal/app/components/page/organization/compound_show_component_preview.rb
+++ b/dpc-portal/app/components/page/organization/compound_show_component_preview.rb
@@ -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
diff --git a/dpc-portal/app/controllers/organizations_controller.rb b/dpc-portal/app/controllers/organizations_controller.rb
index c42a0cb265..0e29462da7 100644
--- a/dpc-portal/app/controllers/organizations_controller.rb
+++ b/dpc-portal/app/controllers/organizations_controller.rb
@@ -17,19 +17,18 @@ 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))
end
def new
diff --git a/dpc-portal/spec/components/page/organization/compound_show_component_spec.rb b/dpc-portal/spec/components/page/organization/compound_show_component_spec.rb
index a52f20ca67..89e34d8d22 100644
--- a/dpc-portal/spec/components/page/organization/compound_show_component_spec.rb
+++ b/dpc-portal/spec/components/page/organization/compound_show_component_spec.rb
@@ -10,14 +10,14 @@
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) }
before do
render_inline(component)
end
- context 'show cds' do
- let(:show_cds) { true }
+ context 'has delegate information' do
+ let(:delegate_info) { { active: [], pending: [], expired: [] } }
it 'Should have org name' do
is_expected.to include("
#{org.name}
")
end
@@ -39,7 +39,7 @@
end
context 'not show cds' do
- let(:show_cds) { false }
+ let(:delegate_info) { {} }
it 'Should have org name' do
is_expected.to include("#{org.name}
")
end
diff --git a/dpc-portal/spec/requests/client_tokens_spec.rb b/dpc-portal/spec/requests/client_tokens_spec.rb
index 3188bdabd8..a7ebcf26c0 100644
--- a/dpc-portal/spec/requests/client_tokens_spec.rb
+++ b/dpc-portal/spec/requests/client_tokens_spec.rb
@@ -161,6 +161,28 @@
end
end
+ context 'as ao' do
+ let!(:user) { create(:user) }
+ let(:org_api_id) { SecureRandom.uuid }
+ let!(:org) { create(:provider_organization, terms_of_service_accepted_by:, dpc_api_organization_id: org_api_id) }
+
+ before do
+ create(:ao_org_link, provider_organization: org, user:)
+ sign_in user
+ end
+
+ it 'redirects to ' do
+ token_guid = SecureRandom.uuid
+ api_client = stub_api_client(message: :get_organization,
+ response: default_get_org_response(org_api_id))
+ stub_self_returning_api_client(message: :create_client_token,
+ response: default_get_client_tokens(guid: token_guid)['entities'].first,
+ api_client:)
+ post "/organizations/#{org.id}/client_tokens", params: { label: 'New Token' }
+ expect(assigns(:organization)).to eq org
+ expect(assigns(:client_token)['id']).to eq token_guid
+ end
+ end
context 'as cd' do
let!(:user) { create(:user) }
let(:org_api_id) { SecureRandom.uuid }
diff --git a/dpc-portal/spec/requests/organizations_spec.rb b/dpc-portal/spec/requests/organizations_spec.rb
index e487341ffd..7921e9948c 100644
--- a/dpc-portal/spec/requests/organizations_spec.rb
+++ b/dpc-portal/spec/requests/organizations_spec.rb
@@ -267,24 +267,24 @@
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
@@ -292,18 +292,18 @@
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
@@ -311,18 +311,18 @@
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
From 9ca3a6874686059679a0e1de09be1b30c12dcdd5 Mon Sep 17 00:00:00 2001
From: jdettmannnava <145699825+jdettmannnava@users.noreply.github.com>
Date: Wed, 27 Nov 2024 16:33:54 -0500
Subject: [PATCH 2/4] add param to redirects
---
.../show_token_component.html.erb | 2 +-
.../organization/compound_show_component.rb | 6 +--
.../controllers/ip_addresses_controller.rb | 4 +-
.../controllers/organizations_controller.rb | 3 +-
.../app/controllers/public_keys_controller.rb | 4 +-
.../client_token/show_token_component_spec.rb | 2 +-
.../compound_show_component_spec.rb | 49 ++++++++++++-------
.../spec/requests/client_tokens_spec.rb | 22 ---------
dpc-portal/spec/requests/ip_addresses_spec.rb | 5 +-
.../spec/requests/organizations_spec.rb | 14 ++++++
dpc-portal/spec/requests/public_keys_spec.rb | 4 +-
11 files changed, 62 insertions(+), 53 deletions(-)
diff --git a/dpc-portal/app/components/page/client_token/show_token_component.html.erb b/dpc-portal/app/components/page/client_token/show_token_component.html.erb
index bb832bacf8..8bfccddf81 100644
--- a/dpc-portal/app/components/page/client_token/show_token_component.html.erb
+++ b/dpc-portal/app/components/page/client_token/show_token_component.html.erb
@@ -1,5 +1,5 @@
-
← <%= link_to organization.name, organization_path(organization.path_id) %>
+
← <%= link_to organization.name, organization_path(organization, credential_start: :true) %>
Client token created
"<%= client_token['label'] %>" created for <%= organization.name %>
diff --git a/dpc-portal/app/components/page/organization/compound_show_component.rb b/dpc-portal/app/components/page/organization/compound_show_component.rb
index e6de7002bf..72b935a281 100644
--- a/dpc-portal/app/components/page/organization/compound_show_component.rb
+++ b/dpc-portal/app/components/page/organization/compound_show_component.rb
@@ -4,10 +4,10 @@ module Page
module Organization
# Shows tabbed credential delegates and credentials
class CompoundShowComponent < ViewComponent::Base
- def initialize(organization, delegate_information)
+ 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 = delegate_information[:active]
@pending_credential_delegates = delegate_information[:pending]
diff --git a/dpc-portal/app/controllers/ip_addresses_controller.rb b/dpc-portal/app/controllers/ip_addresses_controller.rb
index cac6f61db9..cd0b119909 100644
--- a/dpc-portal/app/controllers/ip_addresses_controller.rb
+++ b/dpc-portal/app/controllers/ip_addresses_controller.rb
@@ -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'
@@ -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
diff --git a/dpc-portal/app/controllers/organizations_controller.rb b/dpc-portal/app/controllers/organizations_controller.rb
index 0e29462da7..a21bfe254c 100644
--- a/dpc-portal/app/controllers/organizations_controller.rb
+++ b/dpc-portal/app/controllers/organizations_controller.rb
@@ -28,7 +28,8 @@ def show
invited_by: current_user).select(&:expired?)
@delegate_information[:active] = CdOrgLink.where(provider_organization: @organization, disabled_at: nil)
end
- render(Page::Organization::CompoundShowComponent.new(@organization, @delegate_information))
+ render(Page::Organization::CompoundShowComponent.new(@organization, @delegate_information,
+ params[:credential_start]))
end
def new
diff --git a/dpc-portal/app/controllers/public_keys_controller.rb b/dpc-portal/app/controllers/public_keys_controller.rb
index 53e931c9ce..0594c3a52d 100644
--- a/dpc-portal/app/controllers/public_keys_controller.rb
+++ b/dpc-portal/app/controllers/public_keys_controller.rb
@@ -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'
@@ -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
diff --git a/dpc-portal/spec/components/page/client_token/show_token_component_spec.rb b/dpc-portal/spec/components/page/client_token/show_token_component_spec.rb
index edcb85dc96..3b62e04db2 100644
--- a/dpc-portal/spec/components/page/client_token/show_token_component_spec.rb
+++ b/dpc-portal/spec/components/page/client_token/show_token_component_spec.rb
@@ -16,7 +16,7 @@
let(:expected_html) do
<<~HTML
-
+
Client token created
"Your token" created for #{org.name}
diff --git a/dpc-portal/spec/components/page/organization/compound_show_component_spec.rb b/dpc-portal/spec/components/page/organization/compound_show_component_spec.rb
index 89e34d8d22..6c3700ac90 100644
--- a/dpc-portal/spec/components/page/organization/compound_show_component_spec.rb
+++ b/dpc-portal/spec/components/page/organization/compound_show_component_spec.rb
@@ -10,7 +10,7 @@
normalize_space(rendered_content)
end
let(:org) { build(:provider_organization, name: 'Health Hut', npi: '11111111', id: 2) }
- let(:component) { described_class.new(org, delegate_info) }
+ let(:component) { described_class.new(org, delegate_info, credential_start) }
before do
render_inline(component)
@@ -18,28 +18,43 @@
context 'has delegate information' do
let(:delegate_info) { { active: [], pending: [], expired: [] } }
- it 'Should have org name' do
- is_expected.to include("
#{org.name}
")
- end
- it 'Should have npi' do
- is_expected.to include(%(
NPI: #{org.npi}
))
+ context 'credential delegate start' do
+ let(:credential_start) { false }
+ it 'Should have org name' do
+ is_expected.to include("
#{org.name}
")
+ end
+ it 'Should have npi' do
+ is_expected.to include(%(
NPI: #{org.npi}
))
+ end
+ it 'Should have script tag' do
+ is_expected.to include('