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
5d381260
Commit
5d381260
authored
Jun 29, 2017
by
Bob Van Landuyt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Memoize feature available
parent
ca43579b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
43 additions
and
14 deletions
+43
-14
app/models/ee/namespace.rb
app/models/ee/namespace.rb
+21
-13
app/models/ee/project.rb
app/models/ee/project.rb
+9
-1
spec/models/ee/namespace_spec.rb
spec/models/ee/namespace_spec.rb
+6
-0
spec/models/ee/project_spec.rb
spec/models/ee/project_spec.rb
+7
-0
No files found.
app/models/ee/namespace.rb
View file @
5d381260
...
...
@@ -33,13 +33,19 @@ module EE
# for a given Namespace plan. This method should consider ancestor groups
# being licensed.
def
feature_available?
(
feature
)
globally_available
=
License
.
feature_available?
(
feature
)
@feature_available
||=
Hash
.
new
do
|
h
,
feature
|
h
[
feature
]
=
load_feature_available
(
feature
)
end
if
current_application_settings
.
should_check_namespace_plan?
globally_available
&&
feature_available_in_plan?
(
feature
)
else
globally_available
@feature_available
[
feature
]
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
def
actual_shared_runners_minutes_limit
...
...
@@ -59,6 +65,16 @@ module EE
private
def
load_feature_available
(
feature
)
globally_available
=
License
.
feature_available?
(
feature
)
if
current_application_settings
.
should_check_namespace_plan?
globally_available
&&
feature_available_in_plan?
(
feature
)
else
globally_available
end
end
def
plans
@ancestors_plans
||=
if
parent_id
...
...
@@ -67,13 +83,5 @@ 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
app/models/ee/project.rb
View file @
5d381260
...
...
@@ -344,11 +344,19 @@ module EE
private
def
licensed_feature_available?
(
feature
)
@licensed_feature_available
||=
Hash
.
new
do
|
h
,
feature
|
h
[
feature
]
=
load_licensed_feature_available
(
feature
)
end
@licensed_feature_available
[
feature
]
end
def
load_licensed_feature_available
(
feature
)
globally_available
=
License
.
feature_available?
(
feature
)
if
current_application_settings
.
should_check_namespace_plan?
globally_available
&&
(
public
?
&&
namespace
.
public?
||
namespace
.
feature_available?
(
feature
))
(
public
?
&&
namespace
.
public?
||
namespace
.
feature_available
_in_plan
?
(
feature
))
else
globally_available
end
...
...
spec/models/ee/namespace_spec.rb
View file @
5d381260
...
...
@@ -59,6 +59,12 @@ describe Namespace, models: true do
is_expected
.
to
be_truthy
end
it
'only checks the plan once'
do
expect
(
group
).
to
receive
(
:load_feature_available
).
once
.
and_call_original
2
.
times
{
group
.
feature_available?
(
:service_desk
)
}
end
context
'when checking namespace plan'
do
before
do
stub_application_setting_on_object
(
group
,
should_check_namespace_plan:
true
)
...
...
spec/models/ee/project_spec.rb
View file @
5d381260
...
...
@@ -99,6 +99,13 @@ describe Project, models: true do
end
end
it
'only loads licensed availability once'
do
expect
(
project
).
to
receive
(
:load_licensed_feature_available
)
.
once
.
and_call_original
2
.
times
{
project
.
feature_available?
(
:service_desk
)
}
end
context
'when feature symbol is not included on Namespace features code'
do
let
(
:feature
)
{
:issues
}
...
...
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