Bug 1092656 - Cannot set default_organization_id at user creation
Summary: Cannot set default_organization_id at user creation
Keywords:
Status: CLOSED WONTFIX
Alias: None
Product: Red Hat Satellite
Classification: Red Hat
Component: API
Version: Nightly
Hardware: Unspecified
OS: Unspecified
unspecified
medium
Target Milestone: Unspecified
Assignee: Dustin Tsang
QA Contact: Katello QA List
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2014-04-29 16:37 UTC by Tomas Lestach
Modified: 2014-06-09 11:48 UTC (History)
5 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2014-06-06 21:10:06 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)
part of /var/log/foreman/production.log (18.59 KB, text/x-log)
2014-04-29 16:37 UTC, Tomas Lestach
no flags Details

Description Tomas Lestach 2014-04-29 16:37:46 UTC
Created attachment 890865 [details]
part of /var/log/foreman/production.log

Description of problem:
Creation of an user via API with default_organization_id set fails with 500 ISE.

Version-Release number of selected component (if applicable):
Satellite-6.0.3-RHEL-6-20140423.1-Satellite-x86_64-dvd1.iso

How reproducible:
always

Steps to Reproduce:
1. Run @api.resource(:users).call(:create, user_hash) with following user_hash:
user_hash = {
          :login => "newuser",
          :firstname => "user",
          :lastname => "new",
          :mail => "root@localhost",
          :auth_source_id => 1,
          :password => "password",
          :organization_ids => [13],
          :default_organization_id => 13,
          :location_ids => [],
          :role_ids => [],
        }

Actual results:
Creation of user failed with: 500 Internal Server Error: {
  "error": {"message":"undefined method `key?' for #<JSON::Ext::Generator::State:0x007f696cecadd8>"}
}
*but* the user was created!

Expected results:
no exceptions or ISEs

Additional info:
- creating of the user without default_organization_id works and setting it using the user update API afterwards works as well

Comment 1 RHEL Program Management 2014-04-29 16:55:16 UTC
Since this issue was entered in Red Hat Bugzilla, the release flag has been
set to ? to ensure that it is properly evaluated for this release.

Comment 3 Dustin Tsang 2014-05-12 02:51:45 UTC
redmine issue created

Comment 4 Dustin Tsang 2014-05-23 16:03:31 UTC
Hi Tomas, I tested the call with what's out on upstream. The issue may have been solved already. ISE is no longer given and a proper validation message is given.
Is this behavior fine? See examples of behavior on the latest upstream code.

https://gist.github.com/dustint-rh/f3e0408e1cc937a8f4fb

Comment 5 Tomas Lestach 2014-05-27 11:38:41 UTC
Hello Dustin,

as this BZ is filed against Satellite 6, it's determinative, when the BZ will be fixed in Satellite 6. 

Checking your examples you're not getting an ISE anymore, but you're still not able to create a user with a default organization set.

I'm not sure what does "Default organization Default organizations need to be user organizations first" mean (and this might be what I'm missing), but if I'm able to create a user with default organization set via WebUI, I'd expect to be able to do it similarly via API as well.

Comment 6 Dustin Tsang 2014-05-28 17:36:10 UTC
removing association to redmine issue, will create a new issue lateer if necessary.

Comment 7 Dustin Tsang 2014-05-28 17:49:28 UTC
Tomas,

Sorry, it wasn't too clear the way I put everything into one gist like that.

If you see the very last example starting at line 100 (https://gist.github.com/dustint-rh/f3e0408e1cc937a8f4fb#file-gistfile1-rb-L100), I was able to create a default organization successfully.

I think the validation message could be clearer. The validation is trying to prevent setting a default organization that doesn't have an association with the user; The default organization being set must also be part of organizations being passed in creation so that the association to the default organization is created. (see lines 105,106 https://gist.github.com/dustint-rh/f3e0408e1cc937a8f4fb#file-gistfile1-rb-L105)

would it be sufficient to make update the validation message?

Comment 8 Dustin Tsang 2014-05-28 17:50:20 UTC
Tomas,

Sorry, it wasn't too clear the way I put everything into one gist like that.

If you see the very last example starting at line 100 (https://gist.github.com/dustint-rh/f3e0408e1cc937a8f4fb#file-gistfile1-rb-L100), I was able to create a default organization successfully.

I think the validation message could be clearer. The validation is trying to prevent setting a default organization that doesn't have an association with the user; The default organization being set must also be part of organizations being passed in creation so that the association to the default organization is created. (see lines 105,106 https://gist.github.com/dustint-rh/f3e0408e1cc937a8f4fb#file-gistfile1-rb-L105)

would it be sufficient to make an update to the validation message?

Comment 9 Tomas Lestach 2014-05-29 11:33:51 UTC
Hello Dustin,

thank you for the explanation.

So, your first call at line 23, where you miss an extra "user" hash within the user_hash should say something else (in case the extra "user" hash is required)

Your second call at line 66 fails because the organization you want to set as default_organization isn't a user organization already. I am totally ok with the error message/exception thrown.

The last call at line 109 succeeds, so it's ok. Just note you set strings ("1") as organization ids instead of integers (1).

Comment 10 Dustin Tsang 2014-06-06 14:45:06 UTC
Hi Tomas,

We can't really provide validation for user_hash to be provided since it really is an optional param to be passed in. Some params like search/pagination can come in as top-level params.

I'm gonna mark it as post.

Comment 12 Dustin Tsang 2014-06-06 21:10:06 UTC
jason, closing as WONTFIX.

Comment 13 Tomas Lestach 2014-06-09 11:48:13 UTC
Hello Dustin, I do not know the code to confront Comment 10.
From user perspective, it's possible to set the default_organization_id at user creation via WEBUI. Why isn't the same possible via API? Cannot the same code be reused?


Note You need to log in before you can comment on or make changes to this bug.