Module: Cyclid::API::Users::Collection
- Defined in:
- app/cyclid/controllers/users/collection.rb
Overview
API endpoints for the User collection
Users collapse
-
#POST(/users) ⇒ 200, ...
Create a new user.
-
#GET(/users) ⇒ Object
Get all of the users.
Class Method Summary collapse
-
.registered(app) ⇒ Object
Sinatra callback.
Class Method Details
.registered(app) ⇒ Object
Sinatra callback
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 |
# File 'app/cyclid/controllers/users/collection.rb', line 71 def self.registered(app) include Errors::HTTPErrors # @macro [attach] sinatra.get # @overload get "$1" # @method get_users # @return [String] JSON represention of all of all the users. # Get all of the users across all organizations. app.get do (Operations::READ) # Retrieve the user data in a form we can more easily manipulate so # that we can sanitize it users = User.all_as_hash # Remove any sensitive data users.map! do |user| sanitize_user(user) end return users.to_json end # @macro [attach] sinatra.post # @overload post "$1" # @method post_users # Create a new user. app.post do (Operations::ADMIN) payload = parse_request_body Cyclid.logger.debug payload begin halt_with_json_response(409, \ DUPLICATE, \ 'a user with that name already exists') \ if User.exists?(username: payload['username']) user = User.new user.username = payload['username'] user.email = payload['email'] user.name = payload['name'] if payload.key? 'name' 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, \ ActiveRecord::UnknownAttributeError => ex Cyclid.logger.debug ex. halt_with_json_response(400, INVALID_JSON, ex.) end return json_response(NO_ERROR, "user #{payload['username']} created") end end |
Instance Method Details
#POST(/users) ⇒ 200, ...
Create a new user. Note that only one of ‘password’ or ‘new_password’ should be passed.
|
# File 'app/cyclid/controllers/users/collection.rb', line 45
|
#GET(/users) ⇒ Object
Get all of the users.
|
# File 'app/cyclid/controllers/users/collection.rb', line 27
|