Commit 7e12dc92 authored by Mark Chao's avatar Mark Chao

Merge branch 'make-frontend-aware-of-namespace-storage-feature-flag' into 'master'

Make frontend follow same storage feature flag logic as backend

See merge request gitlab-org/gitlab!45804
parents fb3f6d80 21c017ae
...@@ -51,7 +51,7 @@ class Projects::IssuesController < Projects::ApplicationController ...@@ -51,7 +51,7 @@ class Projects::IssuesController < Projects::ApplicationController
real_time_feature_flag = :real_time_issue_sidebar real_time_feature_flag = :real_time_issue_sidebar
real_time_enabled = Gitlab::ActionCable::Config.in_app? || Feature.enabled?(real_time_feature_flag, @project) real_time_enabled = Gitlab::ActionCable::Config.in_app? || Feature.enabled?(real_time_feature_flag, @project)
gon.push({ features: { real_time_feature_flag.to_s.camelize(:lower) => real_time_enabled } }, true) push_to_gon_features(real_time_feature_flag, real_time_enabled)
record_experiment_user(:invite_members_version_a) record_experiment_user(:invite_members_version_a)
record_experiment_user(:invite_members_version_b) record_experiment_user(:invite_members_version_b)
......
...@@ -3,9 +3,7 @@ ...@@ -3,9 +3,7 @@
class Groups::UsageQuotasController < Groups::ApplicationController class Groups::UsageQuotasController < Groups::ApplicationController
before_action :authorize_admin_group! before_action :authorize_admin_group!
before_action :verify_usage_quotas_enabled! before_action :verify_usage_quotas_enabled!
before_action do before_action :push_additional_repo_storage_by_namespace_feature, only: :index
push_frontend_feature_flag(:additional_repo_storage_by_namespace, @group)
end
layout 'group_settings' layout 'group_settings'
...@@ -21,4 +19,8 @@ class Groups::UsageQuotasController < Groups::ApplicationController ...@@ -21,4 +19,8 @@ class Groups::UsageQuotasController < Groups::ApplicationController
render_404 unless License.feature_available?(:usage_quotas) render_404 unless License.feature_available?(:usage_quotas)
render_404 if @group.has_parent? render_404 if @group.has_parent?
end 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?)
end
end end
# frozen_string_literal: true # frozen_string_literal: true
class Profiles::UsageQuotasController < Profiles::ApplicationController class Profiles::UsageQuotasController < Profiles::ApplicationController
before_action do before_action :push_additional_repo_storage_by_namespace_feature, only: :index
push_frontend_feature_flag(:additional_repo_storage_by_namespace, @group)
end
feature_category :purchase feature_category :purchase
...@@ -11,4 +9,10 @@ class Profiles::UsageQuotasController < Profiles::ApplicationController ...@@ -11,4 +9,10 @@ class Profiles::UsageQuotasController < Profiles::ApplicationController
@namespace = current_user.namespace @namespace = current_user.namespace
@projects = @namespace.projects.with_shared_runners_limit_enabled.page(params[:page]) @projects = @namespace.projects.with_shared_runners_limit_enabled.page(params[:page])
end end
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?)
end
end end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Groups::UsageQuotasController do
let_it_be(:group) { create(:group, :private) }
let_it_be(:user) { create(:user) }
before do
sign_in(user)
group.add_owner(user)
end
describe 'Pushing the `additionalRepoStorageByNamespace` feature flag to the frontend' do
context 'when both flags are true' do
before do
stub_feature_flags(additional_repo_storage_by_namespace: true, namespace_storage_limit: true)
end
it 'is disabled' do
get :index, params: { group_id: group }
expect(Gon.features).to include('additionalRepoStorageByNamespace' => false)
end
end
context 'when `namespace_storage_limit` flag is false' do
before do
stub_feature_flags(additional_repo_storage_by_namespace: true, namespace_storage_limit: false)
end
it 'is enabled' do
get :index, params: { group_id: group }
expect(Gon.features).to include('additionalRepoStorageByNamespace' => true)
end
end
context 'when both flags are false' do
before do
stub_feature_flags(additional_repo_storage_by_namespace: false, namespace_storage_limit: false)
end
it 'is disabled' do
get :index, params: { group_id: group }
expect(Gon.features).to include('additionalRepoStorageByNamespace' => false)
end
end
end
end
...@@ -16,4 +16,42 @@ RSpec.describe Profiles::UsageQuotasController do ...@@ -16,4 +16,42 @@ RSpec.describe Profiles::UsageQuotasController do
expect(subject).to render_template(:index) expect(subject).to render_template(:index)
end end
end end
describe 'Pushing the `additionalRepoStorageByNamespace` feature flag to the frontend' do
context 'when both flags are true' do
before do
stub_feature_flags(additional_repo_storage_by_namespace: true, namespace_storage_limit: true)
end
it 'is disabled' do
get :index
expect(Gon.features).to include('additionalRepoStorageByNamespace' => false)
end
end
context 'when `namespace_storage_limit` flag is false' do
before do
stub_feature_flags(additional_repo_storage_by_namespace: true, namespace_storage_limit: false)
end
it 'is enabled' do
get :index
expect(Gon.features).to include('additionalRepoStorageByNamespace' => true)
end
end
context 'when both flags are false' do
before do
stub_feature_flags(additional_repo_storage_by_namespace: false, namespace_storage_limit: false)
end
it 'is disabled' do
get :index
expect(Gon.features).to include('additionalRepoStorageByNamespace' => false)
end
end
end
end end
...@@ -9,35 +9,12 @@ RSpec.describe 'Groups > Usage Quotas' do ...@@ -9,35 +9,12 @@ RSpec.describe 'Groups > Usage Quotas' do
let(:gitlab_dot_com) { true } let(:gitlab_dot_com) { true }
before do before do
stub_feature_flags(additional_repo_storage_by_namespace: true)
allow(Gitlab).to receive(:com?).and_return(gitlab_dot_com) allow(Gitlab).to receive(:com?).and_return(gitlab_dot_com)
group.add_owner(user) group.add_owner(user)
sign_in(user) sign_in(user)
end end
it 'pushes frontend feature flags' do
visit visit_pipeline_quota_page
expect(page).to have_pushed_frontend_feature_flags(
additionalRepoStorageByNamespace: true
)
end
context 'when `additional_repo_storage_by_namespace` is disabled for a group' do
before do
stub_feature_flags(additional_repo_storage_by_namespace: false, thing: group)
end
it 'pushes disabled feature flag to the frontend' do
visit visit_pipeline_quota_page
expect(page).to have_pushed_frontend_feature_flags(
additionalRepoStorageByNamespace: false
)
end
end
shared_examples 'linked in group settings dropdown' do shared_examples 'linked in group settings dropdown' do
it 'is linked within the group settings dropdown' do it 'is linked within the group settings dropdown' do
visit edit_group_path(group) visit edit_group_path(group)
......
...@@ -12,32 +12,9 @@ RSpec.describe 'Profile > Usage Quota' do ...@@ -12,32 +12,9 @@ RSpec.describe 'Profile > Usage Quota' do
let_it_be(:other_project) { create(:project, namespace: namespace, shared_runners_enabled: false) } let_it_be(:other_project) { create(:project, namespace: namespace, shared_runners_enabled: false) }
before do before do
stub_feature_flags(additional_repo_storage_by_namespace: true)
gitlab_sign_in(user) gitlab_sign_in(user)
end end
it 'pushes frontend feature flags' do
visit profile_usage_quotas_path
expect(page).to have_pushed_frontend_feature_flags(
additionalRepoStorageByNamespace: true
)
end
context 'when `additional_repo_storage_by_namespace` is disabled for a namespace' do
before do
stub_feature_flags(additional_repo_storage_by_namespace: false, thing: namespace)
end
it 'pushes disabled feature flag to the frontend' do
visit profile_usage_quotas_path
expect(page).to have_pushed_frontend_feature_flags(
additionalRepoStorageByNamespace: false
)
end
end
it 'is linked within the profile page' do it 'is linked within the profile page' do
visit profile_path visit profile_path
......
...@@ -58,9 +58,13 @@ module Gitlab ...@@ -58,9 +58,13 @@ module Gitlab
# args - Any additional arguments to pass to `Feature.enabled?`. This allows # args - Any additional arguments to pass to `Feature.enabled?`. This allows
# you to check if a flag is enabled for a particular user. # you to check if a flag is enabled for a particular user.
def push_frontend_feature_flag(name, *args, **kwargs) def push_frontend_feature_flag(name, *args, **kwargs)
var_name = name.to_s.camelize(:lower)
enabled = Feature.enabled?(name, *args, **kwargs) enabled = Feature.enabled?(name, *args, **kwargs)
push_to_gon_features(name, enabled)
end
def push_to_gon_features(name, enabled)
var_name = name.to_s.camelize(:lower)
# Here the `true` argument signals gon that the value should be merged # Here the `true` argument signals gon that the value should be merged
# into any existing ones, instead of overwriting them. This allows you to # into any existing ones, instead of overwriting them. This allows you to
# use this method to push multiple feature flags. # use this method to push multiple feature flags.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment