##// END OF EJS Templates
Refactor: rename WikiController#index to #show, it's a single resource action...
Eric Davis -
r4152:c259ada6e1c4
parent child
Show More
@@ -22,14 +22,14 class WikiController < ApplicationController
22 22 before_filter :find_wiki, :authorize
23 23 before_filter :find_existing_page, :only => [:rename, :protect, :history, :diff, :annotate, :add_attachment, :destroy]
24 24
25 verify :method => :post, :only => [:destroy, :protect], :redirect_to => { :action => :index }
25 verify :method => :post, :only => [:destroy, :protect], :redirect_to => { :action => :show }
26 26
27 27 helper :attachments
28 28 include AttachmentsHelper
29 29 helper :watchers
30 30
31 31 # display a page (in editing mode if it doesn't exist)
32 def index
32 def show
33 33 page_title = params[:page]
34 34 @page = @wiki.find_or_new_page(page_title)
35 35 if @page.new_record?
@@ -79,7 +79,7 class WikiController < ApplicationController
79 79 attachments = Attachment.attach_files(@page, params[:attachments])
80 80 render_attachment_warning_if_needed(@page)
81 81 # don't save if text wasn't changed
82 redirect_to :action => 'index', :project_id => @project, :page => @page.title
82 redirect_to :action => 'show', :project_id => @project, :page => @page.title
83 83 return
84 84 end
85 85 #@content.text = params[:content][:text]
@@ -91,7 +91,7 class WikiController < ApplicationController
91 91 attachments = Attachment.attach_files(@page, params[:attachments])
92 92 render_attachment_warning_if_needed(@page)
93 93 call_hook(:controller_wiki_edit_after_save, { :params => params, :page => @page})
94 redirect_to :action => 'index', :project_id => @project, :page => @page.title
94 redirect_to :action => 'show', :project_id => @project, :page => @page.title
95 95 end
96 96 end
97 97 rescue ActiveRecord::StaleObjectError
@@ -107,13 +107,13 class WikiController < ApplicationController
107 107 @original_title = @page.pretty_title
108 108 if request.post? && @page.update_attributes(params[:wiki_page])
109 109 flash[:notice] = l(:notice_successful_update)
110 redirect_to :action => 'index', :project_id => @project, :page => @page.title
110 redirect_to :action => 'show', :project_id => @project, :page => @page.title
111 111 end
112 112 end
113 113
114 114 def protect
115 115 @page.update_attribute :protected, params[:protected]
116 redirect_to :action => 'index', :project_id => @project, :page => @page.title
116 redirect_to :action => 'show', :project_id => @project, :page => @page.title
117 117 end
118 118
119 119 # show page history
@@ -176,7 +176,7 class WikiController < ApplicationController
176 176 export = render_to_string :action => 'export_multiple', :layout => false
177 177 send_data(export, :type => 'text/html', :filename => "wiki.html")
178 178 else
179 redirect_to :action => 'index', :project_id => @project, :page => nil
179 redirect_to :action => 'show', :project_id => @project, :page => nil
180 180 end
181 181 end
182 182
@@ -204,7 +204,7 class WikiController < ApplicationController
204 204 return render_403 unless editable?
205 205 attachments = Attachment.attach_files(@page, params[:attachments])
206 206 render_attachment_warning_if_needed(@page)
207 redirect_to :action => 'index', :page => @page.title
207 redirect_to :action => 'show', :page => @page.title
208 208 end
209 209
210 210 private
@@ -182,7 +182,7 module ApplicationHelper
182 182 content << "<ul class=\"pages-hierarchy\">\n"
183 183 pages[node].each do |page|
184 184 content << "<li>"
185 content << link_to(h(page.pretty_title), {:controller => 'wiki', :action => 'index', :project_id => page.project, :page => page.title},
185 content << link_to(h(page.pretty_title), {:controller => 'wiki', :action => 'show', :project_id => page.project, :page => page.title},
186 186 :title => (page.respond_to?(:updated_on) ? l(:label_updated_time, distance_of_time_in_words(Time.now, page.updated_on)) : nil))
187 187 content << "\n" + render_page_hierarchy(pages, page.id) if pages[page.id]
188 188 content << "</li>\n"
@@ -551,7 +551,7 module ApplicationHelper
551 551 when :local; "#{title}.html"
552 552 when :anchor; "##{title}" # used for single-file wiki export
553 553 else
554 url_for(:only_path => only_path, :controller => 'wiki', :action => 'index', :project_id => link_project, :page => Wiki.titleize(page), :anchor => anchor)
554 url_for(:only_path => only_path, :controller => 'wiki', :action => 'show', :project_id => link_project, :page => Wiki.titleize(page), :anchor => anchor)
555 555 end
556 556 link_to((title || page), url, :class => ('wiki-page' + (wiki_page ? '' : ' new')))
557 557 else
@@ -4,6 +4,6
4 4
5 5 <h3><%= l(:label_wiki) %></h3>
6 6
7 <%= link_to l(:field_start_page), {:action => 'index', :page => nil} %><br />
7 <%= link_to l(:field_start_page), {:action => 'show', :page => nil} %><br />
8 8 <%= link_to l(:label_index_by_title), {:action => 'page_index'} %><br />
9 9 <%= link_to l(:label_index_by_date), {:action => 'date_index'} %><br />
@@ -6,7 +6,7
6 6 <h2><%= @page.pretty_title %></h2>
7 7
8 8 <p>
9 <%= l(:label_version) %> <%= link_to @annotate.content.version, :action => 'index', :page => @page.title, :version => @annotate.content.version %>
9 <%= l(:label_version) %> <%= link_to @annotate.content.version, :action => 'show', :page => @page.title, :version => @annotate.content.version %>
10 10 <em>(<%= @annotate.content.author ? @annotate.content.author.name : "anonyme" %>, <%= format_time(@annotate.content.updated_on) %>)</em>
11 11 </p>
12 12
@@ -18,7 +18,7
18 18 <% @annotate.lines.each do |line| -%>
19 19 <tr class="bloc-<%= colors[line[0]] %>">
20 20 <th class="line-num"><%= line_num %></th>
21 <td class="revision"><%= link_to line[0], :controller => 'wiki', :action => 'index', :project_id => @project, :page => @page.title, :version => line[0] %></td>
21 <td class="revision"><%= link_to line[0], :controller => 'wiki', :action => 'show', :project_id => @project, :page => @page.title, :version => line[0] %></td>
22 22 <td class="author"><%= h(line[1]) %></td>
23 23 <td class="line-code"><pre><%=h line[2] %></pre></td>
24 24 </tr>
@@ -12,7 +12,7
12 12 <h3><%= format_date(date) %></h3>
13 13 <ul>
14 14 <% @pages_by_date[date].each do |page| %>
15 <li><%= link_to page.pretty_title, :action => 'index', :page => page.title %></li>
15 <li><%= link_to page.pretty_title, :action => 'show', :page => page.title %></li>
16 16 <% end %>
17 17 </ul>
18 18 <% end %>
@@ -23,11 +23,11
23 23
24 24 <% unless @pages.empty? %>
25 25 <% other_formats_links do |f| %>
26 <%= f.link_to 'Atom', :url => {:controller => 'activities', :action => 'index', :id => @project, :show_wiki_edits => 1, :key => User.current.rss_key} %>
26 <%= f.link_to 'Atom', :url => {:controller => 'activities', :action => 'show', :id => @project, :show_wiki_edits => 1, :key => User.current.rss_key} %>
27 27 <%= f.link_to('HTML', :url => {:action => 'export'}) if User.current.allowed_to?(:export_wiki_pages, @project) %>
28 28 <% end %>
29 29 <% end %>
30 30
31 31 <% content_for :header_tags do %>
32 <%= auto_discovery_link_tag(:atom, :controller => 'activities', :action => 'index', :id => @project, :show_wiki_edits => 1, :format => 'atom', :key => User.current.rss_key) %>
32 <%= auto_discovery_link_tag(:atom, :controller => 'activities', :action => 'show', :id => @project, :show_wiki_edits => 1, :format => 'atom', :key => User.current.rss_key) %>
33 33 <% end %>
@@ -15,5 +15,5
15 15 </div>
16 16
17 17 <%= submit_tag l(:button_apply) %>
18 <%= link_to l(:button_cancel), :controller => 'wiki', :action => 'index', :project_id => @project, :page => @page.title %>
18 <%= link_to l(:button_cancel), :controller => 'wiki', :action => 'show', :project_id => @project, :page => @page.title %>
19 19 <% end %>
@@ -5,10 +5,10
5 5 <h2><%= @page.pretty_title %></h2>
6 6
7 7 <p>
8 <%= l(:label_version) %> <%= link_to @diff.content_from.version, :action => 'index', :page => @page.title, :version => @diff.content_from.version %>
8 <%= l(:label_version) %> <%= link_to @diff.content_from.version, :action => 'show', :page => @page.title, :version => @diff.content_from.version %>
9 9 <em>(<%= @diff.content_from.author ? @diff.content_from.author.name : "anonyme" %>, <%= format_time(@diff.content_from.updated_on) %>)</em>
10 10 &#8594;
11 <%= l(:label_version) %> <%= link_to @diff.content_to.version, :action => 'index', :page => @page.title, :version => @diff.content_to.version %>/<%= @page.content.version %>
11 <%= l(:label_version) %> <%= link_to @diff.content_to.version, :action => 'show', :page => @page.title, :version => @diff.content_to.version %>/<%= @page.content.version %>
12 12 <em>(<%= @diff.content_to.author ? @diff.content_to.author.name : "anonyme" %>, <%= format_time(@diff.content_to.updated_on) %>)</em>
13 13 </p>
14 14
@@ -19,7 +19,7
19 19 <% line_num = 1 %>
20 20 <% @versions.each do |ver| %>
21 21 <tr class="<%= cycle("odd", "even") %>">
22 <td class="id"><%= link_to ver.version, :action => 'index', :page => @page.title, :version => ver.version %></td>
22 <td class="id"><%= link_to ver.version, :action => 'show', :page => @page.title, :version => ver.version %></td>
23 23 <td class="checkbox"><%= radio_button_tag('version', ver.version, (line_num==1), :id => "cb-#{line_num}", :onclick => "$('cbto-#{line_num+1}').checked=true;") if show_diff && (line_num < @versions.size) %></td>
24 24 <td class="checkbox"><%= radio_button_tag('version_from', ver.version, (line_num==2), :id => "cbto-#{line_num}") if show_diff && (line_num > 1) %></td>
25 25 <td align="center"><%= format_time(ver.updated_on) %></td>
@@ -16,11 +16,11
16 16
17 17 <% unless @pages.empty? %>
18 18 <% other_formats_links do |f| %>
19 <%= f.link_to 'Atom', :url => {:controller => 'activities', :action => 'index', :id => @project, :show_wiki_edits => 1, :key => User.current.rss_key} %>
19 <%= f.link_to 'Atom', :url => {:controller => 'activities', :action => 'show', :id => @project, :show_wiki_edits => 1, :key => User.current.rss_key} %>
20 20 <%= f.link_to('HTML', :url => {:action => 'export'}) if User.current.allowed_to?(:export_wiki_pages, @project) %>
21 21 <% end %>
22 22 <% end %>
23 23
24 24 <% content_for :header_tags do %>
25 <%= auto_discovery_link_tag(:atom, :controller => 'activities', :action => 'index', :id => @project, :show_wiki_edits => 1, :format => 'atom', :key => User.current.rss_key) %>
25 <%= auto_discovery_link_tag(:atom, :controller => 'activities', :action => 'show', :id => @project, :show_wiki_edits => 1, :format => 'atom', :key => User.current.rss_key) %>
26 26 <% end %>
@@ -15,11 +15,11
15 15
16 16 <% if @content.version != @page.content.version %>
17 17 <p>
18 <%= link_to(('&#171; ' + l(:label_previous)), :action => 'index', :page => @page.title, :version => (@content.version - 1)) + " - " if @content.version > 1 %>
18 <%= link_to(('&#171; ' + l(:label_previous)), :action => 'show', :page => @page.title, :version => (@content.version - 1)) + " - " if @content.version > 1 %>
19 19 <%= "#{l(:label_version)} #{@content.version}/#{@page.content.version}" %>
20 20 <%= '(' + link_to('diff', :controller => 'wiki', :action => 'diff', :page => @page.title, :version => @content.version) + ')' if @content.version > 1 %> -
21 <%= link_to((l(:label_next) + ' &#187;'), :action => 'index', :page => @page.title, :version => (@content.version + 1)) + " - " if @content.version < @page.content.version %>
22 <%= link_to(l(:label_current_version), :action => 'index', :page => @page.title) %>
21 <%= link_to((l(:label_next) + ' &#187;'), :action => 'show', :page => @page.title, :version => (@content.version + 1)) + " - " if @content.version < @page.content.version %>
22 <%= link_to(l(:label_current_version), :action => 'show', :page => @page.title) %>
23 23 <br />
24 24 <em><%= @content.author ? @content.author.name : "anonyme" %>, <%= format_time(@content.updated_on) %> </em><br />
25 25 <%=h @content.comments %>
@@ -32,7 +32,7 ActionController::Routing::Routes.draw do |map|
32 32 wiki_views.connect 'projects/:project_id/wiki/export', :action => 'export'
33 33 wiki_views.connect 'projects/:project_id/wiki/page_index', :action => 'page_index'
34 34 wiki_views.connect 'projects/:project_id/wiki/date_index', :action => 'date_index'
35 wiki_views.connect 'projects/:project_id/wiki/:page', :action => 'index', :page => nil
35 wiki_views.connect 'projects/:project_id/wiki/:page', :action => 'show', :page => nil
36 36 wiki_views.connect 'projects/:project_id/wiki/:page/edit', :action => 'edit'
37 37 wiki_views.connect 'projects/:project_id/wiki/:page/rename', :action => 'rename'
38 38 wiki_views.connect 'projects/:project_id/wiki/:page/history', :action => 'history'
@@ -111,7 +111,7 Redmine::AccessControl.map do |map|
111 111 map.permission :manage_wiki, {:wikis => [:edit, :destroy]}, :require => :member
112 112 map.permission :rename_wiki_pages, {:wiki => :rename}, :require => :member
113 113 map.permission :delete_wiki_pages, {:wiki => :destroy}, :require => :member
114 map.permission :view_wiki_pages, :wiki => [:index, :special, :page_index, :date_index]
114 map.permission :view_wiki_pages, :wiki => [:show, :special, :page_index, :date_index]
115 115 map.permission :export_wiki_pages, :wiki => [:export]
116 116 map.permission :view_wiki_edits, :wiki => [:history, :diff, :annotate]
117 117 map.permission :edit_wiki_pages, :wiki => [:edit, :preview, :add_attachment]
@@ -195,7 +195,7 Redmine::MenuManager.map :project_menu do |menu|
195 195 menu.push :calendar, { :controller => 'calendars', :action => 'show' }, :param => :project_id, :caption => :label_calendar
196 196 menu.push :news, { :controller => 'news', :action => 'index' }, :param => :project_id, :caption => :label_news_plural
197 197 menu.push :documents, { :controller => 'documents', :action => 'index' }, :param => :project_id, :caption => :label_document_plural
198 menu.push :wiki, { :controller => 'wiki', :action => 'index', :page => nil }, :param => :project_id,
198 menu.push :wiki, { :controller => 'wiki', :action => 'show', :page => nil }, :param => :project_id,
199 199 :if => Proc.new { |p| p.wiki && !p.wiki.new_record? }
200 200 menu.push :boards, { :controller => 'boards', :action => 'index', :id => nil }, :param => :project_id,
201 201 :if => Proc.new { |p| p.boards.any? }, :caption => :label_board_plural
@@ -32,7 +32,7 class WikiControllerTest < ActionController::TestCase
32 32 end
33 33
34 34 def test_show_start_page
35 get :index, :project_id => 'ecookbook'
35 get :show, :project_id => 'ecookbook'
36 36 assert_response :success
37 37 assert_template 'show'
38 38 assert_tag :tag => 'h1', :content => /CookBook documentation/
@@ -45,7 +45,7 class WikiControllerTest < ActionController::TestCase
45 45 end
46 46
47 47 def test_show_page_with_name
48 get :index, :project_id => 1, :page => 'Another_page'
48 get :show, :project_id => 1, :page => 'Another_page'
49 49 assert_response :success
50 50 assert_template 'show'
51 51 assert_tag :tag => 'h1', :content => /Another page/
@@ -60,20 +60,20 class WikiControllerTest < ActionController::TestCase
60 60 page.content = WikiContent.new(:text => 'Side bar content for test_show_with_sidebar')
61 61 page.save!
62 62
63 get :index, :project_id => 1, :page => 'Another_page'
63 get :show, :project_id => 1, :page => 'Another_page'
64 64 assert_response :success
65 65 assert_tag :tag => 'div', :attributes => {:id => 'sidebar'},
66 66 :content => /Side bar content for test_show_with_sidebar/
67 67 end
68 68
69 69 def test_show_unexistent_page_without_edit_right
70 get :index, :project_id => 1, :page => 'Unexistent page'
70 get :show, :project_id => 1, :page => 'Unexistent page'
71 71 assert_response 404
72 72 end
73 73
74 74 def test_show_unexistent_page_with_edit_right
75 75 @request.session[:user_id] = 2
76 get :index, :project_id => 1, :page => 'Unexistent page'
76 get :show, :project_id => 1, :page => 'Unexistent page'
77 77 assert_response :success
78 78 assert_template 'edit'
79 79 end
@@ -85,7 +85,7 class WikiControllerTest < ActionController::TestCase
85 85 :content => {:comments => 'Created the page',
86 86 :text => "h1. New page\n\nThis is a new page",
87 87 :version => 0}
88 assert_redirected_to :action => 'index', :project_id => 'ecookbook', :page => 'New_page'
88 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :page => 'New_page'
89 89 page = Project.find(1).wiki.find_page('New page')
90 90 assert !page.new_record?
91 91 assert_not_nil page.content
@@ -176,7 +176,7 class WikiControllerTest < ActionController::TestCase
176 176 post :rename, :project_id => 1, :page => 'Another_page',
177 177 :wiki_page => { :title => 'Another renamed page',
178 178 :redirect_existing_links => 1 }
179 assert_redirected_to :action => 'index', :project_id => 'ecookbook', :page => 'Another_renamed_page'
179 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :page => 'Another_renamed_page'
180 180 wiki = Project.find(1).wiki
181 181 # Check redirects
182 182 assert_not_nil wiki.find_page('Another page')
@@ -188,7 +188,7 class WikiControllerTest < ActionController::TestCase
188 188 post :rename, :project_id => 1, :page => 'Another_page',
189 189 :wiki_page => { :title => 'Another renamed page',
190 190 :redirect_existing_links => "0" }
191 assert_redirected_to :action => 'index', :project_id => 'ecookbook', :page => 'Another_renamed_page'
191 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :page => 'Another_renamed_page'
192 192 wiki = Project.find(1).wiki
193 193 # Check that there's no redirects
194 194 assert_nil wiki.find_page('Another page')
@@ -280,7 +280,7 class WikiControllerTest < ActionController::TestCase
280 280 get :export, :project_id => 'ecookbook'
281 281
282 282 should_respond_with :redirect
283 should_redirect_to('wiki index') { {:action => 'index', :project_id => @project, :page => nil} }
283 should_redirect_to('wiki index') { {:action => 'show', :project_id => @project, :page => nil} }
284 284 end
285 285 end
286 286 end
@@ -298,7 +298,7 class WikiControllerTest < ActionController::TestCase
298 298 end
299 299
300 300 def test_not_found
301 get :index, :project_id => 999
301 get :show, :project_id => 999
302 302 assert_response 404
303 303 end
304 304
@@ -307,7 +307,7 class WikiControllerTest < ActionController::TestCase
307 307 assert !page.protected?
308 308 @request.session[:user_id] = 2
309 309 post :protect, :project_id => 1, :page => page.title, :protected => '1'
310 assert_redirected_to :action => 'index', :project_id => 'ecookbook', :page => 'Another_page'
310 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :page => 'Another_page'
311 311 assert page.reload.protected?
312 312 end
313 313
@@ -316,13 +316,13 class WikiControllerTest < ActionController::TestCase
316 316 assert page.protected?
317 317 @request.session[:user_id] = 2
318 318 post :protect, :project_id => 1, :page => page.title, :protected => '0'
319 assert_redirected_to :action => 'index', :project_id => 'ecookbook', :page => 'CookBook_documentation'
319 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :page => 'CookBook_documentation'
320 320 assert !page.reload.protected?
321 321 end
322 322
323 323 def test_show_page_with_edit_link
324 324 @request.session[:user_id] = 2
325 get :index, :project_id => 1
325 get :show, :project_id => 1
326 326 assert_response :success
327 327 assert_template 'show'
328 328 assert_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' }
@@ -330,7 +330,7 class WikiControllerTest < ActionController::TestCase
330 330
331 331 def test_show_page_without_edit_link
332 332 @request.session[:user_id] = 4
333 get :index, :project_id => 1
333 get :show, :project_id => 1
334 334 assert_response :success
335 335 assert_template 'show'
336 336 assert_no_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' }
@@ -311,8 +311,8 class RoutingTest < ActionController::IntegrationTest
311 311 end
312 312
313 313 context "wiki (singular, project's pages)" do
314 should_route :get, "/projects/567/wiki", :controller => 'wiki', :action => 'index', :project_id => '567'
315 should_route :get, "/projects/567/wiki/lalala", :controller => 'wiki', :action => 'index', :project_id => '567', :page => 'lalala'
314 should_route :get, "/projects/567/wiki", :controller => 'wiki', :action => 'show', :project_id => '567'
315 should_route :get, "/projects/567/wiki/lalala", :controller => 'wiki', :action => 'show', :project_id => '567', :page => 'lalala'
316 316 should_route :get, "/projects/567/wiki/my_page/edit", :controller => 'wiki', :action => 'edit', :project_id => '567', :page => 'my_page'
317 317 should_route :get, "/projects/1/wiki/CookBook_documentation/history", :controller => 'wiki', :action => 'history', :project_id => '1', :page => 'CookBook_documentation'
318 318 should_route :get, "/projects/1/wiki/CookBook_documentation/diff/2/vs/1", :controller => 'wiki', :action => 'diff', :project_id => '1', :page => 'CookBook_documentation', :version => '2', :version_from => '1'
General Comments 0
You need to be logged in to leave comments. Login now