Commit a962650f authored by Phil Hughes's avatar Phil Hughes

Merge branch 'al-55240-access-policy-check-for-new-snippet-button' into 'master'

Access policy check for new snippet button

See merge request gitlab-org/gitlab!23560
parents c59d0236 15a91a82
- page_title _("Snippets") - page_title _("Snippets")
- new_project_snippet_link = new_project_snippet_path(@project) if can?(current_user, :create_snippet, @project)
- if @snippets.exists? - if @snippets.exists?
- if current_user - if current_user
...@@ -6,10 +7,10 @@ ...@@ -6,10 +7,10 @@
- include_private = @project.team.member?(current_user) || current_user.admin? - include_private = @project.team.member?(current_user) || current_user.admin?
= render partial: 'snippets/snippets_scope_menu', locals: { subject: @project, include_private: include_private } = render partial: 'snippets/snippets_scope_menu', locals: { subject: @project, include_private: include_private }
- if can?(current_user, :create_snippet, @project) - if new_project_snippet_link.present?
.nav-controls .nav-controls
= link_to _("New snippet"), new_project_snippet_path(@project), class: "btn btn-success", title: _("New snippet") = link_to _("New snippet"), new_project_snippet_link, class: "btn btn-success", title: _("New snippet")
= render 'shared/snippets/list' = render 'shared/snippets/list'
- else - else
= render 'shared/empty_states/snippets', button_path: new_namespace_project_snippet_path(@project.namespace, @project) = render 'shared/empty_states/snippets', button_path: new_project_snippet_link
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
- if secondary_button_link.present? - if secondary_button_link.present?
= link_to secondary_button_label, secondary_button_link, class: 'btn btn-success btn-inverted' = link_to secondary_button_label, secondary_button_link, class: 'btn btn-success btn-inverted'
= link_to primary_button_label, primary_button_link, class: 'btn btn-success' - if primary_button_link.present?
= link_to primary_button_label, primary_button_link, class: 'btn btn-success'
- else - else
%h5= visitor_empty_message %h5= visitor_empty_message
---
title: Ensure New Snippet button is displayed based on the :create_snippet permission
in Project Snippets page and User profile > Snippets tab
merge_request: 55240
author:
type: fixed
...@@ -3,32 +3,97 @@ ...@@ -3,32 +3,97 @@
require 'spec_helper' require 'spec_helper'
describe 'Projects > Snippets > User views snippets' do describe 'Projects > Snippets > User views snippets' do
let(:project) { create(:project) } let_it_be(:project) { create(:project) }
let!(:project_snippet) { create(:project_snippet, project: project, author: user) }
let!(:snippet) { create(:snippet, author: user) }
let(:snippets) { [project_snippet, snippet] } # Used by the shared examples
let(:user) { create(:user) } let(:user) { create(:user) }
before do def visit_project_snippets
project.add_maintainer(user)
sign_in(user)
visit(project_snippets_path(project)) visit(project_snippets_path(project))
end end
context 'pagination' do context 'snippets list' do
let!(:project_snippet) { create(:project_snippet, project: project, author: user) }
let!(:snippet) { create(:snippet, author: user) }
let(:snippets) { [project_snippet, snippet] } # Used by the shared examples
before do before do
create(:project_snippet, project: project, author: user) project.add_maintainer(user)
allow(Snippet).to receive(:default_per_page).and_return(1) sign_in(user)
end
context 'pagination' do
before do
create(:project_snippet, project: project, author: user)
allow(Snippet).to receive(:default_per_page).and_return(1)
visit project_snippets_path(project) visit_project_snippets
end
it_behaves_like 'paginated snippets'
end end
it_behaves_like 'paginated snippets' it 'shows snippets' do
visit_project_snippets
expect(page).to have_link(project_snippet.title, href: project_snippet_path(project, project_snippet))
expect(page).not_to have_content(snippet.title)
end
end end
it 'shows snippets' do context 'when current user is a guest' do
expect(page).to have_link(project_snippet.title, href: project_snippet_path(project, project_snippet)) before do
expect(page).not_to have_content(snippet.title) project.add_guest(user)
sign_in(user)
end
context 'when snippets list is empty' do
it 'hides New Snippet button' do
visit_project_snippets
page.within(find('.empty-state')) do
expect(page).not_to have_link('New snippet')
end
end
end
context 'when project has snippets' do
let!(:project_snippet) { create(:project_snippet, project: project, author: user) }
it 'hides New Snippet button' do
visit_project_snippets
page.within(find('.top-area')) do
expect(page).not_to have_link('New snippet')
end
end
end
end
context 'when current user is not a guest' do
before do
project.add_developer(user)
sign_in(user)
end
context 'when snippets list is empty' do
it 'shows New Snippet button' do
visit_project_snippets
page.within(find('.empty-state')) do
expect(page).to have_link('New snippet')
end
end
end
context 'when project has snippets' do
let!(:project_snippet) { create(:project_snippet, project: project, author: user) }
it 'shows New Snippet button' do
visit_project_snippets
page.within(find('.top-area')) do
expect(page).to have_link('New snippet')
end
end
end
end end
end end
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