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
Show 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
class
License
<
ActiveRecord
::
Base
include
ActionView
::
Helpers
::
NumberHelper
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
:valid_license
validate
:check_users_limit
,
if: :new_record?
,
unless: :validate_with_trueup?
validate
:check_users_limit
,
if: :new_record?
,
unless: :validate_with_trueup?
validate
:check_trueup
,
unless: :persisted?
,
if: :validate_with_trueup?
validate
:check_trueup
,
unless: :persisted?
,
if: :validate_with_trueup?
...
@@ -14,6 +32,10 @@ class License < ActiveRecord::Base
...
@@ -14,6 +32,10 @@ class License < ActiveRecord::Base
scope
:previous
,
->
{
order
(
created_at: :desc
).
offset
(
1
)
}
scope
:previous
,
->
{
order
(
created_at: :desc
).
offset
(
1
)
}
class
<<
self
class
<<
self
def
features_for_plan
(
plan
)
FEATURES_BY_PLAN
.
fetch
(
plan
,
[]).
reduce
({},
:merge
)
end
def
current
def
current
if
RequestStore
.
active?
if
RequestStore
.
active?
RequestStore
.
fetch
(
:current_license
)
{
load_license
}
RequestStore
.
fetch
(
:current_license
)
{
load_license
}
...
@@ -83,8 +105,14 @@ class License < ActiveRecord::Base
...
@@ -83,8 +105,14 @@ class License < ActiveRecord::Base
end
end
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
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
end
def
add_on?
(
code
)
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
...
@@ -211,6 +211,17 @@ describe License do
allow
(
described_class
).
to
receive
(
:last
).
and_return
(
license
)
allow
(
described_class
).
to
receive
(
:last
).
and_return
(
license
)
end
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
describe
".current"
do
context
"when there is no license"
do
context
"when there is no license"
do
let!
(
:license
)
{
nil
}
let!
(
:license
)
{
nil
}
...
@@ -317,6 +328,15 @@ describe License do
...
@@ -317,6 +328,15 @@ describe License do
expect
(
license
.
add_ons
[
'custom-domain'
]).
to
eq
(
2
)
expect
(
license
.
add_ons
[
'custom-domain'
]).
to
eq
(
2
)
end
end
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
end
describe
'#add_on?'
do
describe
'#add_on?'
do
...
@@ -339,8 +359,8 @@ describe License do
...
@@ -339,8 +359,8 @@ describe License do
end
end
end
end
def
build_license_with_add_ons
(
add_ons
)
def
build_license_with_add_ons
(
add_ons
,
plan:
nil
)
gl_license
=
build
(
:gitlab_license
,
restrictions:
{
add_ons:
add_ons
})
gl_license
=
build
(
:gitlab_license
,
restrictions:
{
add_ons:
add_ons
,
plan:
plan
})
build
(
:license
,
data:
gl_license
.
export
)
build
(
:license
,
data:
gl_license
.
export
)
end
end
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