Module: Cyclid::API::Users::Document
- Defined in:
- app/cyclid/controllers/users/document.rb
Overview
API endpoints for a single Organization document
Users collapse
-
#DELETE(/users/: username) ⇒ 200, 404
Delete a specific user.
-
#GET(/users/: username) ⇒ Object
Get a specific user.
-
#PUT(/users/: username) ⇒ 200, ...
Modify a specific user.
Class Method Summary collapse
-
.registered(app) ⇒ Object
Sinatra callback.
Class Method Details
.registered(app) ⇒ Object
Sinatra callback
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'app/cyclid/controllers/users/document.rb', line 64 def self.registered(app) include Errors::HTTPErrors # Get a specific user. app.get do (params[:username], Operations::READ) user = User.find_by(username: params[:username]) halt_with_json_response(404, INVALID_USER, 'user does not exist') \ if user.nil? Cyclid.logger.debug user.organizations # Convert to a Hash and inject the User data user_hash = user.serializable_hash user_hash['organizations'] = user.organizations.map(&:name) # DO provide the users HMAC secret, in this instance user_hash = sanitize_user(user_hash, ['password']) return user_hash.to_json end # Modify a specific user. app.put do (params[:username], Operations::WRITE) payload = parse_request_body Cyclid.logger.debug payload user = User.find_by(username: params[:username]) halt_with_json_response(404, INVALID_USER, 'user does not exist') \ if user.nil? begin user.name = payload['name'] if payload.key? 'name' user.email = payload['email'] if payload.key? 'email' user.password = payload['password'] if payload.key? 'password' user.secret = payload['secret'] if payload.key? 'secret' user.new_password = payload['new_password'] if payload.key? 'new_password' user.save! rescue ActiveRecord::ActiveRecordError => ex Cyclid.logger.debug ex. halt_with_json_response(400, INVALID_JSON, ex.) end return json_response(NO_ERROR, "user #{payload['username']} modified") end # Delete a specific user. app.delete do (params[:username], Operations::ADMIN) user = User.find_by(username: params[:username]) halt_with_json_response(404, INVALID_USER, 'user does not exist') \ if user.nil? begin user.delete rescue ActiveRecord::ActiveRecordError => ex Cyclid.logger.debug ex. halt_with_json_response(400, INVALID_JSON, ex.) end return json_response(NO_ERROR, "user #{params['username']} deleted") end end |
Instance Method Details
#DELETE(/users/: username) ⇒ 200, 404
Delete a specific user.
|
# File 'app/cyclid/controllers/users/document.rb', line 52
|
#GET(/users/: username) ⇒ Object
Get a specific user.
|
# File 'app/cyclid/controllers/users/document.rb', line 27
|
#PUT(/users/: username) ⇒ 200, ...
Modify a specific user.
|
# File 'app/cyclid/controllers/users/document.rb', line 35
|