##// END OF EJS Templates
Fixed that project, issue and activity should be preserved when logging time with "Create and continue" (#11038)....
Jean-Philippe Lang -
r9558:4ee133e77eb7
parent child
Show More
@@ -18,12 +18,13
18 class TimelogController < ApplicationController
18 class TimelogController < ApplicationController
19 menu_item :issues
19 menu_item :issues
20
20
21 before_filter :find_project, :only => [:create]
21 before_filter :find_project_for_new_time_entry, :only => [:create]
22 before_filter :find_time_entry, :only => [:show, :edit, :update]
22 before_filter :find_time_entry, :only => [:show, :edit, :update]
23 before_filter :find_time_entries, :only => [:bulk_edit, :bulk_update, :destroy]
23 before_filter :find_time_entries, :only => [:bulk_edit, :bulk_update, :destroy]
24 before_filter :authorize, :except => [:new, :index, :report]
24 before_filter :authorize, :except => [:new, :index, :report]
25
25
26 before_filter :find_optional_project, :only => [:new, :index, :report]
26 before_filter :find_optional_project, :only => [:index, :report]
27 before_filter :find_optional_project_for_new_time_entry, :only => [:new]
27 before_filter :authorize_global, :only => [:new, :index, :report]
28 before_filter :authorize_global, :only => [:new, :index, :report]
28
29
29 accept_rss_auth :index
30 accept_rss_auth :index
@@ -133,9 +134,13 class TimelogController < ApplicationController
133 flash[:notice] = l(:notice_successful_create)
134 flash[:notice] = l(:notice_successful_create)
134 if params[:continue]
135 if params[:continue]
135 if params[:project_id]
136 if params[:project_id]
136 redirect_to :action => 'new', :project_id => @time_entry.project, :issue_id => @time_entry.issue, :back_url => params[:back_url]
137 redirect_to :action => 'new', :project_id => @time_entry.project, :issue_id => @time_entry.issue,
138 :time_entry => {:issue_id => @time_entry.issue_id, :activity_id => @time_entry.activity_id},
139 :back_url => params[:back_url]
137 else
140 else
138 redirect_to :action => 'new', :back_url => params[:back_url]
141 redirect_to :action => 'new',
142 :time_entry => {:project_id => @time_entry.project_id, :issue_id => @time_entry.issue_id, :activity_id => @time_entry.activity_id},
143 :back_url => params[:back_url]
139 end
144 end
140 else
145 else
141 redirect_back_or_default :action => 'index', :project_id => @time_entry.project
146 redirect_back_or_default :action => 'index', :project_id => @time_entry.project
@@ -258,7 +263,7 private
258 end
263 end
259 end
264 end
260
265
261 def find_project
266 def find_optional_project_for_new_time_entry
262 if (project_id = (params[:project_id] || params[:time_entry] && params[:time_entry][:project_id])).present?
267 if (project_id = (params[:project_id] || params[:time_entry] && params[:time_entry][:project_id])).present?
263 @project = Project.find(project_id)
268 @project = Project.find(project_id)
264 end
269 end
@@ -266,12 +271,15 private
266 @issue = Issue.find(issue_id)
271 @issue = Issue.find(issue_id)
267 @project ||= @issue.project
272 @project ||= @issue.project
268 end
273 end
274 rescue ActiveRecord::RecordNotFound
275 render_404
276 end
277
278 def find_project_for_new_time_entry
279 find_optional_project_for_new_time_entry
269 if @project.nil?
280 if @project.nil?
270 render_404
281 render_404
271 return false
272 end
282 end
273 rescue ActiveRecord::RecordNotFound
274 render_404
275 end
283 end
276
284
277 def find_optional_project
285 def find_optional_project
@@ -65,6 +65,17 class TimelogControllerTest < ActionController::TestCase
65 assert_select 'input[name=project_id]', 0
65 assert_select 'input[name=project_id]', 0
66 end
66 end
67
67
68 def test_new_without_project_should_prefill_the_form
69 @request.session[:user_id] = 3
70 get :new, :time_entry => {:project_id => '1'}
71 assert_response :success
72 assert_template 'new'
73 assert_select 'select[name=?]', 'time_entry[project_id]' do
74 assert_select 'option[value=1][selected=selected]'
75 end
76 assert_select 'input[name=project_id]', 0
77 end
78
68 def test_new_without_project_should_deny_without_permission
79 def test_new_without_project_should_deny_without_permission
69 Role.all.each {|role| role.remove_permission! :log_time}
80 Role.all.each {|role| role.remove_permission! :log_time}
70 @request.session[:user_id] = 3
81 @request.session[:user_id] = 3
@@ -146,7 +157,7 class TimelogControllerTest < ActionController::TestCase
146 :spent_on => '2008-03-14',
157 :spent_on => '2008-03-14',
147 :hours => '7.3'},
158 :hours => '7.3'},
148 :continue => '1'
159 :continue => '1'
149 assert_redirected_to '/projects/ecookbook/time_entries/new'
160 assert_redirected_to '/projects/ecookbook/time_entries/new?time_entry%5Bactivity_id%5D=11&time_entry%5Bissue_id%5D='
150 end
161 end
151
162
152 def test_create_and_continue_with_issue_id
163 def test_create_and_continue_with_issue_id
@@ -157,7 +168,7 class TimelogControllerTest < ActionController::TestCase
157 :spent_on => '2008-03-14',
168 :spent_on => '2008-03-14',
158 :hours => '7.3'},
169 :hours => '7.3'},
159 :continue => '1'
170 :continue => '1'
160 assert_redirected_to '/projects/ecookbook/issues/1/time_entries/new'
171 assert_redirected_to '/projects/ecookbook/issues/1/time_entries/new?time_entry%5Bactivity_id%5D=11&time_entry%5Bissue_id%5D=1'
161 end
172 end
162
173
163 def test_create_and_continue_without_project
174 def test_create_and_continue_without_project
@@ -169,7 +180,7 class TimelogControllerTest < ActionController::TestCase
169 :hours => '7.3'},
180 :hours => '7.3'},
170 :continue => '1'
181 :continue => '1'
171
182
172 assert_redirected_to '/time_entries/new'
183 assert_redirected_to '/time_entries/new?time_entry%5Bactivity_id%5D=11&time_entry%5Bissue_id%5D=&time_entry%5Bproject_id%5D=1'
173 end
184 end
174
185
175 def test_create_without_log_time_permission_should_be_denied
186 def test_create_without_log_time_permission_should_be_denied
General Comments 0
You need to be logged in to leave comments. Login now