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
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)

@ -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

@ -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:

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

@ -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

@ -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

@ -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

@ -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'

@ -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)

Loading…
Cancel
Save