Commit aea78ded authored by Sam Rose's avatar Sam Rose

Redirect to signin when New Issue for not logged in

parent 9ed3db91
...@@ -6,6 +6,8 @@ class Projects::IssuesController < Projects::ApplicationController ...@@ -6,6 +6,8 @@ class Projects::IssuesController < Projects::ApplicationController
include IssuableCollections include IssuableCollections
include SpammableActions include SpammableActions
prepend_before_action :authenticate_user!, only: [:new]
before_action :redirect_to_external_issue_tracker, only: [:index, :new] before_action :redirect_to_external_issue_tracker, only: [:index, :new]
before_action :module_enabled before_action :module_enabled
before_action :issue, only: [:edit, :update, :show, :referenced_merge_requests, before_action :issue, only: [:edit, :update, :show, :referenced_merge_requests,
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
.nav-controls .nav-controls
= link_to params.merge(rss_url_options), class: 'btn append-right-10 has-tooltip', title: 'Subscribe' do = link_to params.merge(rss_url_options), class: 'btn append-right-10 has-tooltip', title: 'Subscribe' do
= icon('rss') = icon('rss')
- if can? current_user, :create_issue, @project
= link_to new_namespace_project_issue_path(@project.namespace, = link_to new_namespace_project_issue_path(@project.namespace,
@project, @project,
issue: { assignee_id: issues_finder.assignee.try(:id), issue: { assignee_id: issues_finder.assignee.try(:id),
......
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
= confidential_icon(@issue) = confidential_icon(@issue)
= issuable_meta(@issue, @project, "Issue") = issuable_meta(@issue, @project, "Issue")
- if can?(current_user, :create_issue, @project) || can?(current_user, :update_issue, @issue)
.issuable-actions .issuable-actions
.clearfix.issue-btn-group.dropdown .clearfix.issue-btn-group.dropdown
%button.btn.btn-default.pull-left.hidden-md.hidden-lg{ type: "button", data: { toggle: "dropdown" } } %button.btn.btn-default.pull-left.hidden-md.hidden-lg{ type: "button", data: { toggle: "dropdown" } }
...@@ -28,7 +27,6 @@ ...@@ -28,7 +27,6 @@
= icon('caret-down') = icon('caret-down')
.dropdown-menu.dropdown-menu-align-right.hidden-lg .dropdown-menu.dropdown-menu-align-right.hidden-lg
%ul %ul
- if can?(current_user, :create_issue, @project)
%li %li
= link_to 'New issue', new_namespace_project_issue_path(@project.namespace, @project), title: 'New issue', id: 'new_issue_link' = link_to 'New issue', new_namespace_project_issue_path(@project.namespace, @project), title: 'New issue', id: 'new_issue_link'
- if can?(current_user, :update_issue, @issue) - if can?(current_user, :update_issue, @issue)
...@@ -42,7 +40,6 @@ ...@@ -42,7 +40,6 @@
%li %li
= link_to 'Submit as spam', mark_as_spam_namespace_project_issue_path(@project.namespace, @project, @issue), method: :post, class: 'btn-spam', title: 'Submit as spam' = link_to 'Submit as spam', mark_as_spam_namespace_project_issue_path(@project.namespace, @project, @issue), method: :post, class: 'btn-spam', title: 'Submit as spam'
- if can?(current_user, :create_issue, @project)
= link_to new_namespace_project_issue_path(@project.namespace, @project), class: 'hidden-xs hidden-sm btn btn-grouped new-issue-link btn-new btn-inverted', title: 'New issue', id: 'new_issue_link' do = link_to new_namespace_project_issue_path(@project.namespace, @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 New issue
- if can?(current_user, :update_issue, @issue) - if can?(current_user, :update_issue, @issue)
......
...@@ -17,6 +17,5 @@ ...@@ -17,6 +17,5 @@
- if project_select_button - if project_select_button
= render 'shared/new_project_item_select', path: 'issues/new', label: 'New issue' = render 'shared/new_project_item_select', path: 'issues/new', label: 'New issue'
- else - else
%h4 There are no issues to show.
= link_to 'New issue', button_path, class: 'btn btn-new', title: 'New issue', id: 'new_issue_link' = link_to 'New issue', button_path, class: 'btn btn-new', title: 'New issue', id: 'new_issue_link'
- else
%h4.text-center There are no issues to show.
...@@ -87,6 +87,12 @@ describe Projects::IssuesController do ...@@ -87,6 +87,12 @@ describe Projects::IssuesController do
end end
describe 'GET #new' do describe 'GET #new' do
it 'redirects to signin if not logged in' do
get :new, namespace_id: project.namespace, project_id: project
expect(response).to redirect_to(new_user_session_path)
end
context 'internal issue tracker' do context 'internal issue tracker' do
before do before do
sign_in(user) sign_in(user)
...@@ -112,6 +118,11 @@ describe Projects::IssuesController do ...@@ -112,6 +118,11 @@ describe Projects::IssuesController do
end end
context 'external issue tracker' do context 'external issue tracker' do
before do
sign_in(user)
project.team << [user, :developer]
end
it 'redirects to the external issue tracker' do it 'redirects to the external issue tracker' do
external = double(new_issue_path: 'https://example.com/issues/new') external = double(new_issue_path: 'https://example.com/issues/new')
allow(project).to receive(:external_issue_tracker).and_return(external) allow(project).to receive(:external_issue_tracker).and_return(external)
......
...@@ -6,7 +6,7 @@ describe 'Issues', feature: true do ...@@ -6,7 +6,7 @@ describe 'Issues', feature: true do
include SortingHelper include SortingHelper
include WaitForAjax include WaitForAjax
let(:project) { create(:project) } let(:project) { create(:project, :public) }
before do before do
login_as :user login_as :user
...@@ -565,6 +565,24 @@ describe 'Issues', feature: true do ...@@ -565,6 +565,24 @@ describe 'Issues', feature: true do
end end
describe 'new issue' do describe 'new issue' do
context 'by unauthenticated user' do
before do
logout
end
it 'redirects to signin then back to new issue after signin' do
visit namespace_project_issues_path(project.namespace, project)
click_link 'New issue'
expect(current_path).to eq new_user_session_path
login_as :user
expect(current_path).to eq new_namespace_project_issue_path(project.namespace, project)
end
end
context 'dropzone upload file', js: true do context 'dropzone upload file', js: true do
before do before do
visit new_namespace_project_issue_path(project.namespace, project) visit new_namespace_project_issue_path(project.namespace, project)
......
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