Commit 574e17a7 authored by Igor Drozdov's avatar Igor Drozdov

Merge branch...

Merge branch '23206-board-lists-lose-their-filter-label-when-said-label-becomes-a-group-label' into 'master'

Update board label filters when a label is promoted

See merge request gitlab-org/gitlab!27662
parents 244966bf cb07c7c4
......@@ -13,13 +13,8 @@ module Labels
new_label = clone_label_to_group_label(label)
label_ids_for_merge(new_label).find_in_batches(batch_size: BATCH_SIZE) do |batched_ids|
update_issuables(new_label, batched_ids)
update_resource_label_events(new_label, batched_ids)
update_issue_board_lists(new_label, batched_ids)
update_priorities(new_label, batched_ids)
subscribe_users(new_label, batched_ids)
# Order is important, project labels need to be last
update_project_labels(batched_ids)
update_old_label_relations(new_label, batched_ids)
destroy_project_labels(batched_ids)
end
# We skipped validations during creation. Let's run them now, after deleting conflicting labels
......@@ -32,6 +27,14 @@ module Labels
private
def update_old_label_relations(new_label, old_label_ids)
update_issuables(new_label, old_label_ids)
update_resource_label_events(new_label, old_label_ids)
update_issue_board_lists(new_label, old_label_ids)
update_priorities(new_label, old_label_ids)
subscribe_users(new_label, old_label_ids)
end
# rubocop: disable CodeReuse/ActiveRecord
def subscribe_users(new_label, label_ids)
# users can be subscribed to multiple labels that will be merged into the group one
......@@ -86,7 +89,7 @@ module Labels
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def update_project_labels(label_ids)
def destroy_project_labels(label_ids)
Label.where(id: label_ids).destroy_all # rubocop: disable DestroyAll
end
# rubocop: enable CodeReuse/ActiveRecord
......@@ -105,3 +108,5 @@ module Labels
end
end
end
Labels::PromoteService.prepend_if_ee('EE::Labels::PromoteService')
---
title: Update board scopes when promoting a label
merge_request: 27662
author:
type: fixed
# frozen_string_literal: true
module EE
module Labels
module PromoteService
extend ::Gitlab::Utils::Override
private
override :update_old_label_relations
def update_old_label_relations(new_label, old_label_ids)
super
update_board_scopes(new_label, old_label_ids)
end
# rubocop: disable CodeReuse/ActiveRecord
def update_board_scopes(new_label, old_label_ids)
BoardLabel
.where(label: old_label_ids)
.update_all(label_id: new_label.id)
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
end
# frozen_string_literal: true
require 'spec_helper'
describe Labels::PromoteService do
let(:user) { create(:admin) }
let(:group) { create(:group) }
let(:project) { create(:project, group: group) }
subject(:service) { described_class.new(project, user) }
describe '#execute' do
it 'updates board scopes to the new promoted label' do
project_label = create(:label, project: project)
board = create(:board, project: project, labels: [project_label])
new_label = service.execute(project_label)
expect(board.reload.labels).to contain_exactly(new_label)
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