Commit 4f75ff3a authored by Eugenia Grieff's avatar Eugenia Grieff Committed by Rajat Jain

Add params filter to bulk update service

Filter params to allow epic value to be '0'
so that the attribute is removed.
parent 6971beed
......@@ -33,6 +33,41 @@ module EE
params[:health_status] = nil if params[:health_status] == IssuableFinder::Params::NONE.to_s
end
override :filter_update_params
def filter_update_params(type)
super
set_epic_param
params
end
def set_epic_param
return unless params[:epic].present?
epic_param = params.delete(:epic)
params[:epic] = nil if no_epic?(epic_param)
return if params[:epic].present?
epic = find_epic(epic_param)
params[:epic] = epic if epic.present?
end
# rubocop: disable CodeReuse/ActiveRecord
def find_epic(id)
group = parent.is_a?(Group) ? parent : parent.group
return unless group.present?
EpicsFinder.new(current_user, group_id: group.id,
include_ancestor_groups: true).find(id)
rescue ActiveRecord::RecordNotFound
nil
end
# rubocop: enable CodeReuse/ActiveRecord
def no_epic?(epic_param)
epic_param == IssuableFinder::Params::NONE.to_s
end
end
end
end
......@@ -56,7 +56,7 @@ module EE
epic_param = params.delete(:epic)
if epic_param
EpicIssues::CreateService.new(::Epic.find(epic_param), current_user, { target_issuable: issue }).execute
EpicIssues::CreateService.new(epic_param, current_user, { target_issuable: issue }).execute
else
link = EpicIssue.find_by(issue_id: issue.id) # rubocop: disable CodeReuse/ActiveRecord
......
......@@ -34,6 +34,7 @@ RSpec.describe Issuable::BulkUpdateService do
let(:issue1) { create(:issue, project: project1, health_status: :at_risk) }
let(:issue2) { create(:issue, project: project2, health_status: :at_risk) }
let(:issuables) { [issue1, issue2] }
let(:epic) { create(:epic, group: group) }
before do
group.add_reporter(user)
......@@ -43,25 +44,28 @@ RSpec.describe Issuable::BulkUpdateService do
let(:params) do
{
issuable_ids: issuables.map(&:id),
health_status: :on_track
health_status: :on_track,
epic_id: epic.id
}
end
context 'when features are enabled' do
before do
stub_licensed_features(issuable_health_status: true)
stub_licensed_features(issuable_health_status: true, epics: true)
end
it 'succeeds and returns the correct number of issuables updated' do
expect(subject.success?).to be_truthy
expect(subject.payload[:count]).to eq(issuables.count)
issuables.each do |issuable|
expect(issuable.reload.health_status).to eq('on_track')
issuable.reload
expect(issuable.health_status).to eq('on_track')
expect(issuable.epic).to eq(epic)
end
end
context "when params value is '0'" do
let(:params) { { issuable_ids: issuables.map(&:id), health_status: '0' } }
let(:params) { { issuable_ids: issuables.map(&:id), health_status: '0', epic_id: '0' } }
it 'succeeds and remove values' do
expect(subject.success?).to be_truthy
......@@ -69,6 +73,7 @@ RSpec.describe Issuable::BulkUpdateService do
issuables.each do |issuable|
issuable.reload
expect(issuable.health_status).to be_nil
expect(issuable.epic).to be_nil
end
end
end
......@@ -88,6 +93,14 @@ RSpec.describe Issuable::BulkUpdateService do
end
it_behaves_like 'does not update issuables attribute', :health_status
it_behaves_like 'does not update issuables attribute', :epic
end
context 'when user can not admin epic' do
let(:epic3) { create(:epic, group: create(:group)) }
let(:params) { { issuable_ids: issuables.map(&:id), epic: epic3.id } }
it_behaves_like 'does not update issuables attribute', :epic
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