mirror of
https://github.com/meineerde/redmine.git
synced 2026-03-20 15:59:53 +00:00
remove trailing white-spaces from app/models/project.rb.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@6517 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
b81c2f17b4
commit
44147ee8f2
@ -5,36 +5,36 @@
|
|||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
# as published by the Free Software Foundation; either version 2
|
# as published by the Free Software Foundation; either version 2
|
||||||
# of the License, or (at your option) any later version.
|
# of the License, or (at your option) any later version.
|
||||||
#
|
#
|
||||||
# This program is distributed in the hope that it will be useful,
|
# This program is distributed in the hope that it will be useful,
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
# GNU General Public License for more details.
|
# GNU General Public License for more details.
|
||||||
#
|
#
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program; if not, write to the Free Software
|
# along with this program; if not, write to the Free Software
|
||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
class Project < ActiveRecord::Base
|
class Project < ActiveRecord::Base
|
||||||
include Redmine::SafeAttributes
|
include Redmine::SafeAttributes
|
||||||
|
|
||||||
# Project statuses
|
# Project statuses
|
||||||
STATUS_ACTIVE = 1
|
STATUS_ACTIVE = 1
|
||||||
STATUS_ARCHIVED = 9
|
STATUS_ARCHIVED = 9
|
||||||
|
|
||||||
# Maximum length for project identifiers
|
# Maximum length for project identifiers
|
||||||
IDENTIFIER_MAX_LENGTH = 100
|
IDENTIFIER_MAX_LENGTH = 100
|
||||||
|
|
||||||
# Specific overidden Activities
|
# Specific overidden Activities
|
||||||
has_many :time_entry_activities
|
has_many :time_entry_activities
|
||||||
has_many :members, :include => [:user, :roles], :conditions => "#{User.table_name}.type='User' AND #{User.table_name}.status=#{User::STATUS_ACTIVE}"
|
has_many :members, :include => [:user, :roles], :conditions => "#{User.table_name}.type='User' AND #{User.table_name}.status=#{User::STATUS_ACTIVE}"
|
||||||
has_many :memberships, :class_name => 'Member'
|
has_many :memberships, :class_name => 'Member'
|
||||||
has_many :member_principals, :class_name => 'Member',
|
has_many :member_principals, :class_name => 'Member',
|
||||||
:include => :principal,
|
:include => :principal,
|
||||||
:conditions => "#{Principal.table_name}.type='Group' OR (#{Principal.table_name}.type='User' AND #{Principal.table_name}.status=#{User::STATUS_ACTIVE})"
|
:conditions => "#{Principal.table_name}.type='Group' OR (#{Principal.table_name}.type='User' AND #{Principal.table_name}.status=#{User::STATUS_ACTIVE})"
|
||||||
has_many :users, :through => :members
|
has_many :users, :through => :members
|
||||||
has_many :principals, :through => :member_principals, :source => :principal
|
has_many :principals, :through => :member_principals, :source => :principal
|
||||||
|
|
||||||
has_many :enabled_modules, :dependent => :delete_all
|
has_many :enabled_modules, :dependent => :delete_all
|
||||||
has_and_belongs_to_many :trackers, :order => "#{Tracker.table_name}.position"
|
has_and_belongs_to_many :trackers, :order => "#{Tracker.table_name}.position"
|
||||||
has_many :issues, :dependent => :destroy, :order => "#{Issue.table_name}.created_on DESC", :include => [:status, :tracker]
|
has_many :issues, :dependent => :destroy, :order => "#{Issue.table_name}.created_on DESC", :include => [:status, :tracker]
|
||||||
@ -50,12 +50,12 @@ class Project < ActiveRecord::Base
|
|||||||
has_many :changesets, :through => :repository
|
has_many :changesets, :through => :repository
|
||||||
has_one :wiki, :dependent => :destroy
|
has_one :wiki, :dependent => :destroy
|
||||||
# Custom field for the project issues
|
# Custom field for the project issues
|
||||||
has_and_belongs_to_many :issue_custom_fields,
|
has_and_belongs_to_many :issue_custom_fields,
|
||||||
:class_name => 'IssueCustomField',
|
:class_name => 'IssueCustomField',
|
||||||
:order => "#{CustomField.table_name}.position",
|
:order => "#{CustomField.table_name}.position",
|
||||||
:join_table => "#{table_name_prefix}custom_fields_projects#{table_name_suffix}",
|
:join_table => "#{table_name_prefix}custom_fields_projects#{table_name_suffix}",
|
||||||
:association_foreign_key => 'custom_field_id'
|
:association_foreign_key => 'custom_field_id'
|
||||||
|
|
||||||
acts_as_nested_set :order => 'name', :dependent => :destroy
|
acts_as_nested_set :order => 'name', :dependent => :destroy
|
||||||
acts_as_attachable :view_permission => :view_files,
|
acts_as_attachable :view_permission => :view_files,
|
||||||
:delete_permission => :manage_files
|
:delete_permission => :manage_files
|
||||||
@ -67,7 +67,7 @@ class Project < ActiveRecord::Base
|
|||||||
:author => nil
|
:author => nil
|
||||||
|
|
||||||
attr_protected :status
|
attr_protected :status
|
||||||
|
|
||||||
validates_presence_of :name, :identifier
|
validates_presence_of :name, :identifier
|
||||||
validates_uniqueness_of :identifier
|
validates_uniqueness_of :identifier
|
||||||
validates_associated :repository, :wiki
|
validates_associated :repository, :wiki
|
||||||
@ -85,12 +85,12 @@ class Project < ActiveRecord::Base
|
|||||||
named_scope :active, { :conditions => "#{Project.table_name}.status = #{STATUS_ACTIVE}"}
|
named_scope :active, { :conditions => "#{Project.table_name}.status = #{STATUS_ACTIVE}"}
|
||||||
named_scope :all_public, { :conditions => { :is_public => true } }
|
named_scope :all_public, { :conditions => { :is_public => true } }
|
||||||
named_scope :visible, lambda {|*args| {:conditions => Project.visible_condition(args.shift || User.current, *args) }}
|
named_scope :visible, lambda {|*args| {:conditions => Project.visible_condition(args.shift || User.current, *args) }}
|
||||||
|
|
||||||
def initialize(attributes = nil)
|
def initialize(attributes = nil)
|
||||||
super
|
super
|
||||||
|
|
||||||
initialized = (attributes || {}).stringify_keys
|
initialized = (attributes || {}).stringify_keys
|
||||||
if !initialized.key?('identifier') && Setting.sequential_project_identifiers?
|
if !initialized.key?('identifier') && Setting.sequential_project_identifiers?
|
||||||
self.identifier = Project.next_identifier
|
self.identifier = Project.next_identifier
|
||||||
end
|
end
|
||||||
if !initialized.key?('is_public')
|
if !initialized.key?('is_public')
|
||||||
@ -103,11 +103,11 @@ class Project < ActiveRecord::Base
|
|||||||
self.trackers = Tracker.all
|
self.trackers = Tracker.all
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def identifier=(identifier)
|
def identifier=(identifier)
|
||||||
super unless identifier_frozen?
|
super unless identifier_frozen?
|
||||||
end
|
end
|
||||||
|
|
||||||
def identifier_frozen?
|
def identifier_frozen?
|
||||||
errors[:identifier].nil? && !(new_record? || identifier.blank?)
|
errors[:identifier].nil? && !(new_record? || identifier.blank?)
|
||||||
end
|
end
|
||||||
@ -122,12 +122,12 @@ class Project < ActiveRecord::Base
|
|||||||
def visible?(user=User.current)
|
def visible?(user=User.current)
|
||||||
user.allowed_to?(:view_project, self)
|
user.allowed_to?(:view_project, self)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.visible_by(user=nil)
|
def self.visible_by(user=nil)
|
||||||
ActiveSupport::Deprecation.warn "Project.visible_by is deprecated and will be removed in Redmine 1.3.0. Use Project.visible_condition instead."
|
ActiveSupport::Deprecation.warn "Project.visible_by is deprecated and will be removed in Redmine 1.3.0. Use Project.visible_condition instead."
|
||||||
visible_condition(user || User.current)
|
visible_condition(user || User.current)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns a SQL conditions string used to find all projects visible by the specified user.
|
# Returns a SQL conditions string used to find all projects visible by the specified user.
|
||||||
#
|
#
|
||||||
# Examples:
|
# Examples:
|
||||||
@ -137,7 +137,7 @@ class Project < ActiveRecord::Base
|
|||||||
def self.visible_condition(user, options={})
|
def self.visible_condition(user, options={})
|
||||||
allowed_to_condition(user, :view_project, options)
|
allowed_to_condition(user, :view_project, options)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns a SQL conditions string used to find all projects for which +user+ has the given +permission+
|
# Returns a SQL conditions string used to find all projects for which +user+ has the given +permission+
|
||||||
#
|
#
|
||||||
# Valid options:
|
# Valid options:
|
||||||
@ -157,7 +157,7 @@ class Project < ActiveRecord::Base
|
|||||||
project_statement << " OR (#{Project.table_name}.lft > #{options[:project].lft} AND #{Project.table_name}.rgt < #{options[:project].rgt})" if options[:with_subprojects]
|
project_statement << " OR (#{Project.table_name}.lft > #{options[:project].lft} AND #{Project.table_name}.rgt < #{options[:project].rgt})" if options[:with_subprojects]
|
||||||
base_statement = "(#{project_statement}) AND (#{base_statement})"
|
base_statement = "(#{project_statement}) AND (#{base_statement})"
|
||||||
end
|
end
|
||||||
|
|
||||||
if user.admin?
|
if user.admin?
|
||||||
base_statement
|
base_statement
|
||||||
else
|
else
|
||||||
@ -211,14 +211,14 @@ class Project < ActiveRecord::Base
|
|||||||
activity.update_attributes(activity_hash) if activity
|
activity.update_attributes(activity_hash) if activity
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Create a new TimeEntryActivity if it overrides a system TimeEntryActivity
|
# Create a new TimeEntryActivity if it overrides a system TimeEntryActivity
|
||||||
#
|
#
|
||||||
# This will raise a ActiveRecord::Rollback if the TimeEntryActivity
|
# This will raise a ActiveRecord::Rollback if the TimeEntryActivity
|
||||||
# does not successfully save.
|
# does not successfully save.
|
||||||
def create_time_entry_activity_if_needed(activity)
|
def create_time_entry_activity_if_needed(activity)
|
||||||
if activity['parent_id']
|
if activity['parent_id']
|
||||||
|
|
||||||
parent_activity = TimeEntryActivity.find(activity['parent_id'])
|
parent_activity = TimeEntryActivity.find(activity['parent_id'])
|
||||||
activity['name'] = parent_activity.name
|
activity['name'] = parent_activity.name
|
||||||
activity['position'] = parent_activity.position
|
activity['position'] = parent_activity.position
|
||||||
@ -245,7 +245,7 @@ class Project < ActiveRecord::Base
|
|||||||
cond = "(#{cond} OR (#{Project.table_name}.lft > #{lft} AND #{Project.table_name}.rgt < #{rgt}))" if with_subprojects
|
cond = "(#{cond} OR (#{Project.table_name}.lft > #{lft} AND #{Project.table_name}.rgt < #{rgt}))" if with_subprojects
|
||||||
cond
|
cond
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.find(*args)
|
def self.find(*args)
|
||||||
if args.first && args.first.is_a?(String) && !args.first.match(/^\d*$/)
|
if args.first && args.first.is_a?(String) && !args.first.match(/^\d*$/)
|
||||||
project = find_by_identifier(*args)
|
project = find_by_identifier(*args)
|
||||||
@ -255,20 +255,20 @@ class Project < ActiveRecord::Base
|
|||||||
super
|
super
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_param
|
def to_param
|
||||||
# id is used for projects with a numeric identifier (compatibility)
|
# id is used for projects with a numeric identifier (compatibility)
|
||||||
@to_param ||= (identifier.to_s =~ %r{^\d*$} ? id : identifier)
|
@to_param ||= (identifier.to_s =~ %r{^\d*$} ? id : identifier)
|
||||||
end
|
end
|
||||||
|
|
||||||
def active?
|
def active?
|
||||||
self.status == STATUS_ACTIVE
|
self.status == STATUS_ACTIVE
|
||||||
end
|
end
|
||||||
|
|
||||||
def archived?
|
def archived?
|
||||||
self.status == STATUS_ARCHIVED
|
self.status == STATUS_ARCHIVED
|
||||||
end
|
end
|
||||||
|
|
||||||
# Archives the project and its descendants
|
# Archives the project and its descendants
|
||||||
def archive
|
def archive
|
||||||
# Check that there is no issue of a non descendant project that is assigned
|
# Check that there is no issue of a non descendant project that is assigned
|
||||||
@ -284,14 +284,14 @@ class Project < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
# Unarchives the project
|
# Unarchives the project
|
||||||
# All its ancestors must be active
|
# All its ancestors must be active
|
||||||
def unarchive
|
def unarchive
|
||||||
return false if ancestors.detect {|a| !a.active?}
|
return false if ancestors.detect {|a| !a.active?}
|
||||||
update_attribute :status, STATUS_ACTIVE
|
update_attribute :status, STATUS_ACTIVE
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns an array of projects the project can be moved to
|
# Returns an array of projects the project can be moved to
|
||||||
# by the current user
|
# by the current user
|
||||||
def allowed_parents
|
def allowed_parents
|
||||||
@ -306,7 +306,7 @@ class Project < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
@allowed_parents
|
@allowed_parents
|
||||||
end
|
end
|
||||||
|
|
||||||
# Sets the parent of the project with authorization check
|
# Sets the parent of the project with authorization check
|
||||||
def set_allowed_parent!(p)
|
def set_allowed_parent!(p)
|
||||||
unless p.nil? || p.is_a?(Project)
|
unless p.nil? || p.is_a?(Project)
|
||||||
@ -326,7 +326,7 @@ class Project < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
set_parent!(p)
|
set_parent!(p)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Sets the parent of the project
|
# Sets the parent of the project
|
||||||
# Argument can be either a Project, a String, a Fixnum or nil
|
# Argument can be either a Project, a String, a Fixnum or nil
|
||||||
def set_parent!(p)
|
def set_parent!(p)
|
||||||
@ -365,7 +365,7 @@ class Project < ActiveRecord::Base
|
|||||||
false
|
false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns an array of the trackers used by the project and its active sub projects
|
# Returns an array of the trackers used by the project and its active sub projects
|
||||||
def rolled_up_trackers
|
def rolled_up_trackers
|
||||||
@rolled_up_trackers ||=
|
@rolled_up_trackers ||=
|
||||||
@ -374,7 +374,7 @@ class Project < ActiveRecord::Base
|
|||||||
:conditions => ["#{Project.table_name}.lft >= ? AND #{Project.table_name}.rgt <= ? AND #{Project.table_name}.status = #{STATUS_ACTIVE}", lft, rgt],
|
:conditions => ["#{Project.table_name}.lft >= ? AND #{Project.table_name}.rgt <= ? AND #{Project.table_name}.status = #{STATUS_ACTIVE}", lft, rgt],
|
||||||
:order => "#{Tracker.table_name}.position")
|
:order => "#{Tracker.table_name}.position")
|
||||||
end
|
end
|
||||||
|
|
||||||
# Closes open and locked project versions that are completed
|
# Closes open and locked project versions that are completed
|
||||||
def close_completed_versions
|
def close_completed_versions
|
||||||
Version.transaction do
|
Version.transaction do
|
||||||
@ -392,7 +392,7 @@ class Project < ActiveRecord::Base
|
|||||||
Version.scoped(:include => :project,
|
Version.scoped(:include => :project,
|
||||||
:conditions => ["#{Project.table_name}.lft >= ? AND #{Project.table_name}.rgt <= ? AND #{Project.table_name}.status = #{STATUS_ACTIVE}", lft, rgt])
|
:conditions => ["#{Project.table_name}.lft >= ? AND #{Project.table_name}.rgt <= ? AND #{Project.table_name}.status = #{STATUS_ACTIVE}", lft, rgt])
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns a scope of the Versions used by the project
|
# Returns a scope of the Versions used by the project
|
||||||
def shared_versions
|
def shared_versions
|
||||||
@shared_versions ||= begin
|
@shared_versions ||= begin
|
||||||
@ -418,31 +418,31 @@ class Project < ActiveRecord::Base
|
|||||||
h
|
h
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Deletes all project's members
|
# Deletes all project's members
|
||||||
def delete_all_members
|
def delete_all_members
|
||||||
me, mr = Member.table_name, MemberRole.table_name
|
me, mr = Member.table_name, MemberRole.table_name
|
||||||
connection.delete("DELETE FROM #{mr} WHERE #{mr}.member_id IN (SELECT #{me}.id FROM #{me} WHERE #{me}.project_id = #{id})")
|
connection.delete("DELETE FROM #{mr} WHERE #{mr}.member_id IN (SELECT #{me}.id FROM #{me} WHERE #{me}.project_id = #{id})")
|
||||||
Member.delete_all(['project_id = ?', id])
|
Member.delete_all(['project_id = ?', id])
|
||||||
end
|
end
|
||||||
|
|
||||||
# Users/groups issues can be assigned to
|
# Users/groups issues can be assigned to
|
||||||
def assignable_users
|
def assignable_users
|
||||||
assignable = Setting.issue_group_assignment? ? member_principals : members
|
assignable = Setting.issue_group_assignment? ? member_principals : members
|
||||||
assignable.select {|m| m.roles.detect {|role| role.assignable?}}.collect {|m| m.principal}.sort
|
assignable.select {|m| m.roles.detect {|role| role.assignable?}}.collect {|m| m.principal}.sort
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns the mail adresses of users that should be always notified on project events
|
# Returns the mail adresses of users that should be always notified on project events
|
||||||
def recipients
|
def recipients
|
||||||
notified_users.collect {|user| user.mail}
|
notified_users.collect {|user| user.mail}
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns the users that should be notified on project events
|
# Returns the users that should be notified on project events
|
||||||
def notified_users
|
def notified_users
|
||||||
# TODO: User part should be extracted to User#notify_about?
|
# TODO: User part should be extracted to User#notify_about?
|
||||||
members.select {|m| m.mail_notification? || m.user.mail_notification == 'all'}.collect {|m| m.user}
|
members.select {|m| m.mail_notification? || m.user.mail_notification == 'all'}.collect {|m| m.user}
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns an array of all custom fields enabled for project issues
|
# Returns an array of all custom fields enabled for project issues
|
||||||
# (explictly associated custom fields and custom fields enabled for all projects)
|
# (explictly associated custom fields and custom fields enabled for all projects)
|
||||||
def all_issue_custom_fields
|
def all_issue_custom_fields
|
||||||
@ -454,19 +454,19 @@ class Project < ActiveRecord::Base
|
|||||||
def all_time_entry_custom_fields
|
def all_time_entry_custom_fields
|
||||||
@all_time_entry_custom_fields ||= (TimeEntryCustomField.for_all + time_entry_custom_fields).uniq.sort
|
@all_time_entry_custom_fields ||= (TimeEntryCustomField.for_all + time_entry_custom_fields).uniq.sort
|
||||||
end
|
end
|
||||||
|
|
||||||
def project
|
def project
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
def <=>(project)
|
def <=>(project)
|
||||||
name.downcase <=> project.name.downcase
|
name.downcase <=> project.name.downcase
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
name
|
name
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns a short description of the projects (first lines)
|
# Returns a short description of the projects (first lines)
|
||||||
def short_description(length = 255)
|
def short_description(length = 255)
|
||||||
description.gsub(/^(.{#{length}}[^\n\r]*).*$/m, '\1...').strip if description
|
description.gsub(/^(.{#{length}}[^\n\r]*).*$/m, '\1...').strip if description
|
||||||
@ -519,7 +519,7 @@ class Project < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Return true if this project is allowed to do the specified action.
|
# Return true if this project is allowed to do the specified action.
|
||||||
# action can be:
|
# action can be:
|
||||||
# * a parameter-like Hash (eg. :controller => 'projects', :action => 'edit')
|
# * a parameter-like Hash (eg. :controller => 'projects', :action => 'edit')
|
||||||
@ -531,12 +531,12 @@ class Project < ActiveRecord::Base
|
|||||||
allowed_permissions.include? action
|
allowed_permissions.include? action
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def module_enabled?(module_name)
|
def module_enabled?(module_name)
|
||||||
module_name = module_name.to_s
|
module_name = module_name.to_s
|
||||||
enabled_modules.detect {|m| m.name == module_name}
|
enabled_modules.detect {|m| m.name == module_name}
|
||||||
end
|
end
|
||||||
|
|
||||||
def enabled_module_names=(module_names)
|
def enabled_module_names=(module_names)
|
||||||
if module_names && module_names.is_a?(Array)
|
if module_names && module_names.is_a?(Array)
|
||||||
module_names = module_names.collect(&:to_s).reject(&:blank?)
|
module_names = module_names.collect(&:to_s).reject(&:blank?)
|
||||||
@ -545,7 +545,7 @@ class Project < ActiveRecord::Base
|
|||||||
enabled_modules.clear
|
enabled_modules.clear
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns an array of the enabled modules names
|
# Returns an array of the enabled modules names
|
||||||
def enabled_module_names
|
def enabled_module_names
|
||||||
enabled_modules.collect(&:name)
|
enabled_modules.collect(&:name)
|
||||||
@ -583,7 +583,7 @@ class Project < ActiveRecord::Base
|
|||||||
|
|
||||||
safe_attributes 'enabled_module_names',
|
safe_attributes 'enabled_module_names',
|
||||||
:if => lambda {|project, user| project.new_record? || user.allowed_to?(:select_project_modules, project) }
|
:if => lambda {|project, user| project.new_record? || user.allowed_to?(:select_project_modules, project) }
|
||||||
|
|
||||||
# Returns an array of projects that are in this project's hierarchy
|
# Returns an array of projects that are in this project's hierarchy
|
||||||
#
|
#
|
||||||
# Example: parents, children, siblings
|
# Example: parents, children, siblings
|
||||||
@ -592,7 +592,7 @@ class Project < ActiveRecord::Base
|
|||||||
descendants = project.descendants || []
|
descendants = project.descendants || []
|
||||||
project_hierarchy = parents | descendants # Set union
|
project_hierarchy = parents | descendants # Set union
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns an auto-generated project identifier based on the last identifier used
|
# Returns an auto-generated project identifier based on the last identifier used
|
||||||
def self.next_identifier
|
def self.next_identifier
|
||||||
p = Project.find(:first, :order => 'created_on DESC')
|
p = Project.find(:first, :order => 'created_on DESC')
|
||||||
@ -616,10 +616,10 @@ class Project < ActiveRecord::Base
|
|||||||
# project.copy(1, :only => ['members', 'versions']) # => copies members and versions
|
# project.copy(1, :only => ['members', 'versions']) # => copies members and versions
|
||||||
def copy(project, options={})
|
def copy(project, options={})
|
||||||
project = project.is_a?(Project) ? project : Project.find(project)
|
project = project.is_a?(Project) ? project : Project.find(project)
|
||||||
|
|
||||||
to_be_copied = %w(wiki versions issue_categories issues members queries boards)
|
to_be_copied = %w(wiki versions issue_categories issues members queries boards)
|
||||||
to_be_copied = to_be_copied & options[:only].to_a unless options[:only].nil?
|
to_be_copied = to_be_copied & options[:only].to_a unless options[:only].nil?
|
||||||
|
|
||||||
Project.transaction do
|
Project.transaction do
|
||||||
if save
|
if save
|
||||||
reload
|
reload
|
||||||
@ -632,7 +632,7 @@ class Project < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
# Copies +project+ and returns the new instance. This will not save
|
# Copies +project+ and returns the new instance. This will not save
|
||||||
# the copy
|
# the copy
|
||||||
def self.copy_from(project)
|
def self.copy_from(project)
|
||||||
@ -659,16 +659,16 @@ class Project < ActiveRecord::Base
|
|||||||
def self.project_tree(projects, &block)
|
def self.project_tree(projects, &block)
|
||||||
ancestors = []
|
ancestors = []
|
||||||
projects.sort_by(&:lft).each do |project|
|
projects.sort_by(&:lft).each do |project|
|
||||||
while (ancestors.any? && !project.is_descendant_of?(ancestors.last))
|
while (ancestors.any? && !project.is_descendant_of?(ancestors.last))
|
||||||
ancestors.pop
|
ancestors.pop
|
||||||
end
|
end
|
||||||
yield project, ancestors.size
|
yield project, ancestors.size
|
||||||
ancestors << project
|
ancestors << project
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# Copies wiki from +project+
|
# Copies wiki from +project+
|
||||||
def copy_wiki(project)
|
def copy_wiki(project)
|
||||||
# Check that the source project has a wiki first
|
# Check that the source project has a wiki first
|
||||||
@ -713,14 +713,14 @@ class Project < ActiveRecord::Base
|
|||||||
self.issue_categories << new_issue_category
|
self.issue_categories << new_issue_category
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Copies issues from +project+
|
# Copies issues from +project+
|
||||||
# Note: issues assigned to a closed version won't be copied due to validation rules
|
# Note: issues assigned to a closed version won't be copied due to validation rules
|
||||||
def copy_issues(project)
|
def copy_issues(project)
|
||||||
# Stores the source issue id as a key and the copied issues as the
|
# Stores the source issue id as a key and the copied issues as the
|
||||||
# value. Used to map the two togeather for issue relations.
|
# value. Used to map the two togeather for issue relations.
|
||||||
issues_map = {}
|
issues_map = {}
|
||||||
|
|
||||||
# Get issues sorted by root_id, lft so that parent issues
|
# Get issues sorted by root_id, lft so that parent issues
|
||||||
# get copied before their children
|
# get copied before their children
|
||||||
project.issues.find(:all, :order => 'root_id, lft').each do |issue|
|
project.issues.find(:all, :order => 'root_id, lft').each do |issue|
|
||||||
@ -743,7 +743,7 @@ class Project < ActiveRecord::Base
|
|||||||
new_issue.parent_issue_id = copied_parent.id
|
new_issue.parent_issue_id = copied_parent.id
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
self.issues << new_issue
|
self.issues << new_issue
|
||||||
if new_issue.new_record?
|
if new_issue.new_record?
|
||||||
logger.info "Project#copy_issues: issue ##{issue.id} could not be copied: #{new_issue.errors.full_messages}" if logger && logger.info
|
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
|
|||||||
# Issue was not copied
|
# Issue was not copied
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
|
|
||||||
# Relations
|
# Relations
|
||||||
issue.relations_from.each do |source_relation|
|
issue.relations_from.each do |source_relation|
|
||||||
new_issue_relation = IssueRelation.new
|
new_issue_relation = IssueRelation.new
|
||||||
@ -770,7 +770,7 @@ class Project < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
new_issue.relations_from << new_issue_relation
|
new_issue.relations_from << new_issue_relation
|
||||||
end
|
end
|
||||||
|
|
||||||
issue.relations_to.each do |source_relation|
|
issue.relations_to.each do |source_relation|
|
||||||
new_issue_relation = IssueRelation.new
|
new_issue_relation = IssueRelation.new
|
||||||
new_issue_relation.attributes = source_relation.attributes.dup.except("id", "issue_from_id", "issue_to_id")
|
new_issue_relation.attributes = source_relation.attributes.dup.except("id", "issue_from_id", "issue_to_id")
|
||||||
@ -789,7 +789,7 @@ class Project < ActiveRecord::Base
|
|||||||
members_to_copy = []
|
members_to_copy = []
|
||||||
members_to_copy += project.memberships.select {|m| m.principal.is_a?(User)}
|
members_to_copy += project.memberships.select {|m| m.principal.is_a?(User)}
|
||||||
members_to_copy += project.memberships.select {|m| !m.principal.is_a?(User)}
|
members_to_copy += project.memberships.select {|m| !m.principal.is_a?(User)}
|
||||||
|
|
||||||
members_to_copy.each do |member|
|
members_to_copy.each do |member|
|
||||||
new_member = Member.new
|
new_member = Member.new
|
||||||
new_member.attributes = member.attributes.dup.except("id", "project_id", "created_on")
|
new_member.attributes = member.attributes.dup.except("id", "project_id", "created_on")
|
||||||
@ -823,7 +823,7 @@ class Project < ActiveRecord::Base
|
|||||||
self.boards << new_board
|
self.boards << new_board
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def allowed_permissions
|
def allowed_permissions
|
||||||
@allowed_permissions ||= begin
|
@allowed_permissions ||= begin
|
||||||
module_names = enabled_modules.all(:select => :name).collect {|m| m.name}
|
module_names = enabled_modules.all(:select => :name).collect {|m| m.name}
|
||||||
@ -838,7 +838,7 @@ class Project < ActiveRecord::Base
|
|||||||
# Returns all the active Systemwide and project specific activities
|
# Returns all the active Systemwide and project specific activities
|
||||||
def active_activities
|
def active_activities
|
||||||
overridden_activity_ids = self.time_entry_activities.collect(&:parent_id)
|
overridden_activity_ids = self.time_entry_activities.collect(&:parent_id)
|
||||||
|
|
||||||
if overridden_activity_ids.empty?
|
if overridden_activity_ids.empty?
|
||||||
return TimeEntryActivity.shared.active
|
return TimeEntryActivity.shared.active
|
||||||
else
|
else
|
||||||
@ -872,7 +872,7 @@ class Project < ActiveRecord::Base
|
|||||||
self.time_entry_activities.active
|
self.time_entry_activities.active
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Archives subprojects recursively
|
# Archives subprojects recursively
|
||||||
def archive!
|
def archive!
|
||||||
children.each do |subproject|
|
children.each do |subproject|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user