diff options
Diffstat (limited to 'app/services/labels/destroy_service.rb')
-rw-r--r-- | app/services/labels/destroy_service.rb | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/app/services/labels/destroy_service.rb b/app/services/labels/destroy_service.rb index 2bd065e13cf..b2bf42112cd 100644 --- a/app/services/labels/destroy_service.rb +++ b/app/services/labels/destroy_service.rb @@ -2,18 +2,27 @@ module Labels class DestroyService < Labels::BaseService def execute(label) Label.transaction do - destroy_project_labels(label.title) if subject.is_a?(Group) 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_project_labels(title) - subject.projects.each do |project| - label = project.labels.find_by(title: title) - label.destroy if label.present? - end + def destroy_labels(subject, title) + Label.with_type(:group_label) + .where(subject: subject, title: title) + .each(&:destroy) end end end |