Project

General

Profile

Feature #31206 » RM_31206_tracker_change_avoid_to_set_blocked_status_for_user_changing_issues_SVN.diff

Jérôme BATAILLE, 2019-04-23 22:42

View differences:

app/models/issue.rb
347 347
    if tracker != tracker_was
348 348
      if status == tracker_was.try(:default_status)
349 349
        self.status = nil
350
      elsif status && tracker && !tracker.issue_status_ids.include?(status.id)
350
      elsif status && tracker && !tracker.issue_status_ids_for_roles(User.current.roles_for_project(project)).include?(status.id)
351 351
        self.status = nil
352 352
      end
353 353
      reassign_custom_field_values
......
977 977
    elsif tracker_id_changed?
978 978
      if Tracker.where(:id => tracker_id_was, :default_status_id => status_id_was).any?
979 979
        initial_status = default_status
980
      elsif tracker.issue_status_ids.include?(status_id_was)
980
      elsif tracker.issue_status_ids_for_roles(user.roles_for_project(project)).include?(status_id_was)
981 981
        initial_status = IssueStatus.find_by_id(status_id_was)
982 982
      else
983 983
        initial_status = default_status
app/models/tracker.rb
91 91
    end
92 92
  end
93 93

  
94
  def issue_status_ids_for_roles(roles)
95
    if roles.present?
96
      scope = IssueStatus.
97
        joins(:workflow_transitions_as_new_status).
98
        where(:workflows => {:role_id => roles.map(&:id), :tracker_id => self.id})
99

  
100
      scope.distinct.pluck(:id).sort
101
    else
102
      []
103
    end
104
  end
105

  
94 106
  def disabled_core_fields
95 107
    i = -1
96 108
    @disabled_core_fields ||= CORE_FIELDS.select { i += 1; (fields_bits || 0) & (2 ** i) != 0}
    (1-1/1)