Skip to content

Commit

Permalink
Call after_update_* from edit_with_params
Browse files Browse the repository at this point in the history
When changes are made to the endpoints or authentications workers which
run with an open connection like event catchers and streaming refresh
workers have to be restarted.

This was done via `after_update_authentication` called from
`update_authentication`.  The issue is that this method is no longer
called when providers are updated via the API with DDF parameters.
  • Loading branch information
agrare committed Dec 6, 2022
1 parent bd821db commit 1ee330a
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions app/models/ext_management_system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -175,18 +175,30 @@ def self.create_from_params(params, endpoints, authentications)

def edit_with_params(params, endpoints, authentications)
tap do |ems|
endpoints_changed = false
authentications_changed = false

transaction do
# Remove endpoints/attributes that are not arriving in the arguments above
ems.endpoints.where.not(:role => nil).where.not(:role => endpoints.map { |ep| ep['role'] }).delete_all
ems.authentications.where.not(:authtype => nil).where.not(:authtype => authentications.map { |au| au['authtype'] }).delete_all
endpoints_to_delete = ems.endpoints.where.not(:role => nil).where.not(:role => endpoints.map { |ep| ep['role'] })
authentications_to_delete = ems.authentications.where.not(:authtype => nil).where.not(:authtype => authentications.map { |au| au['authtype'] })

endpoints_changed ||= endpoints_to_delete.delete_all > 0
authentications_changed ||= authentications_to_delete.delete_all > 0

ems.assign_attributes(params)
ems.endpoints = endpoints.map(&method(:assign_nested_endpoint))
ems.endpoints = endpoints.map(&method(:assign_nested_endpoint))
ems.authentications = authentications.map(&method(:assign_nested_authentication))

endpoints_changed ||= ems.endpoints.any?(&:changed?)
authentications_changed ||= ems.authentications.any?(&:changed?)

ems.provider.save! if ems.provider.present? && ems.provider.changed?
ems.save!
end

after_update_endpoints if endpoints_changed
after_update_authentication if authentications_changed
end
end

Expand Down Expand Up @@ -867,6 +879,10 @@ def after_update_authentication
stop_event_monitor_queue_on_credential_change
end

def after_update_endpoints
stop_event_monitor_queue_on_credential_change
end

###################################
# Event Monitor
###################################
Expand Down

0 comments on commit 1ee330a

Please sign in to comment.