-
Notifications
You must be signed in to change notification settings - Fork 898
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 to catch the retirement requester in automate. #17033
Conversation
@@ -15,7 +15,10 @@ def retire(ids, options = {}) | |||
object = find_by(:id => id) | |||
object.retire(options) if object.respond_to?(:retire) | |||
end | |||
MiqQueue.put(:class_name => 'RetirementManager', :method_name => 'check') | |||
q_options = {:class_name => 'RetirementManager', :method_name => 'check'} | |||
user = User.current_user |
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.
@lfu How do we ensure that the User.current_user is set? Should we be raising an error if its not set
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.
@mkanoor We only take and store the user info into the queue only when the user is set. The retirement requester would default to system
if no user is specified.
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.
The system
account would be used when retirement is initiated from the scheduler.
@@ -143,6 +143,18 @@ | |||
@vm.raise_retirement_event(event_name) | |||
end | |||
|
|||
it "#raise_retirement_event with current user" do | |||
User.current_user = FactoryGirl.create(:user_with_group, :userid => 'freddy') |
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.
@lfu Instead of directly setting the User.current user you should use the User.with_user e.g. https://github.com/ManageIQ/manageiq/blob/master/spec/models/miq_event_spec.rb#L112
63266f0
to
bc7e5a0
Compare
@lfu Looks good. |
@@ -178,6 +181,7 @@ def retired_event_name | |||
end | |||
|
|||
def raise_retirement_event(event_name, requester = nil) | |||
requester ||= User.current_user.try(:userid) |
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.
The raise_retirement_event
method gets call from two places: retirement_check
and retire_now
.
The retirement_check
method is called from the scheduler and I do not believe it gets called anywhere else, so I would expect User.current_user
to be nil.
The retire_now
method can get called directly by a user and on line 128 sets update_attributes(:retirement_requester => requester)
. With your current code change the User.current_user
would be passed to the event, but not set for the retirement_requester
on the object, so this is only a partial fix.
Moving requester ||= User.current_user.try(:userid)
into retire_now
before the update_attributes
call would resolve this.
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.
retirement_check
gets called when running Set Retirement Date
.
When retire_now
gets called from UI or API, requester
is already set with this change.
bc7e5a0
to
1c1ec01
Compare
There is still one place where the userid is set to system with this PR as shown in the audit log messages.
That happens when retirement is done, |
@lfu Wouldn't it be safe to assume that |
1c1ec01
to
a51fa32
Compare
@lfu Please review test failures which are based on passing |
a51fa32
to
037c427
Compare
Checked commit lfu@037c427 with ruby 2.3.3, rubocop 0.52.0, haml-lint 0.20.0, and yamllint 1.10.0 |
Changes to catch the retirement requester in automate. (cherry picked from commit 7856a59) https://bugzilla.redhat.com/show_bug.cgi?id=1552800
Gaprindashvili backport details:
|
The retirement_initiator is 'system' instead of 'user' as it is when it is initiated from the UI.
https://bugzilla.redhat.com/show_bug.cgi?id=1547527
@miq-bot assign @gmcculloug
@miq-bot add_label bug, gaprindashvili/yes
cc @tinaafitz @mkanoor