Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
dcc1ab97
Commit
dcc1ab97
authored
Jan 10, 2018
by
Jarka Kadlecová
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Keep subscribers when promoting labels to group labels
parent
3576d59a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
1 deletion
+29
-1
app/services/labels/promote_service.rb
app/services/labels/promote_service.rb
+11
-1
changelogs/unreleased/37199-labels-fix.yml
changelogs/unreleased/37199-labels-fix.yml
+5
-0
spec/services/labels/promote_service_spec.rb
spec/services/labels/promote_service_spec.rb
+13
-0
No files found.
app/services/labels/promote_service.rb
View file @
dcc1ab97
...
...
@@ -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
).
de
lete
_all
Label
.
where
(
id:
label_ids
).
de
stroy
_all
end
def
clone_label_to_group_label
(
label
)
...
...
changelogs/unreleased/37199-labels-fix.yml
0 → 100644
View file @
dcc1ab97
---
title
:
Keep subscribers when promoting labels to group labels
merge_request
:
author
:
type
:
fixed
spec/services/labels/promote_service_spec.rb
View file @
dcc1ab97
...
...
@@ -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
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment