Skip to content

Commit

Permalink
Merge branch 'master' into yoom/15416-handle-bgs-connection-error
Browse files Browse the repository at this point in the history
  • Loading branch information
yoomlam authored Oct 26, 2020
2 parents f3dcab0 + ecd819c commit a394649
Show file tree
Hide file tree
Showing 65 changed files with 1,948 additions and 374 deletions.
8 changes: 6 additions & 2 deletions app/controllers/api/docs/v3/decision_reviews.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -914,10 +914,14 @@ paths:
parameters:
- name: X-VA-SSN
in: header
required: true
description: The SSN of the veteran.
description: The SSN of the veteran. Either SSN or file number must be passed.
schema:
type : string
- name: X-VA-File-Number
in: header
description: The file number of the veteran. Either SSN or file number must be passed.
schema:
type: string
- name: X-VA-Receipt-Date
in: header
required: true
Expand Down
16 changes: 0 additions & 16 deletions app/controllers/api/v3/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,6 @@ def status_from_errors(errors)
end

protect_from_forgery with: :null_session
before_action :api_released?

def api_released?
return true if FeatureToggle.enabled?(:api_v3)

render json: {
errors: [
{
status: "501",
title: "Not Implemented",
detail: "This endpoint is not yet supported."
}
]
},
status: :not_implemented
end

def render_errors(errors)
errors = Array.wrap(errors)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ module V3
module DecisionReviews
module Appeals
class ContestableIssuesController < BaseContestableIssuesController
include ApiV3FeatureToggleConcern

before_action only: [:index] do
api_released?(:api_v3_appeals_contestable_issues)
end

private

def standin_decision_review
Expand Down
6 changes: 6 additions & 0 deletions app/controllers/api/v3/decision_reviews/appeals_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# frozen_string_literal: true

class Api::V3::DecisionReviews::AppealsController < Api::V3::BaseController
include ApiV3FeatureToggleConcern

before_action do
api_released?(:api_v3_appeals)
end

# stub
def create
render json: {}, status: :not_found
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,32 @@ def validate_params
end

def veteran_valid?
unless veteran_ssn_is_formatted_correctly?
if veteran_ssn.present? && !veteran_ssn_is_formatted_correctly?
render_invalid_veteran_ssn
return false
end
unless veteran
if veteran_identifier.nil?
render_missing_headers
return false
end
unless veteran.present? && veteran_matches
render_veteran_not_found
return false
end
true
end

def veteran_matches
if veteran_ssn.present? && veteran_ssn != veteran.ssn
return false
end
if veteran_file_number.present? && veteran_file_number != veteran.file_number
return false
end

true
end

def receipt_date_valid?
unless receipt_date.is_a? Date
render_invalid_receipt_date
Expand All @@ -69,11 +84,19 @@ def receipt_date_valid?
end

def veteran
@veteran ||= VeteranFinder.find_best_match veteran_ssn
@veteran ||= VeteranFinder.find_best_match veteran_identifier
end

def veteran_ssn
@veteran_ssn ||= request.headers["X-VA-SSN"].to_s.strip
@veteran_ssn ||= request.headers["X-VA-SSN"].presence&.strip
end

def veteran_file_number
@veteran_file_number ||= request.headers["X-VA-File-Number"].presence&.strip
end

def veteran_identifier
veteran_file_number || veteran_ssn
end

def veteran_ssn_is_formatted_correctly?
Expand All @@ -97,6 +120,14 @@ def render_veteran_not_found
)
end

def render_missing_headers
render_errors(
status: 422,
code: :missing_identifying_headers,
title: "Veteran file number or SSN header is required"
)
end

def receipt_date
@receipt_date ||= begin
Date.iso8601 receipt_date_header
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ module V3
module DecisionReviews
module HigherLevelReviews
class ContestableIssuesController < BaseContestableIssuesController
include ApiV3FeatureToggleConcern

before_action only: [:index] do
api_released?(:api_v3_higher_level_reviews_contestable_issues)
end

private

def standin_decision_review
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# frozen_string_literal: true

class Api::V3::DecisionReviews::HigherLevelReviewsController < Api::V3::BaseController
include ApiV3FeatureToggleConcern

before_action do
api_released?(:api_v3_higher_level_reviews)
end

SUCCESSFUL_CREATION_HTTP_STATUS = 202

def create
Expand Down
20 changes: 20 additions & 0 deletions app/controllers/concerns/api_v3_feature_toggle_concern.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

module ApiV3FeatureToggleConcern
extend ActiveSupport::Concern

def api_released?(feature)
return true if FeatureToggle.enabled?(feature)

render json: {
errors: [
{
status: "501",
title: "Not Implemented",
detail: "This endpoint is not yet supported."
}
]
},
status: :not_implemented
end
end
2 changes: 1 addition & 1 deletion app/controllers/organizations/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def index

render json: {
organization_name: organization.name,
judge_team: FeatureToggle.enabled?(:judge_admin_scm) && organization.type == JudgeTeam.name,
judge_team: organization.type == JudgeTeam.name,
dvc_team: organization.type == DvcTeam.name,
organization_users: json_administered_users(organization_users)
}
Expand Down
7 changes: 5 additions & 2 deletions app/controllers/tasks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class TasksController < ApplicationController
BlockedSpecialCaseMovementTask: BlockedSpecialCaseMovementTask,
ChangeHearingDispositionTask: ChangeHearingDispositionTask,
ColocatedTask: ColocatedTask,
DocketSwitchDeniedTask: DocketSwitchDeniedTask,
DocketSwitchGrantedTask: DocketSwitchGrantedTask,
EvidenceSubmissionWindowTask: EvidenceSubmissionWindowTask,
FoiaTask: FoiaTask,
HearingAdminActionTask: HearingAdminActionTask,
Expand Down Expand Up @@ -109,12 +111,13 @@ def update
rescue ActiveRecord::RecordInvalid => error
invalid_record_error(error.record)
rescue AssignHearingDispositionTask::HearingAssociationMissing => error
Raven.capture_exception(error)
Raven.capture_exception(error, extra: { application: "hearings" })

render json: {
"errors": ["title": "Missing Associated Hearing", "detail": error]
}, status: :bad_request
rescue Caseflow::Error::VirtualHearingConversionFailed => error
Raven.capture_exception(error)
Raven.capture_exception(error, extra: { application: "hearings" })

render json: {
"errors": ["title": COPY::FAILED_HEARING_UPDATE, "message": error.message, "code": error.code]
Expand Down
33 changes: 19 additions & 14 deletions app/jobs/update_cached_appeals_attributes_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -286,20 +286,36 @@ def case_fields_for_vacols_ids(vacols_ids)
# ...
# }
VACOLS::Case.where(bfkey: vacols_ids).map do |vacols_case|
legacy_appeal = AppealRepository.build_appeal(vacols_case) # build non-persisting legacy appeal object
original_request = original_hearing_request_type_for_vacols_case(vacols_case)
changed_request = changed_hearing_request_type_for_all_vacols_ids[vacols_case.bfkey]
# Replicates LegacyAppeal#current_hearing_request_type
current_request = HearingDay::REQUEST_TYPES.key(changed_request)&.to_sym || original_request

[
vacols_case.bfkey,
{
location: vacols_case.bfcurloc,
status: VACOLS::Case::TYPES[vacols_case.bfac],
hearing_request_type: legacy_appeal.current_hearing_request_type(readable: true),
former_travel: former_travel?(legacy_appeal)
hearing_request_type: LegacyAppeal::READABLE_HEARING_REQUEST_TYPES[current_request],
former_travel: original_request == :travel_board && current_request != :travel_board
}
]
end.to_h
end

# Gets the symbolic representation of the original type of hearing requested for a vacols case record
# Replicates logic in LegacyAppeal#original_hearing_request_type
def original_hearing_request_type_for_vacols_case(vacols_case)
request_type = VACOLS::Case::HEARING_REQUEST_TYPES[vacols_case.bfhr]

(request_type == :travel_board && vacols_case.bfdocind == "V") ? :video : request_type
end

# Maps vacols ids to their leagcy appeal's changed hearing request type
def changed_hearing_request_type_for_all_vacols_ids
@changed_hearing_request_type_for_all_vacols_ids ||= LegacyAppeal.pluck(:vacols_id, :changed_request_type).to_h
end

def issues_counts_for_vacols_folders(vacols_ids)
VACOLS::CaseIssue.where(isskey: vacols_ids).group(:isskey).count
end
Expand All @@ -322,15 +338,4 @@ def veteran_names_for_file_numbers(veteran_file_numbers)
[veteran.file_number, "#{veteran.last_name&.split(' ')&.last}, #{veteran.first_name}"]
end.to_h
end

# checks to see if the hearing request type was former_travel
def former_travel?(legacy_appeal)
# the current request type is travel
if legacy_appeal.current_hearing_request_type == :travel_board
return false
end

# otherwise check if og request type was travel
legacy_appeal.original_hearing_request_type == :travel_board
end
end
5 changes: 3 additions & 2 deletions app/models/cavc_remand.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
# Model to store information captured when processing a form for an appeal remanded by CAVC

class CavcRemand < CaseflowRecord
include UpdatedByUserConcern

belongs_to :created_by, class_name: "User"
belongs_to :updated_by, class_name: "User"
belongs_to :appeal

validates :created_by, :updated_by, :appeal, :cavc_docket_number, :represented_by_attorney, :cavc_judge_full_name,
validates :created_by, :appeal, :cavc_docket_number, :represented_by_attorney, :cavc_judge_full_name,
:cavc_decision_type, :decision_date, :decision_issue_ids, :instructions, presence: true
validates :remand_subtype, presence: true, if: :remand?
validates :judgement_date, :mandate_date, presence: true, unless: :mdr?
Expand Down
2 changes: 1 addition & 1 deletion app/models/docket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def age_of_n_oldest_genpop_priority_appeals(num)
end

def age_of_oldest_priority_appeal
@age_of_oldest_priority_appeal ||= appeals(priority: true, ready: true).limit(1).first.ready_for_distribution_at
@age_of_oldest_priority_appeal ||= appeals(priority: true, ready: true).limit(1).first&.ready_for_distribution_at
end

def oldest_priority_appeal_days_waiting
Expand Down
3 changes: 2 additions & 1 deletion app/models/end_product_establishment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,10 @@ def on_decision_issue_sync_processed(processing_request_issue)
end

def status
ep_code = Constants::EP_CLAIM_TYPES[code]
if committed?
{
ep_code: "#{modifier} #{Constants::EP_CLAIM_TYPES[code]['offical_label']}",
ep_code: "#{modifier} #{ep_code ? ep_code['offical_label'] : 'Unknown'}",
ep_status: [status_type, sync_status].compact.join(", ")
}
else
Expand Down
2 changes: 1 addition & 1 deletion app/models/hearings/forms/base_hearing_update_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class BaseHearingUpdateForm
def update
virtual_hearing_changed = false

ActiveRecord::Base.transaction do
ActiveRecord::Base.multi_transaction do
update_hearing
add_update_hearing_alert if show_update_alert?
if should_create_or_update_virtual_hearing?
Expand Down
2 changes: 2 additions & 0 deletions app/models/legacy_appeal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ def sanitized_changed_request_type(changed_request_type)
# values. Also, `hearing_request_type` alone can't disambiguate a video hearing
# from a travel board hearing
# This method cleans all of these issues up to return a sanitized version of the original type requested by Appellant.
# Replicated in UpdateCachedAppealAttributesJob#original_hearing_request_type_for_vacols_case
def original_hearing_request_type(readable: false)
original_hearing_request_type = case hearing_request_type
when :central_office
Expand All @@ -435,6 +436,7 @@ def original_hearing_request_type(readable: false)
# This method captures if a travel board hearing request type was overridden in Caseflow.
# In general, this method returns the current hearing request type which could be dervied
# from `change_request_type` or VACOLS `hearing_request_type`
# Replicated in UpdateCachedAppealAttributesJob#case_fields_for_vacols_ids
def current_hearing_request_type(readable: false)
current_hearing_request_type = if changed_request_type.present?
sanitized_changed_request_type(changed_request_type)
Expand Down
3 changes: 3 additions & 0 deletions app/models/promulgated_rating.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ def retry_fetching_rating_profile
)
matching_rating = ratings_at_issue.find { |rating| profile_date_matches(rating.profile_date) }
matching_rating.present? ? matching_rating.rating_profile : {}
rescue BGS::ShareError, Rating::NilRatingProfileListError => error
Raven.capture_exception(error)
{}
end

# The profile date is used as a key when fetching a rating by profile date.
Expand Down
Loading

0 comments on commit a394649

Please sign in to comment.