Skip to content

Commit

Permalink
- Add a check for type_ses when loading object pages, and show a 404 …
Browse files Browse the repository at this point in the history
…if missing

- Filter search results to remove any where type_ses is missing
  • Loading branch information
j-corry committed Nov 22, 2024
1 parent 763b5c4 commit 9b7225c
Show file tree
Hide file tree
Showing 14 changed files with 1,455 additions and 1,267 deletions.
32 changes: 18 additions & 14 deletions app/controllers/content_objects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,32 @@ def show
raise 'unknown error occurred'
end
elsif @response['docs'].blank?
# API responds with success but no results - show a 404
render template: 'layouts/shared/error/404', locals: { status: 404, message: 'Page not found' }
else
object_data = @response['docs'].first
@object = ContentObject.generate(object_data)

associated_object_query = AssociatedObjects.new(@object).data
@associated_object_data = associated_object_query[:object_data]
if object_data.dig('type_ses').blank?
render template: 'layouts/shared/error/404', locals: { status: 404, message: 'Page not found' }
else
@object = ContentObject.generate(object_data)

# Combine SES IDs from associated objects if any
associated_ses_ids = associated_object_query&.dig(:ses_ids)
all_ses_ids = associated_ses_ids.blank? ? @object.ses_lookup_ids : @object.ses_lookup_ids + associated_ses_ids
associated_object_query = AssociatedObjects.new(@object).data
@associated_object_data = associated_object_query[:object_data]

# Single SES lookup using all IDs
@ses_data = SesLookup.new(all_ses_ids).data
# Combine SES IDs from associated objects if any
associated_ses_ids = associated_object_query&.dig(:ses_ids)
all_ses_ids = associated_ses_ids.blank? ? @object.ses_lookup_ids : @object.ses_lookup_ids + associated_ses_ids

@page_title = @object.object_title
# Single SES lookup using all IDs
@ses_data = SesLookup.new(all_ses_ids).data

if @ses_data&.has_key?(:error)
render template: 'layouts/shared/error/500', locals: { status: 500, message: 'There was an error resolving names using the SES service' }
else
render template: @object.template, :locals => { :object => @object }
@page_title = @object.object_title

if @ses_data&.has_key?(:error)
render template: 'layouts/shared/error/500', locals: { status: 500, message: 'There was an error resolving names using the SES service' }
else
render template: @object.template, :locals => { :object => @object }
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/api_call.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def initialize(params)
end

def object_data
all_data['response']['docs']
all_data['response']['docs']&.reject{|h| h.dig('type_ses').blank?}
end

def all_data
Expand Down
2 changes: 1 addition & 1 deletion app/models/search_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def error_partial_path
def object_data
return unless search

search.dig(:data, 'response', 'docs')
search.dig(:data, 'response', 'docs')&.reject { |h| h.dig('type_ses').blank? }
end

def objects
Expand Down
2 changes: 1 addition & 1 deletion coverage/.last_run.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"result": {
"line": 80.23
"line": 80.25
}
}
Loading

0 comments on commit 9b7225c

Please sign in to comment.