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

99525 create new next steps page downloads #19991

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
@@ -0,0 +1,39 @@
# frozen_string_literal: true

module RepresentationManagement
module V0
class NextStepsPdfController < ApplicationController
service_tag 'representation-management'
skip_before_action :authenticate
before_action :feature_enabled
def create
data = RepresentationManagement::NextStepsPdfData.new(next_step_pdf_params)

if data.valid?
Tempfile.create do |tempfile|
tempfile.binmode
RepresentationManagement::V0::PdfConstructor::NextSteps.new(tempfile).construct(form)
send_data tempfile.read,
filename: 'next_steps.pdf',
type: 'application/pdf',
disposition: 'attachment',
status: :ok
end
# The Tempfile is automatically deleted after the block ends
else
render json: { errors: data.errors.full_messages }, status: :unprocessable_entity
end
end

private

def feature_enabled
routing_error unless Flipper.enabled?(:use_veteran_models_for_appoint)
end

def next_step_pdf_params
params.require(:next_steps_pdf).permit(:representative_id, :organization_id)
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# frozen_string_literal: true

module RepresentationManagement
class NextStepsPdfData
include ActiveModel::Model

next_steps_pdf_attrs = %i[
organization_id
representative_id
]

attr_accessor(*next_steps_pdf_attrs)

validate :org_or_rep_specified?
validate :entities_exist?

def organization
@organization ||= find_organization
end

def representative
@representative ||= find_representative
end

# def entity_display_type
# if entity.is_a?(Veteran::Service::Representative) || entity.is_a?(AccreditedIndividual)
# representative_type
# else
# 'Veterans Service Organization'
# end
# end

# def entity_name
# if entity_type == 'individual'
# entity.full_name.strip
# elsif entity_type == 'organization'
# entity.name.strip
# end
# end

# def entity_address
# <<~ADDRESS.squish
# #{entity.address_line1}
# #{entity.address_line2}
# #{entity.address_line3}
# #{entity.city}, #{entity.state_code} #{entity.zip_code}
# #{entity.country_code_iso3}
# ADDRESS
# end

private

# def find_entity
# if entity_type == 'individual'
# find_representative
# elsif entity_type == 'organization'
# find_organization
# end
# end

def entities_exist?
return unless organization.nil? && representative.nil?

errors.add(:base, 'Organization or representative not found')
end

def org_or_rep_specified?
return unless organization_id.present? || representative_id.present?

errors.add(:base, 'At least one of organization_id or representative_id must be specified')
end

def find_organization
AccreditedOrganization.find_by(id: organization_id) ||
Veteran::Service::Organization.find_by(poa: organization_id)
end

def find_representative
AccreditedIndividual.find_by(id: representative_id) ||
Veteran::Service::Representative.find_by(representative_id: representative_id)
end

# def representative_type
# if entity.is_a?(Veteran::Service::Representative)
# type_string = entity.user_types.first
# elsif entity.is_a?(AccreditedIndividual)
# type_string = entity.individual_type
# end
# return '' if type_string.blank?

# case type_string
# when 'claims_agent', 'claim_agents'
# 'claims agent'
# when 'representative', 'veteran_service_officer'
# 'VSO representative'
# when 'attorney'
# 'attorney'
# else
# ''
# end
# end
end
end
1 change: 1 addition & 0 deletions modules/representation_management/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
resources :accredited_individuals, only: %i[index]
resources :flag_accredited_representatives, only: %i[create]
resources :next_steps_email, only: %i[create]
resources :next_steps_pdf, only: %i[create]
resources :original_entities, only: %i[index]
resources :pdf_generator2122, only: %i[create]
resources :pdf_generator2122a, only: %i[create]
Expand Down
Loading