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,39 +29,29 @@ describe Environment do
subject { environment.protected? }
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_falsy }
end
context 'when Protected Environments feature is on' do
let(:enabled) { true }
context 'when Protected Environments feature is available on the project' do
let(:feature_available) { true }
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
context 'when the environment is protected' do
before do
allow(project).to receive(:feature_available?)
.with(:protected_environments).and_return(true)
create(:protected_environment, name: environment.name, project: project)
end
context 'when the environment is protected' do
before do
create(:protected_environment, name: environment.name, project: project)
end
it { is_expected.to be_truthy }
end
it { is_expected.to be_truthy }
end
context 'when the environment is not protected' do
it { is_expected.to be_falsy }
end
context 'when the environment is not protected' do
it { is_expected.to be_falsy }
end
end
end
......@@ -73,43 +63,37 @@ 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 on the project' do
let(:feature_available) { 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 the environment is not protected' do
it { is_expected.to be_truthy }
end
context 'when the environment is not protected' do
it { is_expected.to be_truthy }
context 'when environment is protected and user dont have access to it' do
before do
protected_environment
end
context 'when environment is protected and user dont have access to it' do
before do
protected_environment
end
it { is_expected.to be_falsy }
end
it { is_expected.to be_falsy }
context 'when environment is protected and user have access to it' do
before do
protected_environment.deploy_access_levels.create(user: user)
end
context 'when environment is protected and user have access to it' do
before do
protected_environment.deploy_access_levels.create(user: user)
end
it { is_expected.to be_truthy }
end
it { is_expected.to be_truthy }
end
end
end
......
......@@ -1585,51 +1585,31 @@ describe Project do
subject { project.protected_environment_by_name('production') }
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_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)
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
it { is_expected.to be_nil }
end
context 'when Protected Environments feature is available on the project' do
let(:environment) { create(:environment, name: 'production') }
let(:protected_environment) { create(:protected_environment, name: environment.name, project: project) }
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) }
context 'when the project environment exists' do
before do
allow(project).to receive(:feature_available?)
.with(:protected_environments).and_return(true)
protected_environment
end
context 'when the project environment exists' do
before do
protected_environment
end
it { is_expected.to eq(protected_environment) }
end
it { is_expected.to eq(protected_environment) }
end
context 'when the project environment does not exists' do
it { is_expected.to be_nil }
end
context 'when the project environment does not exists' do
it { is_expected.to be_nil }
end
end
end
......@@ -1643,48 +1623,38 @@ describe Project do
subject { project.protected_environment_accessible_to?(environment.name, 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 on the project' do
let(:feature_available) { true }
context 'when Protected Environments feature is not available on the project' do
context 'when project does not have protected environments' do
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
context 'when project has protected environments' do
context 'when user has the right access' do
before do
protected_environment.deploy_access_levels.create(user_id: user.id)
end
context 'when project does not have protected environments' do
it { is_expected.to be_truthy }
end
context 'when project has protected environments' do
context 'when user has the right access' do
before do
protected_environment.deploy_access_levels.create(user_id: user.id)
end
it { is_expected.to be_truthy }
context 'when user does not have the right access' do
before do
protected_environment.deploy_access_levels.create
end
context 'when user does not have the right access' do
before do
protected_environment.deploy_access_levels.create
end
it { is_expected.to be_falsy }
end
it { is_expected.to be_falsy }
end
end
end
......
......@@ -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,37 +29,27 @@ 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 on project' do
let(:feature_available) { 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)
context 'when user does not have access to the environment' do
it 'should fail the build' do
subject
protected_environment
expect(ci_build.failed?).to be_truthy
expect(ci_build.failure_reason).to eq('protected_environment_failure')
end
end
context 'when user does not have access to the environment' do
it 'should fail the build' do
subject
expect(ci_build.failed?).to be_truthy
expect(ci_build.failure_reason).to eq('protected_environment_failure')
end
context 'when user has access to the environment' do
before do
protected_environment.deploy_access_levels.create(user: user)
end
context 'when user has access to the environment' do
before do
protected_environment.deploy_access_levels.create(user: user)
end
it 'enqueues the build' do
subject
it 'enqueues the build' do
subject
expect(ci_build.pending?).to be_truthy
end
expect(ci_build.pending?).to be_truthy
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