From 9b02269a928da585e4b33d347399813788408339 Mon Sep 17 00:00:00 2001 From: Lucy Fu Date: Mon, 20 Aug 2018 17:36:45 -0400 Subject: [PATCH] Add username, button id/name and automate entry point to CustomButtonEvent. https://bugzilla.redhat.com/show_bug.cgi?id=1511126 --- app/models/custom_button.rb | 5 ++++- app/models/custom_button_event.rb | 10 ++++++++++ app/models/resource_action.rb | 1 + spec/models/resource_action_spec.rb | 1 + 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/models/custom_button.rb b/app/models/custom_button.rb index 7b1c0b379fb0..72586d2c2800 100644 --- a/app/models/custom_button.rb +++ b/app/models/custom_button.rb @@ -101,12 +101,15 @@ def publish_event(source, target, args) :message => 'Custom button launched', :source => source, :target => target, + :username => args[:username], :user_id => args[:user_id], :group_id => args[:miq_group_id], :tenant_id => args[:tenant_id], :full_data => { :args => args, - :automate_entry_point => resource_action.ae_path + :automate_entry_point => resource_action.ae_path, + :button_id => id, + :button_name => name } ) end diff --git a/app/models/custom_button_event.rb b/app/models/custom_button_event.rb index d2d56e01ad8e..f2fbaf88b199 100644 --- a/app/models/custom_button_event.rb +++ b/app/models/custom_button_event.rb @@ -1,2 +1,12 @@ class CustomButtonEvent < EventStream + virtual_column :button_name, :type => :string + virtual_column :automate_entry_point, :type => :string + + def automate_entry_point + full_data[:automate_entry_point] + end + + def button_name + CustomButton.find(full_data[:button_id])&.name || full_data[:button_name] + end end diff --git a/app/models/resource_action.rb b/app/models/resource_action.rb index 56b876f9384f..b0fe17e2afe8 100644 --- a/app/models/resource_action.rb +++ b/app/models/resource_action.rb @@ -38,6 +38,7 @@ def automate_queue_hash(target, override_attrs, user) args[:user_id] ||= user.id args[:miq_group_id] ||= user.current_group.id args[:tenant_id] ||= user.current_tenant.id + args[:username] ||= user.userid end end diff --git a/spec/models/resource_action_spec.rb b/spec/models/resource_action_spec.rb index 1159d8bc7e99..e40f7cd51014 100644 --- a/spec/models/resource_action_spec.rb +++ b/spec/models/resource_action_spec.rb @@ -14,6 +14,7 @@ :user_id => user.id, :miq_group_id => user.current_group.id, :tenant_id => user.current_tenant.id, + :username => user.userid, :attrs => ae_attributes, } end