diff options
author | Eric Davis <edavis@littlestreamsoftware.com> | 2010-10-11 15:31:42 +0000 |
---|---|---|
committer | Eric Davis <edavis@littlestreamsoftware.com> | 2010-10-11 15:31:42 +0000 |
commit | 435c90eb478e705dff9ea239fd280a958a4287e3 (patch) | |
tree | 531e116594529af7016f7360d78ae67e7e9cdacd | |
parent | 700c302fca1ef401eff2744ffc5d955406136b17 (diff) | |
download | redmine-435c90eb478e705dff9ea239fd280a958a4287e3.tar.gz redmine-435c90eb478e705dff9ea239fd280a958a4287e3.zip |
Refactor: extract TimelogController#edit to #update
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4248 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r-- | app/controllers/timelog_controller.rb | 18 | ||||
-rw-r--r-- | app/views/timelog/edit.rhtml | 7 | ||||
-rw-r--r-- | config/routes.rb | 1 | ||||
-rw-r--r-- | lib/redmine.rb | 6 | ||||
-rw-r--r-- | test/functional/timelog_controller_test.rb | 4 | ||||
-rw-r--r-- | test/integration/routing_test.rb | 3 |
6 files changed, 27 insertions, 12 deletions
diff --git a/app/controllers/timelog_controller.rb b/app/controllers/timelog_controller.rb index b9f8724a0..d533b10ef 100644 --- a/app/controllers/timelog_controller.rb +++ b/app/controllers/timelog_controller.rb @@ -17,7 +17,7 @@ class TimelogController < ApplicationController menu_item :issues - before_filter :find_project, :authorize, :only => [:new, :create, :edit, :destroy] + before_filter :find_project, :authorize, :only => [:new, :create, :edit, :update, :destroy] before_filter :find_optional_project, :only => [:index] verify :method => :post, :only => :destroy, :redirect_to => { :action => :index } @@ -111,18 +111,26 @@ class TimelogController < ApplicationController def edit (render_403; return) if @time_entry && !@time_entry.editable_by?(User.current) - @time_entry ||= TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => User.current.today) + @time_entry.attributes = params[:time_entry] + + call_hook(:controller_timelog_edit_before_save, { :params => params, :time_entry => @time_entry }) + end + + verify :method => :put, :only => :update, :render => {:nothing => true, :status => :method_not_allowed } + def update + (render_403; return) if @time_entry && !@time_entry.editable_by?(User.current) @time_entry.attributes = params[:time_entry] call_hook(:controller_timelog_edit_before_save, { :params => params, :time_entry => @time_entry }) - if request.post? and @time_entry.save + if @time_entry.save flash[:notice] = l(:notice_successful_update) redirect_back_or_default :action => 'index', :project_id => @time_entry.project - return + else + render :action => 'edit' end end - + def destroy (render_404; return) unless @time_entry (render_403; return) unless @time_entry.editable_by?(User.current) diff --git a/app/views/timelog/edit.rhtml b/app/views/timelog/edit.rhtml index 79a95b572..5ab977460 100644 --- a/app/views/timelog/edit.rhtml +++ b/app/views/timelog/edit.rhtml @@ -1,6 +1,11 @@ <h2><%= l(:label_spent_time) %></h2> -<% 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| %> +<% labelled_tabular_form_for(:time_entry, @time_entry, :url => { + :action => (@time_entry.new_record? ? 'create' : 'update'), + :id => @time_entry, + :project_id => @time_entry.project + }, + :html => {:method => @time_entry.new_record? ? :post : :put}) do |f| %> <%= error_messages_for 'time_entry' %> <%= back_url_hidden_field_tag %> diff --git a/config/routes.rb b/config/routes.rb index 702bcf89e..9e8a75a53 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -15,6 +15,7 @@ ActionController::Routing::Routes.draw do |map| map.connect 'help/:ctrl/:page', :controller => 'help' map.connect 'time_entries/:id/edit', :action => 'edit', :controller => 'timelog' + map.connect 'time_entries/:id', :action => 'update', :controller => 'timelog', :conditions => {:method => :put} map.connect 'projects/:project_id/time_entries/new', :action => 'new', :controller => 'timelog' map.connect 'projects/:project_id/issues/:issue_id/time_entries/new', :action => 'new', :controller => 'timelog' diff --git a/lib/redmine.rb b/lib/redmine.rb index 10bdf4c24..e5694a705 100644 --- a/lib/redmine.rb +++ b/lib/redmine.rb @@ -84,10 +84,10 @@ Redmine::AccessControl.map do |map| end map.project_module :time_tracking do |map| - map.permission :log_time, {:timelog => [:new, :create, :edit]}, :require => :loggedin + map.permission :log_time, {:timelog => [:new, :create, :edit, :update]}, :require => :loggedin map.permission :view_time_entries, :timelog => [:index], :time_entry_reports => [:report] - map.permission :edit_time_entries, {:timelog => [:new, :create, :edit, :destroy]}, :require => :member - map.permission :edit_own_time_entries, {:timelog => [:new, :create, :edit, :destroy]}, :require => :loggedin + map.permission :edit_time_entries, {:timelog => [:new, :create, :edit, :update, :destroy]}, :require => :member + map.permission :edit_own_time_entries, {:timelog => [:new, :create, :edit, :update, :destroy]}, :require => :loggedin map.permission :manage_project_activities, {:project_enumerations => [:update, :destroy]}, :require => :member end diff --git a/test/functional/timelog_controller_test.rb b/test/functional/timelog_controller_test.rb index 91b8ca47c..28ca93531 100644 --- a/test/functional/timelog_controller_test.rb +++ b/test/functional/timelog_controller_test.rb @@ -56,7 +56,7 @@ class TimelogControllerTest < ActionController::TestCase assert_response :success assert_template 'edit' # Default activity selected - assert_tag :tag => 'form', :attributes => { :action => '/projects/ecookbook/timelog/edit/2' } + assert_tag :tag => 'form', :attributes => { :action => '/projects/ecookbook/timelog/update/2' } end def test_get_edit_with_an_existing_time_entry_with_inactive_activity @@ -101,7 +101,7 @@ class TimelogControllerTest < ActionController::TestCase assert_equal 2, entry.user_id @request.session[:user_id] = 1 - post :edit, :id => 1, + put :update, :id => 1, :time_entry => {:issue_id => '2', :hours => '8'} assert_redirected_to :action => 'index', :project_id => 'ecookbook' diff --git a/test/integration/routing_test.rb b/test/integration/routing_test.rb index 8f96745bb..401ce960f 100644 --- a/test/integration/routing_test.rb +++ b/test/integration/routing_test.rb @@ -239,8 +239,9 @@ class RoutingTest < ActionController::IntegrationTest should_route :get, "/time_entries/22/edit", :controller => 'timelog', :action => 'edit', :id => '22' should_route :post, "/projects/ecookbook/timelog/edit", :controller => 'timelog', :action => 'create', :project_id => 'ecookbook' - should_route :post, "/time_entries/22/edit", :controller => 'timelog', :action => 'edit', :id => '22' should_route :post, "/time_entries/55/destroy", :controller => 'timelog', :action => 'destroy', :id => '55' + + should_route :put, "/time_entries/22", :controller => 'timelog', :action => 'update', :id => '22' end context "time_entry_reports" do |