Replaces TimeEntry.visible_by with a visible scope.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@5149 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
65333f1a6c
commit
3c19cacf97
@ -1,5 +1,5 @@
|
|||||||
# Redmine - project management software
|
# Redmine - project management software
|
||||||
# Copyright (C) 2006-2009 Jean-Philippe Lang
|
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@ -156,11 +156,10 @@ class ProjectsController < ApplicationController
|
|||||||
:include => [:project, :status, :tracker],
|
:include => [:project, :status, :tracker],
|
||||||
:conditions => cond)
|
:conditions => cond)
|
||||||
|
|
||||||
TimeEntry.visible_by(User.current) do
|
if User.current.allowed_to?(:view_time_entries, @project)
|
||||||
@total_hours = TimeEntry.sum(:hours,
|
@total_hours = TimeEntry.visible.sum(:hours, :include => :project, :conditions => cond).to_f
|
||||||
:include => :project,
|
|
||||||
:conditions => cond).to_f
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@key = User.current.rss_key
|
@key = User.current.rss_key
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
|
@ -40,60 +40,56 @@ class TimelogController < ApplicationController
|
|||||||
'hours' => 'hours'
|
'hours' => 'hours'
|
||||||
|
|
||||||
cond = ARCondition.new
|
cond = ARCondition.new
|
||||||
if @project.nil?
|
if @issue
|
||||||
cond << Project.allowed_to_condition(User.current, :view_time_entries)
|
|
||||||
elsif @issue.nil?
|
|
||||||
cond << @project.project_condition(Setting.display_subprojects_issues?)
|
|
||||||
else
|
|
||||||
cond << "#{Issue.table_name}.root_id = #{@issue.root_id} AND #{Issue.table_name}.lft >= #{@issue.lft} AND #{Issue.table_name}.rgt <= #{@issue.rgt}"
|
cond << "#{Issue.table_name}.root_id = #{@issue.root_id} AND #{Issue.table_name}.lft >= #{@issue.lft} AND #{Issue.table_name}.rgt <= #{@issue.rgt}"
|
||||||
|
elsif @project
|
||||||
|
cond << @project.project_condition(Setting.display_subprojects_issues?)
|
||||||
end
|
end
|
||||||
|
|
||||||
retrieve_date_range
|
retrieve_date_range
|
||||||
cond << ['spent_on BETWEEN ? AND ?', @from, @to]
|
cond << ['spent_on BETWEEN ? AND ?', @from, @to]
|
||||||
|
|
||||||
TimeEntry.visible_by(User.current) do
|
respond_to do |format|
|
||||||
respond_to do |format|
|
format.html {
|
||||||
format.html {
|
# Paginate results
|
||||||
# Paginate results
|
@entry_count = TimeEntry.visible.count(:include => [:project, :issue], :conditions => cond.conditions)
|
||||||
@entry_count = TimeEntry.count(:include => [:project, :issue], :conditions => cond.conditions)
|
@entry_pages = Paginator.new self, @entry_count, per_page_option, params['page']
|
||||||
@entry_pages = Paginator.new self, @entry_count, per_page_option, params['page']
|
@entries = TimeEntry.visible.find(:all,
|
||||||
@entries = TimeEntry.find(:all,
|
:include => [:project, :activity, :user, {:issue => :tracker}],
|
||||||
:include => [:project, :activity, :user, {:issue => :tracker}],
|
:conditions => cond.conditions,
|
||||||
:conditions => cond.conditions,
|
:order => sort_clause,
|
||||||
:order => sort_clause,
|
:limit => @entry_pages.items_per_page,
|
||||||
:limit => @entry_pages.items_per_page,
|
:offset => @entry_pages.current.offset)
|
||||||
:offset => @entry_pages.current.offset)
|
@total_hours = TimeEntry.visible.sum(:hours, :include => [:project, :issue], :conditions => cond.conditions).to_f
|
||||||
@total_hours = TimeEntry.sum(:hours, :include => [:project, :issue], :conditions => cond.conditions).to_f
|
|
||||||
|
|
||||||
render :layout => !request.xhr?
|
render :layout => !request.xhr?
|
||||||
}
|
}
|
||||||
format.api {
|
format.api {
|
||||||
@entry_count = TimeEntry.count(:include => [:project, :issue], :conditions => cond.conditions)
|
@entry_count = TimeEntry.visible.count(:include => [:project, :issue], :conditions => cond.conditions)
|
||||||
@entry_pages = Paginator.new self, @entry_count, per_page_option, params['page']
|
@entry_pages = Paginator.new self, @entry_count, per_page_option, params['page']
|
||||||
@entries = TimeEntry.find(:all,
|
@entries = TimeEntry.visible.find(:all,
|
||||||
:include => [:project, :activity, :user, {:issue => :tracker}],
|
:include => [:project, :activity, :user, {:issue => :tracker}],
|
||||||
:conditions => cond.conditions,
|
:conditions => cond.conditions,
|
||||||
:order => sort_clause,
|
:order => sort_clause,
|
||||||
:limit => @entry_pages.items_per_page,
|
:limit => @entry_pages.items_per_page,
|
||||||
:offset => @entry_pages.current.offset)
|
:offset => @entry_pages.current.offset)
|
||||||
}
|
}
|
||||||
format.atom {
|
format.atom {
|
||||||
entries = TimeEntry.find(:all,
|
entries = TimeEntry.visible.find(:all,
|
||||||
:include => [:project, :activity, :user, {:issue => :tracker}],
|
:include => [:project, :activity, :user, {:issue => :tracker}],
|
||||||
:conditions => cond.conditions,
|
:conditions => cond.conditions,
|
||||||
:order => "#{TimeEntry.table_name}.created_on DESC",
|
:order => "#{TimeEntry.table_name}.created_on DESC",
|
||||||
:limit => Setting.feeds_limit.to_i)
|
:limit => Setting.feeds_limit.to_i)
|
||||||
render_feed(entries, :title => l(:label_spent_time))
|
render_feed(entries, :title => l(:label_spent_time))
|
||||||
}
|
}
|
||||||
format.csv {
|
format.csv {
|
||||||
# Export all entries
|
# Export all entries
|
||||||
@entries = TimeEntry.find(:all,
|
@entries = TimeEntry.visible.find(:all,
|
||||||
:include => [:project, :activity, :user, {:issue => [:tracker, :assigned_to, :priority]}],
|
:include => [:project, :activity, :user, {:issue => [:tracker, :assigned_to, :priority]}],
|
||||||
:conditions => cond.conditions,
|
:conditions => cond.conditions,
|
||||||
:order => sort_clause)
|
:order => sort_clause)
|
||||||
send_data(entries_to_csv(@entries), :type => 'text/csv; header=present', :filename => 'timelog.csv')
|
send_data(entries_to_csv(@entries), :type => 'text/csv; header=present', :filename => 'timelog.csv')
|
||||||
}
|
}
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# redMine - project management software
|
# Redmine - project management software
|
||||||
# Copyright (C) 2006-2008 Jean-Philippe Lang
|
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@ -38,6 +38,11 @@ class TimeEntry < ActiveRecord::Base
|
|||||||
validates_presence_of :user_id, :activity_id, :project_id, :hours, :spent_on
|
validates_presence_of :user_id, :activity_id, :project_id, :hours, :spent_on
|
||||||
validates_numericality_of :hours, :allow_nil => true, :message => :invalid
|
validates_numericality_of :hours, :allow_nil => true, :message => :invalid
|
||||||
validates_length_of :comments, :maximum => 255, :allow_nil => true
|
validates_length_of :comments, :maximum => 255, :allow_nil => true
|
||||||
|
|
||||||
|
named_scope :visible, lambda {|*args| {
|
||||||
|
:include => :project,
|
||||||
|
:conditions => Project.allowed_to_condition(args.first || User.current, :view_time_entries)
|
||||||
|
}}
|
||||||
|
|
||||||
def after_initialize
|
def after_initialize
|
||||||
if new_record? && self.activity.nil?
|
if new_record? && self.activity.nil?
|
||||||
@ -79,7 +84,9 @@ class TimeEntry < ActiveRecord::Base
|
|||||||
(usr == user && usr.allowed_to?(:edit_own_time_entries, project)) || usr.allowed_to?(:edit_time_entries, project)
|
(usr == user && usr.allowed_to?(:edit_own_time_entries, project)) || usr.allowed_to?(:edit_time_entries, project)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# TODO: remove this method in 1.3.0
|
||||||
def self.visible_by(usr)
|
def self.visible_by(usr)
|
||||||
|
ActiveSupport::Deprecation.warn "TimeEntry.visible_by is deprecated and will be removed in Redmine 1.3.0. Use the visible scope instead."
|
||||||
with_scope(:find => { :conditions => Project.allowed_to_condition(usr, :view_time_entries) }) do
|
with_scope(:find => { :conditions => Project.allowed_to_condition(usr, :view_time_entries) }) do
|
||||||
yield
|
yield
|
||||||
end
|
end
|
||||||
|
@ -64,7 +64,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<% content_for :sidebar do %>
|
<% content_for :sidebar do %>
|
||||||
<% if @total_hours && User.current.allowed_to?(:view_time_entries, @project) %>
|
<% if @total_hours.present? %>
|
||||||
<h3><%= l(:label_spent_time) %></h3>
|
<h3><%= l(:label_spent_time) %></h3>
|
||||||
<p><span class="icon icon-time"><%= l_hours(@total_hours) %></span></p>
|
<p><span class="icon icon-time"><%= l_hours(@total_hours) %></span></p>
|
||||||
<p>
|
<p>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user