##// END OF EJS Templates
remove trailing white-spaces from app/models/project.rb....
Toshi MARUYAMA -
r6397:44147ee8f290
parent child
Show More
@@ -5,36 +5,36
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 class Project < ActiveRecord::Base
18 class Project < ActiveRecord::Base
19 include Redmine::SafeAttributes
19 include Redmine::SafeAttributes
20
20
21 # Project statuses
21 # Project statuses
22 STATUS_ACTIVE = 1
22 STATUS_ACTIVE = 1
23 STATUS_ARCHIVED = 9
23 STATUS_ARCHIVED = 9
24
24
25 # Maximum length for project identifiers
25 # Maximum length for project identifiers
26 IDENTIFIER_MAX_LENGTH = 100
26 IDENTIFIER_MAX_LENGTH = 100
27
27
28 # Specific overidden Activities
28 # Specific overidden Activities
29 has_many :time_entry_activities
29 has_many :time_entry_activities
30 has_many :members, :include => [:user, :roles], :conditions => "#{User.table_name}.type='User' AND #{User.table_name}.status=#{User::STATUS_ACTIVE}"
30 has_many :members, :include => [:user, :roles], :conditions => "#{User.table_name}.type='User' AND #{User.table_name}.status=#{User::STATUS_ACTIVE}"
31 has_many :memberships, :class_name => 'Member'
31 has_many :memberships, :class_name => 'Member'
32 has_many :member_principals, :class_name => 'Member',
32 has_many :member_principals, :class_name => 'Member',
33 :include => :principal,
33 :include => :principal,
34 :conditions => "#{Principal.table_name}.type='Group' OR (#{Principal.table_name}.type='User' AND #{Principal.table_name}.status=#{User::STATUS_ACTIVE})"
34 :conditions => "#{Principal.table_name}.type='Group' OR (#{Principal.table_name}.type='User' AND #{Principal.table_name}.status=#{User::STATUS_ACTIVE})"
35 has_many :users, :through => :members
35 has_many :users, :through => :members
36 has_many :principals, :through => :member_principals, :source => :principal
36 has_many :principals, :through => :member_principals, :source => :principal
37
37
38 has_many :enabled_modules, :dependent => :delete_all
38 has_many :enabled_modules, :dependent => :delete_all
39 has_and_belongs_to_many :trackers, :order => "#{Tracker.table_name}.position"
39 has_and_belongs_to_many :trackers, :order => "#{Tracker.table_name}.position"
40 has_many :issues, :dependent => :destroy, :order => "#{Issue.table_name}.created_on DESC", :include => [:status, :tracker]
40 has_many :issues, :dependent => :destroy, :order => "#{Issue.table_name}.created_on DESC", :include => [:status, :tracker]
@@ -50,12 +50,12 class Project < ActiveRecord::Base
50 has_many :changesets, :through => :repository
50 has_many :changesets, :through => :repository
51 has_one :wiki, :dependent => :destroy
51 has_one :wiki, :dependent => :destroy
52 # Custom field for the project issues
52 # Custom field for the project issues
53 has_and_belongs_to_many :issue_custom_fields,
53 has_and_belongs_to_many :issue_custom_fields,
54 :class_name => 'IssueCustomField',
54 :class_name => 'IssueCustomField',
55 :order => "#{CustomField.table_name}.position",
55 :order => "#{CustomField.table_name}.position",
56 :join_table => "#{table_name_prefix}custom_fields_projects#{table_name_suffix}",
56 :join_table => "#{table_name_prefix}custom_fields_projects#{table_name_suffix}",
57 :association_foreign_key => 'custom_field_id'
57 :association_foreign_key => 'custom_field_id'
58
58
59 acts_as_nested_set :order => 'name', :dependent => :destroy
59 acts_as_nested_set :order => 'name', :dependent => :destroy
60 acts_as_attachable :view_permission => :view_files,
60 acts_as_attachable :view_permission => :view_files,
61 :delete_permission => :manage_files
61 :delete_permission => :manage_files
@@ -67,7 +67,7 class Project < ActiveRecord::Base
67 :author => nil
67 :author => nil
68
68
69 attr_protected :status
69 attr_protected :status
70
70
71 validates_presence_of :name, :identifier
71 validates_presence_of :name, :identifier
72 validates_uniqueness_of :identifier
72 validates_uniqueness_of :identifier
73 validates_associated :repository, :wiki
73 validates_associated :repository, :wiki
@@ -85,12 +85,12 class Project < ActiveRecord::Base
85 named_scope :active, { :conditions => "#{Project.table_name}.status = #{STATUS_ACTIVE}"}
85 named_scope :active, { :conditions => "#{Project.table_name}.status = #{STATUS_ACTIVE}"}
86 named_scope :all_public, { :conditions => { :is_public => true } }
86 named_scope :all_public, { :conditions => { :is_public => true } }
87 named_scope :visible, lambda {|*args| {:conditions => Project.visible_condition(args.shift || User.current, *args) }}
87 named_scope :visible, lambda {|*args| {:conditions => Project.visible_condition(args.shift || User.current, *args) }}
88
88
89 def initialize(attributes = nil)
89 def initialize(attributes = nil)
90 super
90 super
91
91
92 initialized = (attributes || {}).stringify_keys
92 initialized = (attributes || {}).stringify_keys
93 if !initialized.key?('identifier') && Setting.sequential_project_identifiers?
93 if !initialized.key?('identifier') && Setting.sequential_project_identifiers?
94 self.identifier = Project.next_identifier
94 self.identifier = Project.next_identifier
95 end
95 end
96 if !initialized.key?('is_public')
96 if !initialized.key?('is_public')
@@ -103,11 +103,11 class Project < ActiveRecord::Base
103 self.trackers = Tracker.all
103 self.trackers = Tracker.all
104 end
104 end
105 end
105 end
106
106
107 def identifier=(identifier)
107 def identifier=(identifier)
108 super unless identifier_frozen?
108 super unless identifier_frozen?
109 end
109 end
110
110
111 def identifier_frozen?
111 def identifier_frozen?
112 errors[:identifier].nil? && !(new_record? || identifier.blank?)
112 errors[:identifier].nil? && !(new_record? || identifier.blank?)
113 end
113 end
@@ -122,12 +122,12 class Project < ActiveRecord::Base
122 def visible?(user=User.current)
122 def visible?(user=User.current)
123 user.allowed_to?(:view_project, self)
123 user.allowed_to?(:view_project, self)
124 end
124 end
125
125
126 def self.visible_by(user=nil)
126 def self.visible_by(user=nil)
127 ActiveSupport::Deprecation.warn "Project.visible_by is deprecated and will be removed in Redmine 1.3.0. Use Project.visible_condition instead."
127 ActiveSupport::Deprecation.warn "Project.visible_by is deprecated and will be removed in Redmine 1.3.0. Use Project.visible_condition instead."
128 visible_condition(user || User.current)
128 visible_condition(user || User.current)
129 end
129 end
130
130
131 # Returns a SQL conditions string used to find all projects visible by the specified user.
131 # Returns a SQL conditions string used to find all projects visible by the specified user.
132 #
132 #
133 # Examples:
133 # Examples:
@@ -137,7 +137,7 class Project < ActiveRecord::Base
137 def self.visible_condition(user, options={})
137 def self.visible_condition(user, options={})
138 allowed_to_condition(user, :view_project, options)
138 allowed_to_condition(user, :view_project, options)
139 end
139 end
140
140
141 # Returns a SQL conditions string used to find all projects for which +user+ has the given +permission+
141 # Returns a SQL conditions string used to find all projects for which +user+ has the given +permission+
142 #
142 #
143 # Valid options:
143 # Valid options:
@@ -157,7 +157,7 class Project < ActiveRecord::Base
157 project_statement << " OR (#{Project.table_name}.lft > #{options[:project].lft} AND #{Project.table_name}.rgt < #{options[:project].rgt})" if options[:with_subprojects]
157 project_statement << " OR (#{Project.table_name}.lft > #{options[:project].lft} AND #{Project.table_name}.rgt < #{options[:project].rgt})" if options[:with_subprojects]
158 base_statement = "(#{project_statement}) AND (#{base_statement})"
158 base_statement = "(#{project_statement}) AND (#{base_statement})"
159 end
159 end
160
160
161 if user.admin?
161 if user.admin?
162 base_statement
162 base_statement
163 else
163 else
@@ -211,14 +211,14 class Project < ActiveRecord::Base
211 activity.update_attributes(activity_hash) if activity
211 activity.update_attributes(activity_hash) if activity
212 end
212 end
213 end
213 end
214
214
215 # Create a new TimeEntryActivity if it overrides a system TimeEntryActivity
215 # Create a new TimeEntryActivity if it overrides a system TimeEntryActivity
216 #
216 #
217 # This will raise a ActiveRecord::Rollback if the TimeEntryActivity
217 # This will raise a ActiveRecord::Rollback if the TimeEntryActivity
218 # does not successfully save.
218 # does not successfully save.
219 def create_time_entry_activity_if_needed(activity)
219 def create_time_entry_activity_if_needed(activity)
220 if activity['parent_id']
220 if activity['parent_id']
221
221
222 parent_activity = TimeEntryActivity.find(activity['parent_id'])
222 parent_activity = TimeEntryActivity.find(activity['parent_id'])
223 activity['name'] = parent_activity.name
223 activity['name'] = parent_activity.name
224 activity['position'] = parent_activity.position
224 activity['position'] = parent_activity.position
@@ -245,7 +245,7 class Project < ActiveRecord::Base
245 cond = "(#{cond} OR (#{Project.table_name}.lft > #{lft} AND #{Project.table_name}.rgt < #{rgt}))" if with_subprojects
245 cond = "(#{cond} OR (#{Project.table_name}.lft > #{lft} AND #{Project.table_name}.rgt < #{rgt}))" if with_subprojects
246 cond
246 cond
247 end
247 end
248
248
249 def self.find(*args)
249 def self.find(*args)
250 if args.first && args.first.is_a?(String) && !args.first.match(/^\d*$/)
250 if args.first && args.first.is_a?(String) && !args.first.match(/^\d*$/)
251 project = find_by_identifier(*args)
251 project = find_by_identifier(*args)
@@ -255,20 +255,20 class Project < ActiveRecord::Base
255 super
255 super
256 end
256 end
257 end
257 end
258
258
259 def to_param
259 def to_param
260 # id is used for projects with a numeric identifier (compatibility)
260 # id is used for projects with a numeric identifier (compatibility)
261 @to_param ||= (identifier.to_s =~ %r{^\d*$} ? id : identifier)
261 @to_param ||= (identifier.to_s =~ %r{^\d*$} ? id : identifier)
262 end
262 end
263
263
264 def active?
264 def active?
265 self.status == STATUS_ACTIVE
265 self.status == STATUS_ACTIVE
266 end
266 end
267
267
268 def archived?
268 def archived?
269 self.status == STATUS_ARCHIVED
269 self.status == STATUS_ARCHIVED
270 end
270 end
271
271
272 # Archives the project and its descendants
272 # Archives the project and its descendants
273 def archive
273 def archive
274 # Check that there is no issue of a non descendant project that is assigned
274 # Check that there is no issue of a non descendant project that is assigned
@@ -284,14 +284,14 class Project < ActiveRecord::Base
284 end
284 end
285 true
285 true
286 end
286 end
287
287
288 # Unarchives the project
288 # Unarchives the project
289 # All its ancestors must be active
289 # All its ancestors must be active
290 def unarchive
290 def unarchive
291 return false if ancestors.detect {|a| !a.active?}
291 return false if ancestors.detect {|a| !a.active?}
292 update_attribute :status, STATUS_ACTIVE
292 update_attribute :status, STATUS_ACTIVE
293 end
293 end
294
294
295 # Returns an array of projects the project can be moved to
295 # Returns an array of projects the project can be moved to
296 # by the current user
296 # by the current user
297 def allowed_parents
297 def allowed_parents
@@ -306,7 +306,7 class Project < ActiveRecord::Base
306 end
306 end
307 @allowed_parents
307 @allowed_parents
308 end
308 end
309
309
310 # Sets the parent of the project with authorization check
310 # Sets the parent of the project with authorization check
311 def set_allowed_parent!(p)
311 def set_allowed_parent!(p)
312 unless p.nil? || p.is_a?(Project)
312 unless p.nil? || p.is_a?(Project)
@@ -326,7 +326,7 class Project < ActiveRecord::Base
326 end
326 end
327 set_parent!(p)
327 set_parent!(p)
328 end
328 end
329
329
330 # Sets the parent of the project
330 # Sets the parent of the project
331 # Argument can be either a Project, a String, a Fixnum or nil
331 # Argument can be either a Project, a String, a Fixnum or nil
332 def set_parent!(p)
332 def set_parent!(p)
@@ -365,7 +365,7 class Project < ActiveRecord::Base
365 false
365 false
366 end
366 end
367 end
367 end
368
368
369 # Returns an array of the trackers used by the project and its active sub projects
369 # Returns an array of the trackers used by the project and its active sub projects
370 def rolled_up_trackers
370 def rolled_up_trackers
371 @rolled_up_trackers ||=
371 @rolled_up_trackers ||=
@@ -374,7 +374,7 class Project < ActiveRecord::Base
374 :conditions => ["#{Project.table_name}.lft >= ? AND #{Project.table_name}.rgt <= ? AND #{Project.table_name}.status = #{STATUS_ACTIVE}", lft, rgt],
374 :conditions => ["#{Project.table_name}.lft >= ? AND #{Project.table_name}.rgt <= ? AND #{Project.table_name}.status = #{STATUS_ACTIVE}", lft, rgt],
375 :order => "#{Tracker.table_name}.position")
375 :order => "#{Tracker.table_name}.position")
376 end
376 end
377
377
378 # Closes open and locked project versions that are completed
378 # Closes open and locked project versions that are completed
379 def close_completed_versions
379 def close_completed_versions
380 Version.transaction do
380 Version.transaction do
@@ -392,7 +392,7 class Project < ActiveRecord::Base
392 Version.scoped(:include => :project,
392 Version.scoped(:include => :project,
393 :conditions => ["#{Project.table_name}.lft >= ? AND #{Project.table_name}.rgt <= ? AND #{Project.table_name}.status = #{STATUS_ACTIVE}", lft, rgt])
393 :conditions => ["#{Project.table_name}.lft >= ? AND #{Project.table_name}.rgt <= ? AND #{Project.table_name}.status = #{STATUS_ACTIVE}", lft, rgt])
394 end
394 end
395
395
396 # Returns a scope of the Versions used by the project
396 # Returns a scope of the Versions used by the project
397 def shared_versions
397 def shared_versions
398 @shared_versions ||= begin
398 @shared_versions ||= begin
@@ -418,31 +418,31 class Project < ActiveRecord::Base
418 h
418 h
419 end
419 end
420 end
420 end
421
421
422 # Deletes all project's members
422 # Deletes all project's members
423 def delete_all_members
423 def delete_all_members
424 me, mr = Member.table_name, MemberRole.table_name
424 me, mr = Member.table_name, MemberRole.table_name
425 connection.delete("DELETE FROM #{mr} WHERE #{mr}.member_id IN (SELECT #{me}.id FROM #{me} WHERE #{me}.project_id = #{id})")
425 connection.delete("DELETE FROM #{mr} WHERE #{mr}.member_id IN (SELECT #{me}.id FROM #{me} WHERE #{me}.project_id = #{id})")
426 Member.delete_all(['project_id = ?', id])
426 Member.delete_all(['project_id = ?', id])
427 end
427 end
428
428
429 # Users/groups issues can be assigned to
429 # Users/groups issues can be assigned to
430 def assignable_users
430 def assignable_users
431 assignable = Setting.issue_group_assignment? ? member_principals : members
431 assignable = Setting.issue_group_assignment? ? member_principals : members
432 assignable.select {|m| m.roles.detect {|role| role.assignable?}}.collect {|m| m.principal}.sort
432 assignable.select {|m| m.roles.detect {|role| role.assignable?}}.collect {|m| m.principal}.sort
433 end
433 end
434
434
435 # Returns the mail adresses of users that should be always notified on project events
435 # Returns the mail adresses of users that should be always notified on project events
436 def recipients
436 def recipients
437 notified_users.collect {|user| user.mail}
437 notified_users.collect {|user| user.mail}
438 end
438 end
439
439
440 # Returns the users that should be notified on project events
440 # Returns the users that should be notified on project events
441 def notified_users
441 def notified_users
442 # TODO: User part should be extracted to User#notify_about?
442 # TODO: User part should be extracted to User#notify_about?
443 members.select {|m| m.mail_notification? || m.user.mail_notification == 'all'}.collect {|m| m.user}
443 members.select {|m| m.mail_notification? || m.user.mail_notification == 'all'}.collect {|m| m.user}
444 end
444 end
445
445
446 # Returns an array of all custom fields enabled for project issues
446 # Returns an array of all custom fields enabled for project issues
447 # (explictly associated custom fields and custom fields enabled for all projects)
447 # (explictly associated custom fields and custom fields enabled for all projects)
448 def all_issue_custom_fields
448 def all_issue_custom_fields
@@ -454,19 +454,19 class Project < ActiveRecord::Base
454 def all_time_entry_custom_fields
454 def all_time_entry_custom_fields
455 @all_time_entry_custom_fields ||= (TimeEntryCustomField.for_all + time_entry_custom_fields).uniq.sort
455 @all_time_entry_custom_fields ||= (TimeEntryCustomField.for_all + time_entry_custom_fields).uniq.sort
456 end
456 end
457
457
458 def project
458 def project
459 self
459 self
460 end
460 end
461
461
462 def <=>(project)
462 def <=>(project)
463 name.downcase <=> project.name.downcase
463 name.downcase <=> project.name.downcase
464 end
464 end
465
465
466 def to_s
466 def to_s
467 name
467 name
468 end
468 end
469
469
470 # Returns a short description of the projects (first lines)
470 # Returns a short description of the projects (first lines)
471 def short_description(length = 255)
471 def short_description(length = 255)
472 description.gsub(/^(.{#{length}}[^\n\r]*).*$/m, '\1...').strip if description
472 description.gsub(/^(.{#{length}}[^\n\r]*).*$/m, '\1...').strip if description
@@ -519,7 +519,7 class Project < ActiveRecord::Base
519 end
519 end
520 end
520 end
521 end
521 end
522
522
523 # Return true if this project is allowed to do the specified action.
523 # Return true if this project is allowed to do the specified action.
524 # action can be:
524 # action can be:
525 # * a parameter-like Hash (eg. :controller => 'projects', :action => 'edit')
525 # * a parameter-like Hash (eg. :controller => 'projects', :action => 'edit')
@@ -531,12 +531,12 class Project < ActiveRecord::Base
531 allowed_permissions.include? action
531 allowed_permissions.include? action
532 end
532 end
533 end
533 end
534
534
535 def module_enabled?(module_name)
535 def module_enabled?(module_name)
536 module_name = module_name.to_s
536 module_name = module_name.to_s
537 enabled_modules.detect {|m| m.name == module_name}
537 enabled_modules.detect {|m| m.name == module_name}
538 end
538 end
539
539
540 def enabled_module_names=(module_names)
540 def enabled_module_names=(module_names)
541 if module_names && module_names.is_a?(Array)
541 if module_names && module_names.is_a?(Array)
542 module_names = module_names.collect(&:to_s).reject(&:blank?)
542 module_names = module_names.collect(&:to_s).reject(&:blank?)
@@ -545,7 +545,7 class Project < ActiveRecord::Base
545 enabled_modules.clear
545 enabled_modules.clear
546 end
546 end
547 end
547 end
548
548
549 # Returns an array of the enabled modules names
549 # Returns an array of the enabled modules names
550 def enabled_module_names
550 def enabled_module_names
551 enabled_modules.collect(&:name)
551 enabled_modules.collect(&:name)
@@ -583,7 +583,7 class Project < ActiveRecord::Base
583
583
584 safe_attributes 'enabled_module_names',
584 safe_attributes 'enabled_module_names',
585 :if => lambda {|project, user| project.new_record? || user.allowed_to?(:select_project_modules, project) }
585 :if => lambda {|project, user| project.new_record? || user.allowed_to?(:select_project_modules, project) }
586
586
587 # Returns an array of projects that are in this project's hierarchy
587 # Returns an array of projects that are in this project's hierarchy
588 #
588 #
589 # Example: parents, children, siblings
589 # Example: parents, children, siblings
@@ -592,7 +592,7 class Project < ActiveRecord::Base
592 descendants = project.descendants || []
592 descendants = project.descendants || []
593 project_hierarchy = parents | descendants # Set union
593 project_hierarchy = parents | descendants # Set union
594 end
594 end
595
595
596 # Returns an auto-generated project identifier based on the last identifier used
596 # Returns an auto-generated project identifier based on the last identifier used
597 def self.next_identifier
597 def self.next_identifier
598 p = Project.find(:first, :order => 'created_on DESC')
598 p = Project.find(:first, :order => 'created_on DESC')
@@ -616,10 +616,10 class Project < ActiveRecord::Base
616 # project.copy(1, :only => ['members', 'versions']) # => copies members and versions
616 # project.copy(1, :only => ['members', 'versions']) # => copies members and versions
617 def copy(project, options={})
617 def copy(project, options={})
618 project = project.is_a?(Project) ? project : Project.find(project)
618 project = project.is_a?(Project) ? project : Project.find(project)
619
619
620 to_be_copied = %w(wiki versions issue_categories issues members queries boards)
620 to_be_copied = %w(wiki versions issue_categories issues members queries boards)
621 to_be_copied = to_be_copied & options[:only].to_a unless options[:only].nil?
621 to_be_copied = to_be_copied & options[:only].to_a unless options[:only].nil?
622
622
623 Project.transaction do
623 Project.transaction do
624 if save
624 if save
625 reload
625 reload
@@ -632,7 +632,7 class Project < ActiveRecord::Base
632 end
632 end
633 end
633 end
634
634
635
635
636 # Copies +project+ and returns the new instance. This will not save
636 # Copies +project+ and returns the new instance. This will not save
637 # the copy
637 # the copy
638 def self.copy_from(project)
638 def self.copy_from(project)
@@ -659,16 +659,16 class Project < ActiveRecord::Base
659 def self.project_tree(projects, &block)
659 def self.project_tree(projects, &block)
660 ancestors = []
660 ancestors = []
661 projects.sort_by(&:lft).each do |project|
661 projects.sort_by(&:lft).each do |project|
662 while (ancestors.any? && !project.is_descendant_of?(ancestors.last))
662 while (ancestors.any? && !project.is_descendant_of?(ancestors.last))
663 ancestors.pop
663 ancestors.pop
664 end
664 end
665 yield project, ancestors.size
665 yield project, ancestors.size
666 ancestors << project
666 ancestors << project
667 end
667 end
668 end
668 end
669
669
670 private
670 private
671
671
672 # Copies wiki from +project+
672 # Copies wiki from +project+
673 def copy_wiki(project)
673 def copy_wiki(project)
674 # Check that the source project has a wiki first
674 # Check that the source project has a wiki first
@@ -713,14 +713,14 class Project < ActiveRecord::Base
713 self.issue_categories << new_issue_category
713 self.issue_categories << new_issue_category
714 end
714 end
715 end
715 end
716
716
717 # Copies issues from +project+
717 # Copies issues from +project+
718 # Note: issues assigned to a closed version won't be copied due to validation rules
718 # Note: issues assigned to a closed version won't be copied due to validation rules
719 def copy_issues(project)
719 def copy_issues(project)
720 # Stores the source issue id as a key and the copied issues as the
720 # Stores the source issue id as a key and the copied issues as the
721 # value. Used to map the two togeather for issue relations.
721 # value. Used to map the two togeather for issue relations.
722 issues_map = {}
722 issues_map = {}
723
723
724 # Get issues sorted by root_id, lft so that parent issues
724 # Get issues sorted by root_id, lft so that parent issues
725 # get copied before their children
725 # get copied before their children
726 project.issues.find(:all, :order => 'root_id, lft').each do |issue|
726 project.issues.find(:all, :order => 'root_id, lft').each do |issue|
@@ -743,7 +743,7 class Project < ActiveRecord::Base
743 new_issue.parent_issue_id = copied_parent.id
743 new_issue.parent_issue_id = copied_parent.id
744 end
744 end
745 end
745 end
746
746
747 self.issues << new_issue
747 self.issues << new_issue
748 if new_issue.new_record?
748 if new_issue.new_record?
749 logger.info "Project#copy_issues: issue ##{issue.id} could not be copied: #{new_issue.errors.full_messages}" if logger && logger.info
749 logger.info "Project#copy_issues: issue ##{issue.id} could not be copied: #{new_issue.errors.full_messages}" if logger && logger.info
@@ -759,7 +759,7 class Project < ActiveRecord::Base
759 # Issue was not copied
759 # Issue was not copied
760 next
760 next
761 end
761 end
762
762
763 # Relations
763 # Relations
764 issue.relations_from.each do |source_relation|
764 issue.relations_from.each do |source_relation|
765 new_issue_relation = IssueRelation.new
765 new_issue_relation = IssueRelation.new
@@ -770,7 +770,7 class Project < ActiveRecord::Base
770 end
770 end
771 new_issue.relations_from << new_issue_relation
771 new_issue.relations_from << new_issue_relation
772 end
772 end
773
773
774 issue.relations_to.each do |source_relation|
774 issue.relations_to.each do |source_relation|
775 new_issue_relation = IssueRelation.new
775 new_issue_relation = IssueRelation.new
776 new_issue_relation.attributes = source_relation.attributes.dup.except("id", "issue_from_id", "issue_to_id")
776 new_issue_relation.attributes = source_relation.attributes.dup.except("id", "issue_from_id", "issue_to_id")
@@ -789,7 +789,7 class Project < ActiveRecord::Base
789 members_to_copy = []
789 members_to_copy = []
790 members_to_copy += project.memberships.select {|m| m.principal.is_a?(User)}
790 members_to_copy += project.memberships.select {|m| m.principal.is_a?(User)}
791 members_to_copy += project.memberships.select {|m| !m.principal.is_a?(User)}
791 members_to_copy += project.memberships.select {|m| !m.principal.is_a?(User)}
792
792
793 members_to_copy.each do |member|
793 members_to_copy.each do |member|
794 new_member = Member.new
794 new_member = Member.new
795 new_member.attributes = member.attributes.dup.except("id", "project_id", "created_on")
795 new_member.attributes = member.attributes.dup.except("id", "project_id", "created_on")
@@ -823,7 +823,7 class Project < ActiveRecord::Base
823 self.boards << new_board
823 self.boards << new_board
824 end
824 end
825 end
825 end
826
826
827 def allowed_permissions
827 def allowed_permissions
828 @allowed_permissions ||= begin
828 @allowed_permissions ||= begin
829 module_names = enabled_modules.all(:select => :name).collect {|m| m.name}
829 module_names = enabled_modules.all(:select => :name).collect {|m| m.name}
@@ -838,7 +838,7 class Project < ActiveRecord::Base
838 # Returns all the active Systemwide and project specific activities
838 # Returns all the active Systemwide and project specific activities
839 def active_activities
839 def active_activities
840 overridden_activity_ids = self.time_entry_activities.collect(&:parent_id)
840 overridden_activity_ids = self.time_entry_activities.collect(&:parent_id)
841
841
842 if overridden_activity_ids.empty?
842 if overridden_activity_ids.empty?
843 return TimeEntryActivity.shared.active
843 return TimeEntryActivity.shared.active
844 else
844 else
@@ -872,7 +872,7 class Project < ActiveRecord::Base
872 self.time_entry_activities.active
872 self.time_entry_activities.active
873 end
873 end
874 end
874 end
875
875
876 # Archives subprojects recursively
876 # Archives subprojects recursively
877 def archive!
877 def archive!
878 children.each do |subproject|
878 children.each do |subproject|
General Comments 0
You need to be logged in to leave comments. Login now