Each version of a project can be shared with: * subprojects * projects in the project hierarchy: ancestors + descendants (needs versions management permission on the root project) * projects in the project tree: root project + all its descendants (same as above) * all projects (can be set by admin users only) Notes: * when sharing a version of a private project with others projects, its name will be visible within the other projects * a project with versions used by non descendant projects can not be archived git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3123 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
1 parent
e178123569
commit
5f8e9d7118
40 files changed
+659
-75
No files matched your search
+43
-1
@@ -17,6 +17,7 @@
|
||||
|
||||
class Version < ActiveRecord::Base
|
||||
before_destroy :check_integrity
|
||||
after_update :update_issue_versions
|
||||
belongs_to :project
|
||||
has_many :fixed_issues, :class_name => 'Issue', :foreign_key => 'fixed_version_id'
|
||||
acts_as_customizable
|
||||
@@ -24,15 +25,24 @@ class Version < ActiveRecord::Base
|
||||
:delete_permission => :manage_files
|
||||
|
||||
VERSION_STATUSES = %w(open locked closed)
|
||||
VERSION_SHARINGS = %w(none descendants hierarchy tree system)
|
||||
|
||||
validates_presence_of :name
|
||||
validates_uniqueness_of :name, :scope => [:project_id]
|
||||
validates_length_of :name, :maximum => 60
|
||||
validates_format_of :effective_date, :with => /^\d{4}-\d{2}-\d{2}$/, :message => :not_a_date, :allow_nil => true
|
||||
validates_inclusion_of :status, :in => VERSION_STATUSES
|
||||
validates_inclusion_of :sharing, :in => VERSION_SHARINGS
|
||||
|
||||
named_scope :open, :conditions => {:status => 'open'}
|
||||
|
||||
named_scope :visible, lambda {|*args| { :include => :project,
|
||||
:conditions => Project.allowed_to_condition(args.first || User.current, :view_issues) } }
|
||||
|
||||
# Returns true if +user+ or current user is allowed to view the version
|
||||
def visible?(user=User.current)
|
||||
user.allowed_to?(:view_issues, self.project)
|
||||
end
|
||||
|
||||
def start_date
|
||||
effective_date
|
||||
end
|
||||
@@ -54,6 +64,10 @@ class Version < ActiveRecord::Base
|
||||
def closed?
|
||||
status == 'closed'
|
||||
end
|
||||
|
||||
def open?
|
||||
status == 'open'
|
||||
end
|
||||
|
||||
# Returns true if the version is completed: due date reached and no open issues
|
||||
def completed?
|
||||
@@ -120,10 +134,38 @@ class Version < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
|
||||
# Returns the sharings that +user+ can set the version to
|
||||
def allowed_sharings(user = User.current)
|
||||
VERSION_SHARINGS.select do |s|
|
||||
if sharing == s
|
||||
true
|
||||
else
|
||||
case s
|
||||
when 'system'
|
||||
# Only admin users can set a systemwide sharing
|
||||
user.admin?
|
||||
when 'hierarchy', 'tree'
|
||||
# Only users allowed to manage versions of the root project can
|
||||
# set sharing to hierarchy or tree
|
||||
project.nil? || user.allowed_to?(:manage_versions, project.root)
|
||||
else
|
||||
true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def check_integrity
|
||||
raise "Can't delete version" if self.fixed_issues.find(:first)
|
||||
end
|
||||
|
||||
# Update the issue's fixed versions. Used if a version's sharing changes.
|
||||
def update_issue_versions
|
||||
if sharing_changed?
|
||||
Issue.update_fixed_versions_from_project_hierarchy_change
|
||||
end
|
||||
end
|
||||
|
||||
# Returns the average estimated time of assigned issues
|
||||
# or 1 if no issue has an estimated time
|
||||
|
||||
Reference in new issue
Block a user