Commit 760d4a16 authored by Christian Couder's avatar Christian Couder

Avoid creating labels when removing them

IssuableBaseService has been updated so that labels are not
created when push options to remove them are received.
parent f00db0c3
......@@ -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]
......
......@@ -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
......
......@@ -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)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment