##// END OF EJS Templates
Refactor: extract TimelogController#create from TimelogController#edit...
Eric Davis -
r4130:4acd990ee295
parent child
Show More
@@ -17,7 +17,7
17 17
18 18 class TimelogController < ApplicationController
19 19 menu_item :issues
20 before_filter :find_project, :authorize, :only => [:new, :edit, :destroy]
20 before_filter :find_project, :authorize, :only => [:new, :create, :edit, :destroy]
21 21 before_filter :find_optional_project, :only => [:index]
22 22
23 23 verify :method => :post, :only => :destroy, :redirect_to => { :action => :index }
@@ -93,6 +93,21 class TimelogController < ApplicationController
93 93 call_hook(:controller_timelog_edit_before_save, { :params => params, :time_entry => @time_entry })
94 94 render :action => 'edit'
95 95 end
96
97 verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed }
98 def create
99 @time_entry ||= TimeEntry.new(:project => @project, :issue => @issue, :user => User.current, :spent_on => User.current.today)
100 @time_entry.attributes = params[:time_entry]
101
102 call_hook(:controller_timelog_edit_before_save, { :params => params, :time_entry => @time_entry })
103
104 if @time_entry.save
105 flash[:notice] = l(:notice_successful_update)
106 redirect_back_or_default :action => 'index', :project_id => @time_entry.project
107 else
108 render :action => 'edit'
109 end
110 end
96 111
97 112 def edit
98 113 (render_403; return) if @time_entry && !@time_entry.editable_by?(User.current)
@@ -1,6 +1,6
1 1 <h2><%= l(:label_spent_time) %></h2>
2 2
3 <% labelled_tabular_form_for :time_entry, @time_entry, :url => {:action => 'edit', :id => @time_entry, :project_id => @time_entry.project} do |f| %>
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| %>
4 4 <%= error_messages_for 'time_entry' %>
5 5 <%= back_url_hidden_field_tag %>
6 6
@@ -40,7 +40,8 ActionController::Routing::Routes.draw do |map|
40 40 timelog.with_options :action => 'new', :conditions => {:method => :get} do |time_edit|
41 41 time_edit.connect 'issues/:issue_id/time_entries/new'
42 42 end
43
43
44 timelog.connect 'projects/:project_id/timelog/edit', :action => 'create', :conditions => {:method => :post}
44 45 timelog.connect 'time_entries/:id/destroy', :action => 'destroy', :conditions => {:method => :post}
45 46 end
46 47
@@ -84,10 +84,10 Redmine::AccessControl.map do |map|
84 84 end
85 85
86 86 map.project_module :time_tracking do |map|
87 map.permission :log_time, {:timelog => :edit}, :require => :loggedin
87 map.permission :log_time, {:timelog => [:new, :create, :edit]}, :require => :loggedin
88 88 map.permission :view_time_entries, :timelog => [:index], :time_entry_reports => [:report]
89 map.permission :edit_time_entries, {:timelog => [:new, :edit, :destroy]}, :require => :member
90 map.permission :edit_own_time_entries, {:timelog => [:new, :edit, :destroy]}, :require => :loggedin
89 map.permission :edit_time_entries, {:timelog => [:new, :create, :edit, :destroy]}, :require => :member
90 map.permission :edit_own_time_entries, {:timelog => [:new, :create, :edit, :destroy]}, :require => :loggedin
91 91 map.permission :manage_project_activities, {:project_enumerations => [:update, :destroy]}, :require => :member
92 92 end
93 93
@@ -72,11 +72,11 class TimelogControllerTest < ActionController::TestCase
72 72 assert_tag :tag => 'option', :content => '--- Please select ---'
73 73 end
74 74
75 def test_post_edit
75 def test_post_create
76 76 # TODO: should POST to issues’ time log instead of project. change form
77 77 # and routing
78 78 @request.session[:user_id] = 3
79 post :edit, :project_id => 1,
79 post :create, :project_id => 1,
80 80 :time_entry => {:comments => 'Some work on TimelogControllerTest',
81 81 # Not the default activity
82 82 :activity_id => '11',
@@ -238,6 +238,7 class RoutingTest < ActionController::IntegrationTest
238 238 should_route :get, "/projects/ecookbook/issues/567/time_entries/new", :controller => 'timelog', :action => 'new', :project_id => 'ecookbook', :issue_id => '567'
239 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 242 should_route :post, "/time_entries/22/edit", :controller => 'timelog', :action => 'edit', :id => '22'
242 243 should_route :post, "/time_entries/55/destroy", :controller => 'timelog', :action => 'destroy', :id => '55'
243 244 end
General Comments 0
You need to be logged in to leave comments. Login now