##// END OF EJS Templates
Enable global time logging at /time_entries/new (#10020)....
Jean-Philippe Lang -
r8571:41eab6615b31
parent child
Show More
@@ -17,11 +17,15
17
17
18 class TimelogController < ApplicationController
18 class TimelogController < ApplicationController
19 menu_item :issues
19 menu_item :issues
20 before_filter :find_project, :only => [:new, :create]
20
21 before_filter :find_project, :only => [:create]
21 before_filter :find_time_entry, :only => [:show, :edit, :update]
22 before_filter :find_time_entry, :only => [:show, :edit, :update]
22 before_filter :find_time_entries, :only => [:bulk_edit, :bulk_update, :destroy]
23 before_filter :find_time_entries, :only => [:bulk_edit, :bulk_update, :destroy]
23 before_filter :authorize, :except => [:index, :report]
24 before_filter :authorize, :except => [:new, :index, :report]
24 before_filter :find_optional_project, :only => [:index, :report]
25
26 before_filter :find_optional_project, :only => [:new, :index, :report]
27 before_filter :authorize_global, :only => [:new, :index, :report]
28
25 accept_rss_auth :index
29 accept_rss_auth :index
26 accept_api_auth :index, :show, :create, :update, :destroy
30 accept_api_auth :index, :show, :create, :update, :destroy
27
31
@@ -129,7 +133,11 class TimelogController < ApplicationController
129 format.html {
133 format.html {
130 flash[:notice] = l(:notice_successful_create)
134 flash[:notice] = l(:notice_successful_create)
131 if params[:continue]
135 if params[:continue]
132 redirect_to :action => 'new', :project_id => @time_entry.project, :issue_id => @time_entry.issue
136 if params[:project_id]
137 redirect_to :action => 'new', :project_id => @time_entry.project, :issue_id => @time_entry.issue
138 else
139 redirect_to :action => 'new'
140 end
133 else
141 else
134 redirect_back_or_default :action => 'index', :project_id => @time_entry.project
142 redirect_back_or_default :action => 'index', :project_id => @time_entry.project
135 end
143 end
@@ -138,7 +146,7 class TimelogController < ApplicationController
138 end
146 end
139 else
147 else
140 respond_to do |format|
148 respond_to do |format|
141 format.html { render :action => 'edit' }
149 format.html { render :action => 'new' }
142 format.api { render_validation_errors(@time_entry) }
150 format.api { render_validation_errors(@time_entry) }
143 end
151 end
144 end
152 end
@@ -274,7 +282,6 private
274 elsif !params[:project_id].blank?
282 elsif !params[:project_id].blank?
275 @project = Project.find(params[:project_id])
283 @project = Project.find(params[:project_id])
276 end
284 end
277 deny_access unless User.current.allowed_to?(:view_time_entries, @project, :global => true)
278 end
285 end
279
286
280 # Retrieves the date range based on predefined ranges or specific from/to param dates
287 # Retrieves the date range based on predefined ranges or specific from/to param dates
@@ -87,6 +87,17 class Project < ActiveRecord::Base
87 named_scope :status, lambda {|arg| arg.blank? ? {} : {:conditions => {:status => arg.to_i}} }
87 named_scope :status, lambda {|arg| arg.blank? ? {} : {:conditions => {:status => arg.to_i}} }
88 named_scope :all_public, { :conditions => { :is_public => true } }
88 named_scope :all_public, { :conditions => { :is_public => true } }
89 named_scope :visible, lambda {|*args| {:conditions => Project.visible_condition(args.shift || User.current, *args) }}
89 named_scope :visible, lambda {|*args| {:conditions => Project.visible_condition(args.shift || User.current, *args) }}
90 named_scope :allowed_to, lambda {|*args|
91 user = User.current
92 permission = nil
93 if args.first.is_a?(Symbol)
94 permission = args.shift
95 else
96 user = args.shift
97 permission = args.shift
98 end
99 { :conditions => Project.allowed_to_condition(user, permission, *args) }
100 }
90 named_scope :like, lambda {|arg|
101 named_scope :like, lambda {|arg|
91 if arg.blank?
102 if arg.blank?
92 {}
103 {}
@@ -2,6 +2,13
2 <%= back_url_hidden_field_tag %>
2 <%= back_url_hidden_field_tag %>
3
3
4 <div class="box tabular">
4 <div class="box tabular">
5 <% if @time_entry.new_record? %>
6 <% if params[:project_id] %>
7 <%= f.hidden_field :project_id %>
8 <% else %>
9 <p><%= f.select :project_id, project_tree_options_for_select(Project.allowed_to(:log_time).all, :selected => @time_entry.project), :required => true %></p>
10 <% end %>
11 <% end %>
5 <p><%= f.text_field :issue_id, :size => 6 %> <em><%= h("#{@time_entry.issue.tracker.name} ##{@time_entry.issue.id}: #{@time_entry.issue.subject}") if @time_entry.issue %></em></p>
12 <p><%= f.text_field :issue_id, :size => 6 %> <em><%= h("#{@time_entry.issue.tracker.name} ##{@time_entry.issue.id}: #{@time_entry.issue.subject}") if @time_entry.issue %></em></p>
6 <p><%= f.text_field :spent_on, :size => 10, :required => true %><%= calendar_for('time_entry_spent_on') %></p>
13 <p><%= f.text_field :spent_on, :size => 10, :required => true %><%= calendar_for('time_entry_spent_on') %></p>
7 <p><%= f.text_field :hours, :size => 6, :required => true %></p>
14 <p><%= f.text_field :hours, :size => 6, :required => true %></p>
@@ -1,5 +1,7
1 <div class="contextual">
1 <div class="contextual">
2 <%= link_to_if_authorized l(:button_log_time), {:controller => 'timelog', :action => 'new', :project_id => @project, :issue_id => @issue}, :class => 'icon icon-time-add' %>
2 <%= link_to l(:button_log_time),
3 {:controller => 'timelog', :action => 'new', :project_id => @project, :issue_id => @issue},
4 :class => 'icon icon-time-add' if User.current.allowed_to?(:log_time, @project, :global => true) %>
3 </div>
5 </div>
4
6
5 <%= render_timelog_breadcrumb %>
7 <%= render_timelog_breadcrumb %>
@@ -1,6 +1,6
1 <h2><%= l(:label_spent_time) %></h2>
1 <h2><%= l(:label_spent_time) %></h2>
2
2
3 <% labelled_form_for @time_entry, :url => project_time_entries_path(@time_entry.project) do |f| %>
3 <% labelled_form_for @time_entry, :url => time_entries_path do |f| %>
4 <%= render :partial => 'form', :locals => {:f => f} %>
4 <%= render :partial => 'form', :locals => {:f => f} %>
5 <%= submit_tag l(:button_create) %>
5 <%= submit_tag l(:button_create) %>
6 <%= submit_tag l(:button_create_and_continue), :name => 'continue' %>
6 <%= submit_tag l(:button_create_and_continue), :name => 'continue' %>
@@ -51,7 +51,24 class TimelogControllerTest < ActionController::TestCase
51 get :new, :project_id => 1
51 get :new, :project_id => 1
52 assert_response :success
52 assert_response :success
53 assert_template 'new'
53 assert_template 'new'
54 assert_no_tag :tag => 'option', :content => 'Inactive Activity'
54 assert_no_tag 'select', :attributes => {:name => 'time_entry[project_id]'}
55 assert_no_tag 'option', :content => 'Inactive Activity'
56 end
57
58 def test_new_without_project
59 @request.session[:user_id] = 3
60 get :new
61 assert_response :success
62 assert_template 'new'
63 assert_tag 'select', :attributes => {:name => 'time_entry[project_id]'}
64 end
65
66 def test_new_without_project_should_deny_without_permission
67 Role.all.each {|role| role.remove_permission! :log_time}
68 @request.session[:user_id] = 3
69
70 get :new
71 assert_response 403
55 end
72 end
56
73
57 def test_get_edit_existing_time
74 def test_get_edit_existing_time
@@ -141,6 +158,18 class TimelogControllerTest < ActionController::TestCase
141 assert_redirected_to '/projects/ecookbook/issues/1/time_entries/new'
158 assert_redirected_to '/projects/ecookbook/issues/1/time_entries/new'
142 end
159 end
143
160
161 def test_create_and_continue_without_project
162 @request.session[:user_id] = 2
163 post :create, :time_entry => {:project_id => '1',
164 :activity_id => '11',
165 :issue_id => '',
166 :spent_on => '2008-03-14',
167 :hours => '7.3'},
168 :continue => '1'
169
170 assert_redirected_to '/time_entries/new'
171 end
172
144 def test_create_without_log_time_permission_should_be_denied
173 def test_create_without_log_time_permission_should_be_denied
145 @request.session[:user_id] = 2
174 @request.session[:user_id] = 2
146 Role.find_by_name('Manager').remove_permission! :log_time
175 Role.find_by_name('Manager').remove_permission! :log_time
@@ -153,6 +182,63 class TimelogControllerTest < ActionController::TestCase
153 assert_response 403
182 assert_response 403
154 end
183 end
155
184
185 def test_create_with_failure
186 @request.session[:user_id] = 2
187 post :create, :project_id => 1,
188 :time_entry => {:activity_id => '',
189 :issue_id => '',
190 :spent_on => '2008-03-14',
191 :hours => '7.3'}
192
193 assert_response :success
194 assert_template 'new'
195 end
196
197 def test_create_without_project
198 @request.session[:user_id] = 2
199 assert_difference 'TimeEntry.count' do
200 post :create, :time_entry => {:project_id => '1',
201 :activity_id => '11',
202 :issue_id => '',
203 :spent_on => '2008-03-14',
204 :hours => '7.3'}
205 end
206
207 assert_redirected_to '/projects/ecookbook/time_entries'
208 time_entry = TimeEntry.first(:order => 'id DESC')
209 assert_equal 1, time_entry.project_id
210 end
211
212 def test_create_without_project_should_deny_without_permission
213 @request.session[:user_id] = 2
214 Project.find(3).disable_module!(:time_tracking)
215
216 assert_no_difference 'TimeEntry.count' do
217 post :create, :time_entry => {:project_id => '3',
218 :activity_id => '11',
219 :issue_id => '',
220 :spent_on => '2008-03-14',
221 :hours => '7.3'}
222 end
223
224 assert_response 403
225 end
226
227 def test_create_without_project_with_failure
228 @request.session[:user_id] = 2
229 assert_no_difference 'TimeEntry.count' do
230 post :create, :time_entry => {:project_id => '1',
231 :activity_id => '11',
232 :issue_id => '',
233 :spent_on => '2008-03-14',
234 :hours => ''}
235 end
236
237 assert_response :success
238 assert_tag 'select', :attributes => {:name => 'time_entry[project_id]'},
239 :child => {:tag => 'option', :attributes => {:value => '1', :selected => 'selected'}}
240 end
241
156 def test_update
242 def test_update
157 entry = TimeEntry.find(1)
243 entry = TimeEntry.find(1)
158 assert_equal 1, entry.issue_id
244 assert_equal 1, entry.issue_id
@@ -289,6 +375,14 class TimelogControllerTest < ActionController::TestCase
289 :attributes => {:action => "/time_entries", :id => 'query_form'}
375 :attributes => {:action => "/time_entries", :id => 'query_form'}
290 end
376 end
291
377
378 def test_index_all_projects_should_show_log_time_link
379 @request.session[:user_id] = 2
380 get :index
381 assert_response :success
382 assert_template 'index'
383 assert_tag 'a', :attributes => {:href => '/time_entries/new'}, :content => /Log time/
384 end
385
292 def test_index_at_project_level
386 def test_index_at_project_level
293 get :index, :project_id => 'ecookbook'
387 get :index, :project_id => 'ecookbook'
294 assert_response :success
388 assert_response :success
General Comments 0
You need to be logged in to leave comments. Login now