Commit fae7cb50 authored by Jan Provaznik's avatar Jan Provaznik

Clarify epic create service

CreateService created new epics with whitelisted params, but at the
same time this service inherits from IssuableBaseService which
updates Issuable with all `params` passed when initializing the service.

To avoid impression that only whitelisted params are
assigned, we process date `params` directly and let
IssuableBaseService assign these params.

Because parms filtering is done on upper layer and UpdateService doesn't
do additional params whitelisting either, there is no reason to
introduce params whitelisting for CreateService.
parent ee9b7754
......@@ -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