summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhil Hughes <me@iamphill.com>2016-09-02 14:33:24 +0100
committerPhil Hughes <me@iamphill.com>2016-09-02 14:33:24 +0100
commit315e6392cd5f4e35fd44d0d24637ea377604b754 (patch)
tree58473e0dfbef1bf207ec51d19d2596ba032b78e5
parenta5d1428a91c16f07b73cf62401f9513db5fb85b7 (diff)
downloadgitlab-ce-branches-mr-button-permissions.tar.gz
Hides merge request button on branches pagebranches-mr-button-permissions
If user does not have the correct permissions, the merge request button is hidden Closes #21805
-rw-r--r--CHANGELOG1
-rw-r--r--app/views/projects/branches/_branch.html.haml5
-rw-r--r--spec/features/projects/branches_spec.rb48
3 files changed, 35 insertions, 19 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 0eb076fd62f..e91bc0b9b17 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -18,6 +18,7 @@ v 8.12.0 (unreleased)
- Shorten task status phrase (ClemMakesApps)
- Add hover color to emoji icon (ClemMakesApps)
- Fix branches page dropdown sort alignment (ClemMakesApps)
+ - Hides merge request button on branches page is user doesn't have permissions
- Add white background for no readme container (ClemMakesApps)
- API: Expose issue confidentiality flag. (Robert Schilling)
- Optimistic locking for Issues and Merge Requests (title and description overriding prevention)
diff --git a/app/views/projects/branches/_branch.html.haml b/app/views/projects/branches/_branch.html.haml
index 808e6b95746..5217b8bf028 100644
--- a/app/views/projects/branches/_branch.html.haml
+++ b/app/views/projects/branches/_branch.html.haml
@@ -3,6 +3,7 @@
- diverging_commit_counts = @repository.diverging_commit_counts(branch)
- number_commits_behind = diverging_commit_counts[:behind]
- number_commits_ahead = diverging_commit_counts[:ahead]
+- merge_project = can?(current_user, :create_merge_request, @project) ? @project : (current_user && current_user.fork_of(@project))
%li(class="js-branch-#{branch.name}")
%div
= link_to namespace_project_tree_path(@project.namespace, @project, branch.name), class: 'item-title str-truncated' do
@@ -19,12 +20,12 @@
%i.fa.fa-lock
protected
.controls.hidden-xs
- - if create_mr_button?(@repository.root_ref, branch.name)
+ - if merge_project && create_mr_button?(@repository.root_ref, branch.name)
= link_to create_mr_path(@repository.root_ref, branch.name), class: 'btn btn-default' do
Merge Request
- if branch.name != @repository.root_ref
- = link_to namespace_project_compare_index_path(@project.namespace, @project, from: @repository.root_ref, to: branch.name), class: 'btn btn-default', method: :post, title: "Compare" do
+ = link_to namespace_project_compare_index_path(@project.namespace, @project, from: @repository.root_ref, to: branch.name), class: "btn btn-default #{'prepend-left-10' unless merge_project}", method: :post, title: "Compare" do
Compare
= render 'projects/buttons/download', project: @project, ref: branch.name
diff --git a/spec/features/projects/branches_spec.rb b/spec/features/projects/branches_spec.rb
index 1b14945bf0a..d26a0caf036 100644
--- a/spec/features/projects/branches_spec.rb
+++ b/spec/features/projects/branches_spec.rb
@@ -1,32 +1,46 @@
require 'spec_helper'
describe 'Branches', feature: true do
- let(:project) { create(:project) }
+ let(:project) { create(:project, :public) }
let(:repository) { project.repository }
- before do
- login_as :user
- project.team << [@user, :developer]
- end
+ context 'logged in' do
+ before do
+ login_as :user
+ project.team << [@user, :developer]
+ end
- describe 'Initial branches page' do
- it 'shows all the branches' do
- visit namespace_project_branches_path(project.namespace, project)
+ describe 'Initial branches page' do
+ it 'shows all the branches' do
+ visit namespace_project_branches_path(project.namespace, project)
- repository.branches { |branch| expect(page).to have_content("#{branch.name}") }
- expect(page).to have_content("Protected branches can be managed in project settings")
+ repository.branches { |branch| expect(page).to have_content("#{branch.name}") }
+ expect(page).to have_content("Protected branches can be managed in project settings")
+ end
+ end
+
+ describe 'Find branches' do
+ it 'shows filtered branches', js: true do
+ visit namespace_project_branches_path(project.namespace, project)
+
+ fill_in 'branch-search', with: 'fix'
+ find('#branch-search').native.send_keys(:enter)
+
+ expect(page).to have_content('fix')
+ expect(find('.all-branches')).to have_selector('li', count: 1)
+ end
end
end
- describe 'Find branches' do
- it 'shows filtered branches', js: true do
+ context 'logged out' do
+ before do
visit namespace_project_branches_path(project.namespace, project)
+ end
- fill_in 'branch-search', with: 'fix'
- find('#branch-search').native.send_keys(:enter)
-
- expect(page).to have_content('fix')
- expect(find('.all-branches')).to have_selector('li', count: 1)
+ it 'does not show merge request button' do
+ page.within first('.all-branches li') do
+ expect(page).not_to have_content 'Merge Request'
+ end
end
end
end