Project

General

Profile

Feature #23555 » 0001-Add-cancel-links-to-create-edit-pages-23555.patch

Florian Walchshofer, 2026-10-22 23:22

View differences:

app/helpers/application_helper.rb
1646 1646
  end
1647 1647

  
1648 1648
  def cancel_button_tag(fallback_url)
1649
    url = validate_back_url(back_url) || fallback_url
1650
    link_to l(:button_cancel), url
1649
    url = validate_back_url(request.get? ? back_url : params[:back_url])
1650
    url = nil if url && url.split('?').first == request.path
1651
    link_to l(:button_cancel), url || fallback_url
1651 1652
  end
1652 1653

  
1653 1654
  def check_all_links(form_name)
app/views/documents/edit.html.erb
1 1
<h2><%=l(:label_document)%></h2>
2 2

  
3 3
<%= labelled_form_for @document, :html => {:multipart => true} do |f| %>
4
  <%= back_url_hidden_field_tag %>
4 5
  <%= render :partial => 'form', :locals => {:f => f} %>
5
  <p><%= submit_tag l(:button_save) %></p>
6
  <p>
7
    <%= submit_tag l(:button_save) %>
8
    <%= cancel_button_tag document_path(@document) %>
9
  </p>
6 10
<% end %>
7 11

  
8 12

  
app/views/documents/new.html.erb
1 1
<h2><%=l(:label_document_new)%></h2>
2 2

  
3 3
<%= labelled_form_for @document, :url => project_documents_path(@project), :html => {:multipart => true} do |f| %>
4
  <%= back_url_hidden_field_tag %>
4 5
  <%= render :partial => 'form', :locals => {:f => f} %>
5
  <p><%= submit_tag l(:button_create) %></p>
6
  <p>
7
    <%= submit_tag l(:button_create) %>
8
    <%= cancel_button_tag project_documents_path(@project) %>
9
  </p>
6 10
<% end %>
app/views/files/new.html.erb
2 2

  
3 3
<%= error_messages_for 'attachment' %>
4 4
<%= form_tag(project_files_path(@project), :multipart => true, :class => "tabular") do %>
5
<%= back_url_hidden_field_tag %>
5 6
<div class="box">
6 7

  
7 8
<% if @versions.any? %>
......
13 14
<p><label><%=l(:label_attachment_plural)%></label><%= render :partial => 'attachments/form' %></p>
14 15
</div>
15 16
<%= submit_tag l(:button_add) %>
17
<%= cancel_button_tag project_files_path(@project) %>
16 18
<% end %>
app/views/issue_categories/edit.html.erb
2 2

  
3 3
<%= labelled_form_for @category, :as => :issue_category,
4 4
                     :url => issue_category_path(@category), :html => {:method => :put} do |f| %>
5
<%= back_url_hidden_field_tag %>
5 6
<%= render :partial => 'issue_categories/form', :locals => { :f => f } %>
6 7
<%= submit_tag l(:button_save) %>
8
<%= cancel_button_tag settings_project_path(@project, :tab => 'categories') %>
7 9
<% end %>
app/views/issue_categories/new.html.erb
2 2

  
3 3
<%= labelled_form_for @category, :as => :issue_category,
4 4
                      :url => project_issue_categories_path(@project) do |f| %>
5
<%= back_url_hidden_field_tag %>
5 6
<%= render :partial => 'issue_categories/form', :locals => { :f => f } %>
6 7
<%= submit_tag l(:button_create) %>
8
<%= cancel_button_tag settings_project_path(@project, :tab => 'categories') %>
7 9
<% end %>
app/views/issues/new.html.erb
42 42
    <%= submit_tag l(:button_create_and_follow), name: 'follow' %>
43 43
  <% end %>
44 44
  <%= submit_tag l(:button_create_and_continue), :name => 'continue' %>
45
  <%= cancel_button_tag _project_issues_path(@project) %>
45 46
<% end %>
46 47

  
47 48
<% content_for :header_tags do %>
app/views/news/edit.html.erb
1 1
<h2><%=l(:label_news)%></h2>
2 2

  
3 3
<%= labelled_form_for @news, :html => { :id => 'news-form', :multipart => true, :method => :put } do |f| %>
4
<%= back_url_hidden_field_tag %>
4 5
<%= render :partial => 'form', :locals => { :f => f } %>
5 6
<%= submit_tag l(:button_save) %>
7
<%= cancel_button_tag news_path(@news) %>
6 8
<% end %>
7 9

  
8 10
<% content_for :header_tags do %>
app/views/news/new.html.erb
2 2

  
3 3
<%= labelled_form_for @news, :url => (@project ? project_news_index_path(@project) : news_index_path),
4 4
                                           :html => { :id => 'news-form', :multipart => true } do |f| %>
5
  <%= back_url_hidden_field_tag %>
5 6
  <%= render :partial => 'news/form', :locals => { :f => f } %>
6 7
  <%= submit_tag l(:button_create) %>
8
  <%= cancel_button_tag(@project ? project_news_index_path(@project) : news_index_path) %>
7 9
<% end %>
app/views/versions/edit.html.erb
3 3
<%= labelled_form_for @version, :html => {:multipart => true} do |f| %>
4 4
<%= render :partial => 'form', :locals => { :f => f } %>
5 5
<%= submit_tag l(:button_save) %>
6
<%= cancel_button_tag settings_project_path(@project, :tab => 'versions') %>
6 7
<% end %>
7 8

  
app/views/versions/new.html.erb
3 3
<%= labelled_form_for @version, :url => project_versions_path(@project), :html => {:multipart => true} do |f| %>
4 4
<%= render :partial => 'versions/form', :locals => { :f => f } %>
5 5
<%= submit_tag l(:button_create) %>
6
<%= cancel_button_tag settings_project_path(@project, :tab => 'versions') %>
6 7
<% end %>
app/views/wiki/new.html.erb
12 12
    </p>
13 13
  </div>
14 14

  
15
  <%= back_url_hidden_field_tag %>
15 16
  <%= submit_tag(l(:label_next)) %>
17
  <%= cancel_button_tag project_wiki_index_path(@project) %>
16 18

  
17 19
<% end %>
test/functional/documents_controller_test.rb
137 137
    assert_response :success
138 138
  end
139 139

  
140
  def test_new_should_have_cancel_link
141
    @request.session[:user_id] = 2
142
    get(:new, :params => {:project_id => 1})
143
    assert_response :success
144
    assert_select 'a[href=?]', '/projects/ecookbook/documents', :text => 'Cancel'
145
  end
146

  
140 147
  def test_create_with_one_attachment
141 148
    ActionMailer::Base.deliveries.clear
142 149
    @request.session[:user_id] = 2
......
210 217
    assert_equal category1, doc.category
211 218
  end
212 219

  
220
  def test_edit_should_have_cancel_link
221
    @request.session[:user_id] = 2
222
    get(:edit, :params => {:id => 1})
223
    assert_response :success
224
    assert_select 'a[href=?]', '/documents/1', :text => 'Cancel'
225
  end
226

  
213 227
  def test_edit
214 228
    @request.session[:user_id] = 2
215 229
    get(
test/functional/files_controller_test.rb
41 41
    assert_select 'a[href=?]', '/attachments/download/9/version_file.zip', :text => 'version_file.zip'
42 42
  end
43 43

  
44
  def test_new_should_have_cancel_link
45
    @request.session[:user_id] = 2
46
    get(:new, :params => {:project_id => 1, :back_url => '/projects/ecookbook'})
47
    assert_response :success
48
    assert_select 'input[type=hidden][name=back_url][value=?]', '/projects/ecookbook'
49
    assert_select 'a[href=?]', '/projects/ecookbook', :text => 'Cancel'
50

  
51
    get(:new, :params => {:project_id => 1})
52
    assert_select 'a[href=?]', '/projects/ecookbook/files', :text => 'Cancel'
53
  end
54

  
44 55
  def test_new
45 56
    @request.session[:user_id] = 2
46 57
    get(
test/functional/issue_categories_controller_test.rb
32 32
    assert_select 'input[name=?]', 'issue_category[name]'
33 33
  end
34 34

  
35
  def test_new_should_have_cancel_link
36
    @request.session[:user_id] = 2
37
    get(:new, :params => {:project_id => '1', :back_url => '/projects/ecookbook/issues'})
38
    assert_response :success
39
    assert_select 'input[type=hidden][name=back_url][value=?]', '/projects/ecookbook/issues'
40
    assert_select 'a[href=?]', '/projects/ecookbook/issues', :text => 'Cancel'
41

  
42
    get(:new, :params => {:project_id => '1'})
43
    assert_select 'a[href=?]', '/projects/ecookbook/settings/categories', :text => 'Cancel'
44
  end
45

  
35 46
  def test_new_from_issue_form
36 47
    @request.session[:user_id] = 2 # manager
37 48
    get(
......
127 138
    assert_select 'input[name=?][value=?]', 'issue_category[name]', 'Recipes'
128 139
  end
129 140

  
141
  def test_edit_should_have_cancel_link
142
    @request.session[:user_id] = 2
143
    get(:edit, :params => {:id => 2})
144
    assert_response :success
145
    assert_select 'a[href=?]', '/projects/ecookbook/settings/categories', :text => 'Cancel'
146
  end
147

  
130 148
  def test_update
131 149
    assert_no_difference 'IssueCategory.count' do
132 150
      put(
test/functional/issues_controller_test.rb
4270 4270
    assert_select 'div#issue_statuses_description', 0
4271 4271
  end
4272 4272

  
4273
  def test_get_new_should_have_cancel_link_to_back_url
4274
    @request.session[:user_id] = 2
4275
    get(:new, :params => {:project_id => 1, :back_url => '/issues/1'})
4276
    assert_response :success
4277
    assert_select 'a[href=?]', '/issues/1', :text => 'Cancel'
4278
  end
4279

  
4280
  def test_get_new_should_have_cancel_link_to_referer
4281
    @request.session[:user_id] = 2
4282
    @request.env['HTTP_REFERER'] = 'http://test.host/projects/ecookbook/roadmap'
4283
    get(:new, :params => {:project_id => 1})
4284
    assert_response :success
4285
    assert_select 'a[href=?]', '/projects/ecookbook/roadmap', :text => 'Cancel'
4286
  end
4287

  
4288
  def test_get_new_should_not_have_cancel_link_to_itself
4289
    @request.session[:user_id] = 2
4290
    # e.g. after "Create and continue"
4291
    @request.env['HTTP_REFERER'] = 'http://test.host/projects/ecookbook/issues/new?issue%5Btracker_id%5D=1'
4292
    get(:new, :params => {:project_id => 'ecookbook'})
4293
    assert_response :success
4294
    assert_select 'a[href=?]', '/projects/ecookbook/issues', :text => 'Cancel'
4295
  end
4296

  
4297
  def test_post_create_with_failure_should_not_have_cancel_link_to_the_form
4298
    @request.session[:user_id] = 2
4299
    @request.env['HTTP_REFERER'] = 'http://test.host/projects/ecookbook/issues/new'
4300
    post(:create, :params => {:project_id => 1, :issue => {:tracker_id => 1, :subject => ''}})
4301
    assert_response :success
4302
    assert_select_error /Subject cannot be blank/
4303
    assert_select 'a[href=?]', '/projects/ecookbook/issues', :text => 'Cancel'
4304
  end
4305

  
4306
  def test_post_create_with_failure_should_keep_cancel_link_to_back_url
4307
    @request.session[:user_id] = 2
4308
    post(
4309
      :create,
4310
      :params => {
4311
        :project_id => 1, :back_url => '/issues/1',
4312
        :issue => {:tracker_id => 1, :subject => ''}
4313
      }
4314
    )
4315
    assert_response :success
4316
    assert_select 'a[href=?]', '/issues/1', :text => 'Cancel'
4317
  end
4318

  
4273 4319
  def test_get_new_should_show_create_and_follow_button_when_issue_is_subtask_and_back_url_is_present
4274 4320
    @request.session[:user_id] = 2
4275 4321
    get :new, params: {
test/functional/news_controller_test.rb
131 131
    assert_select 'input[name=?]', 'news[title]'
132 132
  end
133 133

  
134
  def test_get_new_should_have_cancel_link
135
    @request.session[:user_id] = 2
136
    get(:new, :params => {:project_id => 1})
137
    assert_response :success
138
    assert_select 'a[href=?]', '/projects/ecookbook/news', :text => 'Cancel'
139

  
140
    get(:new)
141
    assert_select 'a[href=?]', '/news', :text => 'Cancel'
142
  end
143

  
134 144
  def test_get_new_without_project_id
135 145
    @request.session[:user_id] = 2
136 146
    get(:new)
......
259 269
    assert_select_error /title cannot be blank/i
260 270
  end
261 271

  
272
  def test_post_create_with_validation_failure_should_keep_cancel_link_to_back_url
273
    @request.session[:user_id] = 2
274
    post(
275
      :create,
276
      :params => {
277
        :project_id => 1, :back_url => '/projects/ecookbook',
278
        :news => {:title => '', :description => 'This is the description'}
279
      }
280
    )
281
    assert_response :success
282
    assert_select 'input[type=hidden][name=back_url][value=?]', '/projects/ecookbook'
283
    assert_select 'a[href=?]', '/projects/ecookbook', :text => 'Cancel'
284
  end
285

  
286
  def test_get_edit_should_have_cancel_link
287
    @request.session[:user_id] = 2
288
    get(:edit, :params => {:id => 1})
289
    assert_response :success
290
    assert_select 'a[href=?]', '/news/1', :text => 'Cancel'
291
  end
292

  
262 293
  def test_get_edit
263 294
    @request.session[:user_id] = 2
264 295
    get(:edit, :params => {:id => 1})
test/functional/versions_controller_test.rb
250 250
    assert_select 'select[name=?]', 'version[status]', false
251 251
  end
252 252

  
253
  def test_new_should_have_cancel_link
254
    @request.session[:user_id] = 2
255
    get :new, :params => {:project_id => '1', :back_url => '/projects/ecookbook/roadmap'}
256
    assert_response :success
257
    assert_select 'a[href=?]', '/projects/ecookbook/roadmap', :text => 'Cancel'
258

  
259
    get :new, :params => {:project_id => '1'}
260
    assert_select 'a[href=?]', '/projects/ecookbook/settings/versions', :text => 'Cancel'
261
  end
262

  
253 263
  def test_new_from_issue_form
254 264
    @request.session[:user_id] = 2
255 265
    get :new, :params => {:project_id => '1'}, :xhr => true
......
291 301
    assert_equal 'text/javascript', response.media_type
292 302
  end
293 303

  
304
  def test_get_edit_should_have_cancel_link
305
    @request.session[:user_id] = 2
306
    get :edit, :params => {:id => 2}
307
    assert_response :success
308
    assert_select 'a[href=?]', '/projects/ecookbook/settings/versions', :text => 'Cancel'
309
  end
310

  
294 311
  def test_get_edit
295 312
    @request.session[:user_id] = 2
296 313
    get :edit, :params => {:id => 2}
test/functional/wiki_controller_test.rb
262 262
    assert_select 'input[name=?]', 'title'
263 263
  end
264 264

  
265
  def test_get_new_should_have_cancel_link
266
    @request.session[:user_id] = 2
267
    get :new, :params => {:project_id => 'ecookbook'}
268
    assert_response :success
269
    assert_select 'a[href=?]', '/projects/ecookbook/wiki/index', :text => 'Cancel'
270
  end
271

  
265 272
  def test_get_new_xhr
266 273
    @request.session[:user_id] = 2
267 274

  
(3-3/3)