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 module ProtectedEnvironmentsHelper
def protected_environments_enabled? def protected_environments_enabled?(project)
Feature.enabled?('protected_environments') project.protected_environments_feature_available?
end end
end end
...@@ -537,7 +537,7 @@ module EE ...@@ -537,7 +537,7 @@ module EE
end end
def protected_environments_feature_available? def protected_environments_feature_available?
Feature.enabled?('protected_environments') && feature_available?(:protected_environments) feature_available?(:protected_environments)
end end
# Because we use default_value_for we need to be sure # Because we use default_value_for we need to be sure
......
...@@ -17,7 +17,8 @@ module EE ...@@ -17,7 +17,8 @@ module EE
alias_method :build, :subject alias_method :build, :subject
def deployable_by_user? 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? return true unless build.project.protected_environments_feature_available?
build.project.protected_environment_accessible_to?(build.expanded_environment_name, user) build.project.protected_environment_accessible_to?(build.expanded_environment_name, user)
......
...@@ -16,7 +16,8 @@ module EE ...@@ -16,7 +16,8 @@ module EE
private private
def allowed_to_deploy?(build) 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? return true unless project.protected_environments_feature_available?
project.protected_environment_accessible_to?(build.expanded_environment_name, build.user) project.protected_environment_accessible_to?(build.expanded_environment_name, build.user)
......
- expanded = Rails.env.test? - expanded = Rails.env.test?
- can_admin_project = can?(current_user, :admin_project, @project) - 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) } %section.protected-environments-settings.settings.no-animate#js-protected-environments-settings{ class: ('expanded' if expanded) }
.settings-header .settings-header
%h4 %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 ...@@ -8,7 +8,6 @@ describe 'Environments page', :js do
let(:user) { create(:user) } let(:user) { create(:user) }
before do before do
stub_feature_flags(protected_environments: true)
allow(License).to receive(:feature_available?).and_call_original allow(License).to receive(:feature_available?).and_call_original
allow(License).to receive(:feature_available?).with(:protected_environments).and_return(true) allow(License).to receive(:feature_available?).with(:protected_environments).and_return(true)
project.add_maintainer(user) project.add_maintainer(user)
......
...@@ -8,8 +8,8 @@ describe 'Protected Environments' do ...@@ -8,8 +8,8 @@ describe 'Protected Environments' do
let(:environments) { %w(production development staging test) } let(:environments) { %w(production development staging test) }
before do 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| environments.each do |environment_name|
create(:environment, name: environment_name, project: project) create(:environment, name: environment_name, project: project)
end end
......
...@@ -29,39 +29,29 @@ describe Environment do ...@@ -29,39 +29,29 @@ describe Environment do
subject { environment.protected? } subject { environment.protected? }
before do before do
stub_feature_flags(protected_environments: enabled) allow(project).to receive(:feature_available?)
.with(:protected_environments).and_return(feature_available)
end end
context 'when Protected Environments feature is not on' do context 'when Protected Environments feature is not available on the project' do
let(:enabled) { false } let(:feature_available) { false }
it { is_expected.to be_falsy } it { is_expected.to be_falsy }
end end
context 'when Protected Environments feature is on' do context 'when Protected Environments feature is available on the project' do
let(:enabled) { true } let(:feature_available) { true }
context 'when Protected Environments feature is not available in the project' do context 'when the environment is protected' do
it { is_expected.to be_falsy }
end
context 'when Protected Environments feature is available in the project' do
before do before do
allow(project).to receive(:feature_available?) create(:protected_environment, name: environment.name, project: project)
.with(:protected_environments).and_return(true)
end end
context 'when the environment is protected' do it { is_expected.to be_truthy }
before do end
create(:protected_environment, name: environment.name, project: project)
end
it { is_expected.to be_truthy }
end
context 'when the environment is not protected' do context 'when the environment is not protected' do
it { is_expected.to be_falsy } it { is_expected.to be_falsy }
end
end end
end end
end end
...@@ -73,43 +63,37 @@ describe Environment do ...@@ -73,43 +63,37 @@ describe Environment do
subject { environment.protected_deployable_by_user?(user) } subject { environment.protected_deployable_by_user?(user) }
before do before do
stub_feature_flags(protected_environments: enabled) allow(project).to receive(:feature_available?)
.with(:protected_environments).and_return(feature_available)
end end
context 'when Protected Environments feature is not on' do context 'when Protected Environments feature is not available on the project' do
let(:enabled) { false } let(:feature_available) { false }
it { is_expected.to be_truthy } it { is_expected.to be_truthy }
end end
context 'when Protected Environments feature is on' do context 'when Protected Environments feature is available on the project' do
let(:enabled) { true } let(:feature_available) { true }
context 'when Protected Environments feature is available in the project' do context 'when the environment is not protected' do
before do it { is_expected.to be_truthy }
allow(project).to receive(:feature_available?) end
.with(:protected_environments).and_return(true)
end
context 'when the environment is not protected' do context 'when environment is protected and user dont have access to it' do
it { is_expected.to be_truthy } before do
protected_environment
end end
context 'when environment is protected and user dont have access to it' do it { is_expected.to be_falsy }
before do end
protected_environment
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 end
context 'when environment is protected and user have access to it' do it { is_expected.to be_truthy }
before do
protected_environment.deploy_access_levels.create(user: user)
end
it { is_expected.to be_truthy }
end
end end
end end
end end
......
...@@ -1585,51 +1585,31 @@ describe Project do ...@@ -1585,51 +1585,31 @@ describe Project do
subject { project.protected_environment_by_name('production') } subject { project.protected_environment_by_name('production') }
before do before do
stub_feature_flags(protected_environments: enabled) allow(project).to receive(:feature_available?)
.with(:protected_environments).and_return(feature_available)
end end
context 'when Protected Environments feature is not on' do context 'when Protected Environments feature is not available on the project' do
let(:enabled) { false } let(:feature_available) { false }
it { is_expected.to be_nil } 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 end
context 'when Protected Environments feature is on' do context 'when Protected Environments feature is available on the project' do
let(:enabled) { true } let(:feature_available) { true }
let(:environment) { create(:environment, name: 'production') }
context 'when Protected Environments feature is not available on the project' do let(:protected_environment) { create(:protected_environment, name: environment.name, project: project) }
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 the project environment exists' do
before do before do
allow(project).to receive(:feature_available?) protected_environment
.with(:protected_environments).and_return(true)
end end
context 'when the project environment exists' do it { is_expected.to eq(protected_environment) }
before do end
protected_environment
end
it { is_expected.to eq(protected_environment) }
end
context 'when the project environment does not exists' do context 'when the project environment does not exists' do
it { is_expected.to be_nil } it { is_expected.to be_nil }
end
end end
end end
end end
...@@ -1643,48 +1623,38 @@ describe Project do ...@@ -1643,48 +1623,38 @@ describe Project do
subject { project.protected_environment_accessible_to?(environment.name, user) } subject { project.protected_environment_accessible_to?(environment.name, user) }
before do before do
stub_feature_flags(protected_environments: enabled) allow(project).to receive(:feature_available?)
.with(:protected_environments).and_return(feature_available)
end end
context 'when Protected Environments feature is not on' do context 'when Protected Environments feature is not available on the project' do
let(:enabled) { false } let(:feature_available) { false }
it { is_expected.to be_truthy } it { is_expected.to be_truthy }
end end
context 'when Protected Environments feature is on' do context 'when Protected Environments feature is available on the project' do
let(:enabled) { true } 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 } it { is_expected.to be_truthy }
end end
context 'when Protected Environments feature is available on the project' do context 'when project has protected environments' do
before do context 'when user has the right access' do
allow(project).to receive(:feature_available?) before do
.with(:protected_environments).and_return(true) protected_environment.deploy_access_levels.create(user_id: user.id)
end end
context 'when project does not have protected environments' do
it { is_expected.to be_truthy } it { is_expected.to be_truthy }
end end
context 'when project has protected environments' do context 'when user does not have the right access' do
context 'when user has the right access' do before do
before do protected_environment.deploy_access_levels.create
protected_environment.deploy_access_levels.create(user_id: user.id)
end
it { is_expected.to be_truthy }
end end
context 'when user does not have the right access' do it { is_expected.to be_falsy }
before do
protected_environment.deploy_access_levels.create
end
it { is_expected.to be_falsy }
end
end end
end end
end end
......
...@@ -11,12 +11,16 @@ describe Ci::EnqueueBuildService, '#execute' do ...@@ -11,12 +11,16 @@ describe Ci::EnqueueBuildService, '#execute' do
subject { described_class.new(project, user).execute(ci_build) } subject { described_class.new(project, user).execute(ci_build) }
before do 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 end
context 'when related to a protected environment' do context 'when related to a protected environment' do
context 'when Protected Environments feature is not on' do context 'when Protected Environments feature is not available on project' do
let(:enabled) { false } let(:feature_available) { false }
it 'enqueues the build' do it 'enqueues the build' do
subject subject
...@@ -25,37 +29,27 @@ describe Ci::EnqueueBuildService, '#execute' do ...@@ -25,37 +29,27 @@ describe Ci::EnqueueBuildService, '#execute' do
end end
end end
context 'when Protected Environments feature is on' do context 'when Protected Environments feature is available on project' do
let(:enabled) { true } let(:feature_available) { true }
context 'when Protected Environments feature is available in the project' do context 'when user does not have access to the environment' do
before do it 'should fail the build' do
allow(License).to receive(:feature_available?).and_call_original subject
allow(License).to receive(:feature_available?)
.with(:protected_environments).and_return(true)
protected_environment expect(ci_build.failed?).to be_truthy
expect(ci_build.failure_reason).to eq('protected_environment_failure')
end end
end
context 'when user does not have access to the environment' do context 'when user has access to the environment' do
it 'should fail the build' do before do
subject protected_environment.deploy_access_levels.create(user: user)
expect(ci_build.failed?).to be_truthy
expect(ci_build.failure_reason).to eq('protected_environment_failure')
end
end end
context 'when user has access to the environment' do it 'enqueues the build' do
before do subject
protected_environment.deploy_access_levels.create(user: user)
end
it 'enqueues the build' do
subject
expect(ci_build.pending?).to be_truthy expect(ci_build.pending?).to be_truthy
end
end end
end end
end end
......
...@@ -3,33 +3,12 @@ RSpec.shared_examples 'protected environments access' do |developer_access = tru ...@@ -3,33 +3,12 @@ RSpec.shared_examples 'protected environments access' do |developer_access = tru
using RSpec::Parameterized::TableSyntax using RSpec::Parameterized::TableSyntax
before do before do
stub_feature_flags(protected_environments: enabled) allow(License).to receive(:feature_available?).and_call_original
end allow(License).to receive(:feature_available?).with(:protected_environments).and_return(feature_available)
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
end end
context 'when Protected Environments feature is not available in the project' do context 'when Protected Environments feature is not available in the project' do
let(:enabled) { true } let(:feature_available) { false }
where(:access_level, :result) do where(:access_level, :result) do
:guest | false :guest | false
...@@ -51,12 +30,7 @@ RSpec.shared_examples 'protected environments access' do |developer_access = tru ...@@ -51,12 +30,7 @@ RSpec.shared_examples 'protected environments access' do |developer_access = tru
end end
context 'when Protected Environments feature is available in the project' do context 'when Protected Environments feature is available in the project' do
let(:enabled) { true } let(:feature_available) { 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
context 'when environment is protected' do context 'when environment is protected' do
let(:protected_environment) { create(:protected_environment, name: environment.name, project: project) } 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