-
Notifications
You must be signed in to change notification settings - Fork 914
[GAPRINDASHVILI] Add requester info to raise_retirement_event #18106
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -106,18 +106,19 @@ def raise_retire_audit_event(message) | |||||
|
|
||||||
| def retirement_check | ||||||
| return if retired? || retiring? || retirement_initialized? | ||||||
| requester = system_context_requester | ||||||
|
|
||||||
| if !retirement_warned? && retirement_warning_due? | ||||||
| begin | ||||||
| self.retirement_last_warn = Time.now.utc | ||||||
| save | ||||||
| raise_retirement_event(retire_warn_event_name) | ||||||
| raise_retirement_event(retire_warn_event_name, requester) | ||||||
| rescue => err | ||||||
| _log.log_backtrace(err) | ||||||
| end | ||||||
| end | ||||||
|
|
||||||
| retire_now if retirement_due? | ||||||
| retire_now(requester) if retirement_due? | ||||||
| end | ||||||
|
|
||||||
| def retire_now(requester = nil) | ||||||
|
|
@@ -195,8 +196,7 @@ def retired_event_name | |||||
| end | ||||||
|
|
||||||
| def raise_retirement_event(event_name, requester = nil) | ||||||
| requester ||= User.current_user.try(:userid) | ||||||
| q_options = retire_queue_options | ||||||
| q_options = q_user_info(retire_queue_options, requester) | ||||||
| $log.info("Raising Retirement Event for [#{name}] with queue options: #{q_options.inspect}") | ||||||
| MiqEvent.raise_evm_event(self, event_name, setup_event_hash(requester), q_options) | ||||||
| end | ||||||
|
|
@@ -231,15 +231,34 @@ def valid_zone? | |||||
| respond_to?(:my_zone) && my_zone.present? | ||||||
| end | ||||||
|
|
||||||
| def setup_event_hash(requester) | ||||||
| event_hash = {:retirement_initiator => "system"} | ||||||
| event_hash[retirement_base_model_name.underscore.to_sym] = self | ||||||
| event_hash[:host] = host if self.respond_to?(:host) | ||||||
| def system_context_requester | ||||||
| if try(:evm_owner_id) | ||||||
| User.find(evm_owner_id) | ||||||
| else | ||||||
| $log.info("System context defaulting to admin user because owner of #{name} not set.") | ||||||
| User.super_admin | ||||||
| end | ||||||
| end | ||||||
|
|
||||||
| def q_user_info(q_options, requester) | ||||||
| if requester | ||||||
| event_hash[:userid] = requester | ||||||
| event_hash[:retirement_initiator] = "user" | ||||||
| if requester.kind_of?(String) | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this ever get called with a string?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup! It can!
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||
| requester = User.find_by(:userid => requester) | ||||||
| end | ||||||
| q_options[:user_id] = requester.id | ||||||
| q_options[:group_id] = requester.current_group.id if requester.current_group | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Heh - this makes me reference the code every time I see it - It is not necessary since the very next line is looking up the
Suggested change
|
||||||
| q_options[:tenant_id] = requester.current_tenant.id if requester.current_tenant | ||||||
| end | ||||||
| q_options | ||||||
| end | ||||||
|
|
||||||
| def setup_event_hash(requester) | ||||||
| { | ||||||
| :userid => requester, | ||||||
| retirement_base_model_name.underscore.to_sym => self, | ||||||
| :type => self.class.name | ||||||
| }.tap do |event| | ||||||
| event[:host] = host if respond_to?(:host) | ||||||
| end | ||||||
| event_hash[:type] ||= self.class.name | ||||||
| event_hash | ||||||
| end | ||||||
| end | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.