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
addb45c3
Commit
addb45c3
authored
Nov 01, 2017
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor Namespace#feature_available_in_plan?
parent
7206b29c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
16 deletions
+36
-16
app/models/license.rb
app/models/license.rb
+19
-8
app/views/shared/billings/_billing_plan_header.html.haml
app/views/shared/billings/_billing_plan_header.html.haml
+1
-1
db/fixtures/test/01_plan.rb
db/fixtures/test/01_plan.rb
+1
-1
ee/app/models/ee/namespace.rb
ee/app/models/ee/namespace.rb
+15
-6
No files found.
app/models/license.rb
View file @
addb45c3
...
...
@@ -92,6 +92,13 @@ class License < ActiveRecord::Base
EARLY_ADOPTER_PLAN
=>
EARLY_ADOPTER_FEATURES
}.
freeze
PLANS_BY_FEATURE
=
FEATURES_BY_PLAN
.
each_with_object
({})
do
|
(
plan
,
features
),
hash
|
features
.
each
do
|
feature
|
hash
[
feature
]
||=
[]
hash
[
feature
]
<<
plan
end
end
.
freeze
# Add on codes that may occur in legacy licenses that don't have a plan yet.
FEATURES_FOR_ADD_ONS
=
{
'GitLab_Auditor_User'
=>
:auditor_user
,
...
...
@@ -135,6 +142,18 @@ class License < ActiveRecord::Base
FEATURES_BY_PLAN
.
fetch
(
plan
,
[])
end
def
plans_with_feature
(
feature
)
if
GLOBAL_FEATURES
.
include?
(
feature
)
raise
ArgumentError
,
"Use `License.feature_available?` for features that cannot be restricted to only a subset of projects or namespaces"
end
PLANS_BY_FEATURE
.
fetch
(
feature
,
[])
end
def
plan_includes_feature?
(
plan
,
feature
)
plans_with_feature
(
feature
).
include?
(
plan
)
end
def
current
if
RequestStore
.
active?
RequestStore
.
fetch
(
:current_license
)
{
load_license
}
...
...
@@ -149,14 +168,6 @@ class License < ActiveRecord::Base
RequestStore
.
delete
(
:current_license
)
end
def
plan_includes_feature?
(
plan
,
feature
)
if
GLOBAL_FEATURES
.
include?
(
feature
)
raise
ArgumentError
,
"Use `License.feature_available?` for features that cannot be restricted to only a subset of projects or namespaces"
end
features_for_plan
(
plan
).
include?
(
feature
)
end
def
load_license
return
unless
self
.
table_exists?
...
...
app/views/shared/billings/_billing_plan_header.html.haml
View file @
addb45c3
...
...
@@ -2,7 +2,7 @@
.billing-plan-header.content-block.center
.billing-plan-logo
-
if
Namespace
::
EE_PLANS
.
keys
.
include?
(
plan
.
code
)
-
if
Namespace
::
PLANS
.
include?
(
plan
.
code
)
=
render
"shared/billings/plans/
#{
plan
.
code
}
.svg"
-
elsif
plan
.
free?
=
render
"shared/billings/plans/free.svg"
...
...
db/fixtures/test/01_plan.rb
View file @
addb45c3
...
...
@@ -3,6 +3,6 @@ require './spec/support/sidekiq'
Plan
.
create!
(
name:
EE
::
Namespace
::
FREE_PLAN
,
title:
EE
::
Namespace
::
FREE_PLAN
.
titleize
)
EE
::
Namespace
::
E
E_PLANS
.
each_key
do
|
plan
|
EE
::
Namespace
::
NAMESPACE_PLANS_TO_LICENS
E_PLANS
.
each_key
do
|
plan
|
Plan
.
create!
(
name:
plan
,
title:
plan
.
titleize
)
end
ee/app/models/ee/namespace.rb
View file @
addb45c3
...
...
@@ -13,13 +13,16 @@ module EE
GOLD_PLAN
=
'gold'
.
freeze
EARLY_ADOPTER_PLAN
=
'early_adopter'
.
freeze
E
E_PLANS
=
{
NAMESPACE_PLANS_TO_LICENS
E_PLANS
=
{
BRONZE_PLAN
=>
License
::
STARTER_PLAN
,
SILVER_PLAN
=>
License
::
PREMIUM_PLAN
,
GOLD_PLAN
=>
License
::
ULTIMATE_PLAN
,
EARLY_ADOPTER_PLAN
=>
License
::
EARLY_ADOPTER_PLAN
}.
freeze
LICENSE_PLANS_TO_NAMESPACE_PLANS
=
NAMESPACE_PLANS_TO_LICENSE_PLANS
.
invert
.
freeze
PLANS
=
NAMESPACE_PLANS_TO_LICENSE_PLANS
.
keys
.
freeze
prepended
do
belongs_to
:plan
...
...
@@ -33,6 +36,12 @@ module EE
validate
:validate_plan_name
end
module
ClassMethods
def
plans_with_feature
(
feature
)
LICENSE_PLANS_TO_NAMESPACE_PLANS
.
values_at
(
*
License
.
plans_with_feature
(
feature
))
end
end
def
root_ancestor
ancestors
.
reorder
(
nil
).
find_by
(
parent_id:
nil
)
end
...
...
@@ -70,7 +79,7 @@ module EE
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
&
.
name
],
feature
)
}
h
[
feature
]
=
(
plans
.
map
(
&
:name
)
&
self
.
class
.
plans_with_feature
(
feature
)).
any?
end
@features_available_in_plan
[
feature
]
...
...
@@ -126,7 +135,7 @@ module EE
private
def
validate_plan_name
if
@plan_name
.
present?
&&
EE_PLANS
.
keys
.
exclude?
(
@plan_name
)
if
@plan_name
.
present?
&&
PLANS
.
exclude?
(
@plan_name
)
errors
.
add
(
:plan
,
'is not included in the list'
)
end
end
...
...
@@ -142,11 +151,11 @@ module EE
end
def
plans
@
ancestors_
plans
||=
@plans
||=
if
parent_id
Plan
.
where
(
id:
ancestors
.
with_plan
.
reorder
(
nil
).
select
(
'plan_id'
))
+
[
plan
]
Plan
.
where
(
id:
self_and_ancestors
.
with_plan
.
reorder
(
nil
).
select
(
:plan_id
))
else
[
plan
]
Array
(
plan
)
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