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
Get the current user if user context is set. #86
Conversation
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.
If you want the Queue worker to run the job in a users context you would have to set the user, group,tenant in the q_options
https://github.com/lfu/manageiq-automation_engine/blob/41f94ee0a43c2a023448a82383e7228714f43c7c/lib/miq_automation_engine/engine/miq_ae_event.rb#L124
8b746af
to
a08fd48
Compare
@@ -115,13 +115,16 @@ def self.process_result(ae_result, aevent) | |||
end | |||
|
|||
def self.call_automate(obj, attrs, instance_name, options = {}) | |||
user = obj.tenant_identity | |||
user = User.current_user || obj.tenant_identity |
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 @gmcculloug
When these events are raised and if the user is part of multiple groups which group should get used. Do we record the group with the events or vm ownership?
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 The user and the group is recorded in the Queue when the event is raised. Then the user is set to the group in the memory when the item get dequeued and processed.
spec/miq_ae_event_spec.rb
Outdated
@@ -124,6 +124,14 @@ | |||
|
|||
MiqAeEvent.raise_evm_event("vm_create", vm, :vm => vm) | |||
end | |||
|
|||
it "has current user" do | |||
User.current_user = 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 use User.with_user similar to https://github.com/ManageIQ/manageiq/blob/b978b61737bf8bffcca23ab3710500b1f677d4fe/spec/lib/rbac/filterer_spec.rb#L242
This we we dont have it set for the whole thread.
When sending events to automate, use the user context if it is available. https://bugzilla.redhat.com/show_bug.cgi?id=1487749
a08fd48
to
d6d39bb
Compare
Checked commit lfu@d6d39bb with ruby 2.3.3, rubocop 0.47.1, and haml-lint 0.20.0 |
@mkanoor Please review. |
PR ManageIQ/manageiq#16089 allows the user_id/group_id/tenant_id to be recorded in the Queue and sets the user context when dispatching the item from the Queue.
This PR would use the user context if it is available when sending events to automate.
Blocks ManageIQ/manageiq#16179.
https://bugzilla.redhat.com/show_bug.cgi?id=1487749
cc @mkanoor