summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJarka Kadlecová <jarka@gitlab.com>2018-01-10 08:29:58 +0100
committerJarka Kadlecová <jarka@gitlab.com>2018-01-12 16:20:38 +0100
commitdcc1ab979a9acdb94aa33a46c262ca21cc8055a9 (patch)
treee5a51bd9504903705b5f2b0c8eb86928a49aceee
parent3576d59ae95a61dd20e997a619dbc6c8e8a70276 (diff)
downloadgitlab-ce-37199-labels-fix.tar.gz
Keep subscribers when promoting labels to group labels37199-labels-fix
-rw-r--r--app/services/labels/promote_service.rb12
-rw-r--r--changelogs/unreleased/37199-labels-fix.yml5
-rw-r--r--spec/services/labels/promote_service_spec.rb13
3 files changed, 29 insertions, 1 deletions
diff --git a/app/services/labels/promote_service.rb b/app/services/labels/promote_service.rb
index 997d247be46..74a85e5c9f0 100644
--- a/app/services/labels/promote_service.rb
+++ b/app/services/labels/promote_service.rb
@@ -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)
diff --git a/changelogs/unreleased/37199-labels-fix.yml b/changelogs/unreleased/37199-labels-fix.yml
new file mode 100644
index 00000000000..bd70babb73d
--- /dev/null
+++ b/changelogs/unreleased/37199-labels-fix.yml
@@ -0,0 +1,5 @@
+---
+title: Keep subscribers when promoting labels to group labels
+merge_request:
+author:
+type: fixed
diff --git a/spec/services/labels/promote_service_spec.rb b/spec/services/labels/promote_service_spec.rb
index 8809b282127..aa9aba6bdff 100644
--- a/spec/services/labels/promote_service_spec.rb
+++ b/spec/services/labels/promote_service_spec.rb
@@ -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)