comparison app/models/project.rb @ 1484:51364c0cd58f redmine-2.4-integration

Merge from live branch. Still need to merge manually in files overridden by plugins.
author Chris Cannam
date Wed, 15 Jan 2014 09:59:14 +0000
parents 261b3d9a4903 0a574315af3e
children c86dacc2ef0a
comparison
equal deleted inserted replaced
1464:261b3d9a4903 1484:51364c0cd58f
88 } 88 }
89 scope :active, lambda { where(:status => STATUS_ACTIVE) } 89 scope :active, lambda { where(:status => STATUS_ACTIVE) }
90 scope :status, lambda {|arg| where(arg.blank? ? nil : {:status => arg.to_i}) } 90 scope :status, lambda {|arg| where(arg.blank? ? nil : {:status => arg.to_i}) }
91 scope :all_public, lambda { where(:is_public => true) } 91 scope :all_public, lambda { where(:is_public => true) }
92 scope :visible, lambda {|*args| where(Project.visible_condition(args.shift || User.current, *args)) } 92 scope :visible, lambda {|*args| where(Project.visible_condition(args.shift || User.current, *args)) }
93 scope :visible_roots, lambda {|*args| where(Project.root_visible_by(args.shift || User.current, *args)) }
93 scope :allowed_to, lambda {|*args| 94 scope :allowed_to, lambda {|*args|
94 user = User.current 95 user = User.current
95 permission = nil 96 permission = nil
96 if args.first.is_a?(Symbol) 97 if args.first.is_a?(Symbol)
97 permission = args.shift 98 permission = args.shift
160 # Project.visible_condition(anonymous) => "((projects.status = 1) AND (projects.is_public = 1))" 161 # Project.visible_condition(anonymous) => "((projects.status = 1) AND (projects.is_public = 1))"
161 def self.visible_condition(user, options={}) 162 def self.visible_condition(user, options={})
162 allowed_to_condition(user, :view_project, options) 163 allowed_to_condition(user, :view_project, options)
163 end 164 end
164 165
166 def self.root_visible_by(user=nil)
167 return "#{Project.table_name}.parent_id IS NULL AND " + visible_condition(user)
168 end
169
165 # Returns a SQL conditions string used to find all projects for which +user+ has the given +permission+ 170 # Returns a SQL conditions string used to find all projects for which +user+ has the given +permission+
166 # 171 #
167 # Valid options: 172 # Valid options:
168 # * :project => limit the condition to project 173 # * :project => limit the condition to project
169 # * :with_subprojects => limit the condition to project and its subprojects 174 # * :with_subprojects => limit the condition to project and its subprojects
540 def to_s 545 def to_s
541 name 546 name
542 end 547 end
543 548
544 # Returns a short description of the projects (first lines) 549 # Returns a short description of the projects (first lines)
545 def short_description(length = 255) 550 def short_description(length = 200)
546 description.gsub(/^(.{#{length}}[^\n\r]*).*$/m, '\1...').strip if description 551
552 ## The short description is used in lists, e.g. Latest projects,
553 ## My projects etc. It should be no more than a line or two with
554 ## no text formatting.
555
556 ## Original Redmine code: this truncates to the CR that is more
557 ## than "length" characters from the start.
558 # description.gsub(/^(.{#{length}}[^\n\r]*).*$/m, '\1...').strip if description
559
560 ## That can leave too much text for us, and also we want to omit
561 ## images and the like. Truncate instead to the first CR that
562 ## follows _any_ non-blank text, and to the next word break beyond
563 ## "length" characters if the result is still longer than that.
564 ##
565 description.gsub(/![^\s]+!/, '').gsub(/^(\s*[^\n\r]*).*$/m, '\1').gsub(/^(.{#{length}}[^\.;:,-]*).*$/m, '\1 ...').strip if description
547 end 566 end
548 567
549 def css_classes 568 def css_classes
550 s = 'project' 569 s = 'project'
551 s << ' root' if root? 570 s << ' root' if root?
667 'is_public', 686 'is_public',
668 'identifier', 687 'identifier',
669 'custom_field_values', 688 'custom_field_values',
670 'custom_fields', 689 'custom_fields',
671 'tracker_ids', 690 'tracker_ids',
672 'issue_custom_field_ids' 691 'issue_custom_field_ids',
692 'has_welcome_page'
673 693
674 safe_attributes 'enabled_module_names', 694 safe_attributes 'enabled_module_names',
675 :if => lambda {|project, user| project.new_record? || user.allowed_to?(:select_project_modules, project) } 695 :if => lambda {|project, user| project.new_record? || user.allowed_to?(:select_project_modules, project) }
676 696
677 safe_attributes 'inherit_members', 697 safe_attributes 'inherit_members',