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

8: [ART] POA request representative #20009

Merged
merged 2 commits into from
Jan 10, 2025
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
6 changes: 6 additions & 0 deletions app/models/accredited_individual.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ class AccreditedIndividual < ApplicationRecord
has_many :accreditations, dependent: :destroy
has_many :accredited_organizations, through: :accreditations

has_many :power_of_attorney_requests,
as: :power_of_attorney_holder,
inverse_of: :power_of_attorney_holder,
class_name: 'AccreditedRepresentativePortal::PowerOfAttorneyRequest',
dependent: :restrict_with_exception

validates :ogc_id, :registration_number, :individual_type, presence: true
validates :poa_code, length: { is: 3 }, allow_blank: true
validates :individual_type, uniqueness: { scope: :registration_number }
Expand Down
6 changes: 6 additions & 0 deletions app/models/accredited_organization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ class AccreditedOrganization < ApplicationRecord
has_many :accreditations, dependent: :destroy
has_many :accredited_individuals, through: :accreditations

has_many :power_of_attorney_requests,
as: :power_of_attorney_holder,
inverse_of: :power_of_attorney_holder,
class_name: 'AccreditedRepresentativePortal::PowerOfAttorneyRequest',
dependent: :restrict_with_exception

validates :ogc_id, :poa_code, presence: true
validates :poa_code, length: { is: 3 }
validates :poa_code, uniqueness: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,29 @@ module AccreditedRepresentativePortal
module V0
class PowerOfAttorneyRequestsController < ApplicationController
def index
poa_requests = PowerOfAttorneyRequest.includes(resolution: :resolving).limit(100)
poa_requests = poa_requests_rel.limit(100)
serializer = PowerOfAttorneyRequestSerializer.new(poa_requests)
render json: serializer.serializable_hash, status: :ok
end

def show
poa_request = PowerOfAttorneyRequest.includes(resolution: :resolving).find(params[:id])
poa_request = poa_requests_rel.find(params[:id])
serializer = PowerOfAttorneyRequestSerializer.new(poa_request)
render json: serializer.serializable_hash, status: :ok
rescue ActiveRecord::RecordNotFound
render json: { error: 'Record not found' }, status: :not_found
end

private

def poa_requests_rel
PowerOfAttorneyRequest.includes(
:power_of_attorney_form,
:power_of_attorney_holder,
:accredited_individual,
resolution: :resolving
)
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,19 @@ module ClaimantTypes
belongs_to :claimant, class_name: 'UserAccount'

has_one :power_of_attorney_form,
class_name: 'AccreditedRepresentativePortal::PowerOfAttorneyForm',
inverse_of: :power_of_attorney_request,
required: true

has_one :resolution,
class_name: 'AccreditedRepresentativePortal::PowerOfAttorneyRequestResolution',
inverse_of: :power_of_attorney_request

belongs_to :power_of_attorney_holder,
inverse_of: :power_of_attorney_requests,
polymorphic: true

belongs_to :accredited_individual

before_validation :set_claimant_type

private
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,17 @@ class PowerOfAttorneyRequestSerializer < ApplicationSerializer
.new(poa_request.resolution)
.serializable_hash
end

attribute :power_of_attorney_holder do |poa_request|
PowerOfAttorneyHolderSerializer
.new(poa_request.power_of_attorney_holder)
.serializable_hash
end

attribute :accredited_individual do |poa_request|
AccreditedIndividualSerializer
.new(poa_request.accredited_individual)
.serializable_hash
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

module AccreditedRepresentativePortal
class PowerOfAttorneyRequestSerializer
class AccreditedIndividualSerializer < ApplicationSerializer
attribute :full_name do |poa_holder|
parts = [
poa_holder.first_name,
poa_holder.middle_initial,
poa_holder.last_name
]

parts.compact_blank.join(' ')
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# frozen_string_literal: true

module AccreditedRepresentativePortal
class PowerOfAttorneyRequestSerializer
class PowerOfAttorneyHolderSerializer < ApplicationSerializer
attribute :type do |poa_holder|
case poa_holder
when AccreditedIndividual
"accredited_#{poa_holder.individual_type}"
when AccreditedOrganization
'veteran_service_organization'
end
end

with_options if: proc { |poa_holder| poa_holder.is_a?(AccreditedOrganization) } do
attribute :name
end

with_options if: proc { |poa_holder| poa_holder.is_a?(AccreditedIndividual) } do
attribute :full_name do |poa_holder|
parts = [
poa_holder.first_name,
poa_holder.middle_initial,
poa_holder.last_name
]

parts.compact_blank.join(' ')
end
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
association :claimant, factory: :user_account
association :power_of_attorney_form, strategy: :build

association :power_of_attorney_holder, factory: %i[accredited_organization with_representatives]
accredited_individual { power_of_attorney_holder.accredited_individuals.first }

trait :with_acceptance do
resolution { create(:power_of_attorney_request_resolution, :acceptance) }
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
end

describe 'GET /accredited_representative_portal/v0/power_of_attorney_requests' do
it 'returns the list of power of attorney requests', skip: 'temporarily for a migration' do
it 'returns the list of power of attorney requests' do
poa_requests

get('/accredited_representative_portal/v0/power_of_attorney_requests')
Expand Down Expand Up @@ -88,6 +88,18 @@
'email' => '[email protected]'
}
},
'power_of_attorney_holder' => {
'id' => poa_requests[0].power_of_attorney_holder.id,
'type' => 'veteran_service_organization',
'name' => poa_requests[0].power_of_attorney_holder.name
},
'accredited_individual' => {
'id' => poa_requests[0].accredited_individual.id,
'full_name' => [
poa_requests[0].accredited_individual.first_name,
poa_requests[0].accredited_individual.last_name
].join(' ')
},
'resolution' => nil
},
{
Expand Down Expand Up @@ -145,6 +157,18 @@
'email' => '[email protected]'
}
},
'power_of_attorney_holder' => {
'id' => poa_requests[1].power_of_attorney_holder.id,
'type' => 'veteran_service_organization',
'name' => poa_requests[1].power_of_attorney_holder.name
},
'accredited_individual' => {
'id' => poa_requests[1].accredited_individual.id,
'full_name' => [
poa_requests[1].accredited_individual.first_name,
poa_requests[1].accredited_individual.last_name
].join(' ')
},
'resolution' => {
'id' => poa_requests[1].resolution.id,
'type' => 'decision',
Expand Down Expand Up @@ -208,6 +232,18 @@
'email' => '[email protected]'
}
},
'power_of_attorney_holder' => {
'id' => poa_requests[2].power_of_attorney_holder.id,
'type' => 'veteran_service_organization',
'name' => poa_requests[2].power_of_attorney_holder.name
},
'accredited_individual' => {
'id' => poa_requests[2].accredited_individual.id,
'full_name' => [
poa_requests[2].accredited_individual.first_name,
poa_requests[2].accredited_individual.last_name
].join(' ')
},
'resolution' => {
'id' => poa_requests[2].resolution.id,
'type' => 'decision',
Expand Down Expand Up @@ -272,6 +308,18 @@
'email' => '[email protected]'
}
},
'power_of_attorney_holder' => {
'id' => poa_requests[3].power_of_attorney_holder.id,
'type' => 'veteran_service_organization',
'name' => poa_requests[3].power_of_attorney_holder.name
},
'accredited_individual' => {
'id' => poa_requests[3].accredited_individual.id,
'full_name' => [
poa_requests[3].accredited_individual.first_name,
poa_requests[3].accredited_individual.last_name
].join(' ')
},
'resolution' => {
'id' => poa_requests[3].resolution.id,
'type' => 'expiration',
Expand All @@ -284,7 +332,7 @@
end

describe 'GET /accredited_representative_portal/v0/power_of_attorney_requests/:id' do
it 'returns the details of a specific power of attorney request', skip: 'temporarily for a migration' do
it 'returns the details of a specific power of attorney request' do
get("/accredited_representative_portal/v0/power_of_attorney_requests/#{poa_request.id}")

parsed_response = JSON.parse(response.body)
Expand Down Expand Up @@ -353,6 +401,18 @@
'creator_id' => poa_request.resolution.resolving.creator_id,
'reason' => 'Didn\'t authorize treatment record disclosure',
'decision_type' => 'declination'
},
'power_of_attorney_holder' => {
'id' => poa_request.power_of_attorney_holder.id,
'type' => 'veteran_service_organization',
'name' => poa_request.power_of_attorney_holder.name
},
'accredited_individual' => {
'id' => poa_request.accredited_individual.id,
'full_name' => [
poa_request.accredited_individual.first_name,
poa_request.accredited_individual.last_name
].join(' ')
}
}
)
Expand Down
Loading