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