##// END OF EJS Templates
Adds edit links on the roadmap (#22756)....
Adds edit links on the roadmap (#22756). git-svn-id: http://svn.redmine.org/redmine/trunk@15370 e93f8b46-1217-0410-a6f0-8f06a7374b81

File last commit:

r14856:cda9c63d9c21
r14988:860ae0631ad5
Show More
time_entry.rb
160 lines | 5.6 KiB | text/x-ruby | RubyLexer
Jean-Philippe Lang
Replaces TimeEntry.visible_by with a visible scope....
r5029 # Redmine - project management software
Jean-Philippe Lang
Updates copyright for 2016....
r14856 # Copyright (C) 2006-2016 Jean-Philippe Lang
Jean-Philippe Lang
Added time report....
r569 #
# 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.
Toshi MARUYAMA
remove trailing white-spaces from time entry model source....
r5700 #
Jean-Philippe Lang
Added time report....
r569 # 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.
Toshi MARUYAMA
remove trailing white-spaces from time entry model source....
r5700 #
Jean-Philippe Lang
Added time report....
r569 # 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.
Jean-Philippe Lang
Simple time tracking functionality added. Time can be logged at issue or project level....
r365 class TimeEntry < ActiveRecord::Base
Jean-Philippe Lang
Prevent mass-assignment when adding/updating a time entry (#10390)....
r9016 include Redmine::SafeAttributes
Jean-Philippe Lang
Simple time tracking functionality added. Time can be logged at issue or project level....
r365 # 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
Jean-Philippe Lang
Removed unneeded :foreign_key option on belongs_to associations....
r13102 belongs_to :activity, :class_name => 'TimeEntryActivity'
Toshi MARUYAMA
remove trailing white-spaces from time entry model source....
r5700
Jean-Philippe Lang
Let the new time_entry form be submitted without project (#17954)....
r13058 attr_protected :user_id, :tyear, :tmonth, :tweek
Jean-Philippe Lang
Adds atom feed on time entries details (#1479)....
r1546
Jean-Philippe Lang
Adds custom fields on time entries (#772)....
r1672 acts_as_customizable
Jean-Philippe Lang
Adds spent time to the activity view (#3809)....
r2763 acts_as_event :title => Proc.new {|o| "#{l_hours(o.hours)} (#{(o.issue || o.project).event_title})"},
Jean-Philippe Lang
Fixed: timelog link in the activity broken by recent refactoring (#6702)....
r4163 :url => Proc.new {|o| {:controller => 'timelog', :action => 'index', :project_id => o.project, :issue_id => o.issue}},
Jean-Philippe Lang
Adds atom feed on time entries details (#1479)....
r1546 :author => :user,
Jean-Philippe Lang
Group events in the activity view (#12542)....
r10724 :group => :issue,
Jean-Philippe Lang
Adds atom feed on time entries details (#1479)....
r1546 :description => :comments
Jean-Philippe Lang
Adds spent time to the activity view (#3809)....
r2763
acts_as_activity_provider :timestamp => "#{table_name}.created_on",
:author_key => :user_id,
Jean-Philippe Lang
TimeEntry acts_as_activity_provider scope should joins(:project) (#18818)....
r13589 :scope => joins(:project).preload(:project)
Jean-Philippe Lang
Adds spent time to the activity view (#3809)....
r2763
Jean-Philippe Lang
Simple time tracking functionality added. Time can be logged at issue or project level....
r365 validates_presence_of :user_id, :activity_id, :project_id, :hours, :spent_on
Jean-Philippe Lang
Merged Rails 2.2 branch. Redmine now requires Rails 2.2.2....
r2430 validates_numericality_of :hours, :allow_nil => true, :message => :invalid
Jean-Philippe Lang
Raises time entries comments limit to 1024 (#19885)....
r14239 validates_length_of :comments, :maximum => 1024, :allow_nil => true
Jean-Philippe Lang
Time entry with 2 digits year should not validate (#3107)....
r11242 validates :spent_on, :date => true
Toshi MARUYAMA
Rails3: model: replace deprecated 'before_validation' method at TimeEntry model...
r7333 before_validation :set_project_if_nil
Toshi MARUYAMA
Rails3: model: replace deprecated 'validate' method at TimeEntry model...
r7328 validate :validate_time_entry
Toshi MARUYAMA
remove trailing white-spaces from time entry model source....
r5700
Jean-Philippe Lang
Rewrites named scopes with ARel queries....
r10723 scope :visible, lambda {|*args|
Jean-Philippe Lang
Merged rails-4.1 branch (#14534)....
r13100 joins(:project).
Jean-Philippe Lang
Adds a role setting that viewing all or own time entries (#8929)....
r13893 where(TimeEntry.visible_condition(args.shift || User.current, *args))
Jean-Philippe Lang
Rewrites named scopes with ARel queries....
r10723 }
scope :on_issue, lambda {|issue|
Jean-Philippe Lang
Merged rails-4.1 branch (#14534)....
r13100 joins(:issue).
where("#{Issue.table_name}.root_id = #{issue.root_id} AND #{Issue.table_name}.lft >= #{issue.lft} AND #{Issue.table_name}.rgt <= #{issue.rgt}")
Jean-Philippe Lang
Rewrites named scopes with ARel queries....
r10723 }
Jean-Philippe Lang
Removed unnecessary calculations in time entries index....
r7965
Jean-Philippe Lang
Let the new time_entry form be submitted without project (#17954)....
r13058 safe_attributes 'hours', 'comments', 'project_id', 'issue_id', 'activity_id', 'spent_on', 'custom_field_values', 'custom_fields'
Jean-Philippe Lang
Prevent mass-assignment when adding/updating a time entry (#10390)....
r9016
Jean-Philippe Lang
Adds a role setting that viewing all or own time entries (#8929)....
r13893 # Returns a SQL conditions string used to find all time entries visible by the specified user
def self.visible_condition(user, options={})
Project.allowed_to_condition(user, :view_time_entries, options) do |role, user|
if role.time_entries_visibility == 'all'
nil
elsif role.time_entries_visibility == 'own' && user.id && user.logged?
"#{table_name}.user_id = #{user.id}"
else
'1=0'
end
end
end
# Returns true if user or current user is allowed to view the time entry
def visible?(user=nil)
(user || User.current).allowed_to?(:view_time_entries, self.project) do |role, user|
if role.time_entries_visibility == 'all'
true
elsif role.time_entries_visibility == 'own'
self.user == user
else
false
end
end
end
Jean-Philippe Lang
Removed after_initialize methods....
r8168 def initialize(attributes=nil, *args)
super
Jean-Philippe Lang
Fixed: time entries created with the default activity even if a different one is specified (#1302)....
r1519 if new_record? && self.activity.nil?
Eric Davis
Changed Enumerations to use a Single Table Inheritance...
r2677 if default_activity = TimeEntryActivity.default
Jean-Philippe Lang
Fixed: time entries created with the default activity even if a different one is specified (#1302)....
r1519 self.activity_id = default_activity.id
end
Jean-Philippe Lang
Force TimeEntry#hours default to nil (#3075, #4449)....
r3118 self.hours = nil if hours == 0
Jean-Philippe Lang
Fixed: IssueController#edit doesn't set default Activity as default (#1302)....
r1447 end
end
Toshi MARUYAMA
remove trailing white-spaces from time entry model source....
r5700
Jean-Philippe Lang
Let user choose an issue of another project when updating a time entry (#16338)....
r12715 def safe_attributes=(attrs, user=User.current)
Jean-Philippe Lang
Let the new time_entry form be submitted without project (#17954)....
r13058 if attrs
attrs = super(attrs)
Jean-Philippe Lang
Fixed validation when logging time on issue (#19464)....
r13780 if issue_id_changed? && issue
Jean-Philippe Lang
Don't let users log time on issues they cannot see in their projects (#21150)....
r14414 if issue.visible?(user) && user.allowed_to?(:log_time, issue.project)
Jean-Philippe Lang
Fixed validation when logging time on issue (#19464)....
r13780 if attrs[:project_id].blank? && issue.project_id != project_id
self.project_id = issue.project_id
end
@invalid_issue_id = nil
else
@invalid_issue_id = issue_id
Jean-Philippe Lang
Let the new time_entry form be submitted without project (#17954)....
r13058 end
Jean-Philippe Lang
Let user choose an issue of another project when updating a time entry (#16338)....
r12715 end
end
attrs
end
Toshi MARUYAMA
Rails3: model: replace deprecated 'before_validation' method at TimeEntry model...
r7333 def set_project_if_nil
Jean-Philippe Lang
Simple time tracking functionality added. Time can be logged at issue or project level....
r365 self.project = issue.project if issue && project.nil?
end
Toshi MARUYAMA
remove trailing white-spaces from time entry model source....
r5700
Toshi MARUYAMA
Rails3: model: replace deprecated 'validate' method at TimeEntry model...
r7328 def validate_time_entry
Jean-Philippe Lang
Merged Rails 2.2 branch. Redmine now requires Rails 2.2.2....
r2430 errors.add :hours, :invalid if hours && (hours < 0 || hours >= 1000)
errors.add :project_id, :invalid if project.nil?
Jean-Philippe Lang
Fixed validation when logging time on issue (#19464)....
r13780 errors.add :issue_id, :invalid if (issue_id && !issue) || (issue && project!=issue.project) || @invalid_issue_id
Jean-Philippe Lang
Validates that activity belongs to project activities (#19656)....
r13906 errors.add :activity_id, :inclusion if activity_id_changed? && project && !project.activities.include?(activity)
Jean-Philippe Lang
Simple time tracking functionality added. Time can be logged at issue or project level....
r365 end
Toshi MARUYAMA
remove trailing white-spaces from time entry model source....
r5700
Jean-Philippe Lang
Accept the following formats for the timelog "hours" field: 1h, 1 h, 1 hour, 2 hours, 30m, 30min, 1h30, 1h30m, 1:30....
r1305 def hours=(h)
Jean-Philippe Lang
Fixed: no error is raised when entering invalid hours on the issue update form (#2465)....
r2249 write_attribute :hours, (h.is_a?(String) ? (h.to_hours || h) : h)
Jean-Philippe Lang
Accept the following formats for the timelog "hours" field: 1h, 1 h, 1 hour, 2 hours, 30m, 30min, 1h30, 1h30m, 1:30....
r1305 end
Toshi MARUYAMA
remove trailing white-spaces from time entry model source....
r5700
Jean-Philippe Lang
Round hours when reading TimeEntry attribute....
r8860 def hours
h = read_attribute(:hours)
if h.is_a?(Float)
h.round(2)
else
h
end
end
Jean-Philippe Lang
Simple time tracking functionality added. Time can be logged at issue or project level....
r365 # 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
Jean-Philippe Lang
Fixed: 10342 Creation of Schema in Oracle...
r476 self.tweek = spent_on ? Date.civil(spent_on.year, spent_on.month, spent_on.day).cweek : nil
Jean-Philippe Lang
Adds date range filter and pagination on time entries detail view (closes #434)....
r1159 end
Toshi MARUYAMA
remove trailing white-spaces from time entry model source....
r5700
Jean-Philippe Lang
Adds date range filter and pagination on time entries detail view (closes #434)....
r1159 # Returns true if the time entry can be edited by usr, otherwise false
def editable_by?(usr)
Jean-Philippe Lang
Adds a role setting that viewing all or own time entries (#8929)....
r13893 visible?(usr) && (
(usr == user && usr.allowed_to?(:edit_own_time_entries, project)) || usr.allowed_to?(:edit_time_entries, project)
)
Jean-Philippe Lang
Adds date range filter and pagination on time entries detail view (closes #434)....
r1159 end
Jean-Philippe Lang
Add time entries custom fields to the context menu for quick bulk edit (#17484)....
r12981
# Returns the custom_field_values that can be edited by the given user
def editable_custom_field_values(user=nil)
visible_custom_field_values
end
# Returns the custom fields that can be edited by the given user
def editable_custom_fields(user=nil)
editable_custom_field_values(user).map(&:custom_field).uniq
end
Jean-Philippe Lang
Simple time tracking functionality added. Time can be logged at issue or project level....
r365 end