Commit 7ec10af5 authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch 'ee-7536-remove-feature-flag-code-for-protected-environments' into 'master'

Removes feature flag code for Protected Environments

Closes #7536

See merge request gitlab-org/gitlab-ee!7338
parents dd4fa164 34c4b46b
module ProtectedEnvironmentsHelper
def protected_environments_enabled?
Feature.enabled?('protected_environments')
def protected_environments_enabled?(project)
project.protected_environments_feature_available?
end
end
......@@ -537,7 +537,7 @@ module EE
end
def protected_environments_feature_available?
Feature.enabled?('protected_environments') && feature_available?(:protected_environments)
feature_available?(:protected_environments)
end
# Because we use default_value_for we need to be sure
......
......@@ -17,7 +17,8 @@ module EE
alias_method :build, :subject
def deployable_by_user?
# This feature flag is used here as evaluating `build.expanded_environment_name` is expensive
# We need to check if Protected Environments feature is available,
# as evaluating `build.expanded_environment_name` is expensive.
return true unless build.project.protected_environments_feature_available?
build.project.protected_environment_accessible_to?(build.expanded_environment_name, user)
......
......@@ -16,7 +16,8 @@ module EE
private
def allowed_to_deploy?(build)
# This feature flag is used here as evaluating `build.expanded_environment_name` is expensive
# We need to check if Protected Environments feature is available,
# as evaluating `build.expanded_environment_name` is expensive.
return true unless project.protected_environments_feature_available?
project.protected_environment_accessible_to?(build.expanded_environment_name, build.user)
......
- expanded = Rails.env.test?
- can_admin_project = can?(current_user, :admin_project, @project)
- if protected_environments_enabled?
- if protected_environments_enabled?(@project)
%section.protected-environments-settings.settings.no-animate#js-protected-environments-settings{ class: ('expanded' if expanded) }
.settings-header
%h4
......
---
title: Removes feature flag code surrounding Protected Environments feature
merge_request: 7338
author:
type: other
......@@ -8,7 +8,6 @@ describe 'Environments page', :js do
let(:user) { create(:user) }
before do
stub_feature_flags(protected_environments: true)
allow(License).to receive(:feature_available?).and_call_original
allow(License).to receive(:feature_available?).with(:protected_environments).and_return(true)
project.add_maintainer(user)
......
......@@ -8,8 +8,8 @@ describe 'Protected Environments' do
let(:environments) { %w(production development staging test) }
before do
stub_feature_flags(protected_environments: true)
allow(License).to receive(:feature_available?).and_call_original
allow(License).to receive(:feature_available?).with(:protected_environments).and_return(true)
environments.each do |environment_name|
create(:environment, name: environment_name, project: project)
end
......
......@@ -29,27 +29,18 @@ describe Environment do
subject { environment.protected? }
before do
stub_feature_flags(protected_environments: enabled)
end
context 'when Protected Environments feature is not on' do
let(:enabled) { false }
it { is_expected.to be_falsy }
allow(project).to receive(:feature_available?)
.with(:protected_environments).and_return(feature_available)
end
context 'when Protected Environments feature is on' do
let(:enabled) { true }
context 'when Protected Environments feature is not available on the project' do
let(:feature_available) { false }
context 'when Protected Environments feature is not available in the project' do
it { is_expected.to be_falsy }
end
context 'when Protected Environments feature is available in the project' do
before do
allow(project).to receive(:feature_available?)
.with(:protected_environments).and_return(true)
end
context 'when Protected Environments feature is available on the project' do
let(:feature_available) { true }
context 'when the environment is protected' do
before do
......@@ -64,7 +55,6 @@ describe Environment do
end
end
end
end
describe '#protected_deployable_by_user?' do
let(:user) { create(:user) }
......@@ -73,23 +63,18 @@ describe Environment do
subject { environment.protected_deployable_by_user?(user) }
before do
stub_feature_flags(protected_environments: enabled)
allow(project).to receive(:feature_available?)
.with(:protected_environments).and_return(feature_available)
end
context 'when Protected Environments feature is not on' do
let(:enabled) { false }
context 'when Protected Environments feature is not available on the project' do
let(:feature_available) { false }
it { is_expected.to be_truthy }
end
context 'when Protected Environments feature is on' do
let(:enabled) { true }
context 'when Protected Environments feature is available in the project' do
before do
allow(project).to receive(:feature_available?)
.with(:protected_environments).and_return(true)
end
context 'when Protected Environments feature is available on the project' do
let(:feature_available) { true }
context 'when the environment is not protected' do
it { is_expected.to be_truthy }
......@@ -112,5 +97,4 @@ describe Environment do
end
end
end
end
end
......@@ -1584,41 +1584,22 @@ describe Project do
subject { project.protected_environment_by_name('production') }
before do
stub_feature_flags(protected_environments: enabled)
end
context 'when Protected Environments feature is not on' do
let(:enabled) { false }
it { is_expected.to be_nil }
context 'when Protected Environments feature is available on the project' do
before do
allow(project).to receive(:feature_available?)
.with(:protected_environments).and_return(true)
.with(:protected_environments).and_return(feature_available)
end
it { is_expected.to be_nil }
end
end
context 'when Protected Environments feature is on' do
let(:enabled) { true }
context 'when Protected Environments feature is not available on the project' do
let(:feature_available) { false }
it { is_expected.to be_nil }
end
context 'when Protected Environments feature is available on the project' do
let(:feature_available) { true }
let(:environment) { create(:environment, name: 'production') }
let(:protected_environment) { create(:protected_environment, name: environment.name, project: project) }
before do
allow(project).to receive(:feature_available?)
.with(:protected_environments).and_return(true)
end
context 'when the project environment exists' do
before do
protected_environment
......@@ -1632,7 +1613,6 @@ describe Project do
end
end
end
end
describe '#protected_environment_accessible_to?' do
let(:project) { create(:project) }
......@@ -1643,27 +1623,18 @@ describe Project do
subject { project.protected_environment_accessible_to?(environment.name, user) }
before do
stub_feature_flags(protected_environments: enabled)
end
context 'when Protected Environments feature is not on' do
let(:enabled) { false }
it { is_expected.to be_truthy }
allow(project).to receive(:feature_available?)
.with(:protected_environments).and_return(feature_available)
end
context 'when Protected Environments feature is on' do
let(:enabled) { true }
context 'when Protected Environments feature is not available on the project' do
let(:feature_available) { false }
it { is_expected.to be_truthy }
end
context 'when Protected Environments feature is available on the project' do
before do
allow(project).to receive(:feature_available?)
.with(:protected_environments).and_return(true)
end
let(:feature_available) { true }
context 'when project does not have protected environments' do
it { is_expected.to be_truthy }
......@@ -1688,7 +1659,6 @@ describe Project do
end
end
end
end
describe '#after_import' do
let(:project) { create(:project) }
......
......@@ -11,12 +11,16 @@ describe Ci::EnqueueBuildService, '#execute' do
subject { described_class.new(project, user).execute(ci_build) }
before do
stub_feature_flags(protected_environments: enabled)
allow(License).to receive(:feature_available?).and_call_original
allow(License).to receive(:feature_available?)
.with(:protected_environments).and_return(feature_available)
protected_environment
end
context 'when related to a protected environment' do
context 'when Protected Environments feature is not on' do
let(:enabled) { false }
context 'when Protected Environments feature is not available on project' do
let(:feature_available) { false }
it 'enqueues the build' do
subject
......@@ -25,17 +29,8 @@ describe Ci::EnqueueBuildService, '#execute' do
end
end
context 'when Protected Environments feature is on' do
let(:enabled) { true }
context 'when Protected Environments feature is available in the project' do
before do
allow(License).to receive(:feature_available?).and_call_original
allow(License).to receive(:feature_available?)
.with(:protected_environments).and_return(true)
protected_environment
end
context 'when Protected Environments feature is available on project' do
let(:feature_available) { true }
context 'when user does not have access to the environment' do
it 'should fail the build' do
......@@ -59,5 +54,4 @@ describe Ci::EnqueueBuildService, '#execute' do
end
end
end
end
end
......@@ -3,33 +3,12 @@ RSpec.shared_examples 'protected environments access' do |developer_access = tru
using RSpec::Parameterized::TableSyntax
before do
stub_feature_flags(protected_environments: enabled)
end
context 'when Protected Environments feature is not on' do
let(:enabled) { false }
where(:access_level, :result) do
:guest | false
:reporter | false
:developer | developer_access
:maintainer | true
:admin | true
end
with_them do
before do
environment
update_user_access(access_level, user, project)
end
it { is_expected.to eq(result) }
end
allow(License).to receive(:feature_available?).and_call_original
allow(License).to receive(:feature_available?).with(:protected_environments).and_return(feature_available)
end
context 'when Protected Environments feature is not available in the project' do
let(:enabled) { true }
let(:feature_available) { false }
where(:access_level, :result) do
:guest | false
......@@ -51,12 +30,7 @@ RSpec.shared_examples 'protected environments access' do |developer_access = tru
end
context 'when Protected Environments feature is available in the project' do
let(:enabled) { true }
before do
allow(License).to receive(:feature_available?).and_call_original
allow(License).to receive(:feature_available?).with(:protected_environments).and_return(true)
end
let(:feature_available) { true }
context 'when environment is protected' do
let(:protected_environment) { create(:protected_environment, name: environment.name, project: project) }
......
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