Commit dcc1ab97 authored by Jarka Kadlecová's avatar Jarka Kadlecová

Keep subscribers when promoting labels to group labels

parent 3576d59a
......@@ -13,6 +13,7 @@ module Labels
update_issuables(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)
end
......@@ -26,6 +27,15 @@ module Labels
private
def subscribe_users(new_label, label_ids)
# users can be subscribed to multiple labels that will be merged into the group one
# we want to keep only one subscription / user
ids_to_update = Subscription.where(subscribable_id: label_ids, subscribable_type: 'Label')
.group(:user_id)
.pluck('MAX(id)')
Subscription.where(id: ids_to_update).update_all(subscribable_id: new_label.id)
end
def label_ids_for_merge(new_label)
LabelsFinder
.new(current_user, title: new_label.title, group_id: project.group.id)
......@@ -53,7 +63,7 @@ module Labels
end
def update_project_labels(label_ids)
Label.where(id: label_ids).delete_all
Label.where(id: label_ids).destroy_all
end
def clone_label_to_group_label(label)
......
---
title: Keep subscribers when promoting labels to group labels
merge_request:
author:
type: fixed
......@@ -85,6 +85,19 @@ describe Labels::PromoteService do
change(project_3.labels, :count).by(-1)
end
it 'keeps users\' subscriptions' do
user2 = create(:user)
project_label_1_1.subscriptions.create(user: user, subscribed: true)
project_label_2_1.subscriptions.create(user: user, subscribed: true)
project_label_3_2.subscriptions.create(user: user, subscribed: true)
project_label_2_1.subscriptions.create(user: user2, subscribed: true)
expect { service.execute(project_label_1_1) }.to change { Subscription.count }.from(4).to(3)
expect(new_label.subscribed?(user)).to be_truthy
expect(new_label.subscribed?(user2)).to be_truthy
end
it 'recreates priorities' do
service.execute(project_label_1_1)
......
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