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