diff --git a/app/controllers/activities_controller.rb b/app/controllers/activities_controller.rb index 8b044b377..b479aef2a 100644 --- a/app/controllers/activities_controller.rb +++ b/app/controllers/activities_controller.rb @@ -145,8 +145,7 @@ def show protected def set_activity - response = Activity.find_by_id(params[:id]) - @activity = response.results.first + @activity = Activity.find_by_request_uuid!(params[:id]) fail ActiveRecord::RecordNotFound if @activity.blank? end end diff --git a/app/serializers/activity_serializer.rb b/app/serializers/activity_serializer.rb index 99c14cc1b..15bd86869 100644 --- a/app/serializers/activity_serializer.rb +++ b/app/serializers/activity_serializer.rb @@ -14,55 +14,49 @@ class ActivitySerializer :version attribute :changes do |object, params| - changes = object._source.changes - pub = changes.publisher - pub_obj = changes.publisher_obj + # Determine the source and action based on the object's type + if object.is_a? Activity + changes = object.audited_changes + action = object.action + else + changes = object._source.changes + action = object._source.action + end - ret = changes + # Extract publisher and publisher_obj from changes + pub = changes&.dig("publisher") + pub_obj = changes&.dig("publisher_obj") - if object._source.action == "update" - if pub || pub_obj - if params[:publisher] == "true" - if !pub_obj - changes.publisher = - [ - { "name": pub[0] }, - { "name": pub[1] }, - ] - else - changes.publisher = changes.publisher_obj - end + # Customize publisher information based on params[:publisher] + if pub || pub_obj + if params&.dig(:publisher) == "true" + if pub_obj + changes["publisher"] = pub_obj else - if !pub - changes.publisher = [ pub_obj[0].name, pub_obj[1].name ] - end + changes["publisher"] = + action == "update" ? [ + pub[0] ? { "name": pub[0] } : nil, + pub[1] ? { "name": pub[1] } : nil + ] : { "name": pub } end - - ret = changes - end - elsif object._source.action == "create" - if pub || pub_obj - if params[:publisher] == "true" - if !pub_obj - changes.publisher = { "name": pub } - else - changes.publisher = changes.publisher_obj - end + else + if pub_obj + changes["publisher"] = + action == "update" ? [ + pub_obj[0] ? pub_obj[0]["name"] : nil, + pub_obj[1] ? pub_obj[1]["name"] : nil + ] : pub_obj["name"] else - if !pub - changes.publisher = pub_obj.name - end + changes["publisher"] = pub end - - ret = changes end end - if pub_obj - changes.delete("publisher_obj") - end + # Remove the not needed "publisher_obj" key + changes.delete("publisher_obj") - ret + # Return the modified changes + changes end attribute "prov:wasDerivedFrom", &:was_derived_from diff --git a/config/routes.rb b/config/routes.rb index f1b42826f..537af3ac8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -178,7 +178,7 @@ resources :heartbeat, only: %i[index] - resources :activities, only: %i[index show] + resources :activities, only: %i[index show], constraints: { id: /.+/ } resources :clients, constraints: { id: /.+/ } do resources :prefixes, constraints: { id: /.+/ } diff --git a/lib/tasks/activity.rake b/lib/tasks/activity.rake index d0891d871..7a8cbcd08 100644 --- a/lib/tasks/activity.rake +++ b/lib/tasks/activity.rake @@ -36,6 +36,11 @@ namespace :activity do puts Activity.monitor_reindex end + desc "Create alias for activities" + task create_alias: :environment do + puts Activity.create_alias(index: ENV["INDEX"], alias: ENV["ALIAS"]) + end + desc "Import all activities" task import: :environment do from_id = (ENV["FROM_ID"] || 1).to_i diff --git a/lib/tasks/elasticsearch.rake b/lib/tasks/elasticsearch.rake index 0e23c31db..e01462cc2 100644 --- a/lib/tasks/elasticsearch.rake +++ b/lib/tasks/elasticsearch.rake @@ -32,6 +32,7 @@ namespace :elasticsearch do Rake::Task["event:create_alias"].invoke Rake::Task["activity:create_index"].invoke + Rake::Task["activity:create_alias"].invoke Rake::Task["contact:create_index"].invoke Rake::Task["contact:create_alias"].invoke