##// END OF EJS Templates
[#20288] Update styles to match CodeRay 1.1.0 (preserving changes of r10132)....
[#20288] Update styles to match CodeRay 1.1.0 (preserving changes of r10132). This commit updates the CSS styles to match with CodeRay 1.1.0, while it preserves the custom changes applied in r10132. The CSS styles were still based on CodeRay 1.0.6 (included since Redmine 1.4.0) with the custom changes from r10132 (included since Redmine 2.1.0). Redmine 2.3.2 till 2.3.4 came with CodeRay 1.0.9, an upgrade that didn't needed changes in the CSS styles. Starting with 2.4.0 Redmine comes with CodeRay 1.1.0, a minor upgrade that came with new/changed token_kinds and lots of changes in the alpha stylesheet, that in turn is used as a base for Redmine's own CodeRay CSS styles. As such, this upgrade needed CSS stylesheet changes like done before in r7618 and r7623 (for 1.0.0 upgrade) and r9389 (for 1.0.6 upgrade). But these changes, plus an update of the Redmine core documentation that is shipped along the core (wiki_syntax_detailed_[markdown|textile].html), aren't integrated up untill today. Contributed by Mischa The Evil. git-svn-id: http://svn.redmine.org/redmine/trunk@14488 e93f8b46-1217-0410-a6f0-8f06a7374b81

File last commit:

r13906:62bed8b93f1b
r14106:6fbb56e55735
Show More
time_entry.rb
160 lines | 5.6 KiB | text/x-ruby | RubyLexer
# Redmine - project management software
# Copyright (C) 2006-2015 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
include Redmine::SafeAttributes
# 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 => 'TimeEntryActivity'
attr_protected :user_id, :tyear, :tmonth, :tweek
acts_as_customizable
acts_as_event :title => Proc.new {|o| "#{l_hours(o.hours)} (#{(o.issue || o.project).event_title})"},
:url => Proc.new {|o| {:controller => 'timelog', :action => 'index', :project_id => o.project, :issue_id => o.issue}},
:author => :user,
:group => :issue,
:description => :comments
acts_as_activity_provider :timestamp => "#{table_name}.created_on",
:author_key => :user_id,
:scope => joins(:project).preload(:project)
validates_presence_of :user_id, :activity_id, :project_id, :hours, :spent_on
validates_numericality_of :hours, :allow_nil => true, :message => :invalid
validates_length_of :comments, :maximum => 255, :allow_nil => true
validates :spent_on, :date => true
before_validation :set_project_if_nil
validate :validate_time_entry
scope :visible, lambda {|*args|
joins(:project).
where(TimeEntry.visible_condition(args.shift || User.current, *args))
}
scope :on_issue, lambda {|issue|
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}")
}
safe_attributes 'hours', 'comments', 'project_id', 'issue_id', 'activity_id', 'spent_on', 'custom_field_values', 'custom_fields'
# 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
def initialize(attributes=nil, *args)
super
if new_record? && self.activity.nil?
if default_activity = TimeEntryActivity.default
self.activity_id = default_activity.id
end
self.hours = nil if hours == 0
end
end
def safe_attributes=(attrs, user=User.current)
if attrs
attrs = super(attrs)
if issue_id_changed? && issue
if user.allowed_to?(:log_time, issue.project)
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
end
end
end
attrs
end
def set_project_if_nil
self.project = issue.project if issue && project.nil?
end
def validate_time_entry
errors.add :hours, :invalid if hours && (hours < 0 || hours >= 1000)
errors.add :project_id, :invalid if project.nil?
errors.add :issue_id, :invalid if (issue_id && !issue) || (issue && project!=issue.project) || @invalid_issue_id
errors.add :activity_id, :inclusion if activity_id_changed? && project && !project.activities.include?(activity)
end
def hours=(h)
write_attribute :hours, (h.is_a?(String) ? (h.to_hours || h) : h)
end
def hours
h = read_attribute(:hours)
if h.is_a?(Float)
h.round(2)
else
h
end
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)
visible?(usr) && (
(usr == user && usr.allowed_to?(:edit_own_time_entries, project)) || usr.allowed_to?(:edit_time_entries, project)
)
end
# 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
end