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
Show 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
...
@@ -92,6 +92,13 @@ class License < ActiveRecord::Base
EARLY_ADOPTER_PLAN
=>
EARLY_ADOPTER_FEATURES
EARLY_ADOPTER_PLAN
=>
EARLY_ADOPTER_FEATURES
}.
freeze
}.
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.
# Add on codes that may occur in legacy licenses that don't have a plan yet.
FEATURES_FOR_ADD_ONS
=
{
FEATURES_FOR_ADD_ONS
=
{
'GitLab_Auditor_User'
=>
:auditor_user
,
'GitLab_Auditor_User'
=>
:auditor_user
,
...
@@ -135,6 +142,18 @@ class License < ActiveRecord::Base
...
@@ -135,6 +142,18 @@ class License < ActiveRecord::Base
FEATURES_BY_PLAN
.
fetch
(
plan
,
[])
FEATURES_BY_PLAN
.
fetch
(
plan
,
[])
end
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
def
current
if
RequestStore
.
active?
if
RequestStore
.
active?
RequestStore
.
fetch
(
:current_license
)
{
load_license
}
RequestStore
.
fetch
(
:current_license
)
{
load_license
}
...
@@ -149,14 +168,6 @@ class License < ActiveRecord::Base
...
@@ -149,14 +168,6 @@ class License < ActiveRecord::Base
RequestStore
.
delete
(
:current_license
)
RequestStore
.
delete
(
:current_license
)
end
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
def
load_license
return
unless
self
.
table_exists?
return
unless
self
.
table_exists?
...
...
app/views/shared/billings/_billing_plan_header.html.haml
View file @
addb45c3
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
.billing-plan-header.content-block.center
.billing-plan-header.content-block.center
.billing-plan-logo
.billing-plan-logo
-
if
Namespace
::
EE_PLANS
.
keys
.
include?
(
plan
.
code
)
-
if
Namespace
::
PLANS
.
include?
(
plan
.
code
)
=
render
"shared/billings/plans/
#{
plan
.
code
}
.svg"
=
render
"shared/billings/plans/
#{
plan
.
code
}
.svg"
-
elsif
plan
.
free?
-
elsif
plan
.
free?
=
render
"shared/billings/plans/free.svg"
=
render
"shared/billings/plans/free.svg"
...
...
db/fixtures/test/01_plan.rb
View file @
addb45c3
...
@@ -3,6 +3,6 @@ require './spec/support/sidekiq'
...
@@ -3,6 +3,6 @@ require './spec/support/sidekiq'
Plan
.
create!
(
name:
EE
::
Namespace
::
FREE_PLAN
,
Plan
.
create!
(
name:
EE
::
Namespace
::
FREE_PLAN
,
title:
EE
::
Namespace
::
FREE_PLAN
.
titleize
)
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
)
Plan
.
create!
(
name:
plan
,
title:
plan
.
titleize
)
end
end
ee/app/models/ee/namespace.rb
View file @
addb45c3
...
@@ -13,13 +13,16 @@ module EE
...
@@ -13,13 +13,16 @@ module EE
GOLD_PLAN
=
'gold'
.
freeze
GOLD_PLAN
=
'gold'
.
freeze
EARLY_ADOPTER_PLAN
=
'early_adopter'
.
freeze
EARLY_ADOPTER_PLAN
=
'early_adopter'
.
freeze
E
E_PLANS
=
{
NAMESPACE_PLANS_TO_LICENS
E_PLANS
=
{
BRONZE_PLAN
=>
License
::
STARTER_PLAN
,
BRONZE_PLAN
=>
License
::
STARTER_PLAN
,
SILVER_PLAN
=>
License
::
PREMIUM_PLAN
,
SILVER_PLAN
=>
License
::
PREMIUM_PLAN
,
GOLD_PLAN
=>
License
::
ULTIMATE_PLAN
,
GOLD_PLAN
=>
License
::
ULTIMATE_PLAN
,
EARLY_ADOPTER_PLAN
=>
License
::
EARLY_ADOPTER_PLAN
EARLY_ADOPTER_PLAN
=>
License
::
EARLY_ADOPTER_PLAN
}.
freeze
}.
freeze
LICENSE_PLANS_TO_NAMESPACE_PLANS
=
NAMESPACE_PLANS_TO_LICENSE_PLANS
.
invert
.
freeze
PLANS
=
NAMESPACE_PLANS_TO_LICENSE_PLANS
.
keys
.
freeze
prepended
do
prepended
do
belongs_to
:plan
belongs_to
:plan
...
@@ -33,6 +36,12 @@ module EE
...
@@ -33,6 +36,12 @@ module EE
validate
:validate_plan_name
validate
:validate_plan_name
end
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
def
root_ancestor
ancestors
.
reorder
(
nil
).
find_by
(
parent_id:
nil
)
ancestors
.
reorder
(
nil
).
find_by
(
parent_id:
nil
)
end
end
...
@@ -70,7 +79,7 @@ module EE
...
@@ -70,7 +79,7 @@ module EE
def
feature_available_in_plan?
(
feature
)
def
feature_available_in_plan?
(
feature
)
@features_available_in_plan
||=
Hash
.
new
do
|
h
,
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
end
@features_available_in_plan
[
feature
]
@features_available_in_plan
[
feature
]
...
@@ -126,7 +135,7 @@ module EE
...
@@ -126,7 +135,7 @@ module EE
private
private
def
validate_plan_name
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'
)
errors
.
add
(
:plan
,
'is not included in the list'
)
end
end
end
end
...
@@ -142,11 +151,11 @@ module EE
...
@@ -142,11 +151,11 @@ module EE
end
end
def
plans
def
plans
@
ancestors_
plans
||=
@plans
||=
if
parent_id
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
else
[
plan
]
Array
(
plan
)
end
end
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