Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-03-16 21:18:33 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-03-16 21:18:33 +0300
commitf64a639bcfa1fc2bc89ca7db268f594306edfd7c (patch)
treea2c3c2ebcc3b45e596949db485d6ed18ffaacfa1 /app/services/boards/base_item_move_service.rb
parentbfbc3e0d6583ea1a91f627528bedc3d65ba4b10f (diff)
Add latest changes from gitlab-org/gitlab@13-10-stable-eev13.10.0-rc40
Diffstat (limited to 'app/services/boards/base_item_move_service.rb')
-rw-r--r--app/services/boards/base_item_move_service.rb72
1 files changed, 72 insertions, 0 deletions
diff --git a/app/services/boards/base_item_move_service.rb b/app/services/boards/base_item_move_service.rb
new file mode 100644
index 00000000000..bf3e29df54b
--- /dev/null
+++ b/app/services/boards/base_item_move_service.rb
@@ -0,0 +1,72 @@
+# frozen_string_literal: true
+
+module Boards
+ class BaseItemMoveService < Boards::BaseService
+ def execute(issuable)
+ issuable_modification_params = issuable_params(issuable)
+ return false if issuable_modification_params.empty?
+
+ move_single_issuable(issuable, issuable_modification_params)
+ end
+
+ private
+
+ def issuable_params(issuable)
+ attrs = {}
+
+ if move_between_lists?
+ attrs.merge!(
+ add_label_ids: add_label_ids,
+ remove_label_ids: remove_label_ids,
+ state_event: issuable_state
+ )
+ end
+
+ attrs
+ end
+
+ def move_single_issuable(issuable, issuable_modification_params)
+ ability_name = :"admin_#{issuable.to_ability_name}"
+ return unless can?(current_user, ability_name, issuable)
+
+ update(issuable, issuable_modification_params)
+ end
+
+ def move_between_lists?
+ moving_from_list.present? && moving_to_list.present? &&
+ moving_from_list != moving_to_list
+ end
+
+ def moving_from_list
+ return unless params[:from_list_id].present?
+
+ @moving_from_list ||= board.lists.id_in(params[:from_list_id]).first
+ end
+
+ def moving_to_list
+ return unless params[:to_list_id].present?
+
+ @moving_to_list ||= board.lists.id_in(params[:to_list_id]).first
+ end
+
+ def issuable_state
+ return 'reopen' if moving_from_list.closed?
+ return 'close' if moving_to_list.closed?
+ end
+
+ def add_label_ids
+ [moving_to_list.label_id].compact
+ end
+
+ def remove_label_ids
+ label_ids =
+ if moving_to_list.movable?
+ moving_from_list.label_id
+ else
+ ::Label.ids_on_board(board.id)
+ end
+
+ Array(label_ids).compact
+ end
+ end
+end