Commit 115beab7 authored by Paul Slaughter's avatar Paul Slaughter

Create feature flag for unsigned alert in IDE

This allows local instance admins to toggle
this particular behavior off while we work on
the [holistic solution][1].

[1]: https://gitlab.com/gitlab-org/gitlab/-/issues/19185
parent a3c410dc
...@@ -208,7 +208,7 @@ export const canPushCodeStatus = (state, getters) => { ...@@ -208,7 +208,7 @@ export const canPushCodeStatus = (state, getters) => {
PUSH_RULE_REJECT_UNSIGNED_COMMITS PUSH_RULE_REJECT_UNSIGNED_COMMITS
]; ];
if (rejectUnsignedCommits) { if (window.gon?.features?.rejectUnsignedCommitsByGitlab && rejectUnsignedCommits) {
return { return {
isAllowed: false, isAllowed: false,
message: MSG_CANNOT_PUSH_UNSIGNED, message: MSG_CANNOT_PUSH_UNSIGNED,
......
...@@ -10,6 +10,7 @@ class IdeController < ApplicationController ...@@ -10,6 +10,7 @@ class IdeController < ApplicationController
before_action do before_action do
push_frontend_feature_flag(:build_service_proxy) push_frontend_feature_flag(:build_service_proxy)
push_frontend_feature_flag(:schema_linting) push_frontend_feature_flag(:schema_linting)
push_frontend_feature_flag(:reject_unsigned_commits_by_gitlab, default_enabled: :yaml)
define_index_vars define_index_vars
end end
......
---
name: reject_unsigned_commits_by_gitlab
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/58453
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/326775
milestone: '13.11'
type: development
group: group::editor
default_enabled: true
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe 'EE user opens IDE', :js do RSpec.describe 'EE user opens IDE', :js do
using RSpec::Parameterized::TableSyntax
include WebIdeSpecHelpers include WebIdeSpecHelpers
let_it_be(:unsigned_commits_warning) { 'This project does not accept unsigned commits.' } let_it_be(:unsigned_commits_warning) { 'This project does not accept unsigned commits.' }
...@@ -16,25 +17,39 @@ RSpec.describe 'EE user opens IDE', :js do ...@@ -16,25 +17,39 @@ RSpec.describe 'EE user opens IDE', :js do
sign_in(user) sign_in(user)
end end
context 'default' do shared_examples 'no warning' do
before do it 'does not show warning' do
ide_visit(project) ide_visit(project)
end
it 'does not show warning' do
expect(page).not_to have_text(unsigned_commits_warning) expect(page).not_to have_text(unsigned_commits_warning)
end end
end end
shared_examples 'has warning' do
it 'shows warning' do
ide_visit(project)
expect(page).to have_text(unsigned_commits_warning)
end
end
context 'no push rules' do
it_behaves_like 'no warning'
end
context 'when has reject_unsigned_commit push rule' do context 'when has reject_unsigned_commit push rule' do
before do before do
create(:push_rule, project: project, reject_unsigned_commits: true) create(:push_rule, project: project, reject_unsigned_commits: true)
ide_visit(project)
end end
it 'shows warning' do it_behaves_like 'has warning'
expect(page).to have_text(unsigned_commits_warning)
context 'and feature flag off' do
before do
stub_feature_flags(reject_unsigned_commits_by_gitlab: false)
end
it_behaves_like 'no warning'
end end
end end
end end
...@@ -24,12 +24,22 @@ const TEST_FORK_PATH = '/test/fork/path'; ...@@ -24,12 +24,22 @@ const TEST_FORK_PATH = '/test/fork/path';
describe('IDE store getters', () => { describe('IDE store getters', () => {
let localState; let localState;
let localStore; let localStore;
let origGon;
beforeEach(() => { beforeEach(() => {
origGon = window.gon;
// Feature flag is defaulted to on in prod
window.gon = { features: { rejectUnsignedCommitsByGitlab: true } };
localStore = createStore(); localStore = createStore();
localState = localStore.state; localState = localStore.state;
}); });
afterEach(() => {
window.gon = origGon;
});
describe('activeFile', () => { describe('activeFile', () => {
it('returns the current active file', () => { it('returns the current active file', () => {
localState.openFiles.push(file()); localState.openFiles.push(file());
...@@ -500,9 +510,25 @@ describe('IDE store getters', () => { ...@@ -500,9 +510,25 @@ describe('IDE store getters', () => {
}, },
}, },
], ],
[
'when can push code, but cannot push unsigned commits, with reject_unsigned_commits_by_gitlab feature off',
{
input: {
pushCode: true,
rejectUnsignedCommits: true,
features: { rejectUnsignedCommitsByGitlab: false },
},
output: {
isAllowed: true,
message: '',
messageShort: '',
},
},
],
])('%s', (testName, { input, output }) => { ])('%s', (testName, { input, output }) => {
const { forkInfo, rejectUnsignedCommits, pushCode } = input; const { forkInfo, rejectUnsignedCommits, pushCode, features = {} } = input;
Object.assign(window.gon.features, features);
localState.links = { forkInfo }; localState.links = { forkInfo };
localState.projects[TEST_PROJECT_ID] = { localState.projects[TEST_PROJECT_ID] = {
pushRules: { pushRules: {
......
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