Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

workflow_transition.rb 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. # frozen_string_literal: true
  2. # Redmine - project management software
  3. # Copyright (C) 2006-2019 Jean-Philippe Lang
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. class WorkflowTransition < WorkflowRule
  19. validates_presence_of :new_status
  20. def self.replace_transitions(trackers, roles, transitions)
  21. trackers = Array.wrap trackers
  22. roles = Array.wrap roles
  23. transaction do
  24. records = WorkflowTransition.where(:tracker_id => trackers.map(&:id), :role_id => roles.map(&:id)).to_a
  25. transitions.each do |old_status_id, transitions_by_new_status|
  26. transitions_by_new_status.each do |new_status_id, transition_by_rule|
  27. transition_by_rule.each do |rule, transition|
  28. trackers.each do |tracker|
  29. roles.each do |role|
  30. w = records.select {|r|
  31. r.old_status_id == old_status_id.to_i &&
  32. r.new_status_id == new_status_id.to_i &&
  33. r.tracker_id == tracker.id &&
  34. r.role_id == role.id &&
  35. !r.destroyed?
  36. }
  37. if rule == 'always'
  38. w = w.select {|r| !r.author && !r.assignee}
  39. else
  40. w = w.select {|r| r.author || r.assignee}
  41. end
  42. if w.size > 1
  43. w[1..-1].each(&:destroy)
  44. end
  45. w = w.first
  46. if transition == "1" || transition == true
  47. unless w
  48. w = WorkflowTransition.new(:old_status_id => old_status_id, :new_status_id => new_status_id, :tracker_id => tracker.id, :role_id => role.id)
  49. records << w
  50. end
  51. w.author = true if rule == "author"
  52. w.assignee = true if rule == "assignee"
  53. w.save if w.changed?
  54. elsif w
  55. if rule == 'always'
  56. w.destroy
  57. elsif rule == 'author'
  58. if w.assignee
  59. w.author = false
  60. w.save if w.changed?
  61. else
  62. w.destroy
  63. end
  64. elsif rule == 'assignee'
  65. if w.author
  66. w.assignee = false
  67. w.save if w.changed?
  68. else
  69. w.destroy
  70. end
  71. end
  72. end
  73. end
  74. end
  75. end
  76. end
  77. end
  78. end
  79. end
  80. end