Patch #31334 » 0001-do-not-lose-submitted-content-when-attempting-to-upd.patch
app/controllers/wiki_controller.rb | ||
---|---|---|
34 | 34 |
class WikiController < ApplicationController |
35 | 35 |
default_search_scope :wiki_pages |
36 | 36 |
before_action :find_wiki, :authorize |
37 |
before_action :find_existing_or_new_page, :only => [:show, :edit, :update]
|
|
37 |
before_action :find_existing_or_new_page, :only => [:show, :edit] |
|
38 | 38 |
before_action :find_existing_page, :only => [:rename, :protect, :history, :diff, :annotate, :add_attachment, :destroy, :destroy_version] |
39 | 39 |
before_action :find_attachments, :only => [:preview] |
40 | 40 |
accept_api_auth :index, :show, :update, :destroy |
... | ... | |
152 | 152 | |
153 | 153 |
# Creates a new page or updates an existing one |
154 | 154 |
def update |
155 |
@page = @wiki.find_or_new_page(params[:id]) |
|
156 | ||
155 | 157 |
return render_403 unless editable? |
156 | 158 |
was_new_page = @page.new_record? |
157 | 159 |
@page.safe_attributes = params[:wiki_page] |
test/integration/wiki_test.rb | ||
---|---|---|
1 |
require File.expand_path('../../test_helper', __FILE__) |
|
2 | ||
3 |
class WikiTest < Redmine::IntegrationTest |
|
4 |
fixtures :projects, |
|
5 |
:users, :email_addresses, |
|
6 |
:roles, |
|
7 |
:members, |
|
8 |
:member_roles, |
|
9 |
:trackers, |
|
10 |
:projects_trackers, |
|
11 |
:enabled_modules, |
|
12 |
:wikis, |
|
13 |
:wiki_pages, |
|
14 |
:wiki_contents |
|
15 | ||
16 |
def test_updating_a_renamed_page |
|
17 |
log_user('jsmith', 'jsmith') |
|
18 | ||
19 |
get '/projects/ecookbook/wiki' |
|
20 |
assert_response :success |
|
21 | ||
22 |
get '/projects/ecookbook/wiki/Wiki/edit' |
|
23 |
assert_response :success |
|
24 | ||
25 |
# this update should not end up with a loss of content |
|
26 |
put '/projects/ecookbook/wiki/Wiki', params: { |
|
27 |
content: { |
|
28 |
text: "# Wiki\r\n\r\ncontent", comments:"" |
|
29 |
}, |
|
30 |
wiki_page: { parent_id: "" } |
|
31 |
} |
|
32 |
assert_redirected_to "/projects/ecookbook/wiki/Wiki" |
|
33 |
follow_redirect! |
|
34 |
assert_select 'div', /content/ |
|
35 |
assert content = WikiContent.last |
|
36 | ||
37 |
# Let's assume somebody else, or the same user in another tab, renames the |
|
38 |
# page while it is being edited. |
|
39 |
post '/projects/ecookbook/wiki/Wiki/rename', params: { wiki_page: { title: "NewTitle" } } |
|
40 |
assert_redirected_to "/projects/ecookbook/wiki/NewTitle" |
|
41 | ||
42 |
# this update should not end up with a loss of content |
|
43 |
put '/projects/ecookbook/wiki/Wiki', params: { |
|
44 |
content: { |
|
45 |
version: content.version, text: "# Wiki\r\n\r\nnew content", comments:"" |
|
46 |
}, |
|
47 |
wiki_page: { parent_id: "" } |
|
48 |
} |
|
49 | ||
50 |
assert_redirected_to "/projects/ecookbook/wiki/NewTitle" |
|
51 |
follow_redirect! |
|
52 |
assert_select 'div', /new content/ |
|
53 |
end |
|
54 | ||
55 |
end |
|
56 |