diff options
author | John Keiser <jkeiser@opscode.com> | 2014-08-21 21:33:04 -0700 |
---|---|---|
committer | John Keiser <jkeiser@opscode.com> | 2014-08-22 09:20:51 -0700 |
commit | e21113a0aabde91dbbfd7e61a7095c84589642f3 (patch) | |
tree | 46e10808ccd3b1d52fba0820ad51db4e5d78e74a /lib | |
parent | 4c355c78a6ccfb888d557d3b96cc268edc7a7fb4 (diff) | |
download | chef-zero-e21113a0aabde91dbbfd7e61a7095c84589642f3.tar.gz |
Add POST /organizations/ORG/users/NAME to add user direct
Diffstat (limited to 'lib')
-rw-r--r-- | lib/chef_zero/endpoints/organization_user_endpoint.rb | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/chef_zero/endpoints/organization_user_endpoint.rb b/lib/chef_zero/endpoints/organization_user_endpoint.rb index c7b4817..ad7a1d1 100644 --- a/lib/chef_zero/endpoints/organization_user_endpoint.rb +++ b/lib/chef_zero/endpoints/organization_user_endpoint.rb @@ -19,6 +19,30 @@ module ChefZero user = JSON.parse(user, :create_additions => false) json_response(200, ChefData::DataNormalizer.normalize_user(user, request.rest_path[3], ['username'], server.options[:osc_compat])) end + + def post(request) + orgname = request.rest_path[1] + username = request.rest_path[3] + + users = get_data(request, [ 'organizations', orgname, 'groups', 'users' ]) + users = JSON.parse(users, :create_additions => false) + + create_data(request, [ 'organizations', orgname, 'users' ], username, '{}') + + # /organizations/ORG/association_requests/USERNAME-ORG + begin + delete_data(request, [ 'organizations', orgname, 'association_requests', "#{username}-#{orgname}"], :data_store_exceptions) + rescue DataStore::DataNotFoundError + end + + # Add the user to the users group if it isn't already there + if !users['users'] || !users['users'].include?(username) + users['users'] ||= [] + users['users'] |= [ username ] + set_data(request, [ 'organizations', orgname, 'groups', 'users' ], JSON.pretty_generate(users)) + end + json_response(200, {}) + end end end end |