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

37 lines
963 B
Ruby
Raw Normal View History

2016-09-13 17:45:13 +05:30
module Boards
module Lists
2018-03-17 18:26:18 +05:30
class CreateService < Boards::BaseService
2016-11-03 12:29:30 +05:30
def execute(board)
2016-09-13 17:45:13 +05:30
List.transaction do
2018-03-17 18:26:18 +05:30
label = available_labels_for(board).find(params[:label_id])
2016-11-03 12:29:30 +05:30
position = next_position(board)
create_list(board, label, position)
2016-09-13 17:45:13 +05:30
end
end
private
2018-03-17 18:26:18 +05:30
def available_labels_for(board)
2018-05-09 12:01:36 +05:30
options = { include_ancestor_groups: true }
2018-03-27 19:54:05 +05:30
if board.group_board?
2018-05-09 12:01:36 +05:30
options.merge!(group_id: parent.id, only_group_labels: true)
2018-03-27 19:54:05 +05:30
else
2018-05-09 12:01:36 +05:30
options[:project_id] = parent.id
2018-03-27 19:54:05 +05:30
end
2018-05-09 12:01:36 +05:30
LabelsFinder.new(current_user, options).execute
2016-11-03 12:29:30 +05:30
end
def next_position(board)
2016-09-13 17:45:13 +05:30
max_position = board.lists.movable.maximum(:position)
max_position.nil? ? 0 : max_position.succ
end
2016-11-03 12:29:30 +05:30
def create_list(board, label, position)
2016-09-29 09:46:39 +05:30
board.lists.create(label: label, list_type: :label, position: position)
2016-09-13 17:45:13 +05:30
end
end
end
end