Propagates time tracking to the parent project (closes #433). Time report enhancements.
git-svn-id: http://redmine.rubyforge.org/svn/trunk@1176 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
@@ -110,6 +110,21 @@ class Project < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
|
||||
def self.allowed_to_condition(user, permission)
|
||||
statements = []
|
||||
active_statement = "#{Project.table_name}.status=#{Project::STATUS_ACTIVE}"
|
||||
if user.admin?
|
||||
# no restriction
|
||||
elsif user.logged?
|
||||
statements << "#{Project.table_name}.is_public = #{connection.quoted_true}" if Role.non_member.allowed_to?(permission)
|
||||
allowed_project_ids = user.memberships.select {|m| m.role.allowed_to?(permission)}.collect {|m| m.project_id}
|
||||
statements << "#{Project.table_name}.id IN (#{allowed_project_ids.join(',')})"
|
||||
else
|
||||
statements << "#{Project.table_name}.is_public = #{connection.quoted_true}" if Role.anonymous.allowed_to?(permission)
|
||||
end
|
||||
statements.empty? ? active_statement : "(#{active_statement} AND (#{statements.join(' OR ')}))"
|
||||
end
|
||||
|
||||
def self.find(*args)
|
||||
if args.first && args.first.is_a?(String) && !args.first.match(/^\d*$/)
|
||||
project = find_by_identifier(*args)
|
||||
|
||||
@@ -52,4 +52,10 @@ class TimeEntry < ActiveRecord::Base
|
||||
def editable_by?(usr)
|
||||
usr == self.user
|
||||
end
|
||||
|
||||
def self.visible_by(usr)
|
||||
with_scope(:find => { :conditions => Project.allowed_to_condition(usr, :view_time_entries) }) do
|
||||
yield
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user