summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJohn Keiser <jkeiser@opscode.com>2014-07-25 12:34:53 -0600
committerJohn Keiser <jkeiser@opscode.com>2014-08-22 09:20:49 -0700
commit91768b0e9a0a151635a0a7a96823113b200c67c6 (patch)
tree416286854dfe2c5cd7318ab08a6d023503dac3b3 /lib
parentd55406b3c3218323d9a9751e1df267fceab08eef (diff)
downloadchef-zero-91768b0e9a0a151635a0a7a96823113b200c67c6.tar.gz
Get association requests passing oc-chef-pedant
Diffstat (limited to 'lib')
-rw-r--r--lib/chef_zero/endpoints/organization_association_requests_endpoint.rb5
-rw-r--r--lib/chef_zero/endpoints/organization_user_endpoint.rb4
-rw-r--r--lib/chef_zero/endpoints/user_association_request_endpoint.rb7
3 files changed, 9 insertions, 7 deletions
diff --git a/lib/chef_zero/endpoints/organization_association_requests_endpoint.rb b/lib/chef_zero/endpoints/organization_association_requests_endpoint.rb
index 4367e6b..6534ff3 100644
--- a/lib/chef_zero/endpoints/organization_association_requests_endpoint.rb
+++ b/lib/chef_zero/endpoints/organization_association_requests_endpoint.rb
@@ -11,8 +11,9 @@ module ChefZero
orgname = request.rest_path[1]
id = "#{username}-#{orgname}"
- if !exists_data?(request, [ 'organizations', orgname, 'users', username ])
- RestErrorResponse.new(409, "User #{username} is already in organization #{orgname}")
+ if exists_data?(request, [ 'organizations', orgname, 'users', username ])
+ # TODO 403? Really?
+ raise RestErrorResponse.new(403, "User #{username} is already in organization #{orgname}")
end
create_data(request, request.rest_path, username, '{}')
diff --git a/lib/chef_zero/endpoints/organization_user_endpoint.rb b/lib/chef_zero/endpoints/organization_user_endpoint.rb
index cce9bea..1178141 100644
--- a/lib/chef_zero/endpoints/organization_user_endpoint.rb
+++ b/lib/chef_zero/endpoints/organization_user_endpoint.rb
@@ -10,14 +10,14 @@ module ChefZero
get_data(request) # 404 if user is not in org
user = get_data(request, [ 'users', username ])
user = JSON.parse(user, :create_additions => false)
- json_response(200, DataNormalizer.normalize_user(user, username, 'username'))
+ json_response(200, DataNormalizer.normalize_user(user, username, ['username']))
end
def delete(request)
user = get_data(request)
delete_data(request)
user = JSON.parse(user, :create_additions => false)
- json_response(200, DataNormalizer.normalize_user(user, request.rest_path[3], 'username'))
+ json_response(200, DataNormalizer.normalize_user(user, request.rest_path[3], ['username']))
end
end
end
diff --git a/lib/chef_zero/endpoints/user_association_request_endpoint.rb b/lib/chef_zero/endpoints/user_association_request_endpoint.rb
index edcbd72..98c9a06 100644
--- a/lib/chef_zero/endpoints/user_association_request_endpoint.rb
+++ b/lib/chef_zero/endpoints/user_association_request_endpoint.rb
@@ -14,15 +14,16 @@ module ChefZero
orgname = $1
json = JSON.parse(request.body, :create_additions => false)
+ association_request_path = [ 'organizations', orgname, 'association_requests', username ]
if json['response'] == 'accept'
+ delete_data(request, association_request_path)
create_data(request, [ 'organizations', orgname, 'users' ], username, '{}')
- delete_data(request, [ 'organizations', orgname, 'association_requests', username ])
elsif json['response'] == 'reject'
- delete_data(request, [ 'organizations', orgname, 'association_requests', username ])
+ delete_data(request, association_request_path)
else
raise RestErrorResponse.new(400, "response parameter was missing or set to the wrong value (must be accept or reject)")
end
- already_json_response(200, request.body)
+ json_response(200, { 'uri' => build_uri(request.base_uri, association_request_path) })
end
end
end