Commit 0f5e40b4 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'unify-boards-create_service.rb' into 'master'

Unify app/services/boards

See merge request gitlab-org/gitlab-ee!6245
parents c8578ac9 bed774a8
module Boards module Boards
class BaseService < ::BaseService class BaseService < ::BaseService
prepend EE::Boards::BaseService
# Parent can either a group or a project # Parent can either a group or a project
attr_accessor :parent, :current_user, :params attr_accessor :parent, :current_user, :params
def initialize(parent, user, params = {}) def initialize(parent, user, params = {})
@parent, @current_user, @params = parent, user, params.dup @parent, @current_user, @params = parent, user, params.dup
end end
def set_assignee
assignee = User.find_by(id: params.delete(:assignee_id))
params.merge!(assignee: assignee)
end
def set_milestone
milestone_id = params[:milestone_id]
return unless milestone_id
return if [::Milestone::None.id,
::Milestone::Upcoming.id,
::Milestone::Started.id].include?(milestone_id)
finder_params =
case parent
when Group
{ group_ids: [parent.id] }
when Project
{ project_ids: [parent.id], group_ids: [parent.group&.id] }
end
milestone = MilestonesFinder.new(finder_params).find_by(id: milestone_id)
params[:milestone_id] = milestone&.id
end
end end
end end
...@@ -13,9 +13,6 @@ module Boards ...@@ -13,9 +13,6 @@ module Boards
end end
def create_board! def create_board!
set_assignee
set_milestone
board = parent.boards.create(params) board = parent.boards.create(params)
if board.persisted? if board.persisted?
......
module EE
module Boards
module BaseService
def set_assignee
assignee = ::User.find_by(id: params.delete(:assignee_id))
params.merge!(assignee: assignee)
end
def set_milestone
milestone_id = params[:milestone_id]
return unless milestone_id
return if [::Milestone::None.id,
::Milestone::Upcoming.id,
::Milestone::Started.id].include?(milestone_id)
finder_params =
case parent
when Group
{ group_ids: [parent.id] }
when Project
{ project_ids: [parent.id], group_ids: [parent.group&.id] }
end
milestone = ::MilestonesFinder.new(finder_params).find_by(id: milestone_id)
params[:milestone_id] = milestone&.id
end
end
end
end
...@@ -7,6 +7,14 @@ module EE ...@@ -7,6 +7,14 @@ module EE
def can_create_board? def can_create_board?
parent.multiple_issue_boards_available? || super parent.multiple_issue_boards_available? || super
end end
override :create_board!
def create_board!
set_assignee
set_milestone
super
end
end end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment