summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Couder <chriscool@tuxfamily.org>2019-08-30 09:51:45 +0200
committerChristian Couder <chriscool@tuxfamily.org>2019-09-04 12:11:31 +0200
commit760d4a16214b2ae77c4c0ea9c719815e9473dcd9 (patch)
tree07c5b8a8db969a741f97294584a1f64c9bb09244
parentf00db0c342d01b33617f269447ff76140944a86e (diff)
downloadgitlab-ce-760d4a16214b2ae77c4c0ea9c719815e9473dcd9.tar.gz
Avoid creating labels when removing them
IssuableBaseService has been updated so that labels are not created when push options to remove them are received.
-rw-r--r--app/services/issuable_base_service.rb2
-rw-r--r--app/services/labels/available_labels_service.rb4
-rw-r--r--app/services/labels/find_or_create_service.rb8
3 files changed, 8 insertions, 6 deletions
diff --git a/app/services/issuable_base_service.rb b/app/services/issuable_base_service.rb
index 71c86106f48..d1803602cb1 100644
--- a/app/services/issuable_base_service.rb
+++ b/app/services/issuable_base_service.rb
@@ -85,7 +85,7 @@ class IssuableBaseService < BaseService
if params[:remove_label_ids]
params[:remove_label_ids] = labels_service.filter_labels_ids_in_param(:remove_label_ids)
elsif params[:remove_labels]
- params[:remove_label_ids] = labels_service.find_or_create_by_titles(:remove_labels).map(&:id)
+ params[:remove_label_ids] = labels_service.find_or_create_by_titles(:remove_labels, find_only: true).map(&:id)
end
if params[:label_ids]
diff --git a/app/services/labels/available_labels_service.rb b/app/services/labels/available_labels_service.rb
index bdd5f660576..8886e58d6ef 100644
--- a/app/services/labels/available_labels_service.rb
+++ b/app/services/labels/available_labels_service.rb
@@ -9,7 +9,7 @@ module Labels
@params = params
end
- def find_or_create_by_titles(key = :labels)
+ def find_or_create_by_titles(key = :labels, find_only: false)
labels = params.delete(key)
return [] unless labels
@@ -23,7 +23,7 @@ module Labels
include_ancestor_groups: true,
title: label_name.strip,
available_labels: available_labels
- ).execute
+ ).execute(find_only: find_only)
label
end.compact
diff --git a/app/services/labels/find_or_create_service.rb b/app/services/labels/find_or_create_service.rb
index 628873519d7..a47dd42aea0 100644
--- a/app/services/labels/find_or_create_service.rb
+++ b/app/services/labels/find_or_create_service.rb
@@ -9,9 +9,9 @@ module Labels
@params = params.dup.with_indifferent_access
end
- def execute(skip_authorization: false)
+ def execute(skip_authorization: false, find_only: false)
@skip_authorization = skip_authorization
- find_or_create_label
+ find_or_create_label(find_only: find_only)
end
private
@@ -30,9 +30,11 @@ module Labels
# Only creates the label if current_user can do so, if the label does not exist
# and the user can not create the label, nil is returned
# rubocop: disable CodeReuse/ActiveRecord
- def find_or_create_label
+ def find_or_create_label(find_only: false)
new_label = available_labels.find_by(title: title)
+ return new_label if find_only
+
if new_label.nil? && (skip_authorization || Ability.allowed?(current_user, :admin_label, parent))
create_params = params.except(:include_ancestor_groups)
new_label = Labels::CreateService.new(create_params).execute(parent_type.to_sym => parent)