Skip to content

Commit

Permalink
Need to pass the user's group in to automate when the provision starts.
Browse files Browse the repository at this point in the history
User's current group might have changed before the provision finishes.
So the user's current group from DB may be different from the user's group when the request is sent into automate.

https://bugzilla.redhat.com/show_bug.cgi?id=1467364
  • Loading branch information
lfu committed Aug 2, 2017
1 parent 1439897 commit 77267db
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
3 changes: 2 additions & 1 deletion lib/miq_automation_engine/engine/miq_ae_engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,8 @@ def self.ae_user_object(options = {})
raise "user_id not specified in Automation request" if options[:user_id].blank?
# raise "group_id not specified in Automation request" if options[:miq_group_id].blank?
User.find_by!(:id => options[:user_id]).tap do |obj|
# obj.current_group = MiqGroup.find_by!(:id => options[:miq_group_id])
obj.current_group = MiqGroup.find_by!(:id => options[:miq_group_id]) if options[:miq_group_id]
$miq_ae_logger.info("User [#{obj.userid}] with current group ID [#{obj.current_group.id}] name [#{obj.current_group.description}]")
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def process_assertions(message)

def user_info_attributes(user)
{'user' => user, 'tenant' => user.current_tenant, 'miq_group' => user.current_group}.each do |k, v|
value = MiqAeObject.convert_value_based_on_datatype(v.id, v.class.name)
value = MiqAeMethodService::MiqAeServiceModelBase.wrap_results(v)
@attributes[k] = value unless value.nil?
end
end
Expand Down
20 changes: 18 additions & 2 deletions spec/miq_ae_engine_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ def call_automate(obj_type, obj_id)
object_type = @cluster.class.name
object_id = @cluster.id
automate_attrs = {"#{object_type}::#{object_type.underscore}" => object_id,
"User::user" => @user.id}
"User::user" => @user.id,
"MiqGroup::miq_group" => @user.current_group.id}
expect(MiqAeEngine).to receive(:create_automation_object).with(@instance_name, automate_attrs, {:vmdb_object => @cluster}).and_return('uri')
expect(call_automate(object_type, object_id)).to be_nil
end
Expand All @@ -89,7 +90,8 @@ def call_automate(obj_type, obj_id)
object_type = @ems.class.name
object_id = @ems.id
automate_attrs = {"#{base_name}::#{base_name.underscore}" => object_id,
"User::user" => @user.id}
"User::user" => @user.id,
"MiqGroup::miq_group" => @user.current_group.id}
expect(MiqAeEngine).to receive(:create_automation_object).with(@instance_name, automate_attrs, {:vmdb_object => @ems}).and_return('uri')
expect(call_automate(object_type, object_id)).to be_nil
end
Expand Down Expand Up @@ -467,6 +469,20 @@ def call_automate(obj_type, obj_id)
end
end

context ".ae_user_object" do
it "user stays in the same group" do
user_obj = MiqAeEngine.ae_user_object(:user_id => @user.id)
expect(user_obj.current_group).to eq(@user.current_group)
end

it "user has changed the group" do
requester_group = FactoryGirl.create(:miq_group)
user_obj = MiqAeEngine.ae_user_object(:user_id => @user.id, :miq_group_id => requester_group.id)
expect(user_obj.current_group).to eq(requester_group)
expect(user_obj.current_group).not_to eq(@user.current_group)
end
end

it "a namespace containing a slash is parsed correctly " do
start = "namespace/more_namespace/my_favorite_class"
msg_attrs = "message=testmessage&object_name=REQUEST&request=NOT_THERE"
Expand Down

0 comments on commit 77267db

Please sign in to comment.