diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-29 03:09:48 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-29 03:09:48 +0300 |
commit | e1862d43d5220910c121a01e7e93ff4831170797 (patch) | |
tree | 802a7c4a5ec68f36e1ba5933652bd393b79b20cf /app/services/boards/lists | |
parent | 66e86bca7a31391e8ecf1ef84c7915ec70110c47 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/services/boards/lists')
-rw-r--r-- | app/services/boards/lists/base_destroy_service.rb | 34 | ||||
-rw-r--r-- | app/services/boards/lists/destroy_service.rb | 32 |
2 files changed, 36 insertions, 30 deletions
diff --git a/app/services/boards/lists/base_destroy_service.rb b/app/services/boards/lists/base_destroy_service.rb new file mode 100644 index 00000000000..dc0247c40b0 --- /dev/null +++ b/app/services/boards/lists/base_destroy_service.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +module Boards + module Lists + # This class is used by issue and epic board lists + # for destroying a single list + class BaseDestroyService < Boards::BaseService + def execute(list) + unless list.destroyable? + return ServiceResponse.error(message: "Open and closed lists on a board cannot be destroyed.") + end + + list.with_lock do + decrement_higher_lists(list) + list.destroy! + end + + ServiceResponse.success + rescue StandardError => e + Gitlab::ErrorTracking.track_and_raise_for_dev_exception(e) + ServiceResponse.error(message: "List destroy failed.") + end + + private + + # rubocop: disable CodeReuse/ActiveRecord + def decrement_higher_lists(list) + list.board.lists.movable.where('position > ?', list.position) + .update_all('position = position - 1') + end + # rubocop: enable CodeReuse/ActiveRecord + end + end +end diff --git a/app/services/boards/lists/destroy_service.rb b/app/services/boards/lists/destroy_service.rb index ebac0f07fe1..10d9f275d3f 100644 --- a/app/services/boards/lists/destroy_service.rb +++ b/app/services/boards/lists/destroy_service.rb @@ -2,36 +2,8 @@ module Boards module Lists - class DestroyService < Boards::BaseService - def execute(list) - unless list.destroyable? - return ServiceResponse.error(message: "The list cannot be destroyed. Only label lists can be destroyed.") - end - - @board = list.board - - list.with_lock do - decrement_higher_lists(list) - remove_list(list) - end - - ServiceResponse.success - end - - private - - attr_reader :board - - # rubocop: disable CodeReuse/ActiveRecord - def decrement_higher_lists(list) - board.lists.movable.where('position > ?', list.position) - .update_all('position = position - 1') - end - # rubocop: enable CodeReuse/ActiveRecord - - def remove_list(list) - list.destroy! - end + # overridden in EE for board lists and also for epic board lists. + class DestroyService < Boards::Lists::BaseDestroyService end end end |