diff options
Diffstat (limited to 'app/services/boards')
-rw-r--r-- | app/services/boards/base_items_list_service.rb | 2 | ||||
-rw-r--r-- | app/services/boards/base_service.rb | 2 | ||||
-rw-r--r-- | app/services/boards/create_service.rb | 2 | ||||
-rw-r--r-- | app/services/boards/issues/create_service.rb | 4 | ||||
-rw-r--r-- | app/services/boards/issues/list_service.rb | 2 | ||||
-rw-r--r-- | app/services/boards/issues/move_service.rb | 4 | ||||
-rw-r--r-- | app/services/boards/lists/base_destroy_service.rb | 34 | ||||
-rw-r--r-- | app/services/boards/lists/base_update_service.rb | 16 | ||||
-rw-r--r-- | app/services/boards/lists/create_service.rb | 2 | ||||
-rw-r--r-- | app/services/boards/lists/destroy_service.rb | 32 | ||||
-rw-r--r-- | app/services/boards/lists/list_service.rb | 2 | ||||
-rw-r--r-- | app/services/boards/lists/update_service.rb | 2 | ||||
-rw-r--r-- | app/services/boards/update_service.rb | 2 | ||||
-rw-r--r-- | app/services/boards/visits/create_service.rb | 16 |
14 files changed, 73 insertions, 49 deletions
diff --git a/app/services/boards/base_items_list_service.rb b/app/services/boards/base_items_list_service.rb index 5aebf216460..cbc7a332cbe 100644 --- a/app/services/boards/base_items_list_service.rb +++ b/app/services/boards/base_items_list_service.rb @@ -129,7 +129,7 @@ module Boards # rubocop: disable CodeReuse/ActiveRecord def label_links(label_ids) LabelLink - .where('label_links.target_type = ?', item_model) + .where(label_links: { target_type: item_model }) .where(item_model.arel_table[:id].eq(LabelLink.arel_table[:target_id]).to_sql) .where(label_id: label_ids) end diff --git a/app/services/boards/base_service.rb b/app/services/boards/base_service.rb index 83bb69b3822..f371f88d44b 100644 --- a/app/services/boards/base_service.rb +++ b/app/services/boards/base_service.rb @@ -13,4 +13,4 @@ module Boards end end -Boards::BaseService.prepend_if_ee('EE::Boards::BaseService') +Boards::BaseService.prepend_mod_with('Boards::BaseService') diff --git a/app/services/boards/create_service.rb b/app/services/boards/create_service.rb index 54dab581686..5f014abe071 100644 --- a/app/services/boards/create_service.rb +++ b/app/services/boards/create_service.rb @@ -37,4 +37,4 @@ module Boards end end -Boards::CreateService.prepend_if_ee('EE::Boards::CreateService') +Boards::CreateService.prepend_mod_with('Boards::CreateService') diff --git a/app/services/boards/issues/create_service.rb b/app/services/boards/issues/create_service.rb index 1769966a049..0639acfb399 100644 --- a/app/services/boards/issues/create_service.rb +++ b/app/services/boards/issues/create_service.rb @@ -30,10 +30,10 @@ module Boards end def create_issue(params) - ::Issues::CreateService.new(project, current_user, params).execute + ::Issues::CreateService.new(project: project, current_user: current_user, params: params).execute end end end end -Boards::Issues::CreateService.prepend_if_ee('EE::Boards::Issues::CreateService') +Boards::Issues::CreateService.prepend_mod_with('Boards::Issues::CreateService') diff --git a/app/services/boards/issues/list_service.rb b/app/services/boards/issues/list_service.rb index c6855f29af0..6284e454561 100644 --- a/app/services/boards/issues/list_service.rb +++ b/app/services/boards/issues/list_service.rb @@ -50,4 +50,4 @@ module Boards end end -Boards::Issues::ListService.prepend_if_ee('EE::Boards::Issues::ListService') +Boards::Issues::ListService.prepend_mod_with('Boards::Issues::ListService') diff --git a/app/services/boards/issues/move_service.rb b/app/services/boards/issues/move_service.rb index 76ea57968b2..959a7fa3ad2 100644 --- a/app/services/boards/issues/move_service.rb +++ b/app/services/boards/issues/move_service.rb @@ -52,7 +52,7 @@ module Boards end def update(issue, issue_modification_params) - ::Issues::UpdateService.new(issue.project, current_user, issue_modification_params).execute(issue) + ::Issues::UpdateService.new(project: issue.project, current_user: current_user, params: issue_modification_params).execute(issue) end def reposition_parent @@ -62,4 +62,4 @@ module Boards end end -Boards::Issues::MoveService.prepend_if_ee('EE::Boards::Issues::MoveService') +Boards::Issues::MoveService.prepend_mod_with('Boards::Issues::MoveService') 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/base_update_service.rb b/app/services/boards/lists/base_update_service.rb index faf58e405fc..bcb7d6c8504 100644 --- a/app/services/boards/lists/base_update_service.rb +++ b/app/services/boards/lists/base_update_service.rb @@ -3,16 +3,30 @@ module Boards module Lists class BaseUpdateService < Boards::BaseService + extend ::Gitlab::Utils::Override + def execute(list) if execute_by_params(list) success(list: list) else - error(list.errors.messages, 422) + message = list.errors.empty? ? 'The update was not successful.' : list.errors.messages + + error(message, { list: list }) end end private + override :error + def error(message, pass_back = {}) + ServiceResponse.error(message: message, http_status: :unprocessable_entity, payload: pass_back) + end + + override :success + def success(pass_back = {}) + ServiceResponse.success(payload: pass_back) + end + def execute_by_params(list) update_preferences_result = update_preferences(list) if can_read?(list) update_position_result = update_position(list) if can_admin?(list) diff --git a/app/services/boards/lists/create_service.rb b/app/services/boards/lists/create_service.rb index 37fe0a815bd..3ee0b6d8821 100644 --- a/app/services/boards/lists/create_service.rb +++ b/app/services/boards/lists/create_service.rb @@ -7,4 +7,4 @@ module Boards end end -Boards::Lists::CreateService.prepend_if_ee('EE::Boards::Lists::CreateService') +Boards::Lists::CreateService.prepend_mod_with('Boards::Lists::CreateService') 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 diff --git a/app/services/boards/lists/list_service.rb b/app/services/boards/lists/list_service.rb index 03d54a8c74c..e81ef467a4e 100644 --- a/app/services/boards/lists/list_service.rb +++ b/app/services/boards/lists/list_service.rb @@ -32,4 +32,4 @@ module Boards end end -Boards::Lists::ListService.prepend_if_ee('EE::Boards::Lists::ListService') +Boards::Lists::ListService.prepend_mod_with('Boards::Lists::ListService') diff --git a/app/services/boards/lists/update_service.rb b/app/services/boards/lists/update_service.rb index 2e1a6592cd9..5c24c0daa73 100644 --- a/app/services/boards/lists/update_service.rb +++ b/app/services/boards/lists/update_service.rb @@ -14,4 +14,4 @@ module Boards end end -Boards::Lists::UpdateService.prepend_if_ee('EE::Boards::Lists::UpdateService') +Boards::Lists::UpdateService.prepend_mod_with('Boards::Lists::UpdateService') diff --git a/app/services/boards/update_service.rb b/app/services/boards/update_service.rb index 48c6e44d55e..6ba8f68a4cb 100644 --- a/app/services/boards/update_service.rb +++ b/app/services/boards/update_service.rb @@ -19,4 +19,4 @@ module Boards end end -Boards::UpdateService.prepend_if_ee('EE::Boards::UpdateService') +Boards::UpdateService.prepend_mod_with('Boards::UpdateService') diff --git a/app/services/boards/visits/create_service.rb b/app/services/boards/visits/create_service.rb index 428ed1a8bcc..4d659596803 100644 --- a/app/services/boards/visits/create_service.rb +++ b/app/services/boards/visits/create_service.rb @@ -5,13 +5,17 @@ module Boards class CreateService < Boards::BaseService def execute(board) return unless current_user && Gitlab::Database.read_write? - return unless board.is_a?(Board) # other board types do not support board visits yet + return unless board - if parent.is_a?(Group) - BoardGroupRecentVisit.visited!(current_user, board) - else - BoardProjectRecentVisit.visited!(current_user, board) - end + model.visited!(current_user, board) + end + + private + + def model + return BoardGroupRecentVisit if parent.is_a?(Group) + + BoardProjectRecentVisit end end end |