Skip to content
代码片段 群组 项目
提交 d95b0c32 编辑于 作者: Artur Fedorov's avatar Artur Fedorov
浏览文件

Merge branch '430304-disable-change-default-branch-button' into 'master'

No related branches found
No related tags found
无相关合并请求
...@@ -8,6 +8,11 @@ export default { ...@@ -8,6 +8,11 @@ export default {
RefSelector, RefSelector,
}, },
props: { props: {
disabled: {
type: Boolean,
required: false,
default: false,
},
persistedDefaultBranch: { persistedDefaultBranch: {
type: String, type: String,
required: true, required: true,
...@@ -26,6 +31,7 @@ export default { ...@@ -26,6 +31,7 @@ export default {
</script> </script>
<template> <template>
<ref-selector <ref-selector
:disabled="disabled"
:value="persistedDefaultBranch" :value="persistedDefaultBranch"
class="gl-w-full" class="gl-w-full"
:project-id="projectId" :project-id="projectId"
......
import Vue from 'vue'; import Vue from 'vue';
import { parseBoolean } from '~/lib/utils/common_utils';
import DefaultBranchSelector from './components/default_branch_selector.vue'; import DefaultBranchSelector from './components/default_branch_selector.vue';
export default (el) => { export default (el) => {
...@@ -6,13 +7,14 @@ export default (el) => { ...@@ -6,13 +7,14 @@ export default (el) => {
return null; return null;
} }
const { projectId, defaultBranch } = el.dataset; const { projectId, defaultBranch, disabled } = el.dataset;
return new Vue({ return new Vue({
el, el,
render(createElement) { render(createElement) {
return createElement(DefaultBranchSelector, { return createElement(DefaultBranchSelector, {
props: { props: {
disabled: parseBoolean(disabled),
persistedDefaultBranch: defaultBranch, persistedDefaultBranch: defaultBranch,
projectId, projectId,
}, },
......
...@@ -28,12 +28,17 @@ export default { ...@@ -28,12 +28,17 @@ export default {
}, },
inheritAttrs: false, inheritAttrs: false,
props: { props: {
disabled: {
type: Boolean,
required: false,
default: false,
},
enabledRefTypes: { enabledRefTypes: {
type: Array, type: Array,
required: false, required: false,
default: () => ALL_REF_TYPES, default: () => ALL_REF_TYPES,
validator: (val) => validator: (val) =>
// It has to be an arrray // It has to be an array
isArray(val) && isArray(val) &&
// with at least one item // with at least one item
val.length > 0 && val.length > 0 &&
...@@ -234,6 +239,10 @@ export default { ...@@ -234,6 +239,10 @@ export default {
this.debouncedSearch(); this.debouncedSearch();
}, },
selectRef(ref) { selectRef(ref) {
if (this.disabled) {
return;
}
this.setSelectedRef(ref); this.setSelectedRef(ref);
this.$emit('input', this.selectedRef); this.$emit('input', this.selectedRef);
}, },
...@@ -262,6 +271,7 @@ export default { ...@@ -262,6 +271,7 @@ export default {
:toggle-class="extendedToggleButtonClass" :toggle-class="extendedToggleButtonClass"
:toggle-text="buttonText" :toggle-text="buttonText"
:icon="dropdownIcon" :icon="dropdownIcon"
:disabled="disabled"
v-bind="$attrs" v-bind="$attrs"
v-on="$listeners" v-on="$listeners"
@hidden="$emit('hide')" @hidden="$emit('hide')"
......
- change_default_disabled = @default_branch_blocked_by_security_policy
- popover_data = {}
- if change_default_disabled
- tag_pair_security_policies_page = tag_pair(link_to('', namespace_project_security_policies_path, target: '_blank', rel: 'noopener noreferrer'), :security_policies_link_start, :security_policies_link_end)
- tag_pair_security_policies_docs = tag_pair(link_to('', help_page_path('user/application_security/policies/scan-result-policies'), target: '_blank', rel: 'noopener noreferrer'), :learn_more_link_start, :learn_more_link_end)
- popover_content = safe_format(s_("SecurityOrchestration|You can't change the default branch because its protection is enforced by one or more %{security_policies_link_start}security policies%{security_policies_link_end}. %{learn_more_link_start}Learn more%{learn_more_link_end}."), tag_pair_security_policies_docs, tag_pair_security_policies_page)
- popover_title = s_("SecurityOrchestration|Security policy overwrites this setting")
- popover_data = { container: 'body', toggle: 'popover', html: 'true', triggers: 'hover', title: popover_title, content: popover_content }
%fieldset#default-branch-settings %fieldset#default-branch-settings
- if @project.empty_repo? - if @project.empty_repo?
.text-secondary .text-secondary
...@@ -6,8 +16,8 @@ ...@@ -6,8 +16,8 @@
.form-group .form-group
= f.label :default_branch, _("Default branch"), class: 'label-bold' = f.label :default_branch, _("Default branch"), class: 'label-bold'
%p= s_('ProjectSettings|All merge requests and commits are made against this branch unless you specify a different one.') %p= s_('ProjectSettings|All merge requests and commits are made against this branch unless you specify a different one.')
.gl-form-input-xl .gl-form-input-xl{ data: { **popover_data } }
.js-select-default-branch{ data: { default_branch: @project.default_branch, project_id: @project.id } } .js-select-default-branch{ data: { default_branch: @project.default_branch, project_id: @project.id, disabled: change_default_disabled.to_s } }
.form-group .form-group
- help_text = _("When merge requests and commits in the default branch close, any issues they reference also close.") - help_text = _("When merge requests and commits in the default branch close, any issues they reference also close.")
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'Projects > Settings > User changes default branch', feature_category: :groups_and_projects do
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project, :repository, namespace: user.namespace) }
let_it_be(:protected_branch) { create(:protected_branch, project: project, name: project.default_branch) }
let(:default_branch_settings) { find('#default-branch-settings') }
let(:default_branch_button) do
within_testid('default-branch-dropdown') do
find('button')
end
end
let(:visit_repository_page) { visit project_settings_repository_path(project) }
before do
sign_in(user)
end
context 'with branch not protected by security policy' do
it 'does not show popover if the default branch can be changed', :aggregate_failures, :js do
visit_repository_page
expect(default_branch_settings).not_to have_selector('[data-toggle="popover"]')
expect(default_branch_button).not_to be_disabled
end
end
context 'with branch protected by security policy' do
include_context 'with scan result policy blocking protected branches' do
let(:branch_name) { project.default_branch }
let(:policy_configuration) do
create(:security_orchestration_policy_configuration, project: project)
end
it 'disables the button and shows the popover if the default branch cannot be changed',
:aggregate_failures,
:js do
visit_repository_page
expect(default_branch_settings).to have_selector('[data-toggle="popover"]')
expect(default_branch_button).to be_disabled
end
end
end
end
...@@ -43315,6 +43315,9 @@ msgstr "" ...@@ -43315,6 +43315,9 @@ msgstr ""
msgid "SecurityOrchestration|Security Scan" msgid "SecurityOrchestration|Security Scan"
msgstr "" msgstr ""
   
msgid "SecurityOrchestration|Security policy overwrites this setting"
msgstr ""
msgid "SecurityOrchestration|Security policy project was linked successfully" msgid "SecurityOrchestration|Security policy project was linked successfully"
msgstr "" msgstr ""
   
...@@ -43465,6 +43468,9 @@ msgstr "" ...@@ -43465,6 +43468,9 @@ msgstr ""
msgid "SecurityOrchestration|You already have the maximum %{maximumAllowed} %{policyType} policies." msgid "SecurityOrchestration|You already have the maximum %{maximumAllowed} %{policyType} policies."
msgstr "" msgstr ""
   
msgid "SecurityOrchestration|You can't change the default branch because its protection is enforced by one or more %{security_policies_link_start}security policies%{security_policies_link_end}. %{learn_more_link_start}Learn more%{learn_more_link_end}."
msgstr ""
msgid "SecurityOrchestration|You can't unprotect this branch because its protection is enforced by one or more %{security_policies_link_start}security policies%{security_policies_link_end}. %{learn_more_link_start}Learn more%{learn_more_link_end}." msgid "SecurityOrchestration|You can't unprotect this branch because its protection is enforced by one or more %{security_policies_link_start}security policies%{security_policies_link_end}. %{learn_more_link_start}Learn more%{learn_more_link_end}."
msgstr "" msgstr ""
   
...@@ -4,6 +4,7 @@ import RefSelector from '~/ref/components/ref_selector.vue'; ...@@ -4,6 +4,7 @@ import RefSelector from '~/ref/components/ref_selector.vue';
import { REF_TYPE_BRANCHES } from '~/ref/constants'; import { REF_TYPE_BRANCHES } from '~/ref/constants';
describe('projects/settings/components/default_branch_selector', () => { describe('projects/settings/components/default_branch_selector', () => {
const disabled = true;
const persistedDefaultBranch = 'main'; const persistedDefaultBranch = 'main';
const projectId = '123'; const projectId = '123';
let wrapper; let wrapper;
...@@ -13,6 +14,7 @@ describe('projects/settings/components/default_branch_selector', () => { ...@@ -13,6 +14,7 @@ describe('projects/settings/components/default_branch_selector', () => {
const buildWrapper = () => { const buildWrapper = () => {
wrapper = shallowMount(DefaultBranchSelector, { wrapper = shallowMount(DefaultBranchSelector, {
propsData: { propsData: {
disabled,
persistedDefaultBranch, persistedDefaultBranch,
projectId, projectId,
}, },
...@@ -25,6 +27,7 @@ describe('projects/settings/components/default_branch_selector', () => { ...@@ -25,6 +27,7 @@ describe('projects/settings/components/default_branch_selector', () => {
it('displays a RefSelector component', () => { it('displays a RefSelector component', () => {
expect(findRefSelector().props()).toEqual({ expect(findRefSelector().props()).toEqual({
disabled,
value: persistedDefaultBranch, value: persistedDefaultBranch,
enabledRefTypes: [REF_TYPE_BRANCHES], enabledRefTypes: [REF_TYPE_BRANCHES],
projectId, projectId,
......
...@@ -46,7 +46,7 @@ describe('Ref selector component', () => { ...@@ -46,7 +46,7 @@ describe('Ref selector component', () => {
let commitApiCallSpy; let commitApiCallSpy;
let requestSpies; let requestSpies;
const createComponent = (mountOverrides = {}, propsData = {}) => { const createComponent = ({ overrides = {}, propsData = {} } = {}) => {
wrapper = mountExtended( wrapper = mountExtended(
RefSelector, RefSelector,
merge( merge(
...@@ -64,7 +64,7 @@ describe('Ref selector component', () => { ...@@ -64,7 +64,7 @@ describe('Ref selector component', () => {
}, },
store: createStore(), store: createStore(),
}, },
mountOverrides, overrides,
), ),
); );
}; };
...@@ -211,7 +211,7 @@ describe('Ref selector component', () => { ...@@ -211,7 +211,7 @@ describe('Ref selector component', () => {
const id = 'git-ref'; const id = 'git-ref';
beforeEach(() => { beforeEach(() => {
createComponent({ attrs: { id } }); createComponent({ overrides: { attrs: { id } } });
return waitForRequests(); return waitForRequests();
}); });
...@@ -326,7 +326,7 @@ describe('Ref selector component', () => { ...@@ -326,7 +326,7 @@ describe('Ref selector component', () => {
describe('branches', () => { describe('branches', () => {
describe('when the branches search returns results', () => { describe('when the branches search returns results', () => {
beforeEach(() => { beforeEach(() => {
createComponent({}, { useSymbolicRefNames: true }); createComponent({ propsData: { useSymbolicRefNames: true } });
return waitForRequests(); return waitForRequests();
}); });
...@@ -389,7 +389,7 @@ describe('Ref selector component', () => { ...@@ -389,7 +389,7 @@ describe('Ref selector component', () => {
describe('tags', () => { describe('tags', () => {
describe('when the tags search returns results', () => { describe('when the tags search returns results', () => {
beforeEach(() => { beforeEach(() => {
createComponent({}, { useSymbolicRefNames: true }); createComponent({ propsData: { useSymbolicRefNames: true } });
return waitForRequests(); return waitForRequests();
}); });
...@@ -569,6 +569,20 @@ describe('Ref selector component', () => { ...@@ -569,6 +569,20 @@ describe('Ref selector component', () => {
}); });
}); });
}); });
describe('disabled', () => {
it('does not disable the dropdown', () => {
createComponent();
expect(findListbox().props('disabled')).toBe(false);
});
it('disables the dropdown', async () => {
createComponent({ propsData: { disabled: true } });
expect(findListbox().props('disabled')).toBe(true);
await selectFirstBranch();
expect(wrapper.emitted('input')).toBeUndefined();
});
});
}); });
describe('with non-default ref types', () => { describe('with non-default ref types', () => {
...@@ -691,9 +705,7 @@ describe('Ref selector component', () => { ...@@ -691,9 +705,7 @@ describe('Ref selector component', () => {
}); });
beforeEach(() => { beforeEach(() => {
createComponent({ createComponent({ overrides: { scopedSlots: { footer: createFooter } } });
scopedSlots: { footer: createFooter },
});
updateQuery('abcd1234'); updateQuery('abcd1234');
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册