##// END OF EJS Templates
Replaces TimeEntry.visible_by with a visible scope....
Jean-Philippe Lang -
r5029:0786b9ef99b0
parent child
Show More
@@ -1,5 +1,5
1 1 # Redmine - project management software
2 # Copyright (C) 2006-2009 Jean-Philippe Lang
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
@@ -156,11 +156,10 class ProjectsController < ApplicationController
156 156 :include => [:project, :status, :tracker],
157 157 :conditions => cond)
158 158
159 TimeEntry.visible_by(User.current) do
160 @total_hours = TimeEntry.sum(:hours,
161 :include => :project,
162 :conditions => cond).to_f
159 if User.current.allowed_to?(:view_time_entries, @project)
160 @total_hours = TimeEntry.visible.sum(:hours, :include => :project, :conditions => cond).to_f
163 161 end
162
164 163 @key = User.current.rss_key
165 164
166 165 respond_to do |format|
@@ -40,60 +40,56 class TimelogController < ApplicationController
40 40 'hours' => 'hours'
41 41
42 42 cond = ARCondition.new
43 if @project.nil?
44 cond << Project.allowed_to_condition(User.current, :view_time_entries)
45 elsif @issue.nil?
46 cond << @project.project_condition(Setting.display_subprojects_issues?)
47 else
43 if @issue
48 44 cond << "#{Issue.table_name}.root_id = #{@issue.root_id} AND #{Issue.table_name}.lft >= #{@issue.lft} AND #{Issue.table_name}.rgt <= #{@issue.rgt}"
45 elsif @project
46 cond << @project.project_condition(Setting.display_subprojects_issues?)
49 47 end
50 48
51 49 retrieve_date_range
52 50 cond << ['spent_on BETWEEN ? AND ?', @from, @to]
53 51
54 TimeEntry.visible_by(User.current) do
55 respond_to do |format|
56 format.html {
57 # Paginate results
58 @entry_count = TimeEntry.count(:include => [:project, :issue], :conditions => cond.conditions)
59 @entry_pages = Paginator.new self, @entry_count, per_page_option, params['page']
60 @entries = TimeEntry.find(:all,
61 :include => [:project, :activity, :user, {:issue => :tracker}],
62 :conditions => cond.conditions,
63 :order => sort_clause,
64 :limit => @entry_pages.items_per_page,
65 :offset => @entry_pages.current.offset)
66 @total_hours = TimeEntry.sum(:hours, :include => [:project, :issue], :conditions => cond.conditions).to_f
52 respond_to do |format|
53 format.html {
54 # Paginate results
55 @entry_count = TimeEntry.visible.count(:include => [:project, :issue], :conditions => cond.conditions)
56 @entry_pages = Paginator.new self, @entry_count, per_page_option, params['page']
57 @entries = TimeEntry.visible.find(:all,
58 :include => [:project, :activity, :user, {:issue => :tracker}],
59 :conditions => cond.conditions,
60 :order => sort_clause,
61 :limit => @entry_pages.items_per_page,
62 :offset => @entry_pages.current.offset)
63 @total_hours = TimeEntry.visible.sum(:hours, :include => [:project, :issue], :conditions => cond.conditions).to_f
67 64
68 render :layout => !request.xhr?
69 }
70 format.api {
71 @entry_count = TimeEntry.count(:include => [:project, :issue], :conditions => cond.conditions)
72 @entry_pages = Paginator.new self, @entry_count, per_page_option, params['page']
73 @entries = TimeEntry.find(:all,
74 :include => [:project, :activity, :user, {:issue => :tracker}],
75 :conditions => cond.conditions,
76 :order => sort_clause,
77 :limit => @entry_pages.items_per_page,
78 :offset => @entry_pages.current.offset)
79 }
80 format.atom {
81 entries = TimeEntry.find(:all,
82 :include => [:project, :activity, :user, {:issue => :tracker}],
83 :conditions => cond.conditions,
84 :order => "#{TimeEntry.table_name}.created_on DESC",
85 :limit => Setting.feeds_limit.to_i)
86 render_feed(entries, :title => l(:label_spent_time))
87 }
88 format.csv {
89 # Export all entries
90 @entries = TimeEntry.find(:all,
91 :include => [:project, :activity, :user, {:issue => [:tracker, :assigned_to, :priority]}],
92 :conditions => cond.conditions,
93 :order => sort_clause)
94 send_data(entries_to_csv(@entries), :type => 'text/csv; header=present', :filename => 'timelog.csv')
95 }
96 end
65 render :layout => !request.xhr?
66 }
67 format.api {
68 @entry_count = TimeEntry.visible.count(:include => [:project, :issue], :conditions => cond.conditions)
69 @entry_pages = Paginator.new self, @entry_count, per_page_option, params['page']
70 @entries = TimeEntry.visible.find(:all,
71 :include => [:project, :activity, :user, {:issue => :tracker}],
72 :conditions => cond.conditions,
73 :order => sort_clause,
74 :limit => @entry_pages.items_per_page,
75 :offset => @entry_pages.current.offset)
76 }
77 format.atom {
78 entries = TimeEntry.visible.find(:all,
79 :include => [:project, :activity, :user, {:issue => :tracker}],
80 :conditions => cond.conditions,
81 :order => "#{TimeEntry.table_name}.created_on DESC",
82 :limit => Setting.feeds_limit.to_i)
83 render_feed(entries, :title => l(:label_spent_time))
84 }
85 format.csv {
86 # Export all entries
87 @entries = TimeEntry.visible.find(:all,
88 :include => [:project, :activity, :user, {:issue => [:tracker, :assigned_to, :priority]}],
89 :conditions => cond.conditions,
90 :order => sort_clause)
91 send_data(entries_to_csv(@entries), :type => 'text/csv; header=present', :filename => 'timelog.csv')
92 }
97 93 end
98 94 end
99 95
@@ -1,5 +1,5
1 # redMine - project management software
2 # Copyright (C) 2006-2008 Jean-Philippe Lang
1 # Redmine - project management software
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
@@ -38,6 +38,11 class TimeEntry < ActiveRecord::Base
38 38 validates_presence_of :user_id, :activity_id, :project_id, :hours, :spent_on
39 39 validates_numericality_of :hours, :allow_nil => true, :message => :invalid
40 40 validates_length_of :comments, :maximum => 255, :allow_nil => true
41
42 named_scope :visible, lambda {|*args| {
43 :include => :project,
44 :conditions => Project.allowed_to_condition(args.first || User.current, :view_time_entries)
45 }}
41 46
42 47 def after_initialize
43 48 if new_record? && self.activity.nil?
@@ -79,7 +84,9 class TimeEntry < ActiveRecord::Base
79 84 (usr == user && usr.allowed_to?(:edit_own_time_entries, project)) || usr.allowed_to?(:edit_time_entries, project)
80 85 end
81 86
87 # TODO: remove this method in 1.3.0
82 88 def self.visible_by(usr)
89 ActiveSupport::Deprecation.warn "TimeEntry.visible_by is deprecated and will be removed in Redmine 1.3.0. Use the visible scope instead."
83 90 with_scope(:find => { :conditions => Project.allowed_to_condition(usr, :view_time_entries) }) do
84 91 yield
85 92 end
@@ -64,7 +64,7
64 64 </div>
65 65
66 66 <% content_for :sidebar do %>
67 <% if @total_hours && User.current.allowed_to?(:view_time_entries, @project) %>
67 <% if @total_hours.present? %>
68 68 <h3><%= l(:label_spent_time) %></h3>
69 69 <p><span class="icon icon-time"><%= l_hours(@total_hours) %></span></p>
70 70 <p><%= link_to(l(:label_details), {:controller => 'timelog', :action => 'index', :project_id => @project}) %> |
General Comments 0
You need to be logged in to leave comments. Login now