blob: b2bf42112cd412364079a818f0f8ff32c5e1f73d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
module Labels
class DestroyService < Labels::BaseService
def execute(label)
Label.transaction do
label.destroy
return unless label.group_label?
if subject.is_a?(Group)
destroy_labels(subject.projects, label.title)
end
if subject.is_a?(Project)
destroy_labels(subject.group, label.title)
destroy_labels(subject.group.projects - [subject], label.title)
end
end
end
private
def destroy_labels(subject, title)
Label.with_type(:group_label)
.where(subject: subject, title: title)
.each(&:destroy)
end
end
end
|