diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2015-07-26 08:30:19 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2015-07-26 08:30:19 +0000 |
commit | 2bc5b60f9de7c533b33348213f6ddac37dc9cdb3 (patch) | |
tree | 803c2d2ece43283b231b59ede3636c9fc2d3828a /app | |
parent | fdecb2a17b450c4524856b0286c2ec27ef113ea6 (diff) | |
download | redmine-2bc5b60f9de7c533b33348213f6ddac37dc9cdb3.tar.gz redmine-2bc5b60f9de7c533b33348213f6ddac37dc9cdb3.zip |
Makes new issue initial status settable in workflow (#5816).
git-svn-id: http://svn.redmine.org/redmine/trunk@14458 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/issues_controller.rb | 12 | ||||
-rw-r--r-- | app/controllers/workflows_controller.rb | 4 | ||||
-rw-r--r-- | app/helpers/workflows_helper.rb | 6 | ||||
-rw-r--r-- | app/models/issue.rb | 25 | ||||
-rw-r--r-- | app/models/issue_status.rb | 22 | ||||
-rw-r--r-- | app/models/workflow_permission.rb | 1 | ||||
-rw-r--r-- | app/models/workflow_rule.rb | 2 | ||||
-rw-r--r-- | app/views/workflows/_form.html.erb | 9 |
8 files changed, 39 insertions, 42 deletions
diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 80f02409a..4238215eb 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -427,12 +427,12 @@ class IssuesController < ApplicationController @issue.author ||= User.current @issue.start_date ||= Date.today if Setting.default_issue_start_date_to_creation_date? - if attrs = params[:issue].deep_dup - if action_name == 'new' && params[:was_default_status] == attrs[:status_id] - attrs.delete(:status_id) - end - @issue.safe_attributes = attrs + attrs = (params[:issue] || {}).deep_dup + if action_name == 'new' && params[:was_default_status] == attrs[:status_id] + attrs.delete(:status_id) end + @issue.safe_attributes = attrs + if @issue.project @issue.tracker ||= @issue.project.trackers.first if @issue.tracker.nil? @@ -446,7 +446,7 @@ class IssuesController < ApplicationController end @priorities = IssuePriority.active - @allowed_statuses = @issue.new_statuses_allowed_to(User.current, @issue.new_record?) + @allowed_statuses = @issue.new_statuses_allowed_to(User.current) end def parse_params_for_bulk_issue_attributes(params) diff --git a/app/controllers/workflows_controller.rb b/app/controllers/workflows_controller.rb index af8c2750b..6f8a65f9c 100644 --- a/app/controllers/workflows_controller.rb +++ b/app/controllers/workflows_controller.rb @@ -43,7 +43,9 @@ class WorkflowsController < ApplicationController end if @trackers && @roles && @statuses.any? - workflows = WorkflowTransition.where(:role_id => @roles.map(&:id), :tracker_id => @trackers.map(&:id)) + workflows = WorkflowTransition. + where(:role_id => @roles.map(&:id), :tracker_id => @trackers.map(&:id)). + preload(:old_status, :new_status) @workflows = {} @workflows['always'] = workflows.select {|w| !w.author && !w.assignee} @workflows['author'] = workflows.select {|w| w.author} diff --git a/app/helpers/workflows_helper.rb b/app/helpers/workflows_helper.rb index 4adaa5067..cfd7a3669 100644 --- a/app/helpers/workflows_helper.rb +++ b/app/helpers/workflows_helper.rb @@ -75,14 +75,14 @@ module WorkflowsHelper end def transition_tag(workflows, old_status, new_status, name) - w = workflows.select {|w| w.old_status_id == old_status.id && w.new_status_id == new_status.id}.size + w = workflows.select {|w| w.old_status == old_status && w.new_status == new_status}.size - tag_name = "transitions[#{ old_status.id }][#{new_status.id}][#{name}]" + tag_name = "transitions[#{ old_status.try(:id) || 0 }][#{new_status.id}][#{name}]" if w == 0 || w == @roles.size * @trackers.size hidden_field_tag(tag_name, "0", :id => nil) + check_box_tag(tag_name, "1", w != 0, - :class => "old-status-#{old_status.id} new-status-#{new_status.id}") + :class => "old-status-#{old_status.try(:id) || 0} new-status-#{new_status.id}") else select_tag tag_name, options_for_select([ diff --git a/app/models/issue.rb b/app/models/issue.rb index e0f93faef..a4a7614d4 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -465,11 +465,15 @@ class Issue < ActiveRecord::Base self.tracker ||= project.trackers.first end + statuses_allowed = new_statuses_allowed_to(user) if (s = attrs.delete('status_id')) && safe_attribute?('status_id') - if new_statuses_allowed_to(user).collect(&:id).include?(s.to_i) + if statuses_allowed.collect(&:id).include?(s.to_i) self.status_id = s end end + if new_record? && !statuses_allowed.include?(status) + self.status = statuses_allowed.first || default_status + end attrs = delete_unsafe_attributes(attrs, user) return if attrs.empty? @@ -825,7 +829,7 @@ class Issue < ActiveRecord::Base else initial_status = nil if new_record? - initial_status = default_status + # nop elsif tracker_id_changed? if Tracker.where(:id => tracker_id_was, :default_status_id => status_id_was).any? initial_status = default_status @@ -843,16 +847,15 @@ class Issue < ActiveRecord::Base (user.id == initial_assigned_to_id || user.group_ids.include?(initial_assigned_to_id)) statuses = [] - if initial_status - statuses += initial_status.find_new_statuses_allowed_to( - user.admin ? Role.all.to_a : user.roles_for_project(project), - tracker, - author == user, - assignee_transitions_allowed - ) - end + statuses += IssueStatus.new_statuses_allowed( + initial_status, + user.admin ? Role.all.to_a : user.roles_for_project(project), + tracker, + author == user, + assignee_transitions_allowed + ) statuses << initial_status unless statuses.empty? - statuses << default_status if include_default + statuses << default_status if include_default || (new_record? && statuses.empty?) statuses = statuses.compact.uniq.sort if blocked? statuses.reject!(&:is_closed?) diff --git a/app/models/issue_status.rb b/app/models/issue_status.rb index 4e9b2ce87..e39d69a76 100644 --- a/app/models/issue_status.rb +++ b/app/models/issue_status.rb @@ -45,28 +45,18 @@ class IssueStatus < ActiveRecord::Base end # Returns an array of all statuses the given role can switch to - # Uses association cache when called more than one time def new_statuses_allowed_to(roles, tracker, author=false, assignee=false) - if roles && tracker - role_ids = roles.collect(&:id) - transitions = workflows.select do |w| - role_ids.include?(w.role_id) && - w.tracker_id == tracker.id && - ((!w.author && !w.assignee) || (author && w.author) || (assignee && w.assignee)) - end - transitions.map(&:new_status).compact.sort - else - [] - end + self.class.new_statuses_allowed(self, roles, tracker, author, assignee) end + alias :find_new_statuses_allowed_to :new_statuses_allowed_to - # Same thing as above but uses a database query - # More efficient than the previous method if called just once - def find_new_statuses_allowed_to(roles, tracker, author=false, assignee=false) + def self.new_statuses_allowed(status, roles, tracker, author=false, assignee=false) if roles.present? && tracker + status_id = status.try(:id) || 0 + scope = IssueStatus. joins(:workflow_transitions_as_new_status). - where(:workflows => {:old_status_id => id, :role_id => roles.map(&:id), :tracker_id => tracker.id}) + where(:workflows => {:old_status_id => status_id, :role_id => roles.map(&:id), :tracker_id => tracker.id}) unless author && assignee if author || assignee diff --git a/app/models/workflow_permission.rb b/app/models/workflow_permission.rb index 6a451fd38..095d75b1c 100644 --- a/app/models/workflow_permission.rb +++ b/app/models/workflow_permission.rb @@ -17,6 +17,7 @@ class WorkflowPermission < WorkflowRule validates_inclusion_of :rule, :in => %w(readonly required) + validates_presence_of :old_status validate :validate_field_name # Returns the workflow permissions for the given trackers and roles diff --git a/app/models/workflow_rule.rb b/app/models/workflow_rule.rb index 25f76d7b2..976713a16 100644 --- a/app/models/workflow_rule.rb +++ b/app/models/workflow_rule.rb @@ -23,7 +23,7 @@ class WorkflowRule < ActiveRecord::Base belongs_to :old_status, :class_name => 'IssueStatus' belongs_to :new_status, :class_name => 'IssueStatus' - validates_presence_of :role, :tracker, :old_status + validates_presence_of :role, :tracker attr_protected :id # Copies workflows from source to targets diff --git a/app/views/workflows/_form.html.erb b/app/views/workflows/_form.html.erb index a788a7a68..76f6fefe3 100644 --- a/app/views/workflows/_form.html.erb +++ b/app/views/workflows/_form.html.erb @@ -20,16 +20,17 @@ </tr> </thead> <tbody> - <% for old_status in @statuses %> + <% for old_status in [nil] + @statuses %> + <% next if old_status.nil? && name != 'always' %> <tr class="<%= cycle("odd", "even") %>"> <td class="name"> - <%= link_to_function(image_tag('toggle_check.png'), "toggleCheckboxesBySelector('table.transitions-#{name} input.old-status-#{old_status.id}')", + <%= link_to_function(image_tag('toggle_check.png'), "toggleCheckboxesBySelector('table.transitions-#{name} input.old-status-#{old_status.try(:id) || 0}')", :title => "#{l(:button_check_all)}/#{l(:button_uncheck_all)}") %> - <%= old_status.name %> + <%= old_status ? old_status.name : content_tag('em', l(:label_issue_new)) %> </td> <% for new_status in @statuses -%> - <% checked = workflows.detect {|w| w.old_status_id == old_status.id && w.new_status_id == new_status.id} %> + <% checked = workflows.detect {|w| w.old_status == old_status && w.new_status == new_status} %> <td class="<%= checked ? 'enabled' : '' %>"> <%= transition_tag workflows, old_status, new_status, name %> </td> |