Module: Cyclid::API::Organizations::Members
- Defined in:
- app/cyclid/controllers/organizations/members.rb
Overview
API endpoints for Organization members
Organizations collapse
-
#GET(/organizations/: organization/members/:username) ⇒ Object
Get the details of the specified user within the organization.
-
#PUT(/organizations/: name/members/:username) ⇒ 200, 404
Modify the permissions of specified user within the organization.
Class Method Summary collapse
-
.registered(app) ⇒ Object
Sinatra callback.
Class Method Details
.registered(app) ⇒ Object
Sinatra callback
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 131 132 133 134 135 136 137 138 139 140 141 |
# File 'app/cyclid/controllers/organizations/members.rb', line 67 def self.registered(app) include Errors::HTTPErrors # Get the details of the specified user within the organization. app.get '/:username' do (params[:name], Operations::READ) org = Organization.find_by(name: params[:name]) halt_with_json_response(404, INVALID_ORG, 'organization does not exist') \ if org.nil? user = org.users.find_by(username: params[:username]) halt_with_json_response(404, INVALID_USER, 'user does not exist') \ if user.nil? begin perms = user..find_by(organization: org) user_hash = user.serializable_hash user_hash.delete_if do |key, _value| key == 'password' || key == 'secret' end perms_hash = perms.serializable_hash perms_hash.delete_if do |key, _value| key == 'id' || key == 'user_id' || key == 'organization_id' end user_hash['permissions'] = perms_hash return user_hash.to_json rescue ActiveRecord::ActiveRecordError, \ ActiveRecord::UnknownAttributeError => ex Cyclid.logger.debug ex. halt_with_json_response(500, INTERNAL_ERROR, ex.) end end # Modify the specified user within the organization. app.put '/:username' do (params[:name], Operations::WRITE) payload = parse_request_body Cyclid.logger.debug payload org = Organization.find_by(name: params[:name]) halt_with_json_response(404, INVALID_ORG, 'organization does not exist') \ if org.nil? user = org.users.find_by(username: params[:username]) halt_with_json_response(404, INVALID_USER, 'user does not exist') \ if user.nil? begin perms = user..find_by(organization: org) payload_perms = payload['permissions'] if payload.key? 'permissions' unless payload_perms.nil? perms.admin = payload_perms['admin'] if payload_perms.key? 'admin' perms.write = payload_perms['write'] if payload_perms.key? 'write' perms.read = payload_perms['read'] if payload_perms.key? 'read' Cyclid.logger.debug perms.serializable_hash perms.save! end rescue ActiveRecord::ActiveRecordError, \ ActiveRecord::UnknownAttributeError => ex Cyclid.logger.debug ex. halt_with_json_response(500, INTERNAL_ERROR, ex.) end end end |
Instance Method Details
#GET(/organizations/: organization/members/:username) ⇒ Object
Get the details of the specified user within the organization.
|
# File 'app/cyclid/controllers/organizations/members.rb', line 27
|
#PUT(/organizations/: name/members/:username) ⇒ 200, 404
Modify the permissions of specified user within the organization.
|
# File 'app/cyclid/controllers/organizations/members.rb', line 46
|