Commit fd387d06 authored by Sri's avatar Sri

Support `project`, `group` and `user` actors

..for the incubation-5mp-google-cloud feature flag.

This will give us control to enable / disable
this feature on gitlab.com for specific projects,
groups and/or users.
parent f080e57c
......@@ -25,7 +25,11 @@ class Projects::GoogleCloud::BaseController < Projects::ApplicationController
end
def feature_flag_enabled!
unless Feature.enabled?(:incubation_5mp_google_cloud)
enabled_for_user = Feature.enabled?(:incubation_5mp_google_cloud, current_user)
enabled_for_group = Feature.enabled?(:incubation_5mp_google_cloud, project.group)
enabled_for_project = Feature.enabled?(:incubation_5mp_google_cloud, project)
feature_is_enabled = enabled_for_user || enabled_for_group || enabled_for_project
unless feature_is_enabled
track_event('feature_flag_enabled!', 'access_denied', 'feature_flag_not_enabled')
access_denied!
end
......
......@@ -90,7 +90,10 @@ module Sidebars
end
def google_cloud_menu_item
feature_is_enabled = Feature.enabled?(:incubation_5mp_google_cloud, context.project)
enabled_for_user = Feature.enabled?(:incubation_5mp_google_cloud, context.current_user)
enabled_for_group = Feature.enabled?(:incubation_5mp_google_cloud, context.project.group)
enabled_for_project = Feature.enabled?(:incubation_5mp_google_cloud, context.project)
feature_is_enabled = enabled_for_user || enabled_for_group || enabled_for_project
user_has_permissions = can?(context.current_user, :admin_project_google_cloud, context.project)
unless feature_is_enabled && user_has_permissions
......
......@@ -112,6 +112,41 @@ RSpec.describe Sidebars::Projects::Menus::InfrastructureMenu do
let(:item_id) { :google_cloud }
it_behaves_like 'access rights checks'
context 'when feature flag is turned off globally' do
before do
stub_feature_flags(incubation_5mp_google_cloud: false)
end
it { is_expected.to be_nil }
end
context 'when feature flag is turned off but enabled for project' do
before do
stub_feature_flags(incubation_5mp_google_cloud: false)
stub_feature_flags(incubation_5mp_google_cloud: project)
end
it_behaves_like 'access rights checks'
end
context 'when feature flag is turned off but enabled for group' do
before do
stub_feature_flags(incubation_5mp_google_cloud: false)
stub_feature_flags(incubation_5mp_google_cloud: project.group)
end
it_behaves_like 'access rights checks'
end
context 'when feature flag is turned off but enabled for user' do
before do
stub_feature_flags(incubation_5mp_google_cloud: false)
stub_feature_flags(incubation_5mp_google_cloud: user)
end
it_behaves_like 'access rights checks'
end
end
end
end
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