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
ca43579b
Commit
ca43579b
authored
Jun 27, 2017
by
Bob Van Landuyt
Committed by
Bob Van Landuyt
Jun 28, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check the global availability inside `Namespace#feature_available?`
parent
3461e5c1
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
23 deletions
+54
-23
app/models/ee/namespace.rb
app/models/ee/namespace.rb
+14
-4
spec/models/ee/namespace_spec.rb
spec/models/ee/namespace_spec.rb
+39
-18
spec/models/ee/project_spec.rb
spec/models/ee/project_spec.rb
+1
-1
No files found.
app/models/ee/namespace.rb
View file @
ca43579b
...
...
@@ -33,11 +33,13 @@ module EE
# for a given Namespace plan. This method should consider ancestor groups
# being licensed.
def
feature_available?
(
feature
)
@features_available
||=
Hash
.
new
do
|
h
,
feature
|
h
[
feature
]
=
plans
.
any?
{
|
plan
|
License
.
plan_includes_feature?
(
EE_PLANS
[
plan
],
feature
)
}
end
globally_available
=
License
.
feature_available?
(
feature
)
@features_available
[
feature
]
if
current_application_settings
.
should_check_namespace_plan?
globally_available
&&
feature_available_in_plan?
(
feature
)
else
globally_available
end
end
def
actual_shared_runners_minutes_limit
...
...
@@ -65,5 +67,13 @@ module EE
[
plan
]
end
end
def
feature_available_in_plan?
(
feature
)
@features_available_in_plan
||=
Hash
.
new
do
|
h
,
feature
|
h
[
feature
]
=
plans
.
any?
{
|
plan
|
License
.
plan_includes_feature?
(
EE_PLANS
[
plan
],
feature
)
}
end
@features_available_in_plan
[
feature
]
end
end
end
spec/models/ee/namespace_spec.rb
View file @
ca43579b
...
...
@@ -43,17 +43,37 @@ describe Namespace, models: true do
end
describe
'#feature_available?'
do
let
(
:plan_license
)
{
Namespace
::
BRONZE_PLAN
}
let
(
:group
)
{
create
(
:group
,
plan:
plan_license
)
}
let
(
:feature
)
{
:service_desk
}
subject
{
group
.
feature_available?
(
feature
)
}
context
'when feature available'
do
let
(
:feature
)
{
:deploy_board
}
before
do
stub_licensed_features
(
feature
=>
true
)
end
it
'uses the global setting when running on premise'
do
stub_application_setting_on_object
(
group
,
should_check_namespace_plan:
false
)
is_expected
.
to
be_truthy
end
context
'when checking namespace plan'
do
before
do
stub_application_setting_on_object
(
group
,
should_check_namespace_plan:
true
)
end
it
'combines the global setting with the group setting when not running on premise'
do
is_expected
.
to
be_falsy
end
context
'when feature available on the plan'
do
let
(
:plan_license
)
{
Namespace
::
GOLD_PLAN
}
context
'when feature available for current group'
do
it
'returns fals
e'
do
is_expected
.
to
eq
(
true
)
it
'returns tru
e'
do
is_expected
.
to
be_truthy
end
end
...
...
@@ -62,18 +82,19 @@ describe Namespace, models: true do
let
(
:child_group
)
{
create
:group
,
parent:
group
}
it
'child group has feature available'
do
expect
(
child_group
.
feature_available?
(
feature
)).
to
eq
(
true
)
expect
(
child_group
.
feature_available?
(
feature
)).
to
be_truthy
end
end
end
end
context
'when feature not available
'
do
context
'when feature not available in the plan
'
do
let
(
:feature
)
{
:deploy_board
}
let
(
:plan_license
)
{
Namespace
::
BRONZE_PLAN
}
it
'returns false'
do
is_expected
.
to
eq
(
false
)
is_expected
.
to
be_falsy
end
end
end
end
...
...
spec/models/ee/project_spec.rb
View file @
ca43579b
...
...
@@ -22,7 +22,7 @@ describe Project, models: true do
before
do
stub_application_setting
(
'check_namespace_plan?'
=>
check_namespace_plan
)
allow
(
Gitlab
).
to
receive
(
:com?
)
{
true
}
expect
(
License
).
to
receive
(
:feature_available?
).
with
(
feature
)
{
allowed_on_global_license
}
stub_licensed_features
(
feature
=>
allowed_on_global_license
)
allow
(
namespace
).
to
receive
(
:plan
)
{
plan_license
}
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