Keep subscribers when promoting labels to group labels
This commit is contained in:
parent
3576d59ae9
commit
dcc1ab979a
3 changed files with 29 additions and 1 deletions
|
@ -13,6 +13,7 @@ module Labels
|
||||||
update_issuables(new_label, batched_ids)
|
update_issuables(new_label, batched_ids)
|
||||||
update_issue_board_lists(new_label, batched_ids)
|
update_issue_board_lists(new_label, batched_ids)
|
||||||
update_priorities(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
|
# Order is important, project labels need to be last
|
||||||
update_project_labels(batched_ids)
|
update_project_labels(batched_ids)
|
||||||
end
|
end
|
||||||
|
@ -26,6 +27,15 @@ module Labels
|
||||||
|
|
||||||
private
|
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)
|
def label_ids_for_merge(new_label)
|
||||||
LabelsFinder
|
LabelsFinder
|
||||||
.new(current_user, title: new_label.title, group_id: project.group.id)
|
.new(current_user, title: new_label.title, group_id: project.group.id)
|
||||||
|
@ -53,7 +63,7 @@ module Labels
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_project_labels(label_ids)
|
def update_project_labels(label_ids)
|
||||||
Label.where(id: label_ids).delete_all
|
Label.where(id: label_ids).destroy_all
|
||||||
end
|
end
|
||||||
|
|
||||||
def clone_label_to_group_label(label)
|
def clone_label_to_group_label(label)
|
||||||
|
|
5
changelogs/unreleased/37199-labels-fix.yml
Normal file
5
changelogs/unreleased/37199-labels-fix.yml
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
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)
|
change(project_3.labels, :count).by(-1)
|
||||||
end
|
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
|
it 'recreates priorities' do
|
||||||
service.execute(project_label_1_1)
|
service.execute(project_label_1_1)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue