[BUG] Service_requests API is not considering same user from remote regions (like manageiq-ui-classic does)

fine

#1

Dear,

I opened a issue in github but I am not sure if that is the best place to address this problem. So, I am posting here also. The issue I opened is: #256

As far as I know, in a ManageIQ with global and remote regions, there are more than one user in users table that represents the same user (one for each region), as you can see below:

vmdb_production=# SELECT id, name, email, userid, current_group_id FROM public.users WHERE name = ‘SPMIQ01’;
id | name | email | userid | current_group_id
----------------±--------±------±------------------------------±-----------------
2000000000005 | SPMIQ01 | | spmiq01@prbbr.produbanbr.corp | 2000000000036
99000000000007 | SPMIQ01 | | spmiq01@prbbr.produbanbr.corp | 99000000000019
1000000000005 | SPMIQ01 | | spmiq01@prbbr.produbanbr.corp | 1000000000039
(3 rows)

I noticed that the service_requests api is not considering this and it is always querying for service requests from the logged user in global (99000000000007 in my case). The point here is that the owner of the service requests in fact is the user from the remote region, as you can see below:

SELECT id, description, type, requester_id, requester_name, userid
FROM miq_requests where
requester_name = ‘SPMIQ01’ AND requester_id = ‘99000000000007’;
id | description | type | requester_id | requester_name | userid

(0 rows)

SELECT id, description, type, requester_id, requester_name, userid
FROM miq_requests where
requester_name = ‘SPMIQ01’ AND requester_id in (‘2000000000005’, ‘1000000000005’);
id | description | type | requester_id | requester_name |
userid

1000000000326 | Provisioning Service [Red Hat 7.2] from [Red Hat 7.2] | ServiceTemplateProvisionRequest | 1000000000005 | SPMIQ01 | spmiq01@pr
bbr.produbanbr.corp
1000000000327 | Provisioning Service [Red Hat 7.2] from [Red Hat 7.2] | ServiceTemplateProvisionRequest | 1000000000005 | SPMIQ01 | spmiq01@pr
bbr.produbanbr.corp

I found the following in the manageiq-api code, that, in my perspective, should be fixed to consider other users from remote regions [that, in fact, is related to the same logged user]:

From manageiq-api - miq_request_controller.rb:

    def find_service_requests(id)
      klass = collection_class(:service_requests)
      return klass.find(id) if User.current_user.admin_user?
      klass.find_by!(:requester => User.current_user, :id => id)
    end

    def service_requests_search_conditions
      return {} if User.current_user.admin_user?
      {:requester => User.current_user}
    end

From manageiq ui the user is able to see all service requests. As far as I understood this is because of the following code, that considers all users from global and remote [that, in fact, is related to the same logged user]:

From manageiq-ui-classic - miq_request_controller.rb:

  def remote_and_global_requestors(requestor)
    condition = []
    requestors = User.where(:userid => requestor.try(:userid))
    if requestors.count > 1
      condition.push("or" => requestors.collect { |user| {"=" => {"value" => user.id, "field" => "MiqRequest-requester_id"}} })
    else
      condition.push("=" => {"value" => requestor.try(:id), "field" => "MiqRequest-requester_id"})
    end
  end

That said, I believe manageiq-api should have the same behavior as manageiq-ui-classic and should return the service requests for the logged user + users in the regions that represents this same user.


#2

Thanks @gfontana
You are correct, Github is the correct place to report any issues.