@@ -36,7 +36,7 class WikiController < ApplicationController | |||||
36 | before_filter :find_wiki, :authorize |
|
36 | before_filter :find_wiki, :authorize | |
37 | before_filter :find_existing_page, :only => [:rename, :protect, :history, :diff, :annotate, :add_attachment, :destroy] |
|
37 | before_filter :find_existing_page, :only => [:rename, :protect, :history, :diff, :annotate, :add_attachment, :destroy] | |
38 |
|
38 | |||
39 |
verify :method => :post, :only => [ |
|
39 | verify :method => :post, :only => [:protect], :redirect_to => { :action => :show } | |
40 |
|
40 | |||
41 | helper :attachments |
|
41 | helper :attachments | |
42 | include AttachmentsHelper |
|
42 | include AttachmentsHelper | |
@@ -172,7 +172,8 class WikiController < ApplicationController | |||||
172 | @annotate = @page.annotate(params[:version]) |
|
172 | @annotate = @page.annotate(params[:version]) | |
173 | render_404 unless @annotate |
|
173 | render_404 unless @annotate | |
174 | end |
|
174 | end | |
175 |
|
175 | |||
|
176 | verify :method => :delete, :only => [:destroy], :redirect_to => { :action => :show } | |||
176 | # Removes a wiki page and its history |
|
177 | # Removes a wiki page and its history | |
177 | # Children can be either set as root pages, removed or reassigned to another parent page |
|
178 | # Children can be either set as root pages, removed or reassigned to another parent page | |
178 | def destroy |
|
179 | def destroy |
@@ -1,6 +1,6 | |||||
1 | <h2><%=h @page.pretty_title %></h2> |
|
1 | <h2><%=h @page.pretty_title %></h2> | |
2 |
|
2 | |||
3 | <% form_tag({}) do %> |
|
3 | <% form_tag({}, :method => :delete) do %> | |
4 | <div class="box"> |
|
4 | <div class="box"> | |
5 | <p><strong><%= l(:text_wiki_page_destroy_question, :descendants => @descendants_count) %></strong></p> |
|
5 | <p><strong><%= l(:text_wiki_page_destroy_question, :descendants => @descendants_count) %></strong></p> | |
6 | <p><label><%= radio_button_tag 'todo', 'nullify', true %> <%= l(:text_wiki_page_nullify_children) %></label><br /> |
|
6 | <p><label><%= radio_button_tag 'todo', 'nullify', true %> <%= l(:text_wiki_page_nullify_children) %></label><br /> |
@@ -5,7 +5,7 | |||||
5 | <%= link_to_if_authorized(l(:button_lock), {:action => 'protect', :page => @page.title, :protected => 1}, :method => :post, :class => 'icon icon-lock') if !@page.protected? %> |
|
5 | <%= link_to_if_authorized(l(:button_lock), {:action => 'protect', :page => @page.title, :protected => 1}, :method => :post, :class => 'icon icon-lock') if !@page.protected? %> | |
6 | <%= link_to_if_authorized(l(:button_unlock), {:action => 'protect', :page => @page.title, :protected => 0}, :method => :post, :class => 'icon icon-unlock') if @page.protected? %> |
|
6 | <%= link_to_if_authorized(l(:button_unlock), {:action => 'protect', :page => @page.title, :protected => 0}, :method => :post, :class => 'icon icon-unlock') if @page.protected? %> | |
7 | <%= link_to_if_authorized(l(:button_rename), {:action => 'rename', :page => @page.title}, :class => 'icon icon-move') if @content.version == @page.content.version %> |
|
7 | <%= link_to_if_authorized(l(:button_rename), {:action => 'rename', :page => @page.title}, :class => 'icon icon-move') if @content.version == @page.content.version %> | |
8 |
<%= link_to_if_authorized(l(:button_delete), {:action => 'destroy', :page => @page.title}, :method => : |
|
8 | <%= link_to_if_authorized(l(:button_delete), {:action => 'destroy', :page => @page.title}, :method => :delete, :confirm => l(:text_are_you_sure), :class => 'icon icon-del') %> | |
9 | <%= link_to_if_authorized(l(:button_rollback), {:action => 'edit', :page => @page.title, :version => @content.version }, :class => 'icon icon-cancel') if @content.version < @page.content.version %> |
|
9 | <%= link_to_if_authorized(l(:button_rollback), {:action => 'edit', :page => @page.title, :version => @content.version }, :class => 'icon icon-cancel') if @content.version < @page.content.version %> | |
10 | <% end %> |
|
10 | <% end %> | |
11 | <%= link_to_if_authorized(l(:label_history), {:action => 'history', :page => @page.title}, :class => 'icon icon-history') %> |
|
11 | <%= link_to_if_authorized(l(:label_history), {:action => 'history', :page => @page.title}, :class => 'icon icon-history') %> |
@@ -41,10 +41,12 ActionController::Routing::Routes.draw do |map| | |||||
41 | end |
|
41 | end | |
42 |
|
42 | |||
43 | wiki_routes.connect 'projects/:project_id/wiki/:page/:action', |
|
43 | wiki_routes.connect 'projects/:project_id/wiki/:page/:action', | |
44 |
:action => /rename| |
|
44 | :action => /rename|preview|protect|add_attachment/, | |
45 | :conditions => {:method => :post} |
|
45 | :conditions => {:method => :post} | |
46 |
|
46 | |||
47 | wiki_routes.connect 'projects/:project_id/wiki/:page/edit', :action => 'update', :conditions => {:method => :post} |
|
47 | wiki_routes.connect 'projects/:project_id/wiki/:page/edit', :action => 'update', :conditions => {:method => :post} | |
|
48 | ||||
|
49 | wiki_routes.connect 'projects/:project_id/wiki/:page', :action => 'destroy', :conditions => {:method => :delete} | |||
48 | end |
|
50 | end | |
49 |
|
51 | |||
50 | map.with_options :controller => 'messages' do |messages_routes| |
|
52 | map.with_options :controller => 'messages' do |messages_routes| |
@@ -196,14 +196,14 class WikiControllerTest < ActionController::TestCase | |||||
196 |
|
196 | |||
197 | def test_destroy_child |
|
197 | def test_destroy_child | |
198 | @request.session[:user_id] = 2 |
|
198 | @request.session[:user_id] = 2 | |
199 |
|
|
199 | delete :destroy, :project_id => 1, :page => 'Child_1' | |
200 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
200 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' | |
201 | end |
|
201 | end | |
202 |
|
202 | |||
203 | def test_destroy_parent |
|
203 | def test_destroy_parent | |
204 | @request.session[:user_id] = 2 |
|
204 | @request.session[:user_id] = 2 | |
205 | assert_no_difference('WikiPage.count') do |
|
205 | assert_no_difference('WikiPage.count') do | |
206 |
|
|
206 | delete :destroy, :project_id => 1, :page => 'Another_page' | |
207 | end |
|
207 | end | |
208 | assert_response :success |
|
208 | assert_response :success | |
209 | assert_template 'destroy' |
|
209 | assert_template 'destroy' | |
@@ -212,7 +212,7 class WikiControllerTest < ActionController::TestCase | |||||
212 | def test_destroy_parent_with_nullify |
|
212 | def test_destroy_parent_with_nullify | |
213 | @request.session[:user_id] = 2 |
|
213 | @request.session[:user_id] = 2 | |
214 | assert_difference('WikiPage.count', -1) do |
|
214 | assert_difference('WikiPage.count', -1) do | |
215 |
|
|
215 | delete :destroy, :project_id => 1, :page => 'Another_page', :todo => 'nullify' | |
216 | end |
|
216 | end | |
217 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
217 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' | |
218 | assert_nil WikiPage.find_by_id(2) |
|
218 | assert_nil WikiPage.find_by_id(2) | |
@@ -221,7 +221,7 class WikiControllerTest < ActionController::TestCase | |||||
221 | def test_destroy_parent_with_cascade |
|
221 | def test_destroy_parent_with_cascade | |
222 | @request.session[:user_id] = 2 |
|
222 | @request.session[:user_id] = 2 | |
223 | assert_difference('WikiPage.count', -3) do |
|
223 | assert_difference('WikiPage.count', -3) do | |
224 |
|
|
224 | delete :destroy, :project_id => 1, :page => 'Another_page', :todo => 'destroy' | |
225 | end |
|
225 | end | |
226 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
226 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' | |
227 | assert_nil WikiPage.find_by_id(2) |
|
227 | assert_nil WikiPage.find_by_id(2) | |
@@ -231,7 +231,7 class WikiControllerTest < ActionController::TestCase | |||||
231 | def test_destroy_parent_with_reassign |
|
231 | def test_destroy_parent_with_reassign | |
232 | @request.session[:user_id] = 2 |
|
232 | @request.session[:user_id] = 2 | |
233 | assert_difference('WikiPage.count', -1) do |
|
233 | assert_difference('WikiPage.count', -1) do | |
234 |
|
|
234 | delete :destroy, :project_id => 1, :page => 'Another_page', :todo => 'reassign', :reassign_to_id => 1 | |
235 | end |
|
235 | end | |
236 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
236 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' | |
237 | assert_nil WikiPage.find_by_id(2) |
|
237 | assert_nil WikiPage.find_by_id(2) |
@@ -325,9 +325,10 class RoutingTest < ActionController::IntegrationTest | |||||
325 | should_route :post, "/projects/567/wiki/my_page/edit", :controller => 'wiki', :action => 'update', :project_id => '567', :page => 'my_page' |
|
325 | should_route :post, "/projects/567/wiki/my_page/edit", :controller => 'wiki', :action => 'update', :project_id => '567', :page => 'my_page' | |
326 | should_route :post, "/projects/567/wiki/CookBook_documentation/preview", :controller => 'wiki', :action => 'preview', :project_id => '567', :page => 'CookBook_documentation' |
|
326 | should_route :post, "/projects/567/wiki/CookBook_documentation/preview", :controller => 'wiki', :action => 'preview', :project_id => '567', :page => 'CookBook_documentation' | |
327 | should_route :post, "/projects/22/wiki/ladida/rename", :controller => 'wiki', :action => 'rename', :project_id => '22', :page => 'ladida' |
|
327 | should_route :post, "/projects/22/wiki/ladida/rename", :controller => 'wiki', :action => 'rename', :project_id => '22', :page => 'ladida' | |
328 | should_route :post, "/projects/22/wiki/ladida/destroy", :controller => 'wiki', :action => 'destroy', :project_id => '22', :page => 'ladida' |
|
|||
329 | should_route :post, "/projects/22/wiki/ladida/protect", :controller => 'wiki', :action => 'protect', :project_id => '22', :page => 'ladida' |
|
328 | should_route :post, "/projects/22/wiki/ladida/protect", :controller => 'wiki', :action => 'protect', :project_id => '22', :page => 'ladida' | |
330 | should_route :post, "/projects/22/wiki/ladida/add_attachment", :controller => 'wiki', :action => 'add_attachment', :project_id => '22', :page => 'ladida' |
|
329 | should_route :post, "/projects/22/wiki/ladida/add_attachment", :controller => 'wiki', :action => 'add_attachment', :project_id => '22', :page => 'ladida' | |
|
330 | ||||
|
331 | should_route :delete, "/projects/22/wiki/ladida", :controller => 'wiki', :action => 'destroy', :project_id => '22', :page => 'ladida' | |||
331 | end |
|
332 | end | |
332 |
|
333 | |||
333 | context "wikis (plural, admin setup)" do |
|
334 | context "wikis (plural, admin setup)" do |
General Comments 0
You need to be logged in to leave comments.
Login now