Commit 81e4711f authored by Jarka Košanová's avatar Jarka Košanová

Merge branch 'fix-epic-service' into 'master'

Epic create service cleanup

See merge request gitlab-org/gitlab!28656
parents 2b639a79 fae7cb50
......@@ -3,15 +3,17 @@
module Epics
class CreateService < Epics::BaseService
def execute
@epic = group.epics.new(whitelisted_epic_params)
@epic.move_to_start if @epic.parent
set_date_params
create(@epic)
epic = group.epics.new
create(epic)
end
private
def before_create(epic)
epic.move_to_start if epic.parent
# current_user (defined in BaseService) is not available within run_after_commit block
user = current_user
epic.run_after_commit do
......@@ -19,18 +21,14 @@ module Epics
end
end
def whitelisted_epic_params
result = params.slice(:title, :description, :label_ids, :parent_id)
def set_date_params
if params[:start_date_fixed] && params[:start_date_is_fixed]
result[:start_date] = params[:start_date_fixed]
params[:start_date] = params[:start_date_fixed]
end
if params[:due_date_fixed] && params[:due_date_is_fixed]
result[:end_date] = params[:due_date_fixed]
params[:end_date] = params[:due_date_fixed]
end
result
end
end
end
......@@ -3,9 +3,9 @@
require 'spec_helper'
describe Epics::CreateService do
let(:group) { create(:group, :internal)}
let(:user) { create(:user) }
let!(:parent_epic) { create(:epic, group: group) }
let_it_be(:group) { create(:group, :internal)}
let_it_be(:user) { create(:user) }
let_it_be(:parent_epic) { create(:epic, group: group) }
let(:params) { { title: 'new epic', description: 'epic description', parent_id: parent_epic.id } }
subject { described_class.new(group, user, params).execute }
......
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