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
ddcf3627
Commit
ddcf3627
authored
Nov 24, 2020
by
Sean Arnold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add push_licensed_feature to gon helper
- Add EE override
parent
de8222fd
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
89 additions
and
6 deletions
+89
-6
app/controllers/projects/issues_controller.rb
app/controllers/projects/issues_controller.rb
+1
-1
ee/app/controllers/groups/usage_quotas_controller.rb
ee/app/controllers/groups/usage_quotas_controller.rb
+1
-1
ee/app/controllers/profiles/usage_quotas_controller.rb
ee/app/controllers/profiles/usage_quotas_controller.rb
+1
-1
ee/lib/ee/gitlab/gon_helper.rb
ee/lib/ee/gitlab/gon_helper.rb
+16
-0
ee/spec/lib/ee/gitlab/gon_helper_spec.rb
ee/spec/lib/ee/gitlab/gon_helper_spec.rb
+43
-0
lib/gitlab/gon_helper.rb
lib/gitlab/gon_helper.rb
+11
-3
spec/lib/gitlab/gon_helper_spec.rb
spec/lib/gitlab/gon_helper_spec.rb
+16
-0
No files found.
app/controllers/projects/issues_controller.rb
View file @
ddcf3627
...
...
@@ -51,7 +51,7 @@ class Projects::IssuesController < Projects::ApplicationController
real_time_feature_flag
=
:real_time_issue_sidebar
real_time_enabled
=
Gitlab
::
ActionCable
::
Config
.
in_app?
||
Feature
.
enabled?
(
real_time_feature_flag
,
@project
)
push_to_gon_
features
(
real_time_feature_flag
,
real_time_enabled
)
push_to_gon_
attributes
(
:features
,
real_time_feature_flag
,
real_time_enabled
)
record_experiment_user
(
:invite_members_version_a
)
record_experiment_user
(
:invite_members_version_b
)
...
...
ee/app/controllers/groups/usage_quotas_controller.rb
View file @
ddcf3627
...
...
@@ -21,6 +21,6 @@ class Groups::UsageQuotasController < Groups::ApplicationController
end
def
push_additional_repo_storage_by_namespace_feature
push_to_gon_
features
(
:additional_repo_storage_by_namespace
,
@group
.
additional_repo_storage_by_namespace_enabled?
)
push_to_gon_
attributes
(
:features
,
:additional_repo_storage_by_namespace
,
@group
.
additional_repo_storage_by_namespace_enabled?
)
end
end
ee/app/controllers/profiles/usage_quotas_controller.rb
View file @
ddcf3627
...
...
@@ -13,6 +13,6 @@ class Profiles::UsageQuotasController < Profiles::ApplicationController
private
def
push_additional_repo_storage_by_namespace_feature
push_to_gon_
features
(
:additional_repo_storage_by_namespace
,
current_user
.
namespace
.
additional_repo_storage_by_namespace_enabled?
)
push_to_gon_
attributes
(
:features
,
:additional_repo_storage_by_namespace
,
current_user
.
namespace
.
additional_repo_storage_by_namespace_enabled?
)
end
end
ee/lib/ee/gitlab/gon_helper.rb
View file @
ddcf3627
...
...
@@ -4,6 +4,7 @@ module EE
module
Gitlab
module
GonHelper
extend
::
Gitlab
::
Utils
::
Override
extend
::
Gitlab
::
Utils
::
Override
override
:add_gon_variables
def
add_gon_variables
...
...
@@ -11,6 +12,21 @@ module EE
gon
.
roadmap_epics_limit
=
1000
end
# Exposes if a licensed feature is available.
#
# name - The name of the licensed feature
# obj - the object to check the licensed feature on (project, namespace)
override
:push_licensed_feature
def
push_licensed_feature
(
name
,
obj
=
nil
)
enabled
=
if
obj
obj
.
feature_available?
(
name
)
else
::
License
.
feature_available?
(
name
)
end
push_to_gon_attributes
(
:licensed_features
,
name
,
enabled
)
end
end
end
end
ee/spec/lib/ee/gitlab/gon_helper_spec.rb
View file @
ddcf3627
...
...
@@ -26,4 +26,47 @@ RSpec.describe EE::Gitlab::GonHelper do
helper
.
add_gon_variables
end
end
describe
'#push_licensed_feature'
do
let_it_be
(
:feature
)
{
License
::
EEU_FEATURES
.
first
}
shared_examples
'sets the licensed features flag'
do
it
'pushes the licensed feature flag to the frotnend'
do
gon
=
instance_double
(
'gon'
)
stub_licensed_features
(
feature
=>
true
)
allow
(
helper
)
.
to
receive
(
:gon
)
.
and_return
(
gon
)
expect
(
gon
)
.
to
receive
(
:push
)
.
with
({
licensed_features:
{
feature
.
to_s
.
camelize
(
:lower
)
=>
true
}
},
true
)
subject
end
end
context
'no obj given'
do
subject
{
helper
.
push_licensed_feature
(
feature
)
}
before
do
expect
(
License
).
to
receive
(
:feature_available?
).
with
(
feature
)
end
it_behaves_like
'sets the licensed features flag'
end
context
'obj given'
do
let
(
:project
)
{
create
(
:project
)
}
subject
{
helper
.
push_licensed_feature
(
feature
,
project
)
}
before
do
expect
(
project
).
to
receive
(
:feature_available?
).
with
(
feature
).
and_call_original
end
it_behaves_like
'sets the licensed features flag'
end
end
end
lib/gitlab/gon_helper.rb
View file @
ddcf3627
...
...
@@ -61,15 +61,23 @@ module Gitlab
def
push_frontend_feature_flag
(
name
,
*
args
,
**
kwargs
)
enabled
=
Feature
.
enabled?
(
name
,
*
args
,
**
kwargs
)
push_to_gon_
features
(
name
,
enabled
)
push_to_gon_
attributes
(
:features
,
name
,
enabled
)
end
def
push_to_gon_features
(
name
,
enabled
)
# Exposes if a licensed feature is available.
# This is always set to false in CE.
# name - The name of the licensed feature
def
push_licensed_feature
(
name
,
_obj
=
nil
)
push_to_gon_attributes
(
:licensed_features
,
name
,
false
)
end
def
push_to_gon_attributes
(
key
,
name
,
enabled
)
var_name
=
name
.
to_s
.
camelize
(
:lower
)
# Here the `true` argument signals gon that the value should be merged
# into any existing ones, instead of overwriting them. This allows you to
# use this method to push multiple feature flags.
gon
.
push
({
features:
{
var_name
=>
enabled
}
},
true
)
gon
.
push
({
key
=>
{
var_name
=>
enabled
}
},
true
)
end
def
default_avatar_url
...
...
spec/lib/gitlab/gon_helper_spec.rb
View file @
ddcf3627
...
...
@@ -32,6 +32,22 @@ RSpec.describe Gitlab::GonHelper do
end
end
describe
'#push_licensed_feature'
do
it
'pushes a licensed flag set to false to the frontend,'
do
gon
=
instance_double
(
'gon'
)
allow
(
helper
)
.
to
receive
(
:gon
)
.
and_return
(
gon
)
expect
(
gon
)
.
to
receive
(
:push
)
.
with
({
licensed_features:
{
'testing'
=>
false
}
},
true
)
helper
.
push_licensed_feature
(
:testing
)
end
end
describe
'#default_avatar_url'
do
it
'returns an absolute URL'
do
url
=
helper
.
default_avatar_url
...
...
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