replace acts_as_silent_list by acts_as_list touch_on_update: false

pull/7393/head
ulferts 5 years ago
parent cec5e31a62
commit 64d3091636
No known key found for this signature in database
GPG Key ID: A205708DE1284017
  1. 5
      Gemfile.lock
  2. 8
      app/models/custom_action.rb
  3. 9
      app/models/work_package.rb
  4. 3
      modules/backlogs/lib/open_project/backlogs/engine.rb
  5. 49
      modules/backlogs/lib/open_project/backlogs/list.rb
  6. 2
      modules/backlogs/lib/open_project/backlogs/patches/version_patch.rb
  7. 38
      modules/backlogs/lib/open_project/backlogs/patches/work_package_patch.rb
  8. 2
      modules/backlogs/openproject-backlogs.gemspec
  9. 8
      modules/backlogs/spec/models/version_spec.rb

@ -113,7 +113,7 @@ PATH
remote: modules/backlogs remote: modules/backlogs
specs: specs:
openproject-backlogs (1.0.0) openproject-backlogs (1.0.0)
acts_as_silent_list (~> 3.0.0) acts_as_list (~> 0.9.18)
openproject-pdf_export openproject-pdf_export
PATH PATH
@ -293,9 +293,8 @@ GEM
i18n (>= 0.7, < 2) i18n (>= 0.7, < 2)
minitest (~> 5.1) minitest (~> 5.1)
tzinfo (~> 1.1) tzinfo (~> 1.1)
acts_as_list (0.9.11) acts_as_list (0.9.19)
activerecord (>= 3.0) activerecord (>= 3.0)
acts_as_silent_list (3.0.0)
acts_as_tree (2.8.0) acts_as_tree (2.8.0)
activerecord (>= 3.0.0) activerecord (>= 3.0.0)
addressable (2.6.0) addressable (2.6.0)

@ -53,7 +53,7 @@ class CustomAction < ActiveRecord::Base
ret ret
end end
def reload def reload(*args)
@conditions = nil @conditions = nil
super super
@ -113,11 +113,7 @@ class CustomAction < ActiveRecord::Base
availables.map do |available| availables.map do |available|
existing = actual.detect { |a| a.key == available.key } existing = actual.detect { |a| a.key == available.key }
if existing existing || available.new
existing
else
available.new
end
end end
end end

@ -246,11 +246,14 @@ class WorkPackage < ActiveRecord::Base
end end
# Users/groups the work_package can be assigned to # Users/groups the work_package can be assigned to
extend Forwardable def assignable_assignees
def_delegator :project, :possible_assignees, :assignable_assignees project.possible_assignees
end
# Users the work_package can be assigned to # 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 # Versions that the work_package can be assigned to
# A work_package can be assigned to: # A work_package can be assigned to:

@ -35,9 +35,6 @@
require 'open_project/plugins' require 'open_project/plugins'
require 'acts_as_silent_list'
module OpenProject::Backlogs module OpenProject::Backlogs
class Engine < ::Rails::Engine class Engine < ::Rails::Engine
engine_name :openproject_backlogs engine_name :openproject_backlogs

@ -34,26 +34,29 @@
#++ #++
module OpenProject::Backlogs::List module OpenProject::Backlogs::List
def self.included(base) extend ActiveSupport::Concern
base.class_eval do
acts_as_silent_list included do
acts_as_list touch_on_update: false
# Reorder list, if work_package is removed from sprint # acts as list adds a before destroy hook which messes
before_update :fix_other_work_package_positions # with the parent_id_was value
before_update :fix_own_work_package_position skip_callback(:destroy, :before, :reload)
# Used by acts_as_silent_list to limit the list to a certain subset within # Reorder list, if work_package is removed from sprint
# the table. before_update :fix_other_work_package_positions
# before_update :fix_own_work_package_position
# Also sanitize_sql seems to be unavailable in a sensible way. Therefore
# we're using send to circumvent visibility work_packages. # Used by acts_list to limit the list to a certain subset within
def scope_condition # the table.
self.class.send(:sanitize_sql, ['project_id = ? AND fixed_version_id = ? AND type_id IN (?)', #
project_id, fixed_version_id, types]) # Also sanitize_sql seems to be unavailable in a sensible way. Therefore
end # we're using send to circumvent visibility work_packages.
def scope_condition
include InstanceMethods self.class.send(:sanitize_sql, ['project_id = ? AND fixed_version_id = ? AND type_id IN (?)',
project_id, fixed_version_id, types])
end end
include InstanceMethods
end end
module InstanceMethods module InstanceMethods
@ -85,6 +88,10 @@ module OpenProject::Backlogs::List
protected protected
def assume_bottom_position
update_columns(position: bottom_position_in_list(self).to_i + 1)
end
def fix_other_work_package_positions def fix_other_work_package_positions
if changes.slice('project_id', 'type_id', 'fixed_version_id').present? if changes.slice('project_id', 'type_id', 'fixed_version_id').present?
if changes.slice('project_id', 'fixed_version_id').blank? and if changes.slice('project_id', 'fixed_version_id').blank? and
@ -138,9 +145,9 @@ module OpenProject::Backlogs::List
end end
if is_story? and fixed_version.present? if is_story? and fixed_version.present?
insert_at_bottom assume_bottom_position
else else
assume_not_in_list remove_from_list
end end
end end
end end

@ -63,7 +63,7 @@ module OpenProject::Backlogs::Patches::VersionPatch
.order(Arel.sql('COALESCE(position, 0), id')) .order(Arel.sql('COALESCE(position, 0), id'))
(stories_w_position + stories_wo_position).each_with_index do |story, index| (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
end end

@ -36,30 +36,30 @@
require_dependency 'work_package' require_dependency 'work_package'
module OpenProject::Backlogs::Patches::WorkPackagePatch module OpenProject::Backlogs::Patches::WorkPackagePatch
def self.included(base) extend ActiveSupport::Concern
base.class_eval do
prepend InstanceMethods
extend ClassMethods
before_validation :backlogs_before_validation, if: lambda { backlogs_enabled? } included do
prepend InstanceMethods
extend ClassMethods
register_on_journal_formatter(:fraction, 'remaining_hours') before_validation :backlogs_before_validation, if: lambda { backlogs_enabled? }
register_on_journal_formatter(:decimal, 'story_points')
register_on_journal_formatter(:decimal, 'position')
validates_numericality_of :story_points, only_integer: true, register_on_journal_formatter(:fraction, 'remaining_hours')
allow_nil: true, register_on_journal_formatter(:decimal, 'story_points')
greater_than_or_equal_to: 0, register_on_journal_formatter(:decimal, 'position')
less_than: 10_000,
if: lambda { backlogs_enabled? }
validates_numericality_of :remaining_hours, only_integer: false, validates_numericality_of :story_points, only_integer: true,
allow_nil: true, allow_nil: true,
greater_than_or_equal_to: 0, greater_than_or_equal_to: 0,
if: lambda { backlogs_enabled? } less_than: 10_000,
if: lambda { backlogs_enabled? }
include OpenProject::Backlogs::List validates_numericality_of :remaining_hours, only_integer: false,
end allow_nil: true,
greater_than_or_equal_to: 0,
if: lambda { backlogs_enabled? }
include OpenProject::Backlogs::List
end end
module ClassMethods module ClassMethods

@ -9,7 +9,7 @@ Gem::Specification.new do |s|
s.files = Dir['{app,config,db,lib,doc}/**/*', 'README.md'] s.files = Dir['{app,config,db,lib,doc}/**/*', 'README.md']
s.test_files = Dir['spec/**/*'] 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' s.add_dependency 'openproject-pdf_export'

@ -143,11 +143,11 @@ describe Version, type: :model do
[e1, s2, s3, s4, s5].each(&:move_to_bottom) [e1, s2, s3, s4, s5].each(&:move_to_bottom)
# Messing around with positions # Messing around with positions
s3.send :assume_not_in_list s3.update_column(:position, nil)
s4.send :assume_not_in_list s4.update_column(:position, nil)
t3.send(:update_attribute_silently, :position, 3) t3.update_column(:position, 3)
o9.send(:update_attribute_silently, :position, 9) o9.update_column(:position, 9)
version.rebuild_positions(project) version.rebuild_positions(project)

Loading…
Cancel
Save