Commit c9492eb5 authored by Drew Blessing's avatar Drew Blessing

Allow adding a new license via the API

parent 6331bc87
......@@ -4,6 +4,7 @@ v 8.8.0 (unreleased)
- [Elastic] Database indexer prints its status
- [Elastic][Fix] Database indexer skips projects with invalid HEAD reference
- Fix skipping pages when restoring backups
- Add EE license via API !400
- [Elastic] More efficient snippets search
- [Elastic] Add rake task for removing all indexes
- [Elastic] Add rake task for clearing indexing status
......
......@@ -56,12 +56,12 @@ module API
mount ::API::Settings
mount ::API::Keys
mount ::API::Tags
mount ::API::LicenseInfo
mount ::API::License
mount ::API::Triggers
mount ::API::Builds
mount ::API::Variables
mount ::API::Runners
mount ::API::Licenses
mount ::API::LicenseTemplates
mount ::API::Subscriptions
end
end
module API
class License < Grape::API
before { authenticated_as_admin! }
resource :license do
# Get information on the currently active license
#
# Example request:
# GET /license
get do
license = ::License.current
present license, with: Entities::License
end
# Add a new license
#
# Parameters:
# license (required) - The license text
#
# Example request:
# POST /license
post do
required_attributes! [:license]
license = ::License.new(data: params[:license])
if license.save
present license, with: Entities::License
else
render_api_error!(license.errors.full_messages.first, 400)
end
end
end
end
end
module API
class LicenseInfo < Grape::API
before { authenticated_as_admin! }
resource :license do
# Get information on the currently active license
#
# Example request:
# GET /license
get do
@license = License.current
present @license, with: Entities::License
end
end
end
end
module API
# Licenses API
class Licenses < Grape::API
class LicenseTemplates < Grape::API
PROJECT_TEMPLATE_REGEX =
/[\<\{\[]
(project|description|
......
......@@ -24,4 +24,29 @@ describe API::API, api: true do
expect(response.status).to eq 403
end
end
describe 'POST /license' do
it 'adds a new license if admin is logged in' do
post api('/license', admin), license: gl_license.export
expect(response.status).to eq 201
expect(json_response['user_limit']).to eq 0
expect(Date.parse(json_response['starts_at'])).to eq Date.today - 1.month
expect(Date.parse(json_response['expires_at'])).to eq Date.today + 11.months
expect(json_response['active_users']).to eq 1
expect(json_response['licensee']).to_not be_empty
end
it 'denies access if not admin' do
post api('/license', user), license: license
expect(response.status).to eq 403
end
it 'returns 400 if the license cannot be saved' do
post api('/license', admin), license: 'foo'
expect(response.status).to eq(400)
end
end
end
require 'spec_helper'
describe API::Licenses, api: true do
describe API::API, api: true do
include ApiHelpers
describe 'Entity' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment