BigW Consortium Gitlab

Commit c39e3f22 by Bob Van Landuyt

Show `New Issue` link for projects

When a user is not logged in, we want to show the `New Issue` link so he gets directed to the login flow first. When a project is archived, we never want to show the link.
parent 04c7d0d5
......@@ -126,6 +126,17 @@ module IssuesHelper
link_to link_text, path
end
def show_new_issue_link?(project)
return false unless project
return false if project.archived?
# We want to show the link to users that are not signed in, that way they
# get directed to the sign-in/sign-up flow and afterwards to the new issue page.
return true unless current_user
can?(current_user, :create_issue, project)
end
# Required for Banzai::Filter::IssueReferenceFilter
module_function :url_for_issue
module_function :url_for_internal_issue
......
......@@ -19,7 +19,7 @@
%li.dropdown-bold-header GitLab
- if @project&.persisted?
- create_project_issue = can?(current_user, :create_issue, @project)
- create_project_issue = show_new_issue_link?(@project)
- merge_project = merge_request_source_project_for_project(@project)
- create_project_snippet = can?(current_user, :create_project_snippet, @project)
- if create_project_issue || merge_project || create_project_snippet
......
- can_create_issue = show_new_issue_link?
- can_create_issue = show_new_issue_link?(@project)
- can_create_project_snippet = can?(current_user, :create_project_snippet, @project)
- can_push_code = can?(current_user, :push_code, @project)
- create_mr_from_new_fork = can?(current_user, :fork_project, @project) && can?(current_user, :create_merge_request_in, @project)
......
......@@ -2,7 +2,7 @@
= icon('rss')
- if @can_bulk_update
= button_tag "Edit issues", class: "btn btn-default append-right-10 js-bulk-update-toggle"
- if !current_user || can?(current_user, :create_issue, @project)
- if show_new_issue_link?(@project)
= link_to "New issue", new_project_issue_path(@project,
issue: { assignee_id: finder.assignee.try(:id),
milestone_id: finder.milestones.first.try(:id) }),
......
......@@ -7,6 +7,7 @@
- can_update_issue = can?(current_user, :update_issue, @issue)
- can_report_spam = @issue.submittable_as_spam_by?(current_user)
- can_create_issue = show_new_issue_link?(@project)
.detail-page-header
.detail-page-header-body
......@@ -42,16 +43,18 @@
%li= link_to 'Reopen issue', issue_path(@issue, issue: { state_event: :reopen }, format: 'json'), class: "btn-reopen js-btn-issue-action #{issue_button_visibility(@issue, false)}", title: 'Reopen issue'
- if can_report_spam
%li= link_to 'Submit as spam', mark_as_spam_project_issue_path(@project, @issue), method: :post, class: 'btn-spam', title: 'Submit as spam'
- if can_update_issue || can_report_spam
%li.divider
%li= link_to 'New issue', new_project_issue_path(@project), title: 'New issue', id: 'new_issue_link'
- if can_create_issue
- if can_update_issue || can_report_spam
%li.divider
%li= link_to 'New issue', new_project_issue_path(@project), title: 'New issue', id: 'new_issue_link'
= render 'shared/issuable/close_reopen_button', issuable: @issue, can_update: can_update_issue
- if can_report_spam
= link_to 'Submit as spam', mark_as_spam_project_issue_path(@project, @issue), method: :post, class: 'hidden-xs hidden-sm btn btn-grouped btn-spam', title: 'Submit as spam'
= link_to new_project_issue_path(@project), class: 'hidden-xs hidden-sm btn btn-grouped new-issue-link btn-new btn-inverted', title: 'New issue', id: 'new_issue_link' do
New issue
- if can_create_issue
= link_to new_project_issue_path(@project), class: 'hidden-xs hidden-sm btn btn-grouped new-issue-link btn-new btn-inverted', title: 'New issue', id: 'new_issue_link' do
New issue
.issue-details.issuable-details
.detail-page-description.content-block
......
......@@ -72,7 +72,7 @@
.title.hide-collapsed
Issues
%span.badge= milestone.issues_visible_to_user(current_user).count
- if project && can?(current_user, :create_issue, project)
- if show_new_issue_link?(project)
= link_to new_project_issue_path(project, issue: { milestone_id: milestone.id }), class: "pull-right", title: "New Issue" do
New issue
.value.hide-collapsed.bold
......
......@@ -89,4 +89,14 @@ describe 'Cherry-pick Commits' do
expect(page).to have_content('The commit has been successfully cherry-picked.')
end
end
context 'when the project is archived' do
let(:project) { create(:project, :repository, namespace: group, archived: true) }
it 'does not show the cherry-pick link' do
find('.header-action-buttons a.dropdown-toggle').click
expect(page).not_to have_css("a[href='#modal-cherry-pick-commit']")
end
end
end
......@@ -10,13 +10,16 @@ describe 'User reverts a commit', :js do
sign_in(user)
visit(project_commit_path(project, sample_commit.id))
end
def click_revert
find('.header-action-buttons .dropdown').click
find('a[href="#modal-revert-commit"]').click
end
context 'without creating a new merge request' do
before do
click_revert
page.within('#modal-revert-commit') do
uncheck('create_merge_request')
click_button('Revert')
......@@ -44,6 +47,10 @@ describe 'User reverts a commit', :js do
end
context 'with creating a new merge request' do
before do
click_revert
end
it 'reverts a commit' do
page.within('#modal-revert-commit') do
click_button('Revert')
......@@ -53,4 +60,14 @@ describe 'User reverts a commit', :js do
expect(page).to have_content("From revert-#{Commit.truncate_sha(sample_commit.id)} into master")
end
end
context 'when the project is archived' do
let(:project) { create(:project, :repository, namespace: user.namespace, archived: true) }
it 'does not show the revert link' do
find('.header-action-buttons .dropdown').click
expect(page).not_to have_link('Revert')
end
end
end
......@@ -6,11 +6,27 @@ describe "User views issue" do
set(:issue) { create(:issue, project: project, description: "# Description header", author: user) }
before do
project.add_guest(user)
project.add_developer(user)
sign_in(user)
visit(project_issue_path(project, issue))
end
it { expect(page).to have_header_with_correct_id_and_link(1, "Description header", "description-header") }
it { expect(page).to have_link('New issue') }
it { expect(page).to have_button('Create merge request') }
it { expect(page).to have_link('Close issue') }
context 'when the project is archived' do
let(:project) { create(:project, :public, archived: true) }
it { expect(page).not_to have_link('New issue') }
it { expect(page).not_to have_button('Create merge request') }
it { expect(page).not_to have_link('Close issue') }
end
end
......@@ -163,4 +163,26 @@ describe IssuesHelper do
end
end
end
describe '#show_new_issue_link?' do
before do
allow(helper).to receive(:current_user)
end
it 'is false when no project there is no project' do
expect(helper.show_new_issue_link?(nil)).to be_falsey
end
it 'is true when there is a project and no logged in user' do
expect(helper.show_new_issue_link?(build(:project))).to be_truthy
end
it 'is true when the current user does not have access to the project' do
project = build(:project)
allow(helper).to receive(:current_user).and_return(project.owner)
expect(helper).to receive(:can?).with(project.owner, :create_issue, project).and_return(true)
expect(helper.show_new_issue_link?(project)).to be_truthy
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