Skip to content

Commit

Permalink
Fixes for activities endpoints.
Browse files Browse the repository at this point in the history
  • Loading branch information
svogt0511 committed Dec 11, 2023
1 parent 3c886cb commit ae61319
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 44 deletions.
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
puts response.inspect
fail ActiveRecord::RecordNotFound if @activity.blank?
end
end
60 changes: 19 additions & 41 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|
changes = object._source.changes
pub = changes.publisher
pub_obj = changes.publisher_obj
if object.is_a? Activity
changes = object.audited_changes
action = object.action
else
changes = object._source.changes
action = object._source.action
end

ret = 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
if params&.dig(:publisher) == "true"
changes[:publisher] =
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" ? [{ "name": pub[0] }, { "name": pub[1] }] : { "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
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, constraints: { id: /.+/ }

resources :clients, constraints: { id: /.+/ } do
resources :prefixes, constraints: { id: /.+/ }
Expand Down

0 comments on commit ae61319

Please sign in to comment.