diff --git app/models/issue.rb app/models/issue.rb index 928dedc..22f2b19 100644 --- app/models/issue.rb +++ app/models/issue.rb @@ -259,6 +259,17 @@ class Issue < ActiveRecord::Base self.status_id end + # Returns the current status if the workflow allows the status to be unchanged + # or the first status from the list of allowed new statuses. + def status_id_or_first_allowed + user = User.current + if new_statuses_allowed_to(user).collect(&:id).include?(status_id.to_i) + status_id + else + new_statuses_allowed_to(user).first(&:id).id + end + end + # Sets the status. def status=(status) if status != self.status @@ -646,6 +657,10 @@ class Issue < ActiveRecord::Base end end end + + unless new_statuses_allowed_to(User.current).collect(&:id).include?(status_id.to_i) + errors.add :status_id + end end # Validates the issue against additional workflow requirements @@ -851,7 +866,7 @@ class Issue < ActiveRecord::Base assignee_transitions_allowed ) end - statuses << initial_status unless statuses.empty? + statuses << initial_status if statuses.empty? statuses << default_status if include_default statuses = statuses.compact.uniq.sort if blocked? diff --git app/views/issues/_attributes.html.erb app/views/issues/_attributes.html.erb index 3d5f85c..5509074 100644 --- app/views/issues/_attributes.html.erb +++ app/views/issues/_attributes.html.erb @@ -3,7 +3,7 @@
<% if @issue.safe_attribute?('status_id') && @allowed_statuses.present? %> -

<%= f.select :status_id, (@allowed_statuses.collect {|p| [p.name, p.id]}), {:required => true}, +

<%= f.select :status_id, (@allowed_statuses.collect {|p| [p.name, p.id]}), {:required => true, :selected => @issue.status_id_or_first_allowed}, :onchange => "updateIssueFrom('#{escape_javascript update_issue_form_path(@project, @issue)}')" %>

<%= hidden_field_tag 'was_default_status', @issue.status_id, :id => nil if @issue.status == @issue.default_status %> <% else %>