From 64d3091636884d91091c8456ea3c41c14a9df7dc Mon Sep 17 00:00:00 2001 From: ulferts Date: Fri, 14 Jun 2019 13:05:17 +0200 Subject: [PATCH] replace acts_as_silent_list by acts_as_list touch_on_update: false --- Gemfile.lock | 5 +- app/models/custom_action.rb | 8 +-- app/models/work_package.rb | 9 ++-- .../lib/open_project/backlogs/engine.rb | 3 -- .../lib/open_project/backlogs/list.rb | 49 +++++++++++-------- .../backlogs/patches/version_patch.rb | 2 +- .../backlogs/patches/work_package_patch.rb | 38 +++++++------- modules/backlogs/openproject-backlogs.gemspec | 2 +- modules/backlogs/spec/models/version_spec.rb | 8 +-- 9 files changed, 63 insertions(+), 61 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 83799d89cc..6cb319e307 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -113,7 +113,7 @@ PATH remote: modules/backlogs specs: openproject-backlogs (1.0.0) - acts_as_silent_list (~> 3.0.0) + acts_as_list (~> 0.9.18) openproject-pdf_export PATH @@ -293,9 +293,8 @@ GEM i18n (>= 0.7, < 2) minitest (~> 5.1) tzinfo (~> 1.1) - acts_as_list (0.9.11) + acts_as_list (0.9.19) activerecord (>= 3.0) - acts_as_silent_list (3.0.0) acts_as_tree (2.8.0) activerecord (>= 3.0.0) addressable (2.6.0) diff --git a/app/models/custom_action.rb b/app/models/custom_action.rb index 04fbbaa328..a15530bbc9 100644 --- a/app/models/custom_action.rb +++ b/app/models/custom_action.rb @@ -53,7 +53,7 @@ class CustomAction < ActiveRecord::Base ret end - def reload + def reload(*args) @conditions = nil super @@ -113,11 +113,7 @@ class CustomAction < ActiveRecord::Base availables.map do |available| existing = actual.detect { |a| a.key == available.key } - if existing - existing - else - available.new - end + existing || available.new end end diff --git a/app/models/work_package.rb b/app/models/work_package.rb index 8773209c7b..24c4e0673a 100644 --- a/app/models/work_package.rb +++ b/app/models/work_package.rb @@ -246,11 +246,14 @@ class WorkPackage < ActiveRecord::Base end # Users/groups the work_package can be assigned to - extend Forwardable - def_delegator :project, :possible_assignees, :assignable_assignees + def assignable_assignees + project.possible_assignees + end # Users the work_package can be assigned to - def_delegator :project, :possible_responsibles, :assignable_responsibles + def assignable_responsibles + project.possible_responsibles + end # Versions that the work_package can be assigned to # A work_package can be assigned to: diff --git a/modules/backlogs/lib/open_project/backlogs/engine.rb b/modules/backlogs/lib/open_project/backlogs/engine.rb index 0dee7d7fbd..a2e3a144f6 100644 --- a/modules/backlogs/lib/open_project/backlogs/engine.rb +++ b/modules/backlogs/lib/open_project/backlogs/engine.rb @@ -35,9 +35,6 @@ require 'open_project/plugins' - -require 'acts_as_silent_list' - module OpenProject::Backlogs class Engine < ::Rails::Engine engine_name :openproject_backlogs diff --git a/modules/backlogs/lib/open_project/backlogs/list.rb b/modules/backlogs/lib/open_project/backlogs/list.rb index 25c0f8a6b5..c6bed5ccd8 100644 --- a/modules/backlogs/lib/open_project/backlogs/list.rb +++ b/modules/backlogs/lib/open_project/backlogs/list.rb @@ -34,26 +34,29 @@ #++ module OpenProject::Backlogs::List - def self.included(base) - base.class_eval do - acts_as_silent_list - - # Reorder list, if work_package is removed from sprint - before_update :fix_other_work_package_positions - before_update :fix_own_work_package_position - - # Used by acts_as_silent_list to limit the list to a certain subset within - # the table. - # - # Also sanitize_sql seems to be unavailable in a sensible way. Therefore - # we're using send to circumvent visibility work_packages. - def scope_condition - self.class.send(:sanitize_sql, ['project_id = ? AND fixed_version_id = ? AND type_id IN (?)', - project_id, fixed_version_id, types]) - end - - include InstanceMethods + extend ActiveSupport::Concern + + included do + acts_as_list touch_on_update: false + # acts as list adds a before destroy hook which messes + # with the parent_id_was value + skip_callback(:destroy, :before, :reload) + + # Reorder list, if work_package is removed from sprint + before_update :fix_other_work_package_positions + before_update :fix_own_work_package_position + + # Used by acts_list to limit the list to a certain subset within + # the table. + # + # Also sanitize_sql seems to be unavailable in a sensible way. Therefore + # we're using send to circumvent visibility work_packages. + def scope_condition + self.class.send(:sanitize_sql, ['project_id = ? AND fixed_version_id = ? AND type_id IN (?)', + project_id, fixed_version_id, types]) end + + include InstanceMethods end module InstanceMethods @@ -85,6 +88,10 @@ module OpenProject::Backlogs::List protected + def assume_bottom_position + update_columns(position: bottom_position_in_list(self).to_i + 1) + end + def fix_other_work_package_positions if changes.slice('project_id', 'type_id', 'fixed_version_id').present? if changes.slice('project_id', 'fixed_version_id').blank? and @@ -138,9 +145,9 @@ module OpenProject::Backlogs::List end if is_story? and fixed_version.present? - insert_at_bottom + assume_bottom_position else - assume_not_in_list + remove_from_list end end end diff --git a/modules/backlogs/lib/open_project/backlogs/patches/version_patch.rb b/modules/backlogs/lib/open_project/backlogs/patches/version_patch.rb index 45a7d36e19..15037ed208 100644 --- a/modules/backlogs/lib/open_project/backlogs/patches/version_patch.rb +++ b/modules/backlogs/lib/open_project/backlogs/patches/version_patch.rb @@ -63,7 +63,7 @@ module OpenProject::Backlogs::Patches::VersionPatch .order(Arel.sql('COALESCE(position, 0), id')) (stories_w_position + stories_wo_position).each_with_index do |story, index| - story.send(:update_attribute_silently, 'position', index + 1) + story.update_column(:position, index + 1) end end diff --git a/modules/backlogs/lib/open_project/backlogs/patches/work_package_patch.rb b/modules/backlogs/lib/open_project/backlogs/patches/work_package_patch.rb index 0ce8acedef..d5be909e2d 100644 --- a/modules/backlogs/lib/open_project/backlogs/patches/work_package_patch.rb +++ b/modules/backlogs/lib/open_project/backlogs/patches/work_package_patch.rb @@ -36,30 +36,30 @@ require_dependency 'work_package' module OpenProject::Backlogs::Patches::WorkPackagePatch - def self.included(base) - base.class_eval do - prepend InstanceMethods - extend ClassMethods + extend ActiveSupport::Concern - before_validation :backlogs_before_validation, if: lambda { backlogs_enabled? } + included do + prepend InstanceMethods + extend ClassMethods - register_on_journal_formatter(:fraction, 'remaining_hours') - register_on_journal_formatter(:decimal, 'story_points') - register_on_journal_formatter(:decimal, 'position') + before_validation :backlogs_before_validation, if: lambda { backlogs_enabled? } - validates_numericality_of :story_points, only_integer: true, - allow_nil: true, - greater_than_or_equal_to: 0, - less_than: 10_000, - if: lambda { backlogs_enabled? } + register_on_journal_formatter(:fraction, 'remaining_hours') + register_on_journal_formatter(:decimal, 'story_points') + register_on_journal_formatter(:decimal, 'position') - validates_numericality_of :remaining_hours, only_integer: false, - allow_nil: true, - greater_than_or_equal_to: 0, - if: lambda { backlogs_enabled? } + validates_numericality_of :story_points, only_integer: true, + allow_nil: true, + greater_than_or_equal_to: 0, + less_than: 10_000, + if: lambda { backlogs_enabled? } - include OpenProject::Backlogs::List - end + validates_numericality_of :remaining_hours, only_integer: false, + allow_nil: true, + greater_than_or_equal_to: 0, + if: lambda { backlogs_enabled? } + + include OpenProject::Backlogs::List end module ClassMethods diff --git a/modules/backlogs/openproject-backlogs.gemspec b/modules/backlogs/openproject-backlogs.gemspec index eed53a0415..126e94a94e 100644 --- a/modules/backlogs/openproject-backlogs.gemspec +++ b/modules/backlogs/openproject-backlogs.gemspec @@ -9,7 +9,7 @@ Gem::Specification.new do |s| s.files = Dir['{app,config,db,lib,doc}/**/*', 'README.md'] s.test_files = Dir['spec/**/*'] - s.add_dependency 'acts_as_silent_list', '~> 3.0.0' + s.add_dependency 'acts_as_list', '~> 0.9.18' s.add_dependency 'openproject-pdf_export' diff --git a/modules/backlogs/spec/models/version_spec.rb b/modules/backlogs/spec/models/version_spec.rb index 5ab86bb076..3eda793702 100644 --- a/modules/backlogs/spec/models/version_spec.rb +++ b/modules/backlogs/spec/models/version_spec.rb @@ -143,11 +143,11 @@ describe Version, type: :model do [e1, s2, s3, s4, s5].each(&:move_to_bottom) # Messing around with positions - s3.send :assume_not_in_list - s4.send :assume_not_in_list + s3.update_column(:position, nil) + s4.update_column(:position, nil) - t3.send(:update_attribute_silently, :position, 3) - o9.send(:update_attribute_silently, :position, 9) + t3.update_column(:position, 3) + o9.update_column(:position, 9) version.rebuild_positions(project)