diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index f906d0ddf6..8d9f4b9f18 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -1646,8 +1646,9 @@ module ApplicationHelper
end
def cancel_button_tag(fallback_url)
- url = validate_back_url(back_url) || fallback_url
- link_to l(:button_cancel), url
+ url = validate_back_url(request.get? ? back_url : params[:back_url])
+ url = nil if url && url.split('?').first == request.path
+ link_to l(:button_cancel), url || fallback_url
end
def check_all_links(form_name)
diff --git a/app/views/documents/edit.html.erb b/app/views/documents/edit.html.erb
index 87e08e1364..c05b102667 100644
--- a/app/views/documents/edit.html.erb
+++ b/app/views/documents/edit.html.erb
@@ -1,8 +1,12 @@
<%=l(:label_document)%>
<%= labelled_form_for @document, :html => {:multipart => true} do |f| %>
+ <%= back_url_hidden_field_tag %>
<%= render :partial => 'form', :locals => {:f => f} %>
- <%= submit_tag l(:button_save) %>
+
+ <%= submit_tag l(:button_save) %>
+ <%= cancel_button_tag document_path(@document) %>
+
<% end %>
diff --git a/app/views/documents/new.html.erb b/app/views/documents/new.html.erb
index a34391e314..199c4499e0 100644
--- a/app/views/documents/new.html.erb
+++ b/app/views/documents/new.html.erb
@@ -1,6 +1,10 @@
<%=l(:label_document_new)%>
<%= labelled_form_for @document, :url => project_documents_path(@project), :html => {:multipart => true} do |f| %>
+ <%= back_url_hidden_field_tag %>
<%= render :partial => 'form', :locals => {:f => f} %>
- <%= submit_tag l(:button_create) %>
+
+ <%= submit_tag l(:button_create) %>
+ <%= cancel_button_tag project_documents_path(@project) %>
+
<% end %>
diff --git a/app/views/files/new.html.erb b/app/views/files/new.html.erb
index ab38b4472f..acb02afe7e 100644
--- a/app/views/files/new.html.erb
+++ b/app/views/files/new.html.erb
@@ -2,6 +2,7 @@
<%= error_messages_for 'attachment' %>
<%= form_tag(project_files_path(@project), :multipart => true, :class => "tabular") do %>
+<%= back_url_hidden_field_tag %>
<% if @versions.any? %>
@@ -13,4 +14,5 @@
<%= render :partial => 'attachments/form' %>
<%= submit_tag l(:button_add) %>
+<%= cancel_button_tag project_files_path(@project) %>
<% end %>
diff --git a/app/views/issue_categories/edit.html.erb b/app/views/issue_categories/edit.html.erb
index c04aacb07d..a0eaf35e73 100644
--- a/app/views/issue_categories/edit.html.erb
+++ b/app/views/issue_categories/edit.html.erb
@@ -2,6 +2,8 @@
<%= labelled_form_for @category, :as => :issue_category,
:url => issue_category_path(@category), :html => {:method => :put} do |f| %>
+<%= back_url_hidden_field_tag %>
<%= render :partial => 'issue_categories/form', :locals => { :f => f } %>
<%= submit_tag l(:button_save) %>
+<%= cancel_button_tag settings_project_path(@project, :tab => 'categories') %>
<% end %>
diff --git a/app/views/issue_categories/new.html.erb b/app/views/issue_categories/new.html.erb
index b8ecf8974f..f1ba54fd41 100644
--- a/app/views/issue_categories/new.html.erb
+++ b/app/views/issue_categories/new.html.erb
@@ -2,6 +2,8 @@
<%= labelled_form_for @category, :as => :issue_category,
:url => project_issue_categories_path(@project) do |f| %>
+<%= back_url_hidden_field_tag %>
<%= render :partial => 'issue_categories/form', :locals => { :f => f } %>
<%= submit_tag l(:button_create) %>
+<%= cancel_button_tag settings_project_path(@project, :tab => 'categories') %>
<% end %>
diff --git a/app/views/issues/new.html.erb b/app/views/issues/new.html.erb
index 40089215ca..77ac483405 100644
--- a/app/views/issues/new.html.erb
+++ b/app/views/issues/new.html.erb
@@ -42,6 +42,7 @@
<%= submit_tag l(:button_create_and_follow), name: 'follow' %>
<% end %>
<%= submit_tag l(:button_create_and_continue), :name => 'continue' %>
+ <%= cancel_button_tag _project_issues_path(@project) %>
<% end %>
<% content_for :header_tags do %>
diff --git a/app/views/news/edit.html.erb b/app/views/news/edit.html.erb
index 50b897324a..bfa9d59f6f 100644
--- a/app/views/news/edit.html.erb
+++ b/app/views/news/edit.html.erb
@@ -1,8 +1,10 @@
<%=l(:label_news)%>
<%= labelled_form_for @news, :html => { :id => 'news-form', :multipart => true, :method => :put } do |f| %>
+<%= back_url_hidden_field_tag %>
<%= render :partial => 'form', :locals => { :f => f } %>
<%= submit_tag l(:button_save) %>
+<%= cancel_button_tag news_path(@news) %>
<% end %>
<% content_for :header_tags do %>
diff --git a/app/views/news/new.html.erb b/app/views/news/new.html.erb
index 6ac32008d0..208d5e0ebf 100644
--- a/app/views/news/new.html.erb
+++ b/app/views/news/new.html.erb
@@ -2,6 +2,8 @@
<%= labelled_form_for @news, :url => (@project ? project_news_index_path(@project) : news_index_path),
:html => { :id => 'news-form', :multipart => true } do |f| %>
+ <%= back_url_hidden_field_tag %>
<%= render :partial => 'news/form', :locals => { :f => f } %>
<%= submit_tag l(:button_create) %>
+ <%= cancel_button_tag(@project ? project_news_index_path(@project) : news_index_path) %>
<% end %>
diff --git a/app/views/versions/edit.html.erb b/app/views/versions/edit.html.erb
index db6bb84e54..359cf8a8af 100644
--- a/app/views/versions/edit.html.erb
+++ b/app/views/versions/edit.html.erb
@@ -3,5 +3,6 @@
<%= labelled_form_for @version, :html => {:multipart => true} do |f| %>
<%= render :partial => 'form', :locals => { :f => f } %>
<%= submit_tag l(:button_save) %>
+<%= cancel_button_tag settings_project_path(@project, :tab => 'versions') %>
<% end %>
diff --git a/app/views/versions/new.html.erb b/app/views/versions/new.html.erb
index b52436dbbe..738fefadc0 100644
--- a/app/views/versions/new.html.erb
+++ b/app/views/versions/new.html.erb
@@ -3,4 +3,5 @@
<%= labelled_form_for @version, :url => project_versions_path(@project), :html => {:multipart => true} do |f| %>
<%= render :partial => 'versions/form', :locals => { :f => f } %>
<%= submit_tag l(:button_create) %>
+<%= cancel_button_tag settings_project_path(@project, :tab => 'versions') %>
<% end %>
diff --git a/app/views/wiki/new.html.erb b/app/views/wiki/new.html.erb
index d0674202df..f0f76ccea9 100644
--- a/app/views/wiki/new.html.erb
+++ b/app/views/wiki/new.html.erb
@@ -12,6 +12,8 @@
+ <%= back_url_hidden_field_tag %>
<%= submit_tag(l(:label_next)) %>
+ <%= cancel_button_tag project_wiki_index_path(@project) %>
<% end %>
diff --git a/test/functional/documents_controller_test.rb b/test/functional/documents_controller_test.rb
index beff79d647..2c9b3a78e5 100644
--- a/test/functional/documents_controller_test.rb
+++ b/test/functional/documents_controller_test.rb
@@ -137,6 +137,13 @@ class DocumentsControllerTest < Redmine::ControllerTest
assert_response :success
end
+ def test_new_should_have_cancel_link
+ @request.session[:user_id] = 2
+ get(:new, :params => {:project_id => 1})
+ assert_response :success
+ assert_select 'a[href=?]', '/projects/ecookbook/documents', :text => 'Cancel'
+ end
+
def test_create_with_one_attachment
ActionMailer::Base.deliveries.clear
@request.session[:user_id] = 2
@@ -210,6 +217,13 @@ class DocumentsControllerTest < Redmine::ControllerTest
assert_equal category1, doc.category
end
+ def test_edit_should_have_cancel_link
+ @request.session[:user_id] = 2
+ get(:edit, :params => {:id => 1})
+ assert_response :success
+ assert_select 'a[href=?]', '/documents/1', :text => 'Cancel'
+ end
+
def test_edit
@request.session[:user_id] = 2
get(
diff --git a/test/functional/files_controller_test.rb b/test/functional/files_controller_test.rb
index 8bb62b96c1..8aec1c77f5 100644
--- a/test/functional/files_controller_test.rb
+++ b/test/functional/files_controller_test.rb
@@ -41,6 +41,17 @@ class FilesControllerTest < Redmine::ControllerTest
assert_select 'a[href=?]', '/attachments/download/9/version_file.zip', :text => 'version_file.zip'
end
+ def test_new_should_have_cancel_link
+ @request.session[:user_id] = 2
+ get(:new, :params => {:project_id => 1, :back_url => '/projects/ecookbook'})
+ assert_response :success
+ assert_select 'input[type=hidden][name=back_url][value=?]', '/projects/ecookbook'
+ assert_select 'a[href=?]', '/projects/ecookbook', :text => 'Cancel'
+
+ get(:new, :params => {:project_id => 1})
+ assert_select 'a[href=?]', '/projects/ecookbook/files', :text => 'Cancel'
+ end
+
def test_new
@request.session[:user_id] = 2
get(
diff --git a/test/functional/issue_categories_controller_test.rb b/test/functional/issue_categories_controller_test.rb
index 8884d2516c..5b14893e58 100644
--- a/test/functional/issue_categories_controller_test.rb
+++ b/test/functional/issue_categories_controller_test.rb
@@ -32,6 +32,17 @@ class IssueCategoriesControllerTest < Redmine::ControllerTest
assert_select 'input[name=?]', 'issue_category[name]'
end
+ def test_new_should_have_cancel_link
+ @request.session[:user_id] = 2
+ get(:new, :params => {:project_id => '1', :back_url => '/projects/ecookbook/issues'})
+ assert_response :success
+ assert_select 'input[type=hidden][name=back_url][value=?]', '/projects/ecookbook/issues'
+ assert_select 'a[href=?]', '/projects/ecookbook/issues', :text => 'Cancel'
+
+ get(:new, :params => {:project_id => '1'})
+ assert_select 'a[href=?]', '/projects/ecookbook/settings/categories', :text => 'Cancel'
+ end
+
def test_new_from_issue_form
@request.session[:user_id] = 2 # manager
get(
@@ -127,6 +138,13 @@ class IssueCategoriesControllerTest < Redmine::ControllerTest
assert_select 'input[name=?][value=?]', 'issue_category[name]', 'Recipes'
end
+ def test_edit_should_have_cancel_link
+ @request.session[:user_id] = 2
+ get(:edit, :params => {:id => 2})
+ assert_response :success
+ assert_select 'a[href=?]', '/projects/ecookbook/settings/categories', :text => 'Cancel'
+ end
+
def test_update
assert_no_difference 'IssueCategory.count' do
put(
diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb
index 4da71e8d99..7a7f87132a 100644
--- a/test/functional/issues_controller_test.rb
+++ b/test/functional/issues_controller_test.rb
@@ -4270,6 +4270,52 @@ class IssuesControllerTest < Redmine::ControllerTest
assert_select 'div#issue_statuses_description', 0
end
+ def test_get_new_should_have_cancel_link_to_back_url
+ @request.session[:user_id] = 2
+ get(:new, :params => {:project_id => 1, :back_url => '/issues/1'})
+ assert_response :success
+ assert_select 'a[href=?]', '/issues/1', :text => 'Cancel'
+ end
+
+ def test_get_new_should_have_cancel_link_to_referer
+ @request.session[:user_id] = 2
+ @request.env['HTTP_REFERER'] = 'http://test.host/projects/ecookbook/roadmap'
+ get(:new, :params => {:project_id => 1})
+ assert_response :success
+ assert_select 'a[href=?]', '/projects/ecookbook/roadmap', :text => 'Cancel'
+ end
+
+ def test_get_new_should_not_have_cancel_link_to_itself
+ @request.session[:user_id] = 2
+ # e.g. after "Create and continue"
+ @request.env['HTTP_REFERER'] = 'http://test.host/projects/ecookbook/issues/new?issue%5Btracker_id%5D=1'
+ get(:new, :params => {:project_id => 'ecookbook'})
+ assert_response :success
+ assert_select 'a[href=?]', '/projects/ecookbook/issues', :text => 'Cancel'
+ end
+
+ def test_post_create_with_failure_should_not_have_cancel_link_to_the_form
+ @request.session[:user_id] = 2
+ @request.env['HTTP_REFERER'] = 'http://test.host/projects/ecookbook/issues/new'
+ post(:create, :params => {:project_id => 1, :issue => {:tracker_id => 1, :subject => ''}})
+ assert_response :success
+ assert_select_error /Subject cannot be blank/
+ assert_select 'a[href=?]', '/projects/ecookbook/issues', :text => 'Cancel'
+ end
+
+ def test_post_create_with_failure_should_keep_cancel_link_to_back_url
+ @request.session[:user_id] = 2
+ post(
+ :create,
+ :params => {
+ :project_id => 1, :back_url => '/issues/1',
+ :issue => {:tracker_id => 1, :subject => ''}
+ }
+ )
+ assert_response :success
+ assert_select 'a[href=?]', '/issues/1', :text => 'Cancel'
+ end
+
def test_get_new_should_show_create_and_follow_button_when_issue_is_subtask_and_back_url_is_present
@request.session[:user_id] = 2
get :new, params: {
diff --git a/test/functional/news_controller_test.rb b/test/functional/news_controller_test.rb
index ca5e6a9834..66cb14a310 100644
--- a/test/functional/news_controller_test.rb
+++ b/test/functional/news_controller_test.rb
@@ -131,6 +131,16 @@ class NewsControllerTest < Redmine::ControllerTest
assert_select 'input[name=?]', 'news[title]'
end
+ def test_get_new_should_have_cancel_link
+ @request.session[:user_id] = 2
+ get(:new, :params => {:project_id => 1})
+ assert_response :success
+ assert_select 'a[href=?]', '/projects/ecookbook/news', :text => 'Cancel'
+
+ get(:new)
+ assert_select 'a[href=?]', '/news', :text => 'Cancel'
+ end
+
def test_get_new_without_project_id
@request.session[:user_id] = 2
get(:new)
@@ -259,6 +269,27 @@ class NewsControllerTest < Redmine::ControllerTest
assert_select_error /title cannot be blank/i
end
+ def test_post_create_with_validation_failure_should_keep_cancel_link_to_back_url
+ @request.session[:user_id] = 2
+ post(
+ :create,
+ :params => {
+ :project_id => 1, :back_url => '/projects/ecookbook',
+ :news => {:title => '', :description => 'This is the description'}
+ }
+ )
+ assert_response :success
+ assert_select 'input[type=hidden][name=back_url][value=?]', '/projects/ecookbook'
+ assert_select 'a[href=?]', '/projects/ecookbook', :text => 'Cancel'
+ end
+
+ def test_get_edit_should_have_cancel_link
+ @request.session[:user_id] = 2
+ get(:edit, :params => {:id => 1})
+ assert_response :success
+ assert_select 'a[href=?]', '/news/1', :text => 'Cancel'
+ end
+
def test_get_edit
@request.session[:user_id] = 2
get(:edit, :params => {:id => 1})
diff --git a/test/functional/versions_controller_test.rb b/test/functional/versions_controller_test.rb
index 382b555f90..638b0bdd40 100644
--- a/test/functional/versions_controller_test.rb
+++ b/test/functional/versions_controller_test.rb
@@ -250,6 +250,16 @@ class VersionsControllerTest < Redmine::ControllerTest
assert_select 'select[name=?]', 'version[status]', false
end
+ def test_new_should_have_cancel_link
+ @request.session[:user_id] = 2
+ get :new, :params => {:project_id => '1', :back_url => '/projects/ecookbook/roadmap'}
+ assert_response :success
+ assert_select 'a[href=?]', '/projects/ecookbook/roadmap', :text => 'Cancel'
+
+ get :new, :params => {:project_id => '1'}
+ assert_select 'a[href=?]', '/projects/ecookbook/settings/versions', :text => 'Cancel'
+ end
+
def test_new_from_issue_form
@request.session[:user_id] = 2
get :new, :params => {:project_id => '1'}, :xhr => true
@@ -291,6 +301,13 @@ class VersionsControllerTest < Redmine::ControllerTest
assert_equal 'text/javascript', response.media_type
end
+ def test_get_edit_should_have_cancel_link
+ @request.session[:user_id] = 2
+ get :edit, :params => {:id => 2}
+ assert_response :success
+ assert_select 'a[href=?]', '/projects/ecookbook/settings/versions', :text => 'Cancel'
+ end
+
def test_get_edit
@request.session[:user_id] = 2
get :edit, :params => {:id => 2}
diff --git a/test/functional/wiki_controller_test.rb b/test/functional/wiki_controller_test.rb
index 9f4ee657b6..55db5d17c8 100644
--- a/test/functional/wiki_controller_test.rb
+++ b/test/functional/wiki_controller_test.rb
@@ -262,6 +262,13 @@ class WikiControllerTest < Redmine::ControllerTest
assert_select 'input[name=?]', 'title'
end
+ def test_get_new_should_have_cancel_link
+ @request.session[:user_id] = 2
+ get :new, :params => {:project_id => 'ecookbook'}
+ assert_response :success
+ assert_select 'a[href=?]', '/projects/ecookbook/wiki/index', :text => 'Cancel'
+ end
+
def test_get_new_xhr
@request.session[:user_id] = 2
--
2.43.0