mirror of
https://github.com/wahyd4/gitlabhq.git
synced 2026-08-12 06:06:05 +10:00
Merge branch 'api-license-info' into 'master'
License information can now be retrieved via the API Fixes #54 @DouweM if you have time to review as well, that would be great. See merge request !65
This commit is contained in:
+2
-1
@@ -1,4 +1,5 @@
|
||||
v 8.3.0 (unreleased)
|
||||
- License information can now be retrieved via the API
|
||||
|
||||
v 8.2.0
|
||||
- Invalidate stored jira password if the endpoint URL is changed
|
||||
@@ -26,7 +27,7 @@ v 8.1.0
|
||||
- Add documentation for "Share project with group" API call
|
||||
- Added an issues template (Hannes Rosenögger)
|
||||
- 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
|
||||
- No EE-specific changes
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
- [Namespaces](namespaces.md)
|
||||
- [Settings](settings.md)
|
||||
- [Keys](keys.md)
|
||||
- [License](license.md)
|
||||
|
||||
## Clients
|
||||
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
# 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
|
||||
}
|
||||
```
|
||||
@@ -56,5 +56,6 @@ module API
|
||||
mount Settings
|
||||
mount Keys
|
||||
mount Tags
|
||||
mount LicenseInfo
|
||||
end
|
||||
end
|
||||
|
||||
@@ -373,5 +373,17 @@ module API
|
||||
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
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
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
|
||||
|
||||
factory :gitlab_license, class: "Gitlab::License" do
|
||||
starts_at { Date.today - 1.month }
|
||||
expires_at { Date.today + 11.months }
|
||||
licensee do
|
||||
{ "Name" => FFaker::Name.name }
|
||||
end
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
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
|
||||
Reference in New Issue
Block a user