##// END OF EJS Templates
Refactor: extract TimelogController#edit to #update...
Eric Davis -
r4134:435c90eb478e
parent child
Show More
@@ -17,7 +17,7
17
17
18 class TimelogController < ApplicationController
18 class TimelogController < ApplicationController
19 menu_item :issues
19 menu_item :issues
20 before_filter :find_project, :authorize, :only => [:new, :create, :edit, :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 }
23 verify :method => :post, :only => :destroy, :redirect_to => { :action => :index }
@@ -111,18 +111,26 class TimelogController < ApplicationController
111
111
112 def edit
112 def edit
113 (render_403; return) if @time_entry && !@time_entry.editable_by?(User.current)
113 (render_403; return) if @time_entry && !@time_entry.editable_by?(User.current)
114 @time_entry ||= TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => User.current.today)
114 @time_entry.attributes = params[:time_entry]
115
116 call_hook(:controller_timelog_edit_before_save, { :params => params, :time_entry => @time_entry })
117 end
118
119 verify :method => :put, :only => :update, :render => {:nothing => true, :status => :method_not_allowed }
120 def update
121 (render_403; return) if @time_entry && !@time_entry.editable_by?(User.current)
115 @time_entry.attributes = params[:time_entry]
122 @time_entry.attributes = params[:time_entry]
116
123
117 call_hook(:controller_timelog_edit_before_save, { :params => params, :time_entry => @time_entry })
124 call_hook(:controller_timelog_edit_before_save, { :params => params, :time_entry => @time_entry })
118
125
119 if request.post? and @time_entry.save
126 if @time_entry.save
120 flash[:notice] = l(:notice_successful_update)
127 flash[:notice] = l(:notice_successful_update)
121 redirect_back_or_default :action => 'index', :project_id => @time_entry.project
128 redirect_back_or_default :action => 'index', :project_id => @time_entry.project
122 return
129 else
130 render :action => 'edit'
123 end
131 end
124 end
132 end
125
133
126 def destroy
134 def destroy
127 (render_404; return) unless @time_entry
135 (render_404; return) unless @time_entry
128 (render_403; return) unless @time_entry.editable_by?(User.current)
136 (render_403; return) unless @time_entry.editable_by?(User.current)
@@ -1,6 +1,11
1 <h2><%= l(:label_spent_time) %></h2>
1 <h2><%= l(:label_spent_time) %></h2>
2
2
3 <% labelled_tabular_form_for :time_entry, @time_entry, :url => {:action => (@time_entry.new_record? ? 'create' : 'edit'), :id => @time_entry, :project_id => @time_entry.project} do |f| %>
3 <% labelled_tabular_form_for(:time_entry, @time_entry, :url => {
4 :action => (@time_entry.new_record? ? 'create' : 'update'),
5 :id => @time_entry,
6 :project_id => @time_entry.project
7 },
8 :html => {:method => @time_entry.new_record? ? :post : :put}) do |f| %>
4 <%= error_messages_for 'time_entry' %>
9 <%= error_messages_for 'time_entry' %>
5 <%= back_url_hidden_field_tag %>
10 <%= back_url_hidden_field_tag %>
6
11
@@ -15,6 +15,7 ActionController::Routing::Routes.draw do |map|
15 map.connect 'help/:ctrl/:page', :controller => 'help'
15 map.connect 'help/:ctrl/:page', :controller => 'help'
16
16
17 map.connect 'time_entries/:id/edit', :action => 'edit', :controller => 'timelog'
17 map.connect 'time_entries/:id/edit', :action => 'edit', :controller => 'timelog'
18 map.connect 'time_entries/:id', :action => 'update', :controller => 'timelog', :conditions => {:method => :put}
18 map.connect 'projects/:project_id/time_entries/new', :action => 'new', :controller => 'timelog'
19 map.connect 'projects/:project_id/time_entries/new', :action => 'new', :controller => 'timelog'
19 map.connect 'projects/:project_id/issues/:issue_id/time_entries/new', :action => 'new', :controller => 'timelog'
20 map.connect 'projects/:project_id/issues/:issue_id/time_entries/new', :action => 'new', :controller => 'timelog'
20
21
@@ -84,10 +84,10 Redmine::AccessControl.map do |map|
84 end
84 end
85
85
86 map.project_module :time_tracking do |map|
86 map.project_module :time_tracking do |map|
87 map.permission :log_time, {:timelog => [:new, :create, :edit]}, :require => :loggedin
87 map.permission :log_time, {:timelog => [:new, :create, :edit, :update]}, :require => :loggedin
88 map.permission :view_time_entries, :timelog => [:index], :time_entry_reports => [:report]
88 map.permission :view_time_entries, :timelog => [:index], :time_entry_reports => [:report]
89 map.permission :edit_time_entries, {:timelog => [:new, :create, :edit, :destroy]}, :require => :member
89 map.permission :edit_time_entries, {:timelog => [:new, :create, :edit, :update, :destroy]}, :require => :member
90 map.permission :edit_own_time_entries, {:timelog => [:new, :create, :edit, :destroy]}, :require => :loggedin
90 map.permission :edit_own_time_entries, {:timelog => [:new, :create, :edit, :update, :destroy]}, :require => :loggedin
91 map.permission :manage_project_activities, {:project_enumerations => [:update, :destroy]}, :require => :member
91 map.permission :manage_project_activities, {:project_enumerations => [:update, :destroy]}, :require => :member
92 end
92 end
93
93
@@ -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/edit/2' }
59 assert_tag :tag => 'form', :attributes => { :action => '/projects/ecookbook/timelog/update/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
@@ -101,7 +101,7 class TimelogControllerTest < ActionController::TestCase
101 assert_equal 2, entry.user_id
101 assert_equal 2, entry.user_id
102
102
103 @request.session[:user_id] = 1
103 @request.session[:user_id] = 1
104 post :edit, :id => 1,
104 put :update, :id => 1,
105 :time_entry => {:issue_id => '2',
105 :time_entry => {:issue_id => '2',
106 :hours => '8'}
106 :hours => '8'}
107 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
107 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
@@ -239,8 +239,9 class RoutingTest < ActionController::IntegrationTest
239 should_route :get, "/time_entries/22/edit", :controller => 'timelog', :action => 'edit', :id => '22'
239 should_route :get, "/time_entries/22/edit", :controller => 'timelog', :action => 'edit', :id => '22'
240
240
241 should_route :post, "/projects/ecookbook/timelog/edit", :controller => 'timelog', :action => 'create', :project_id => 'ecookbook'
241 should_route :post, "/projects/ecookbook/timelog/edit", :controller => 'timelog', :action => 'create', :project_id => 'ecookbook'
242 should_route :post, "/time_entries/22/edit", :controller => 'timelog', :action => 'edit', :id => '22'
243 should_route :post, "/time_entries/55/destroy", :controller => 'timelog', :action => 'destroy', :id => '55'
242 should_route :post, "/time_entries/55/destroy", :controller => 'timelog', :action => 'destroy', :id => '55'
243
244 should_route :put, "/time_entries/22", :controller => 'timelog', :action => 'update', :id => '22'
244 end
245 end
245
246
246 context "time_entry_reports" do
247 context "time_entry_reports" do
General Comments 0
You need to be logged in to leave comments. Login now