Commit d9242f20 authored by Phil Hughes's avatar Phil Hughes

Show create merge request button on confidential issues

https://gitlab.com/gitlab-org/gitlab-ce/issues/58583
parent 733f384b
......@@ -135,6 +135,20 @@ module IssuesHelper
can?(current_user, :create_issue, project)
end
def create_confidential_merge_request_enabled?
Feature.enabled?(:create_confidential_merge_request, @project)
end
def show_new_branch_button?
can_create_confidential_merge_request? || !@issue.confidential?
end
def can_create_confidential_merge_request?
@issue.confidential? && !@project.private? &&
create_confidential_merge_request_enabled? &&
can?(current_user, :create_merge_request_in, @project)
end
# Required for Banzai::Filter::IssueReferenceFilter
module_function :url_for_issue
module_function :url_for_internal_issue
......
......@@ -2,6 +2,7 @@
- can_create_merge_request = can?(current_user, :create_merge_request_in, @project)
- data_action = can_create_merge_request ? 'create-mr' : 'create-branch'
- value = can_create_merge_request ? 'Create merge request' : 'Create branch'
- value = can_create_confidential_merge_request? ? _('Create confidential merge request') : value
- can_create_path = can_create_branch_project_issue_path(@project, @issue)
- create_mr_path = create_merge_request_project_issue_path(@project, @issue, branch_name: @issue.to_branch_name, ref: @project.default_branch)
......@@ -23,12 +24,15 @@
= icon('caret-down')
.droplab-dropdown
%ul#create-merge-request-dropdown.create-merge-request-dropdown-menu.dropdown-menu.dropdown-menu-right.gl-show-field-errors{ data: { dropdown: true } }
%ul#create-merge-request-dropdown.create-merge-request-dropdown-menu.dropdown-menu.dropdown-menu-right.gl-show-field-errors{ class: ("create-confidential-merge-request-dropdown-menu" if can_create_confidential_merge_request?), data: { dropdown: true } }
- if can_create_merge_request
%li.droplab-item-selected{ role: 'button', data: { value: 'create-mr', text: _('Create merge request') } }
.menu-item
= icon('check', class: 'icon')
= _('Create merge request and branch')
- if can_create_confidential_merge_request?
= _('Create confidential merge request and branch')
- else
= _('Create merge request and branch')
%li{ class: [!can_create_merge_request && 'droplab-item-selected'], role: 'button', data: { value: 'create-branch', text: _('Create branch') } }
.menu-item
......
......@@ -91,7 +91,7 @@
= render 'award_emoji/awards_block', awardable: @issue, inline: true
.col-md-12.col-lg-6.new-branch-col
#js-vue-discussion-filter{ data: { default_filter: current_user&.notes_filter_for(@issue), notes_filters: UserPreference.notes_filters.to_json } }
= render 'new_branch' unless @issue.confidential?
= render 'new_branch' if show_new_branch_button?
= render_if_exists 'projects/issues/discussion'
......
......@@ -3056,6 +3056,12 @@ msgstr ""
msgid "Create commit"
msgstr ""
msgid "Create confidential merge request"
msgstr ""
msgid "Create confidential merge request and branch"
msgstr ""
msgid "Create directory"
msgstr ""
......
......@@ -3,7 +3,7 @@ require 'rails_helper'
describe 'User creates branch and merge request on issue page', :js do
let(:membership_level) { :developer }
let(:user) { create(:user) }
let!(:project) { create(:project, :repository) }
let!(:project) { create(:project, :repository, :public) }
let(:issue) { create(:issue, project: project, title: 'Cherry-Coloured Funk') }
context 'when signed out' do
......@@ -163,10 +163,21 @@ describe 'User creates branch and merge request on issue page', :js do
let(:issue) { create(:issue, :confidential, project: project) }
it 'disables the create branch button' do
stub_feature_flags(create_confidential_merge_request: false)
visit project_issue_path(project, issue)
expect(page).not_to have_css('.create-mr-dropdown-wrap')
end
it 'enables the create branch button when feature flag is enabled' do
stub_feature_flags(create_confidential_merge_request: true)
visit project_issue_path(project, issue)
expect(page).to have_css('.create-mr-dropdown-wrap')
expect(page).to have_button('Create confidential merge request')
end
end
context 'when related branch exists' do
......
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