##// END OF EJS Templates
r18645@gaspard (orig r1887): jplang | 2008-09-20 16:07:52 +0200...
r18645@gaspard (orig r1887): jplang | 2008-09-20 16:07:52 +0200 Fixed: Roadmap crashes when a version has a due date > 2037. r18646@gaspard (orig r1888): jplang | 2008-09-21 10:54:02 +0200 Fixed: invalid effective date (eg. 99999-01-01) causes an error on version edition screen. r18647@gaspard (orig r1889): jplang | 2008-09-21 10:54:50 +0200 Fixes VersionTest class. r18648@gaspard (orig r1890): jplang | 2008-09-21 14:07:44 +0200 Fixed: login filter providing incorrect back_url for Redmine installed in sub-directory (#1900). r18649@gaspard (orig r1891): winterheart | 2008-09-21 14:31:34 +0200 de.yml from #1745, thank to Sven Schuchmann and Thomas Löber for contribution r18650@gaspard (orig r1892): winterheart | 2008-09-21 14:32:16 +0200 #1928, update for Italian language r18651@gaspard (orig r1893): jplang | 2008-09-21 14:45:22 +0200 Unescape back_url param before calling redirect_to. r18652@gaspard (orig r1894): jplang | 2008-09-21 15:28:12 +0200 Strip LDAP attribute names before saving (#1890). r18653@gaspard (orig r1895): jplang | 2008-09-21 20:45:30 +0200 Switch order of current and previous revisions in side-by-side diff (#1903). r18654@gaspard (orig r1896): jplang | 2008-09-21 22:38:36 +0200 Typo in migration 97 name (#1929). r18655@gaspard (orig r1897): winterheart | 2008-09-22 16:49:18 +0200 #1921, pt translation git-svn-id: http://redmine.rubyforge.org/svn/branches/nbc@1898 e93f8b46-1217-0410-a6f0-8f06a7374b81

File last commit:

r1672:898fac293b3d
r1896:9b94342bc3ba
Show More
time_entry.rb
79 lines | 3.1 KiB | text/x-ruby | RubyLexer
# redMine - project management software
# Copyright (C) 2006-2008 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class TimeEntry < ActiveRecord::Base
# could have used polymorphic association
# project association here allows easy loading of time entries at project level with one database trip
belongs_to :project
belongs_to :issue
belongs_to :user
belongs_to :activity, :class_name => 'Enumeration', :foreign_key => :activity_id
attr_protected :project_id, :user_id, :tyear, :tmonth, :tweek
acts_as_customizable
acts_as_event :title => Proc.new {|o| "#{o.user}: #{lwr(:label_f_hour, o.hours)} (#{(o.issue || o.project).event_title})"},
:url => Proc.new {|o| {:controller => 'timelog', :action => 'details', :project_id => o.project}},
:author => :user,
:description => :comments
validates_presence_of :user_id, :activity_id, :project_id, :hours, :spent_on
validates_numericality_of :hours, :allow_nil => true
validates_length_of :comments, :maximum => 255, :allow_nil => true
def after_initialize
if new_record? && self.activity.nil?
if default_activity = Enumeration.default('ACTI')
self.activity_id = default_activity.id
end
end
end
def before_validation
self.project = issue.project if issue && project.nil?
end
def validate
errors.add :hours, :activerecord_error_invalid if hours && (hours < 0 || hours >= 1000)
errors.add :project_id, :activerecord_error_invalid if project.nil?
errors.add :issue_id, :activerecord_error_invalid if (issue_id && !issue) || (issue && project!=issue.project)
end
def hours=(h)
write_attribute :hours, (h.is_a?(String) ? h.to_hours : h)
end
# tyear, tmonth, tweek assigned where setting spent_on attributes
# these attributes make time aggregations easier
def spent_on=(date)
super
self.tyear = spent_on ? spent_on.year : nil
self.tmonth = spent_on ? spent_on.month : nil
self.tweek = spent_on ? Date.civil(spent_on.year, spent_on.month, spent_on.day).cweek : nil
end
# Returns true if the time entry can be edited by usr, otherwise false
def editable_by?(usr)
(usr == user && usr.allowed_to?(:edit_own_time_entries, project)) || usr.allowed_to?(:edit_time_entries, project)
end
def self.visible_by(usr)
with_scope(:find => { :conditions => Project.allowed_to_condition(usr, :view_time_entries) }) do
yield
end
end
end