Commit edc6d00b authored by Patricio Cano's avatar Patricio Cano

License information can now be retrieved via the API

parent 437679ec
v 8.3.0 (unreleased) v 8.3.0 (unreleased)
- License information can now be retrieved via the API
v 8.2.0 v 8.2.0
- Invalidate stored jira password if the endpoint URL is changed - Invalidate stored jira password if the endpoint URL is changed
...@@ -26,7 +27,7 @@ v 8.1.0 ...@@ -26,7 +27,7 @@ v 8.1.0
- Add documentation for "Share project with group" API call - Add documentation for "Share project with group" API call
- Added an issues template (Hannes Rosenögger) - Added an issues template (Hannes Rosenögger)
- Add documentation for "Share project with group" API call - Add documentation for "Share project with group" API call
- Abiliy to disable 'Share with Group' feature (via UI and API) - Ability to disable 'Share with Group' feature (via UI and API)
v 8.0.6 v 8.0.6
- No EE-specific changes - No EE-specific changes
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
- [Namespaces](namespaces.md) - [Namespaces](namespaces.md)
- [Settings](settings.md) - [Settings](settings.md)
- [Keys](keys.md) - [Keys](keys.md)
- [License](license.md)
## Clients ## Clients
......
# License
## Retrieve information about the current license
In order to retrieve the license information, you need to authenticate yourself
as an admin.
```
GET /license
```
```json
{
"starts_at": "2015-10-24",
"expires_at": "2016-10-24",
"licensee": {
"Name": "John Doe",
"Company": "Doe, Inc.",
"Email": "john@doe.com"
},
"user_limit": 100,
"active_users": 60
}
```
\ No newline at end of file
...@@ -56,5 +56,6 @@ module API ...@@ -56,5 +56,6 @@ module API
mount Settings mount Settings
mount Keys mount Keys
mount Tags mount Tags
mount LicenseInfo
end end
end end
...@@ -373,5 +373,17 @@ module API ...@@ -373,5 +373,17 @@ module API
end end
end end
end end
class License < Grape::Entity
expose :starts_at, :expires_at, :licensee
expose :user_limit do |license, options|
license.restricted?(:active_user_count) ? license.restrictions[:active_user_count] : 0
end
expose :active_users do |license, options|
::User.active.count
end
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
...@@ -225,6 +225,7 @@ FactoryGirl.define do ...@@ -225,6 +225,7 @@ FactoryGirl.define do
factory :gitlab_license, class: "Gitlab::License" do factory :gitlab_license, class: "Gitlab::License" do
starts_at { Date.today - 1.month } starts_at { Date.today - 1.month }
expires_at { Date.today + 11.months }
licensee do licensee do
{ "Name" => FFaker::Name.name } { "Name" => FFaker::Name.name }
end end
......
require 'spec_helper'
describe API::API, api: true do
include ApiHelpers
let(:gl_license) { build(:gitlab_license) }
let(:license) { build(:license, data: gl_license.export) }
let(:admin) { create(:admin) }
let(:user) { create(:user) }
describe 'GET /license' do
it 'should retrieve the license information if admin is logged in' do
get api('/license', admin)
expect(response.status).to eq 200
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 'should deny access if not admin' do
get api('/license', user)
expect(response.status).to eq 403
end
end
end
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