debian-mirror-gitlab/app/services/boards/lists/destroy_service.rb

38 lines
858 B
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2016-09-13 17:45:13 +05:30
module Boards
module Lists
2018-03-17 18:26:18 +05:30
class DestroyService < Boards::BaseService
2016-09-13 17:45:13 +05:30
def execute(list)
2021-01-03 14:25:43 +05:30
unless list.destroyable?
return ServiceResponse.error(message: "The list cannot be destroyed. Only label lists can be destroyed.")
end
2016-09-13 17:45:13 +05:30
2016-11-03 12:29:30 +05:30
@board = list.board
2016-09-13 17:45:13 +05:30
list.with_lock do
decrement_higher_lists(list)
remove_list(list)
end
2021-01-03 14:25:43 +05:30
ServiceResponse.success
2016-09-13 17:45:13 +05:30
end
private
2016-11-03 12:29:30 +05:30
attr_reader :board
2018-12-05 23:21:45 +05:30
# rubocop: disable CodeReuse/ActiveRecord
2016-09-13 17:45:13 +05:30
def decrement_higher_lists(list)
2019-03-02 22:35:43 +05:30
board.lists.movable.where('position > ?', list.position)
2016-09-13 17:45:13 +05:30
.update_all('position = position - 1')
end
2018-12-05 23:21:45 +05:30
# rubocop: enable CodeReuse/ActiveRecord
2016-09-13 17:45:13 +05:30
def remove_list(list)
2021-01-03 14:25:43 +05:30
list.destroy!
2016-09-13 17:45:13 +05:30
end
end
end
end