Permalink
Browse files

pass username instead of user id

  • Loading branch information...
obfuscurity committed Mar 16, 2012
1 parent 7cb6a17 commit d265009a87eb2d624ae1350632b331367a19c58d
Showing with 15 additions and 15 deletions.
  1. +8 −8 api.rb
  2. +4 −4 tests/test_api.rb
  3. +3 −3 views/api.haml
View
16 api.rb
@@ -49,8 +49,8 @@ def validate_site(uuid)
@site = Site.filter(:uuid => :$u, :owner_id => @user.id, :enabled => true).call(:first, :u => uuid)
halt 404, { :message => 'site not found' }.to_json if @site.nil?
end
- def validate_site_user(id)
- @site_user = User.filter(:id => :$i, :site_id => @site.id, :enabled => true).call(:first, :i => id)
+ def validate_site_user(username)
+ @site_user = User.filter(:username => :$u, :site_id => @site.id, :enabled => true).call(:first, :u => username)
halt 404, { :message => 'user not found' }.to_json if @site_user.nil?
end
end
@@ -115,25 +115,25 @@ def validate_site_user(id)
@site_users.to_json
end
- get '/sites/:uuid/users/:id/?' do
+ get '/sites/:uuid/users/:username/?' do
validate_site(params[:uuid])
- validate_site_user(params[:id])
+ validate_site_user(params[:username])
@site_user.values.to_json
end
- put '/sites/:uuid/users/:id' do
+ put '/sites/:uuid/users/:username' do
validate_site(params[:uuid])
- validate_site_user(params[:id])
+ validate_site_user(params[:username])
@site_user.update_password(params[:password]) if params[:password]
@site_user.update(:custom => params[:custom]) if params[:custom]
@site_user.save
[ :password, :email, :api_token, :confirm_token, :email_is_username, :enabled, :site_id ].each {|k| @site_user.values.delete(k)}
@site_user.values.to_json
end
- delete '/sites/:uuid/users/:id' do
+ delete '/sites/:uuid/users/:username' do
validate_site(params[:uuid])
- validate_site_user(params[:id])
+ validate_site_user(params[:username])
@site_user.destroy
status 204
end
View
@@ -126,7 +126,7 @@ def test_13_list_users
def test_14_modify_user
"Modifying the custom data blob of our test user"
- put "/sites/#{@@site['uuid']}/users/#{@@site_user['id']}", {:custom => '{"firstname":"Test","lastname":"Tester"}'}, @@options
+ put "/sites/#{@@site['uuid']}/users/#{@@site_user['username']}", {:custom => '{"firstname":"Test","lastname":"Tester"}'}, @@options
@@site_user = JSON.parse(last_response.body)
assert last_response.status == 200
assert_equal JSON.parse(@@site_user['custom'])['firstname'], 'Test'
@@ -141,7 +141,7 @@ def test_15_get_user_unknown
def test_16_get_user
"Getting the details of our test user"
- get "/sites/#{@@site['uuid']}/users/#{@@site_user['id']}", {}, @@options
+ get "/sites/#{@@site['uuid']}/users/#{@@site_user['username']}", {}, @@options
@@site_user = JSON.parse(last_response.body)
assert last_response.status == 200
assert_equal JSON.parse(@@site_user['custom'])['firstname'], 'Test'
@@ -163,15 +163,15 @@ def test_18_auth_user
def test_19_delete_user
"Deleting our test user"
- delete "/sites/#{@@site['uuid']}/users/#{@@site_user['id']}", {}, @@options
+ delete "/sites/#{@@site['uuid']}/users/#{@@site_user['username']}", {}, @@options
assert last_response.status == 204
user = User[@@site_user['id']]
assert user.values[:enabled] == false
end
def test_20_get_invalid_user
"Getting user details should fail after deleting user"
- get "/sites/#{@@site['uuid']}/users/#{@@site_user['id']}", {}, @@options
+ get "/sites/#{@@site['uuid']}/users/#{@@site_user['username']}", {}, @@options
assert last_response.status == 404
end
View
@@ -402,7 +402,7 @@
%pre.code
:preserve
$ curl -i -H 'X_API_VERSION:1' -H 'X_API_TOKEN:4192x459-a0b0-243fdaffb1239' \
- https://vellup-api.herokuapp.com/sites/98790123ab908098abffad4328/users/13
+ https://vellup-api.herokuapp.com/sites/98790123ab908098abffad4328/users/testy7%40domain.com
%h4 Response
@@ -437,7 +437,7 @@
:preserve
$ curl -i -H 'X_API_VERSION:1' -H 'X_API_TOKEN:4192x459-a0b0-243fdaffb1239' \
-d 'password=changeme' \
- -X PUT https://vellup-api.herokuapp.com/sites/98790123ab908098abffad4328/users/13
+ -X PUT https://vellup-api.herokuapp.com/sites/98790123ab908098abffad4328/users/testy7%40domain.com
%h4 Response
@@ -515,7 +515,7 @@
%pre.code
:preserve
$ curl -i -H 'X_API_VERSION:1' -H 'X_API_TOKEN:4192x459-a0b0-243fdaffb1239' \
- -X DELETE https://vellup-api.herokuapp.com/sites/98790123ab908098abffad4328/users/14
+ -X DELETE https://vellup-api.herokuapp.com/sites/98790123ab908098abffad4328/users/testy8%40domain.com
%h4 Response

0 comments on commit d265009

Please sign in to comment.