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

Fixes for activities endpoints. #1063

Merged
merged 10 commits into from
Dec 12, 2023
5 changes: 3 additions & 2 deletions app/controllers/activities_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,9 @@ def show

protected
def set_activity
response = Activity.find_by_id(params[:id])
@activity = response.results.first
response = Activity.find_by_request_uuid!(params[:id])
@activity = response

svogt0511 marked this conversation as resolved.
Show resolved Hide resolved
fail ActiveRecord::RecordNotFound if @activity.blank?
end
end
62 changes: 20 additions & 42 deletions app/serializers/activity_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,55 +14,33 @@ class ActivitySerializer
:version

attribute :changes do |object, params|
svogt0511 marked this conversation as resolved.
Show resolved Hide resolved
changes = object._source.changes
pub = changes.publisher
pub_obj = changes.publisher_obj

ret = changes
# Object is of different class if it comes from /activities/:uid
if object.is_a? Activity
changes = object.audited_changes
action = object.action
else
changes = object._source.changes
action = object._source.action
end

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
else
if !pub
changes.publisher = [ pub_obj[0].name, pub_obj[1].name ]
end
end
pub = changes&.dig("publisher")
pub_obj = changes&.dig("publisher_obj")

ret = changes
if params&.dig(:publisher) == "true"
if pub_obj
changes[:publisher] = pub_obj
else
changes[:publisher] = action == "update" ? [{ "name": pub[0] }, { "name": pub[1] }] : { "name": pub }
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
changes.publisher = pub_obj.name
end
end

ret = changes
else
if pub_obj
changes[:publisher] = action == "update" ? [pub_obj[0]["name"], pub_obj[1]["name"]] : pub_obj["name"]
end
end

if pub_obj
changes.delete("publisher_obj")
end
changes.delete("publisher_obj") if pub_obj

ret
changes
end

attribute "prov:wasDerivedFrom", &:was_derived_from
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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: /.+/ }
Expand Down
5 changes: 5 additions & 0 deletions lib/tasks/activity.rake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/tasks/elasticsearch.rake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down