Commit ff9b180d authored by jplang's avatar jplang
Browse files

Adds version status to limit issue assignments (#1245).

Available version statuses are:
* open: no restriction
* locked: can not assign new issues to the version
* closed: can not assign new issues and can not reopen assigned issues

git-svn-id: https://svn.redmine.org/redmine/trunk@3020 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent a184a684
......@@ -143,6 +143,14 @@ class Issue < ActiveRecord::Base
if start_date && soonest_start && start_date < soonest_start
errors.add :start_date, :invalid
end
if fixed_version
if !assignable_versions.include?(fixed_version)
errors.add :fixed_version_id, :inclusion
elsif reopened? && fixed_version.closed?
errors.add_to_base I18n.t(:error_can_not_reopen_issue_on_closed_version)
end
end
end
def validate_on_create
......@@ -193,6 +201,18 @@ class Issue < ActiveRecord::Base
self.status.is_closed?
end
# Return true if the issue is being reopened
def reopened?
if !new_record? && status_id_changed?
status_was = IssueStatus.find_by_id(status_id_was)
status_new = IssueStatus.find_by_id(status_id)
if status_was && status_new && status_was.is_closed? && !status_new.is_closed?
return true
end
end
false
end
# Returns true if the issue is overdue
def overdue?
!due_date.nil? && (due_date < Date.today) && !status.is_closed?
......@@ -203,6 +223,11 @@ class Issue < ActiveRecord::Base
project.assignable_users
end
# Versions that the issue can be assigned to
def assignable_versions
@assignable_versions ||= (project.versions.open + [Version.find_by_id(fixed_version_id_was)]).compact.uniq.sort
end
# Returns true if this issue is blocked by another issue that is still open
def blocked?
!relations_to.detect {|ir| ir.relation_type == 'blocks' && !ir.issue_from.closed?}.nil?
......
......@@ -22,11 +22,16 @@ class Version < ActiveRecord::Base
acts_as_attachable :view_permission => :view_files,
:delete_permission => :manage_files
VERSION_STATUSES = %w(open locked closed)
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
named_scope :open, :conditions => {:status => 'open'}
def start_date
effective_date
end
......@@ -45,6 +50,10 @@ class Version < ActiveRecord::Base
@spent_hours ||= TimeEntry.sum(:hours, :include => :issue, :conditions => ["#{Issue.table_name}.fixed_version_id = ?", id]).to_f
end
def closed?
status == 'closed'
end
# Returns true if the version is completed: due date reached and no open issues
def completed?
effective_date && (effective_date <= Date.today) && (open_issues_count == 0)
......
......@@ -32,9 +32,9 @@
{:controller => 'projects', :action => 'add_issue_category', :id => @project},
:class => 'small', :tabindex => 199) if authorize_for('projects', 'add_issue_category') %></p>
<% end %>
<%= content_tag('p', f.select(:fixed_version_id,
(@project.versions.sort.collect {|v| [v.name, v.id]}),
{ :include_blank => true })) unless @project.versions.empty? %>
<% unless @issue.assignable_versions.empty? %>
<p><%= f.select :fixed_version_id, (@issue.assignable_versions.collect {|v| [v.name, v.id]}), :include_blank => true %></p>
<% end %>
</div>
<div class="splitcontentright">
......
......@@ -5,8 +5,8 @@
</div>
<div class="splitcontentright">
<p><%= f.select :done_ratio, ((0..10).to_a.collect {|r| ["#{r*10} %", r*10] }) %></p>
<%= content_tag('p', f.select(:fixed_version_id,
(@project.versions.sort.collect {|v| [v.name, v.id]}),
{ :include_blank => true })) unless @project.versions.empty? %>
<% unless @issue.assignable_versions.empty? %>
<p><%= f.select :fixed_version_id, (@issue.assignable_versions.collect {|v| [v.name, v.id]}), :include_blank => true %></p>
<% end %>
</div>
</div>
......@@ -27,7 +27,7 @@
<label><%= l(:field_fixed_version) %>:
<%= select_tag('fixed_version_id', content_tag('option', l(:label_no_change_option), :value => '') +
content_tag('option', l(:label_none), :value => 'none') +
options_from_collection_for_select(@project.versions.sort, :id, :name)) %></label>
options_from_collection_for_select(@project.versions.open.sort, :id, :name)) %></label>
</p>
<p>
......
......@@ -27,11 +27,11 @@
<% end -%>
</ul>
</li>
<% unless @project.nil? || @project.versions.empty? -%>
<% unless @project.nil? || @project.versions.open.empty? -%>
<li class="folder">
<a href="#" class="submenu"><%= l(:field_fixed_version) %></a>
<ul>
<% @project.versions.sort.each do |v| -%>
<% @project.versions.open.sort.each do |v| -%>
<li><%= context_menu_link v.name, {:controller => 'issues', :action => 'bulk_edit', :ids => @issues.collect(&:id), 'fixed_version_id' => v, :back_to => @back}, :method => :post,
:selected => (@issue && v == @issue.fixed_version), :disabled => !@can[:update] %></li>
<% end -%>
......
<% if @project.versions.any? %>
<table class="list">
<table class="list versions">
<thead>
<th><%= l(:label_version) %></th>
<th><%= l(:field_effective_date) %></th>
<th><%= l(:field_description) %></th>
<th><%= l(:field_status) %></th>
<th><%= l(:label_wiki_page) unless @project.wiki.nil? %></th>
<th style="width:15%"></th>
<th style="width:15%"></th>
</thead>
<tbody>
<% for version in @project.versions.sort %>
<tr class="<%= cycle 'odd', 'even' %>">
<tr class="version <%= cycle 'odd', 'even' %> <%=h version.status %>">
<td><%= link_to h(version.name), :controller => 'versions', :action => 'show', :id => version %></td>
<td align="center"><%= format_date(version.effective_date) %></td>
<td><%=h version.description %></td>
<td><%= l("version_status_#{version.status}") %></td>
<td><%= link_to(h(version.wiki_page_title), :controller => 'wiki', :page => Wiki.titleize(version.wiki_page_title)) unless version.wiki_page_title.blank? || @project.wiki.nil? %></td>
<td align="center"><%= link_to_if_authorized l(:button_edit), { :controller => 'versions', :action => 'edit', :id => version }, :class => 'icon icon-edit' %></td>
<td align="center"><%= link_to_if_authorized l(:button_delete), {:controller => 'versions', :action => 'destroy', :id => version}, :confirm => l(:text_are_you_sure), :method => :post, :class => 'icon icon-del' %></td>
<td class="buttons">
<%= link_to_if_authorized l(:button_edit), {:controller => 'versions', :action => 'edit', :id => version }, :class => 'icon icon-edit' %>
<%= link_to_if_authorized l(:button_delete), {:controller => 'versions', :action => 'destroy', :id => version}, :confirm => l(:text_are_you_sure), :method => :post, :class => 'icon icon-del' %>
</td>
</tr>
<% end; reset_cycle %>
</tbody>
......
......@@ -3,6 +3,7 @@
<div class="box">
<p><%= f.text_field :name, :size => 60, :required => true %></p>
<p><%= f.text_field :description, :size => 60 %></p>
<p><%= f.select :status, Version::VERSION_STATUSES.collect {|s| [l("version_status_#{s}"), s]} %></p>
<p><%= f.text_field :wiki_page_title, :label => :label_wiki_page, :size => 60, :disabled => @project.wiki.nil? %></p>
<p><%= f.text_field :effective_date, :size => 10 %><%= calendar_for('version_effective_date') %></p>
</div>
......@@ -827,3 +827,7 @@ bg:
field_active: Active
enumeration_system_activity: System Activity
permission_delete_issue_watchers: Delete watchers
version_status_closed: closed
version_status_locked: locked
version_status_open: open
error_can_not_reopen_issue_on_closed_version: An issue assigned to a closed version can not be reopened
......@@ -851,3 +851,7 @@ bs:
field_active: Active
enumeration_system_activity: System Activity
permission_delete_issue_watchers: Delete watchers
version_status_closed: closed
version_status_locked: locked
version_status_open: open
error_can_not_reopen_issue_on_closed_version: An issue assigned to a closed version can not be reopened
......@@ -830,3 +830,7 @@ ca:
field_active: Active
enumeration_system_activity: System Activity
permission_delete_issue_watchers: Delete watchers
version_status_closed: closed
version_status_locked: locked
version_status_open: open
error_can_not_reopen_issue_on_closed_version: An issue assigned to a closed version can not be reopened
......@@ -833,3 +833,7 @@ cs:
field_active: Active
enumeration_system_activity: System Activity
permission_delete_issue_watchers: Delete watchers
version_status_closed: closed
version_status_locked: locked
version_status_open: open
error_can_not_reopen_issue_on_closed_version: An issue assigned to a closed version can not be reopened
......@@ -853,3 +853,7 @@ da:
field_active: Active
enumeration_system_activity: System Activity
permission_delete_issue_watchers: Delete watchers
version_status_closed: closed
version_status_locked: locked
version_status_open: open
error_can_not_reopen_issue_on_closed_version: An issue assigned to a closed version can not be reopened
......@@ -853,3 +853,7 @@ de:
field_active: Active
enumeration_system_activity: System Activity
permission_delete_issue_watchers: Delete watchers
version_status_closed: closed
version_status_locked: locked
version_status_open: open
error_can_not_reopen_issue_on_closed_version: An issue assigned to a closed version can not be reopened
......@@ -833,3 +833,7 @@ el:
field_active: Active
enumeration_system_activity: System Activity
permission_delete_issue_watchers: Delete watchers
version_status_closed: closed
version_status_locked: locked
version_status_open: open
error_can_not_reopen_issue_on_closed_version: An issue assigned to a closed version can not be reopened
......@@ -155,6 +155,7 @@ en:
error_issue_not_found_in_project: 'The issue was not found or does not belong to this project'
error_no_tracker_in_project: 'No tracker is associated to this project. Please check the Project settings.'
error_no_default_issue_status: 'No default issue status is defined. Please check your configuration (Go to "Administration -> Issue statuses").'
error_can_not_reopen_issue_on_closed_version: 'An issue assigned to a closed version can not be reopened'
warning_attachments_not_saved: "{{count}} file(s) could not be saved."
......@@ -749,6 +750,10 @@ en:
status_active: active
status_registered: registered
status_locked: locked
version_status_open: open
version_status_locked: locked
version_status_closed: closed
field_active: Active
......
......@@ -874,3 +874,7 @@ es:
field_active: Active
enumeration_system_activity: System Activity
permission_delete_issue_watchers: Delete watchers
version_status_closed: closed
version_status_locked: locked
version_status_open: open
error_can_not_reopen_issue_on_closed_version: An issue assigned to a closed version can not be reopened
......@@ -863,3 +863,7 @@ fi:
field_active: Active
enumeration_system_activity: System Activity
permission_delete_issue_watchers: Delete watchers
version_status_closed: closed
version_status_locked: locked
version_status_open: open
error_can_not_reopen_issue_on_closed_version: An issue assigned to a closed version can not be reopened
......@@ -177,6 +177,7 @@ fr:
error_scm_command_failed: "Une erreur s'est produite lors de l'accès au dépôt: {{value}}"
error_scm_annotate: "L'entrée n'existe pas ou ne peut pas être annotée."
error_issue_not_found_in_project: "La demande n'existe pas ou n'appartient pas à ce projet"
error_can_not_reopen_issue_on_closed_version: 'Une demande assignée à une version fermée ne peut pas être réouverte'
warning_attachments_not_saved: "{{count}} fichier(s) n'ont pas pu être sauvegardés."
......@@ -767,6 +768,10 @@ fr:
status_registered: enregistré
status_locked: vérouillé
version_status_open: ouvert
version_status_locked: vérouillé
version_status_closed: fermé
text_select_mail_notifications: Actions pour lesquelles une notification par e-mail est envoyée
text_regexp_info: ex. ^[A-Z0-9]+$
text_min_max_length_info: 0 pour aucune restriction
......
......@@ -853,3 +853,7 @@ gl:
field_active: Active
enumeration_system_activity: System Activity
permission_delete_issue_watchers: Delete watchers
version_status_closed: closed
version_status_locked: locked
version_status_open: open
error_can_not_reopen_issue_on_closed_version: An issue assigned to a closed version can not be reopened
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment