diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2008-02-27 20:50:19 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2008-02-27 20:50:19 +0000 |
commit | 200842ba5e753f342940d7df0f1cc342ae8485d4 (patch) | |
tree | 50ceded1ab5f0472b3896a07a330b8304521a84d /app/models | |
parent | 421d4203113a3cefdcc6998a9b9cc92ddbb27321 (diff) | |
download | redmine-200842ba5e753f342940d7df0f1cc342ae8485d4.tar.gz redmine-200842ba5e753f342940d7df0f1cc342ae8485d4.zip |
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
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/project.rb | 15 | ||||
-rw-r--r-- | app/models/time_entry.rb | 6 |
2 files changed, 21 insertions, 0 deletions
diff --git a/app/models/project.rb b/app/models/project.rb index 73a8d6404..8f1dada1d 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -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) diff --git a/app/models/time_entry.rb b/app/models/time_entry.rb index 04df5233f..0f8f62889 100644 --- a/app/models/time_entry.rb +++ b/app/models/time_entry.rb @@ -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 |