##// END OF EJS Templates
Refactor: convert WikiController to a REST resource...
Eric Davis -
r4189:c514dd6885af
parent child
Show More
@@ -98,7 +98,7 class WikiController < ApplicationController
98 flash[:error] = l(:notice_locking_conflict)
98 flash[:error] = l(:notice_locking_conflict)
99 end
99 end
100
100
101 verify :method => :post, :only => :update, :render => {:nothing => true, :status => :method_not_allowed }
101 verify :method => :put, :only => :update, :render => {:nothing => true, :status => :method_not_allowed }
102 # Creates a new page or updates an existing one
102 # Creates a new page or updates an existing one
103 def update
103 def update
104 @page = @wiki.find_or_new_page(params[:id])
104 @page = @wiki.find_or_new_page(params[:id])
@@ -234,7 +234,7 class WikiController < ApplicationController
234 return render_403 unless editable?
234 return render_403 unless editable?
235 attachments = Attachment.attach_files(@page, params[:attachments])
235 attachments = Attachment.attach_files(@page, params[:attachments])
236 render_attachment_warning_if_needed(@page)
236 render_attachment_warning_if_needed(@page)
237 redirect_to :action => 'show', :id => @page.title
237 redirect_to :action => 'show', :id => @page.title, :project_id => @project
238 end
238 end
239
239
240 private
240 private
@@ -541,7 +541,8 module ApplicationHelper
541 when :local; "#{title}.html"
541 when :local; "#{title}.html"
542 when :anchor; "##{title}" # used for single-file wiki export
542 when :anchor; "##{title}" # used for single-file wiki export
543 else
543 else
544 url_for(:only_path => only_path, :controller => 'wiki', :action => 'show', :project_id => link_project, :id => Wiki.titleize(page), :anchor => anchor)
544 wiki_page_id = page.present? ? Wiki.titleize(page) : nil
545 url_for(:only_path => only_path, :controller => 'wiki', :action => 'show', :project_id => link_project, :id => wiki_page_id, :anchor => anchor)
545 end
546 end
546 link_to((title || page), url, :class => ('wiki-page' + (wiki_page ? '' : ' new')))
547 link_to((title || page), url, :class => ('wiki-page' + (wiki_page ? '' : ' new')))
547 else
548 else
@@ -17,7 +17,7
17 <td class="description"><%=h version.description %></td>
17 <td class="description"><%=h version.description %></td>
18 <td class="status"><%= l("version_status_#{version.status}") %></td>
18 <td class="status"><%= l("version_status_#{version.status}") %></td>
19 <td class="sharing"><%=h format_version_sharing(version.sharing) %></td>
19 <td class="sharing"><%=h format_version_sharing(version.sharing) %></td>
20 <td><%= link_to(h(version.wiki_page_title), :controller => 'wiki', :id => Wiki.titleize(version.wiki_page_title)) unless version.wiki_page_title.blank? || @project.wiki.nil? %></td>
20 <td><%= link_to(h(version.wiki_page_title), :controller => 'wiki', :action => 'show', :id => Wiki.titleize(version.wiki_page_title), :project_id => @project) unless version.wiki_page_title.blank? || @project.wiki.nil? %></td>
21 <td class="buttons">
21 <td class="buttons">
22 <% if version.project == @project %>
22 <% if version.project == @project %>
23 <%= link_to_if_authorized l(:button_edit), {:controller => 'versions', :action => 'edit', :id => version }, :class => 'icon icon-edit' %>
23 <%= link_to_if_authorized l(:button_edit), {:controller => 'versions', :action => 'edit', :id => version }, :class => 'icon icon-edit' %>
@@ -12,7 +12,7
12 <h3><%= format_date(date) %></h3>
12 <h3><%= format_date(date) %></h3>
13 <ul>
13 <ul>
14 <% @pages_by_date[date].each do |page| %>
14 <% @pages_by_date[date].each do |page| %>
15 <li><%= link_to page.pretty_title, :action => 'show', :id => page.title %></li>
15 <li><%= link_to page.pretty_title, :action => 'show', :id => page.title, :project_id => page.project %></li>
16 <% end %>
16 <% end %>
17 </ul>
17 </ul>
18 <% end %>
18 <% end %>
@@ -1,6 +1,6
1 <h2><%=h @page.pretty_title %></h2>
1 <h2><%=h @page.pretty_title %></h2>
2
2
3 <% form_for :content, @content, :url => {:action => 'update', :id => @page.title}, :html => {:multipart => true, :id => 'wiki_form'} do |f| %>
3 <% form_for :content, @content, :url => {:action => 'update', :id => @page.title}, :html => {:method => :put, :multipart => true, :id => 'wiki_form'} do |f| %>
4 <%= f.hidden_field :version %>
4 <%= f.hidden_field :version %>
5 <%= error_messages_for 'content' %>
5 <%= error_messages_for 'content' %>
6
6
@@ -11,7 +11,7
11 <p><%= submit_tag l(:button_save) %>
11 <p><%= submit_tag l(:button_save) %>
12 <%= link_to_remote l(:label_preview),
12 <%= link_to_remote l(:label_preview),
13 { :url => { :controller => 'wiki', :action => 'preview', :project_id => @project, :id => @page.title },
13 { :url => { :controller => 'wiki', :action => 'preview', :project_id => @project, :id => @page.title },
14 :method => 'post',
14 :method => :post,
15 :update => 'preview',
15 :update => 'preview',
16 :with => "Form.serialize('wiki_form')",
16 :with => "Form.serialize('wiki_form')",
17 :complete => "Element.scrollTo('preview')"
17 :complete => "Element.scrollTo('preview')"
@@ -19,7 +19,7
19 <% line_num = 1 %>
19 <% line_num = 1 %>
20 <% @versions.each do |ver| %>
20 <% @versions.each do |ver| %>
21 <tr class="<%= cycle("odd", "even") %>">
21 <tr class="<%= cycle("odd", "even") %>">
22 <td class="id"><%= link_to ver.version, :action => 'show', :id => @page.title, :version => ver.version %></td>
22 <td class="id"><%= link_to ver.version, :action => 'show', :id => @page.title, :project_id => @page.project, :version => ver.version %></td>
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>
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 <td class="checkbox"><%= radio_button_tag('version_from', ver.version, (line_num==2), :id => "cbto-#{line_num}") if show_diff && (line_num > 1) %></td>
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 <td align="center"><%= format_time(ver.updated_on) %></td>
25 <td align="center"><%= format_time(ver.updated_on) %></td>
@@ -11,15 +11,15
11 <%= link_to_if_authorized(l(:label_history), {:action => 'history', :id => @page.title}, :class => 'icon icon-history') %>
11 <%= link_to_if_authorized(l(:label_history), {:action => 'history', :id => @page.title}, :class => 'icon icon-history') %>
12 </div>
12 </div>
13
13
14 <%= breadcrumb(@page.ancestors.reverse.collect {|parent| link_to h(parent.pretty_title), {:id => parent.title}}) %>
14 <%= breadcrumb(@page.ancestors.reverse.collect {|parent| link_to h(parent.pretty_title), {:id => parent.title, :project_id => parent.project}}) %>
15
15
16 <% if @content.version != @page.content.version %>
16 <% if @content.version != @page.content.version %>
17 <p>
17 <p>
18 <%= link_to(('&#171; ' + l(:label_previous)), :action => 'show', :id => @page.title, :version => (@content.version - 1)) + " - " if @content.version > 1 %>
18 <%= link_to(('&#171; ' + l(:label_previous)), :action => 'show', :id => @page.title, :project_id => @page.project, :version => (@content.version - 1)) + " - " if @content.version > 1 %>
19 <%= "#{l(:label_version)} #{@content.version}/#{@page.content.version}" %>
19 <%= "#{l(:label_version)} #{@content.version}/#{@page.content.version}" %>
20 <%= '(' + link_to('diff', :controller => 'wiki', :action => 'diff', :id => @page.title, :version => @content.version) + ')' if @content.version > 1 %> -
20 <%= '(' + link_to('diff', :controller => 'wiki', :action => 'diff', :id => @page.title, :project_id => @page.project, :version => @content.version) + ')' if @content.version > 1 %> -
21 <%= link_to((l(:label_next) + ' &#187;'), :action => 'show', :id => @page.title, :version => (@content.version + 1)) + " - " if @content.version < @page.content.version %>
21 <%= link_to((l(:label_next) + ' &#187;'), :action => 'show', :id => @page.title, :project_id => @page.project, :version => (@content.version + 1)) + " - " if @content.version < @page.content.version %>
22 <%= link_to(l(:label_current_version), :action => 'show', :id => @page.title) %>
22 <%= link_to(l(:label_current_version), :action => 'show', :id => @page.title, :project_id => @page.project) %>
23 <br />
23 <br />
24 <em><%= @content.author ? @content.author.name : "anonyme" %>, <%= format_time(@content.updated_on) %> </em><br />
24 <em><%= @content.author ? @content.author.name : "anonyme" %>, <%= format_time(@content.updated_on) %> </em><br />
25 <%=h @content.comments %>
25 <%=h @content.comments %>
@@ -27,27 +27,6 ActionController::Routing::Routes.draw do |map|
27 map.connect 'projects/:id/wiki', :controller => 'wikis', :action => 'edit', :conditions => {:method => :post}
27 map.connect 'projects/:id/wiki', :controller => 'wikis', :action => 'edit', :conditions => {:method => :post}
28 map.connect 'projects/:id/wiki/destroy', :controller => 'wikis', :action => 'destroy', :conditions => {:method => :get}
28 map.connect 'projects/:id/wiki/destroy', :controller => 'wikis', :action => 'destroy', :conditions => {:method => :get}
29 map.connect 'projects/:id/wiki/destroy', :controller => 'wikis', :action => 'destroy', :conditions => {:method => :post}
29 map.connect 'projects/:id/wiki/destroy', :controller => 'wikis', :action => 'destroy', :conditions => {:method => :post}
30 map.with_options :controller => 'wiki' do |wiki_routes|
31 wiki_routes.with_options :conditions => {:method => :get} do |wiki_views|
32 wiki_views.connect 'projects/:project_id/wiki/export', :action => 'export'
33 wiki_views.connect 'projects/:project_id/wiki/index', :action => 'index'
34 wiki_views.connect 'projects/:project_id/wiki/date_index', :action => 'date_index'
35 wiki_views.connect 'projects/:project_id/wiki/:id', :action => 'show', :id => nil
36 wiki_views.connect 'projects/:project_id/wiki/:id/edit', :action => 'edit'
37 wiki_views.connect 'projects/:project_id/wiki/:id/rename', :action => 'rename'
38 wiki_views.connect 'projects/:project_id/wiki/:id/history', :action => 'history'
39 wiki_views.connect 'projects/:project_id/wiki/:id/diff/:version/vs/:version_from', :action => 'diff'
40 wiki_views.connect 'projects/:project_id/wiki/:id/annotate/:version', :action => 'annotate'
41 end
42
43 wiki_routes.connect 'projects/:project_id/wiki/:id/:action',
44 :action => /rename|preview|protect|add_attachment/,
45 :conditions => {:method => :post}
46
47 wiki_routes.connect 'projects/:project_id/wiki/:id/edit', :action => 'update', :conditions => {:method => :post}
48
49 wiki_routes.connect 'projects/:project_id/wiki/:id', :action => 'destroy', :conditions => {:method => :delete}
50 end
51
30
52 map.with_options :controller => 'messages' do |messages_routes|
31 map.with_options :controller => 'messages' do |messages_routes|
53 messages_routes.with_options :conditions => {:method => :get} do |messages_views|
32 messages_routes.with_options :conditions => {:method => :get} do |messages_views|
@@ -168,7 +147,21 ActionController::Routing::Routes.draw do |map|
168 project.resources :news, :shallow => true
147 project.resources :news, :shallow => true
169 project.resources :time_entries, :controller => 'timelog', :path_prefix => 'projects/:project_id'
148 project.resources :time_entries, :controller => 'timelog', :path_prefix => 'projects/:project_id'
170
149
171
150 project.wiki_start_page 'wiki', :controller => 'wiki', :action => 'show', :conditions => {:method => :get}
151 project.wiki_index 'wiki/index', :controller => 'wiki', :action => 'index', :conditions => {:method => :get}
152 project.wiki_diff 'wiki/:id/diff/:version/vs/:version_from', :controller => 'wiki', :action => 'diff'
153 project.wiki_annotate 'wiki/:id/annotate/:version', :controller => 'wiki', :action => 'annotate'
154 project.resources :wiki, :except => [:new, :create], :member => {
155 :rename => [:get, :post],
156 :history => :get,
157 :preview => :any,
158 :protect => :post,
159 :add_attachment => :post
160 }, :collection => {
161 :export => :get,
162 :date_index => :get
163 }
164
172 end
165 end
173
166
174 # Destroy uses a get request to prompt the user before the actual DELETE request
167 # Destroy uses a get request to prompt the user before the actual DELETE request
@@ -80,7 +80,7 class WikiControllerTest < ActionController::TestCase
80
80
81 def test_create_page
81 def test_create_page
82 @request.session[:user_id] = 2
82 @request.session[:user_id] = 2
83 post :update, :project_id => 1,
83 put :update, :project_id => 1,
84 :id => 'New page',
84 :id => 'New page',
85 :content => {:comments => 'Created the page',
85 :content => {:comments => 'Created the page',
86 :text => "h1. New page\n\nThis is a new page",
86 :text => "h1. New page\n\nThis is a new page",
@@ -96,7 +96,7 class WikiControllerTest < ActionController::TestCase
96 @request.session[:user_id] = 2
96 @request.session[:user_id] = 2
97 assert_difference 'WikiPage.count' do
97 assert_difference 'WikiPage.count' do
98 assert_difference 'Attachment.count' do
98 assert_difference 'Attachment.count' do
99 post :update, :project_id => 1,
99 put :update, :project_id => 1,
100 :id => 'New page',
100 :id => 'New page',
101 :content => {:comments => 'Created the page',
101 :content => {:comments => 'Created the page',
102 :text => "h1. New page\n\nThis is a new page",
102 :text => "h1. New page\n\nThis is a new page",
@@ -322,12 +322,13 class RoutingTest < ActionController::IntegrationTest
322 should_route :get, "/projects/567/wiki/date_index", :controller => 'wiki', :action => 'date_index', :project_id => '567'
322 should_route :get, "/projects/567/wiki/date_index", :controller => 'wiki', :action => 'date_index', :project_id => '567'
323 should_route :get, "/projects/567/wiki/export", :controller => 'wiki', :action => 'export', :project_id => '567'
323 should_route :get, "/projects/567/wiki/export", :controller => 'wiki', :action => 'export', :project_id => '567'
324
324
325 should_route :post, "/projects/567/wiki/my_page/edit", :controller => 'wiki', :action => 'update', :project_id => '567', :id => 'my_page'
326 should_route :post, "/projects/567/wiki/CookBook_documentation/preview", :controller => 'wiki', :action => 'preview', :project_id => '567', :id => 'CookBook_documentation'
325 should_route :post, "/projects/567/wiki/CookBook_documentation/preview", :controller => 'wiki', :action => 'preview', :project_id => '567', :id => 'CookBook_documentation'
327 should_route :post, "/projects/22/wiki/ladida/rename", :controller => 'wiki', :action => 'rename', :project_id => '22', :id => 'ladida'
326 should_route :post, "/projects/22/wiki/ladida/rename", :controller => 'wiki', :action => 'rename', :project_id => '22', :id => 'ladida'
328 should_route :post, "/projects/22/wiki/ladida/protect", :controller => 'wiki', :action => 'protect', :project_id => '22', :id => 'ladida'
327 should_route :post, "/projects/22/wiki/ladida/protect", :controller => 'wiki', :action => 'protect', :project_id => '22', :id => 'ladida'
329 should_route :post, "/projects/22/wiki/ladida/add_attachment", :controller => 'wiki', :action => 'add_attachment', :project_id => '22', :id => 'ladida'
328 should_route :post, "/projects/22/wiki/ladida/add_attachment", :controller => 'wiki', :action => 'add_attachment', :project_id => '22', :id => 'ladida'
330
329
330 should_route :put, "/projects/567/wiki/my_page", :controller => 'wiki', :action => 'update', :project_id => '567', :id => 'my_page'
331
331 should_route :delete, "/projects/22/wiki/ladida", :controller => 'wiki', :action => 'destroy', :project_id => '22', :id => 'ladida'
332 should_route :delete, "/projects/22/wiki/ladida", :controller => 'wiki', :action => 'destroy', :project_id => '22', :id => 'ladida'
332 end
333 end
333
334
@@ -253,8 +253,8 RAW
253 '[[Unknown page]]' => '<a href="/projects/ecookbook/wiki/Unknown_page" class="wiki-page new">Unknown page</a>',
253 '[[Unknown page]]' => '<a href="/projects/ecookbook/wiki/Unknown_page" class="wiki-page new">Unknown page</a>',
254 '[[Unknown page|404]]' => '<a href="/projects/ecookbook/wiki/Unknown_page" class="wiki-page new">404</a>',
254 '[[Unknown page|404]]' => '<a href="/projects/ecookbook/wiki/Unknown_page" class="wiki-page new">404</a>',
255 # link to another project wiki
255 # link to another project wiki
256 '[[onlinestore:]]' => '<a href="/projects/onlinestore/wiki/" class="wiki-page">onlinestore</a>',
256 '[[onlinestore:]]' => '<a href="/projects/onlinestore/wiki" class="wiki-page">onlinestore</a>',
257 '[[onlinestore:|Wiki]]' => '<a href="/projects/onlinestore/wiki/" class="wiki-page">Wiki</a>',
257 '[[onlinestore:|Wiki]]' => '<a href="/projects/onlinestore/wiki" class="wiki-page">Wiki</a>',
258 '[[onlinestore:Start page]]' => '<a href="/projects/onlinestore/wiki/Start_page" class="wiki-page">Start page</a>',
258 '[[onlinestore:Start page]]' => '<a href="/projects/onlinestore/wiki/Start_page" class="wiki-page">Start page</a>',
259 '[[onlinestore:Start page|Text]]' => '<a href="/projects/onlinestore/wiki/Start_page" class="wiki-page">Text</a>',
259 '[[onlinestore:Start page|Text]]' => '<a href="/projects/onlinestore/wiki/Start_page" class="wiki-page">Text</a>',
260 '[[onlinestore:Unknown page]]' => '<a href="/projects/onlinestore/wiki/Unknown_page" class="wiki-page new">Unknown page</a>',
260 '[[onlinestore:Unknown page]]' => '<a href="/projects/onlinestore/wiki/Unknown_page" class="wiki-page new">Unknown page</a>',
General Comments 0
You need to be logged in to leave comments. Login now