##// END OF EJS Templates
Refactor: convert timelogs to a REST resource (:time_entries)...
Eric Davis -
r4136:718816c5d4b0
parent child
Show More
@@ -20,8 +20,6 class TimelogController < ApplicationController
20 before_filter :find_project, :authorize, :only => [:new, :create, :edit, :update, :destroy]
20 before_filter :find_project, :authorize, :only => [:new, :create, :edit, :update, :destroy]
21 before_filter :find_optional_project, :only => [:index]
21 before_filter :find_optional_project, :only => [:index]
22
22
23 verify :method => :post, :only => :destroy, :redirect_to => { :action => :index }
24
25 helper :sort
23 helper :sort
26 include SortHelper
24 include SortHelper
27 helper :issues
25 helper :issues
@@ -131,6 +129,7 class TimelogController < ApplicationController
131 end
129 end
132 end
130 end
133
131
132 verify :method => :delete, :only => :destroy, :render => {:nothing => true, :status => :method_not_allowed }
134 def destroy
133 def destroy
135 (render_404; return) unless @time_entry
134 (render_404; return) unless @time_entry
136 (render_403; return) unless @time_entry.editable_by?(User.current)
135 (render_403; return) unless @time_entry.editable_by?(User.current)
@@ -31,7 +31,7
31 :title => l(:button_edit) %>
31 :title => l(:button_edit) %>
32 <%= link_to image_tag('delete.png'), {:controller => 'timelog', :action => 'destroy', :id => entry, :project_id => nil},
32 <%= link_to image_tag('delete.png'), {:controller => 'timelog', :action => 'destroy', :id => entry, :project_id => nil},
33 :confirm => l(:text_are_you_sure),
33 :confirm => l(:text_are_you_sure),
34 :method => :post,
34 :method => :delete,
35 :title => l(:button_delete) %>
35 :title => l(:button_delete) %>
36 <% end -%>
36 <% end -%>
37 </td>
37 </td>
@@ -13,38 +13,16 ActionController::Routing::Routes.draw do |map|
13
13
14 map.connect 'roles/workflow/:id/:role_id/:tracker_id', :controller => 'roles', :action => 'workflow'
14 map.connect 'roles/workflow/:id/:role_id/:tracker_id', :controller => 'roles', :action => 'workflow'
15 map.connect 'help/:ctrl/:page', :controller => 'help'
15 map.connect 'help/:ctrl/:page', :controller => 'help'
16
17 map.connect 'time_entries/:id/edit', :action => 'edit', :controller => 'timelog'
18 map.connect 'time_entries/:id', :action => 'update', :controller => 'timelog', :conditions => {:method => :put}
19 map.connect 'projects/:project_id/time_entries/new', :action => 'new', :controller => 'timelog'
20 map.connect 'projects/:project_id/issues/:issue_id/time_entries/new', :action => 'new', :controller => 'timelog'
21
22 map.with_options :controller => 'timelog' do |timelog|
23 timelog.connect 'projects/:project_id/time_entries', :action => 'index'
24
25 timelog.with_options :action => 'index', :conditions => {:method => :get} do |time_details|
26 time_details.connect 'time_entries'
27 time_details.connect 'time_entries.:format'
28 time_details.connect 'issues/:issue_id/time_entries'
29 time_details.connect 'issues/:issue_id/time_entries.:format'
30 time_details.connect 'projects/:project_id/time_entries.:format'
31 time_details.connect 'projects/:project_id/issues/:issue_id/time_entries'
32 time_details.connect 'projects/:project_id/issues/:issue_id/time_entries.:format'
33 end
34 timelog.connect 'projects/:project_id/time_entries/report', :controller => 'time_entry_reports', :action => 'report'
35 timelog.with_options :controller => 'time_entry_reports', :action => 'report',:conditions => {:method => :get} do |time_report|
36 time_report.connect 'time_entries/report'
37 time_report.connect 'time_entries/report.:format'
38 time_report.connect 'projects/:project_id/time_entries/report.:format'
39 end
40
41 timelog.with_options :action => 'new', :conditions => {:method => :get} do |time_edit|
42 time_edit.connect 'issues/:issue_id/time_entries/new'
43 end
44
16
45 timelog.connect 'projects/:project_id/timelog/edit', :action => 'create', :conditions => {:method => :post}
17 map.connect 'projects/:project_id/time_entries/report', :controller => 'time_entry_reports', :action => 'report'
46 timelog.connect 'time_entries/:id/destroy', :action => 'destroy', :conditions => {:method => :post}
18 map.with_options :controller => 'time_entry_reports', :action => 'report',:conditions => {:method => :get} do |time_report|
19 time_report.connect 'time_entries/report'
20 time_report.connect 'time_entries/report.:format'
21 time_report.connect 'projects/:project_id/time_entries/report.:format'
47 end
22 end
23
24 # TODO: wasteful since this is also nested under issues, projects, and projects/issues
25 map.resources :time_entries, :controller => 'timelog'
48
26
49 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}
50 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}
@@ -131,8 +109,13 ActionController::Routing::Routes.draw do |map|
131 map.connect '/issues', :controller => 'issues', :action => 'index', :conditions => { :method => :post }
109 map.connect '/issues', :controller => 'issues', :action => 'index', :conditions => { :method => :post }
132 map.connect '/issues/create', :controller => 'issues', :action => 'index', :conditions => { :method => :post }
110 map.connect '/issues/create', :controller => 'issues', :action => 'index', :conditions => { :method => :post }
133
111
134 map.resources :issues, :member => { :edit => :post }, :collection => {}
112 map.resources :issues, :member => { :edit => :post }, :collection => {} do |issues|
135 map.resources :issues, :path_prefix => '/projects/:project_id', :collection => { :create => :post }
113 issues.resources :time_entries, :controller => 'timelog'
114 end
115
116 map.resources :issues, :path_prefix => '/projects/:project_id', :collection => { :create => :post } do |issues|
117 issues.resources :time_entries, :controller => 'timelog'
118 end
136
119
137 map.with_options :controller => 'issue_relations', :conditions => {:method => :post} do |relations|
120 map.with_options :controller => 'issue_relations', :conditions => {:method => :post} do |relations|
138 relations.connect 'issues/:issue_id/relations/:id', :action => 'new'
121 relations.connect 'issues/:issue_id/relations/:id', :action => 'new'
@@ -177,6 +160,9 ActionController::Routing::Routes.draw do |map|
177 project.resources :files, :only => [:index, :new, :create]
160 project.resources :files, :only => [:index, :new, :create]
178 project.resources :versions, :collection => {:close_completed => :put}, :member => {:status_by => :post}
161 project.resources :versions, :collection => {:close_completed => :put}, :member => {:status_by => :post}
179 project.resources :news, :shallow => true
162 project.resources :news, :shallow => true
163 project.resources :time_entries, :controller => 'timelog', :path_prefix => 'projects/:project_id'
164
165
180 end
166 end
181
167
182 # Destroy uses a get request to prompt the user before the actual DELETE request
168 # Destroy uses a get request to prompt the user before the actual DELETE request
@@ -56,7 +56,7 class TimelogControllerTest < ActionController::TestCase
56 assert_response :success
56 assert_response :success
57 assert_template 'edit'
57 assert_template 'edit'
58 # Default activity selected
58 # Default activity selected
59 assert_tag :tag => 'form', :attributes => { :action => '/projects/ecookbook/timelog/update/2' }
59 assert_tag :tag => 'form', :attributes => { :action => '/projects/ecookbook/time_entries/2' }
60 end
60 end
61
61
62 def test_get_edit_with_an_existing_time_entry_with_inactive_activity
62 def test_get_edit_with_an_existing_time_entry_with_inactive_activity
@@ -114,7 +114,7 class TimelogControllerTest < ActionController::TestCase
114
114
115 def test_destroy
115 def test_destroy
116 @request.session[:user_id] = 2
116 @request.session[:user_id] = 2
117 post :destroy, :id => 1
117 delete :destroy, :id => 1
118 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
118 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
119 assert_equal I18n.t(:notice_successful_delete), flash[:notice]
119 assert_equal I18n.t(:notice_successful_delete), flash[:notice]
120 assert_nil TimeEntry.find_by_id(1)
120 assert_nil TimeEntry.find_by_id(1)
@@ -128,7 +128,7 class TimelogControllerTest < ActionController::TestCase
128 end
128 end
129
129
130 @request.session[:user_id] = 2
130 @request.session[:user_id] = 2
131 post :destroy, :id => 1
131 delete :destroy, :id => 1
132 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
132 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
133 assert_equal I18n.t(:notice_unable_delete_time_entry), flash[:error]
133 assert_equal I18n.t(:notice_unable_delete_time_entry), flash[:error]
134 assert_not_nil TimeEntry.find_by_id(1)
134 assert_not_nil TimeEntry.find_by_id(1)
@@ -221,27 +221,60 class RoutingTest < ActionController::IntegrationTest
221 should_route :post, "/projects/redmine/repository/edit", :controller => 'repositories', :action => 'edit', :id => 'redmine'
221 should_route :post, "/projects/redmine/repository/edit", :controller => 'repositories', :action => 'edit', :id => 'redmine'
222 end
222 end
223
223
224 context "timelogs" do
224 context "timelogs (global)" do
225 should_route :get, "/time_entries", :controller => 'timelog', :action => 'index'
225 should_route :get, "/time_entries", :controller => 'timelog', :action => 'index'
226 should_route :get, "/time_entries.csv", :controller => 'timelog', :action => 'index', :format => 'csv'
226 should_route :get, "/time_entries.csv", :controller => 'timelog', :action => 'index', :format => 'csv'
227 should_route :get, "/time_entries.atom", :controller => 'timelog', :action => 'index', :format => 'atom'
227 should_route :get, "/time_entries.atom", :controller => 'timelog', :action => 'index', :format => 'atom'
228 should_route :get, "/time_entries/new", :controller => 'timelog', :action => 'new'
229 should_route :get, "/time_entries/22/edit", :controller => 'timelog', :action => 'edit', :id => '22'
230
231 should_route :post, "/time_entries", :controller => 'timelog', :action => 'create'
232
233 should_route :put, "/time_entries/22", :controller => 'timelog', :action => 'update', :id => '22'
234
235 should_route :delete, "/time_entries/55", :controller => 'timelog', :action => 'destroy', :id => '55'
236 end
237
238 context "timelogs (scoped under project)" do
228 should_route :get, "/projects/567/time_entries", :controller => 'timelog', :action => 'index', :project_id => '567'
239 should_route :get, "/projects/567/time_entries", :controller => 'timelog', :action => 'index', :project_id => '567'
229 should_route :get, "/projects/567/time_entries.csv", :controller => 'timelog', :action => 'index', :project_id => '567', :format => 'csv'
240 should_route :get, "/projects/567/time_entries.csv", :controller => 'timelog', :action => 'index', :project_id => '567', :format => 'csv'
230 should_route :get, "/projects/567/time_entries.atom", :controller => 'timelog', :action => 'index', :project_id => '567', :format => 'atom'
241 should_route :get, "/projects/567/time_entries.atom", :controller => 'timelog', :action => 'index', :project_id => '567', :format => 'atom'
242 should_route :get, "/projects/567/time_entries/new", :controller => 'timelog', :action => 'new', :project_id => '567'
243 should_route :get, "/projects/567/time_entries/22/edit", :controller => 'timelog', :action => 'edit', :id => '22', :project_id => '567'
244
245 should_route :post, "/projects/567/time_entries", :controller => 'timelog', :action => 'create', :project_id => '567'
246
247 should_route :put, "/projects/567/time_entries/22", :controller => 'timelog', :action => 'update', :id => '22', :project_id => '567'
248
249 should_route :delete, "/projects/567/time_entries/55", :controller => 'timelog', :action => 'destroy', :id => '55', :project_id => '567'
250 end
251
252 context "timelogs (scoped under issues)" do
231 should_route :get, "/issues/234/time_entries", :controller => 'timelog', :action => 'index', :issue_id => '234'
253 should_route :get, "/issues/234/time_entries", :controller => 'timelog', :action => 'index', :issue_id => '234'
232 should_route :get, "/issues/234/time_entries.csv", :controller => 'timelog', :action => 'index', :issue_id => '234', :format => 'csv'
254 should_route :get, "/issues/234/time_entries.csv", :controller => 'timelog', :action => 'index', :issue_id => '234', :format => 'csv'
233 should_route :get, "/issues/234/time_entries.atom", :controller => 'timelog', :action => 'index', :issue_id => '234', :format => 'atom'
255 should_route :get, "/issues/234/time_entries.atom", :controller => 'timelog', :action => 'index', :issue_id => '234', :format => 'atom'
234 should_route :get, "/projects/ecookbook/issues/123/time_entries", :controller => 'timelog', :action => 'index', :project_id => 'ecookbook', :issue_id => '123'
256 should_route :get, "/issues/234/time_entries/new", :controller => 'timelog', :action => 'new', :issue_id => '234'
257 should_route :get, "/issues/234/time_entries/22/edit", :controller => 'timelog', :action => 'edit', :id => '22', :issue_id => '234'
235
258
236 should_route :get, "/issues/567/time_entries/new", :controller => 'timelog', :action => 'new', :issue_id => '567'
259 should_route :post, "/issues/234/time_entries", :controller => 'timelog', :action => 'create', :issue_id => '234'
237 should_route :get, "/projects/ecookbook/time_entries/new", :controller => 'timelog', :action => 'new', :project_id => 'ecookbook'
238 should_route :get, "/projects/ecookbook/issues/567/time_entries/new", :controller => 'timelog', :action => 'new', :project_id => 'ecookbook', :issue_id => '567'
239 should_route :get, "/time_entries/22/edit", :controller => 'timelog', :action => 'edit', :id => '22'
240
260
241 should_route :post, "/projects/ecookbook/timelog/edit", :controller => 'timelog', :action => 'create', :project_id => 'ecookbook'
261 should_route :put, "/issues/234/time_entries/22", :controller => 'timelog', :action => 'update', :id => '22', :issue_id => '234'
242 should_route :post, "/time_entries/55/destroy", :controller => 'timelog', :action => 'destroy', :id => '55'
243
262
244 should_route :put, "/time_entries/22", :controller => 'timelog', :action => 'update', :id => '22'
263 should_route :delete, "/issues/234/time_entries/55", :controller => 'timelog', :action => 'destroy', :id => '55', :issue_id => '234'
264 end
265
266 context "timelogs (scoped under project and issues)" do
267 should_route :get, "/projects/ecookbook/issues/234/time_entries", :controller => 'timelog', :action => 'index', :issue_id => '234', :project_id => 'ecookbook'
268 should_route :get, "/projects/ecookbook/issues/234/time_entries.csv", :controller => 'timelog', :action => 'index', :issue_id => '234', :project_id => 'ecookbook', :format => 'csv'
269 should_route :get, "/projects/ecookbook/issues/234/time_entries.atom", :controller => 'timelog', :action => 'index', :issue_id => '234', :project_id => 'ecookbook', :format => 'atom'
270 should_route :get, "/projects/ecookbook/issues/234/time_entries/new", :controller => 'timelog', :action => 'new', :issue_id => '234', :project_id => 'ecookbook'
271 should_route :get, "/projects/ecookbook/issues/234/time_entries/22/edit", :controller => 'timelog', :action => 'edit', :id => '22', :issue_id => '234', :project_id => 'ecookbook'
272
273 should_route :post, "/projects/ecookbook/issues/234/time_entries", :controller => 'timelog', :action => 'create', :issue_id => '234', :project_id => 'ecookbook'
274
275 should_route :put, "/projects/ecookbook/issues/234/time_entries/22", :controller => 'timelog', :action => 'update', :id => '22', :issue_id => '234', :project_id => 'ecookbook'
276
277 should_route :delete, "/projects/ecookbook/issues/234/time_entries/55", :controller => 'timelog', :action => 'destroy', :id => '55', :issue_id => '234', :project_id => 'ecookbook'
245 end
278 end
246
279
247 context "time_entry_reports" do
280 context "time_entry_reports" do
General Comments 0
You need to be logged in to leave comments. Login now