Module: Cyclid::API::Organizations::Document
- Defined in:
- app/cyclid/controllers/organizations/document.rb
Overview
API endpoints for a single Organization document
Organizations collapse
-
#GET(/organizations/: organization) ⇒ Object
Get a specific organization.
-
#PUT(/organizations/: organization) ⇒ 200, 404
Modify an organization.
Class Method Summary collapse
-
.registered(app) ⇒ Object
Sinatra callback.
Class Method Details
.registered(app) ⇒ Object
Sinatra callback
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 |
# File 'app/cyclid/controllers/organizations/document.rb', line 68 def self.registered(app) include Errors::HTTPErrors # Get a specific organization. app.get 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? # Base64 encode the public key public_key = Base64.strict_encode64(org.rsa_public_key) # Convert to a Hash, sanitize and inject the Users data & encoded # RSA key org_hash = sanitize_organization(org.serializable_hash) org_hash['users'] = org.users.map(&:username) org_hash['public_key'] = public_key return org_hash.to_json end # Modify a specific organization. app.put 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? begin # Change the owner email if one is provided org['owner_email'] = payload['owner_email'] if payload.key? 'owner_email' # Change the users if a list of users was provided if payload.key? 'users' # Add each provided user to the Organization org.users = payload['users'].map do |username| user = User.find_by(username: username) halt_with_json_response(404, \ INVALID_USER, \ "user #{username} does not exist") \ if user.nil? user end end org.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, "organization #{params['name']} updated") end end |
Instance Method Details
#GET(/organizations/: organization) ⇒ Object
Get a specific organization. The RSA public key is in Base64 encoded DER format, and can be used to encrypt secrets that can be decrypted only by the server.
|
# File 'app/cyclid/controllers/organizations/document.rb', line 27
|
#PUT(/organizations/: organization) ⇒ 200, 404
Modify an organization. The organizations name or public key can not be changed. If a list of users is provided, the current list will be replaced, so clients should first retrieve the full list of users, modify it, and then use this API to set the final list of users.
|
# File 'app/cyclid/controllers/organizations/document.rb', line 44
|