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

61 lines
1.4 KiB
Ruby
Raw Normal View History

2019-12-04 20:38:33 +05:30
# frozen_string_literal: true
module Boards
module Lists
class UpdateService < Boards::BaseService
def execute(list)
2019-12-21 20:55:43 +05:30
if execute_by_params(list)
2019-12-04 20:38:33 +05:30
success(list: list)
else
error(list.errors.messages, 422)
end
end
2019-12-21 20:55:43 +05:30
private
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)
update_preferences_result || update_position_result
end
2019-12-04 20:38:33 +05:30
def update_preferences(list)
return unless preferences?
list.update_preferences_for(current_user, preferences)
end
def update_position(list)
return unless position?
move_service = Boards::Lists::MoveService.new(parent, current_user, params)
move_service.execute(list)
end
def preferences
{ collapsed: Gitlab::Utils.to_boolean(params[:collapsed]) }
end
def preferences?
params.has_key?(:collapsed)
end
def position?
params.has_key?(:position)
end
def can_read?(list)
2021-04-17 20:07:23 +05:30
Ability.allowed?(current_user, :read_issue_board_list, parent)
2019-12-04 20:38:33 +05:30
end
def can_admin?(list)
2021-04-17 20:07:23 +05:30
Ability.allowed?(current_user, :admin_issue_board_list, parent)
2019-12-04 20:38:33 +05:30
end
end
end
end
2019-12-21 20:55:43 +05:30
Boards::Lists::UpdateService.prepend_if_ee('EE::Boards::Lists::UpdateService')