diff options
author | Eric Davis <edavis@littlestreamsoftware.com> | 2009-03-21 00:39:53 +0000 |
---|---|---|
committer | Eric Davis <edavis@littlestreamsoftware.com> | 2009-03-21 00:39:53 +0000 |
commit | c2dfffd7f267b2064bb51d46aac6fb1429b37132 (patch) | |
tree | c6457a13a31ec69a4b8d8a3398a6b52523c68473 /app/models/project.rb | |
parent | 451ef7f21f411d4bfe4138a71be269f566cd4647 (diff) | |
download | redmine-c2dfffd7f267b2064bb51d46aac6fb1429b37132.tar.gz redmine-c2dfffd7f267b2064bb51d46aac6fb1429b37132.zip |
Added some RDoc documentation for some models.
Submitted by austenito on Github.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2612 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/project.rb')
-rw-r--r-- | app/models/project.rb | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/app/models/project.rb b/app/models/project.rb index 980d194b1..5778966e7 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -99,6 +99,11 @@ class Project < ActiveRecord::Base find(:all, :limit => count, :conditions => visible_by(user), :order => "created_on DESC") end + # Returns a SQL :conditions string used to find all active projects for the specified user. + # + # Examples: + # Projects.visible_by(admin) => "projects.status = 1" + # Projects.visible_by(normal_user) => "projects.status = 1 AND projects.is_public = 1" def self.visible_by(user=nil) user ||= User.current if user && user.admin? @@ -141,7 +146,12 @@ class Project < ActiveRecord::Base end statements.empty? ? base_statement : "((#{base_statement}) AND (#{statements.join(' OR ')}))" end - + + # Returns a :conditions SQL string that can be used to find the issues associated with this project. + # + # Examples: + # project.project_condition(true) => "(projects.id = 1 OR (projects.lft > 1 AND projects.rgt < 10))" + # project.project_condition(false) => "projects.id = 1" def project_condition(with_subprojects) cond = "#{Project.table_name}.id = #{id}" cond = "(#{cond} OR (#{Project.table_name}.lft > #{lft} AND #{Project.table_name}.rgt < #{rgt}))" if with_subprojects @@ -273,6 +283,10 @@ class Project < ActiveRecord::Base description.gsub(/^(.{#{length}}[^\n\r]*).*$/m, '\1...').strip if description end + # Return true if this project is allowed to do the specified action. + # action can be: + # * a parameter-like Hash (eg. :controller => 'projects', :action => 'edit') + # * a permission Symbol (eg. :edit_project) def allows_to?(action) if action.is_a? Hash allowed_actions.include? "#{action[:controller]}/#{action[:action]}" |