:order => 'title'
@pages_by_date = @pages.group_by {|p| p.updated_on.to_date}
@pages_by_parent_id = @pages.group_by(&:parent_id)
- # export wiki to a single html file
when 'export'
- if User.current.allowed_to?(:export_wiki_pages, @project)
- @pages = @wiki.pages.find :all, :order => 'title'
- export = render_to_string :action => 'export_multiple', :layout => false
- send_data(export, :type => 'text/html', :filename => "wiki.html")
- else
- redirect_to :action => 'index', :id => @project, :page => nil
- end
- return
+ redirect_to :action => 'export', :id => @project # Compatibility stub while refactoring
+ return
else
# requested special page doesn't exist, redirect to default page
redirect_to :action => 'index', :id => @project, :page => nil
end
render :action => "special_#{page_title}"
end
+
+ # Export wiki to a single html file
+ def export
+ if User.current.allowed_to?(:export_wiki_pages, @project)
+ @pages = @wiki.pages.find :all, :order => 'title'
+ export = render_to_string :action => 'export_multiple', :layout => false
+ send_data(export, :type => 'text/html', :filename => "wiki.html")
+ else
+ redirect_to :action => 'index', :id => @project, :page => nil
+ end
+ end
def preview
page = @wiki.find_page(params[:page])
<% unless @pages.empty? %>
<% other_formats_links do |f| %>
<%= f.link_to 'Atom', :url => {:controller => 'activities', :action => 'index', :id => @project, :show_wiki_edits => 1, :key => User.current.rss_key} %>
- <%= f.link_to('HTML', :url => {:action => 'special', :page => 'export'}) if User.current.allowed_to?(:export_wiki_pages, @project) %>
+ <%= f.link_to('HTML', :url => {:action => 'export'}) if User.current.allowed_to?(:export_wiki_pages, @project) %>
<% end %>
<% end %>
<% unless @pages.empty? %>
<% other_formats_links do |f| %>
<%= f.link_to 'Atom', :url => {:controller => 'activities', :action => 'index', :id => @project, :show_wiki_edits => 1, :key => User.current.rss_key} %>
- <%= f.link_to('HTML', :url => {:action => 'special', :page => 'export'}) if User.current.allowed_to?(:export_wiki_pages, @project) %>
+ <%= f.link_to('HTML', :url => {:action => 'export'}) if User.current.allowed_to?(:export_wiki_pages, @project) %>
<% end %>
<% end %>
map.connect 'projects/:id/wiki/destroy', :controller => 'wikis', :action => 'destroy', :conditions => {:method => :post}
map.with_options :controller => 'wiki' do |wiki_routes|
wiki_routes.with_options :conditions => {:method => :get} do |wiki_views|
- wiki_views.connect 'projects/:id/wiki/:page', :action => 'special', :page => /page_index|date_index|export/i
+ wiki_views.connect 'projects/:id/wiki/export', :action => 'export'
+ wiki_views.connect 'projects/:id/wiki/:page', :action => 'special', :page => /page_index|date_index/i
wiki_views.connect 'projects/:id/wiki/:page', :action => 'index', :page => nil
wiki_views.connect 'projects/:id/wiki/:page/edit', :action => 'edit'
wiki_views.connect 'projects/:id/wiki/:page/rename', :action => 'rename'
map.permission :rename_wiki_pages, {:wiki => :rename}, :require => :member
map.permission :delete_wiki_pages, {:wiki => :destroy}, :require => :member
map.permission :view_wiki_pages, :wiki => [:index, :special]
- map.permission :export_wiki_pages, {}
+ map.permission :export_wiki_pages, :wiki => [:export]
map.permission :view_wiki_edits, :wiki => [:history, :diff, :annotate]
map.permission :edit_wiki_pages, :wiki => [:edit, :preview, :add_attachment]
map.permission :delete_wiki_pages_attachments, {}
:child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Another_page' },
:content => 'Another page' } }
end
+
+ context "GET :export" do
+ context "with an authorized user to export the wiki" do
+ setup do
+ @request.session[:user_id] = 2
+ get :export, :id => 'ecookbook'
+ end
+
+ should_respond_with :success
+ should_assign_to :pages
+ should_respond_with_content_type "text/html"
+ should "export all of the wiki pages to a single html file" do
+ assert_select "a[name=?]", "CookBook_documentation"
+ assert_select "a[name=?]", "Another_page"
+ assert_select "a[name=?]", "Page_with_an_inline_image"
+ end
+
+ end
+
+ context "with an unauthorized user" do
+ setup do
+ get :export, :id => 'ecookbook'
+
+ should_respond_with :redirect
+ should_redirect_to('wiki index') { {:action => 'index', :id => @project, :page => nil} }
+ end
+ end
+ end
def test_not_found
get :index, :id => 999
should_route :get, "/projects/567/wiki/page_index", :controller => 'wiki', :action => 'special', :id => '567', :page => 'page_index'
should_route :get, "/projects/567/wiki/Page_Index", :controller => 'wiki', :action => 'special', :id => '567', :page => 'Page_Index'
should_route :get, "/projects/567/wiki/date_index", :controller => 'wiki', :action => 'special', :id => '567', :page => 'date_index'
- should_route :get, "/projects/567/wiki/export", :controller => 'wiki', :action => 'special', :id => '567', :page => 'export'
+ should_route :get, "/projects/567/wiki/export", :controller => 'wiki', :action => 'export', :id => '567'
should_route :post, "/projects/567/wiki/my_page/edit", :controller => 'wiki', :action => 'edit', :id => '567', :page => 'my_page'
should_route :post, "/projects/567/wiki/CookBook_documentation/preview", :controller => 'wiki', :action => 'preview', :id => '567', :page => 'CookBook_documentation'