Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
d80fc724
Commit
d80fc724
authored
May 08, 2017
by
Oswaldo Ferreira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Feature availability check using feature list AND license addons
parent
40dac302
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
55 additions
and
3 deletions
+55
-3
app/models/license.rb
app/models/license.rb
+29
-1
changelogs/unreleased-ee/license-check-using-feature-list.yml
...gelogs/unreleased-ee/license-check-using-feature-list.yml
+4
-0
spec/models/license_spec.rb
spec/models/license_spec.rb
+22
-2
No files found.
app/models/license.rb
View file @
d80fc724
class
License
<
ActiveRecord
::
Base
include
ActionView
::
Helpers
::
NumberHelper
EES_FEATURES
=
[
# ..
].
freeze
EEP_FEATURES
=
[
*
EES_FEATURES
,
{
'GitLab_DeployBoard'
=>
1
},
{
'GitLab_FileLocks'
=>
1
},
{
'GitLab_Geo'
=>
1
},
{
'GitLab_Auditor_User'
=>
1
},
{
'GitLab_ServiceDesk'
=>
1
},
].
freeze
FEATURES_BY_PLAN
=
{
'starter'
=>
EES_FEATURES
,
'premium'
=>
EEP_FEATURES
,
}.
freeze
validate
:valid_license
validate
:check_users_limit
,
if: :new_record?
,
unless: :validate_with_trueup?
validate
:check_trueup
,
unless: :persisted?
,
if: :validate_with_trueup?
...
...
@@ -14,6 +32,10 @@ class License < ActiveRecord::Base
scope
:previous
,
->
{
order
(
created_at: :desc
).
offset
(
1
)
}
class
<<
self
def
features_for_plan
(
plan
)
FEATURES_BY_PLAN
.
fetch
(
plan
,
[]).
reduce
({},
:merge
)
end
def
current
if
RequestStore
.
active?
RequestStore
.
fetch
(
:current_license
)
{
load_license
}
...
...
@@ -83,8 +105,14 @@ class License < ActiveRecord::Base
end
end
# New licenses persists only the `plan` (premium, starter, ..). But, old licenses
# keep `add_ons`, therefore this method needs to be backward-compatible in that sense.
# See https://gitlab.com/gitlab-org/gitlab-ee/issues/2019
def
add_ons
restricted_attr
(
:add_ons
,
{})
explicit_add_ons
=
restricted_attr
(
:add_ons
,
{})
plan_features
=
self
.
class
.
features_for_plan
(
plan
)
explicit_add_ons
.
merge
(
plan_features
)
end
def
add_on?
(
code
)
...
...
changelogs/unreleased-ee/license-check-using-feature-list.yml
0 → 100644
View file @
d80fc724
---
title
:
Feature availability check using feature list AND license addons
merge_request
:
author
:
spec/models/license_spec.rb
View file @
d80fc724
...
...
@@ -211,6 +211,17 @@ describe License do
allow
(
described_class
).
to
receive
(
:last
).
and_return
(
license
)
end
describe
'.features_for_plan'
do
it
'returns features for given plan'
do
expect
(
described_class
.
features_for_plan
(
'premium'
))
.
to
include
({
'GitLab_DeployBoard'
=>
1
,
'GitLab_FileLocks'
=>
1
})
end
it
'returns empty Hash if no features for given plan'
do
expect
(
described_class
.
features_for_plan
(
'starter'
)).
to
eq
({})
end
end
describe
".current"
do
context
"when there is no license"
do
let!
(
:license
)
{
nil
}
...
...
@@ -317,6 +328,15 @@ describe License do
expect
(
license
.
add_ons
[
'custom-domain'
]).
to
eq
(
2
)
end
end
context
'with extra features mapped by plan'
do
it
'returns all available add-ons and extra features'
do
license
=
build_license_with_add_ons
({
'support'
=>
1
},
plan:
'premium'
)
eep_features
=
License
::
EEP_FEATURES
.
reduce
({},
:merge
).
keys
expect
(
license
.
add_ons
.
keys
).
to
include
(
'support'
,
*
eep_features
)
end
end
end
describe
'#add_on?'
do
...
...
@@ -339,8 +359,8 @@ describe License do
end
end
def
build_license_with_add_ons
(
add_ons
)
gl_license
=
build
(
:gitlab_license
,
restrictions:
{
add_ons:
add_ons
})
def
build_license_with_add_ons
(
add_ons
,
plan:
nil
)
gl_license
=
build
(
:gitlab_license
,
restrictions:
{
add_ons:
add_ons
,
plan:
plan
})
build
(
:license
,
data:
gl_license
.
export
)
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment