summaryrefslogtreecommitdiff
path: root/lib/chef_zero/endpoints
diff options
context:
space:
mode:
authorJohn Keiser <jkeiser@opscode.com>2014-08-21 17:30:48 -0700
committerJohn Keiser <jkeiser@opscode.com>2014-08-22 09:20:51 -0700
commit25c8afd9561fcee0c3f1bd0e2a5fb2dd79cb8f5d (patch)
tree1eb63242f49c3b0eb854317ccdf5d49f86ccb629 /lib/chef_zero/endpoints
parentf903287e6207954c4686900f5d4d4dba7a83d0fa (diff)
downloadchef-zero-25c8afd9561fcee0c3f1bd0e2a5fb2dd79cb8f5d.tar.gz
Add users to the users group in an org if not already there
Diffstat (limited to 'lib/chef_zero/endpoints')
-rw-r--r--lib/chef_zero/endpoints/user_association_request_endpoint.rb10
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/chef_zero/endpoints/user_association_request_endpoint.rb b/lib/chef_zero/endpoints/user_association_request_endpoint.rb
index b57839e..ead081b 100644
--- a/lib/chef_zero/endpoints/user_association_request_endpoint.rb
+++ b/lib/chef_zero/endpoints/user_association_request_endpoint.rb
@@ -16,8 +16,18 @@ module ChefZero
json = JSON.parse(request.body, :create_additions => false)
association_request_path = [ 'organizations', orgname, 'association_requests', username ]
if json['response'] == 'accept'
+ users = get_data(request, [ 'organizations', orgname, 'groups', 'users' ])
+ users = JSON.parse(users, :create_additions => false)
+
delete_data(request, association_request_path)
create_data(request, [ 'organizations', orgname, 'users' ], username, '{}')
+
+ # 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
elsif json['response'] == 'reject'
delete_data(request, association_request_path)
else