diff options
Diffstat (limited to 'app/services/labels/destroy_service.rb')
-rw-r--r-- | app/services/labels/destroy_service.rb | 46 |
1 files changed, 35 insertions, 11 deletions
diff --git a/app/services/labels/destroy_service.rb b/app/services/labels/destroy_service.rb index 82a1dba3aee..16d07e9687b 100644 --- a/app/services/labels/destroy_service.rb +++ b/app/services/labels/destroy_service.rb @@ -4,23 +4,47 @@ module Labels Label.transaction do label.destroy - return unless label.group_label? + return if label.project_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 + destroy_global_label(label.label_type, label.title) if label.global_label? + destroy_group_label(label.label_type, label.title) if label.group_label? end end private - def destroy_labels(subject, title) - find_labels(subject, title).each(&:destroy) + def destroy_global_label(label_type, title) + if subject.nil? + destroy_labels(Group.all, label_type, title) + destroy_labels(Project.all, label_type, title) + end + + if subject.is_a?(Group) + destroy_labels(nil, label_type, title) + destroy_labels(Group.where.not(id: subject), label_type, title) + destroy_labels(Project.all, label_type, title) + end + + if subject.is_a?(Project) + destroy_labels(nil, label_type, title) + destroy_labels(Group.all, label_type, title) + destroy_labels(Project.where.not(id: subject), label_type, title) + end + end + + def destroy_group_label(label_type, title) + if subject.is_a?(Group) + destroy_labels(subject.projects, label_type, title) + end + + if subject.is_a?(Project) + destroy_labels(subject.group, label_type, title) + destroy_labels(subject.group.projects.where.not(id: subject), label_type, title) + end + end + + def destroy_labels(subject, label_type, title) + find_labels(subject, label_type, title).each(&:destroy) end end end |