Skip to content
Snippets Groups Projects
Commit 76c2901e authored by tiagonbotelho's avatar tiagonbotelho
Browse files

if issue is not valid we revert back to the old labels when updating

parent 7f0bcf04
No related branches found
No related tags found
1 merge request!5720user is now notified when creating an issue through the api
Pipeline #
Loading
@@ -45,6 +45,7 @@ v 8.12.0 (unreleased)
Loading
@@ -45,6 +45,7 @@ v 8.12.0 (unreleased)
   
v 8.11.4 (unreleased) v 8.11.4 (unreleased)
- Fix broken gitlab:backup:restore because of bad permissions on repo storage !6098 (Dirk Hörner) - Fix broken gitlab:backup:restore because of bad permissions on repo storage !6098 (Dirk Hörner)
- Creating an issue through our API now emails label subscribers !5720
   
v 8.11.3 (unreleased) v 8.11.3 (unreleased)
- Allow system info page to handle case where info is unavailable - Allow system info page to handle case where info is unavailable
Loading
@@ -70,7 +71,6 @@ v 8.11.0
Loading
@@ -70,7 +71,6 @@ v 8.11.0
- Remove the http_parser.rb dependency by removing the tinder gem. !5758 (tbalthazar) - Remove the http_parser.rb dependency by removing the tinder gem. !5758 (tbalthazar)
- Add Koding (online IDE) integration - Add Koding (online IDE) integration
- Ability to specify branches for Pivotal Tracker integration (Egor Lynko) - Ability to specify branches for Pivotal Tracker integration (Egor Lynko)
- Creating an issue through our API now emails label subscribers !5720
- Fix don't pass a local variable called `i` to a partial. !20510 (herminiotorres) - Fix don't pass a local variable called `i` to a partial. !20510 (herminiotorres)
- Fix rename `add_users_into_project` and `projects_ids`. !20512 (herminiotorres) - Fix rename `add_users_into_project` and `projects_ids`. !20512 (herminiotorres)
- Fix adding line comments on the initial commit to a repo !5900 - Fix adding line comments on the initial commit to a repo !5900
Loading
Loading
Loading
@@ -45,6 +45,7 @@ class IssuableBaseService < BaseService
Loading
@@ -45,6 +45,7 @@ class IssuableBaseService < BaseService
   
unless can?(current_user, ability, project) unless can?(current_user, ability, project)
params.delete(:milestone_id) params.delete(:milestone_id)
params.delete(:labels)
params.delete(:add_label_ids) params.delete(:add_label_ids)
params.delete(:remove_label_ids) params.delete(:remove_label_ids)
params.delete(:label_ids) params.delete(:label_ids)
Loading
@@ -72,6 +73,7 @@ class IssuableBaseService < BaseService
Loading
@@ -72,6 +73,7 @@ class IssuableBaseService < BaseService
filter_labels_in_param(:add_label_ids) filter_labels_in_param(:add_label_ids)
filter_labels_in_param(:remove_label_ids) filter_labels_in_param(:remove_label_ids)
filter_labels_in_param(:label_ids) filter_labels_in_param(:label_ids)
find_or_create_label_ids
end end
   
def filter_labels_in_param(key) def filter_labels_in_param(key)
Loading
@@ -80,6 +82,17 @@ class IssuableBaseService < BaseService
Loading
@@ -80,6 +82,17 @@ class IssuableBaseService < BaseService
params[key] = project.labels.where(id: params[key]).pluck(:id) params[key] = project.labels.where(id: params[key]).pluck(:id)
end end
   
def find_or_create_label_ids
labels = params.delete(:labels)
return unless labels
params[:label_ids] = labels.split(",").map do |label_name|
project.labels.create_with(color: Label::DEFAULT_COLOR)
.find_or_create_by(title: label_name.strip)
.id
end
end
def process_label_ids(attributes, existing_label_ids: nil) def process_label_ids(attributes, existing_label_ids: nil)
label_ids = attributes.delete(:label_ids) label_ids = attributes.delete(:label_ids)
add_label_ids = attributes.delete(:add_label_ids) add_label_ids = attributes.delete(:add_label_ids)
Loading
Loading
Loading
@@ -102,14 +102,6 @@ module API
Loading
@@ -102,14 +102,6 @@ module API
label || not_found!('Label') label || not_found!('Label')
end end
   
def get_label_ids(labels)
labels.split(",").map do |label_name|
user_project.labels.create_with(color: Label::DEFAULT_COLOR)
.find_or_create_by(title: label_name.strip)
.id
end
end
def find_project_issue(id) def find_project_issue(id)
issue = user_project.issues.find(id) issue = user_project.issues.find(id)
not_found! unless can?(current_user, :read_issue, issue) not_found! unless can?(current_user, :read_issue, issue)
Loading
Loading
Loading
@@ -154,9 +154,7 @@ module API
Loading
@@ -154,9 +154,7 @@ module API
render_api_error!({ labels: errors }, 400) render_api_error!({ labels: errors }, 400)
end end
   
# Find or create labels to attach to the issue. Labels are vaild attrs[:labels] = params[:labels] if params[:labels]
# because we already checked its name, so there can't be an error here
attrs[:label_ids] = get_label_ids(params[:labels]) if params[:labels].present?
   
issue = ::Issues::CreateService.new(user_project, current_user, attrs.merge(request: request, api: true)).execute issue = ::Issues::CreateService.new(user_project, current_user, attrs.merge(request: request, api: true)).execute
   
Loading
@@ -198,12 +196,7 @@ module API
Loading
@@ -198,12 +196,7 @@ module API
render_api_error!({ labels: errors }, 400) render_api_error!({ labels: errors }, 400)
end end
   
# Find or create labels and attach to issue. Labels are valid because attrs[:labels] = params[:labels] if params[:labels]
# we already checked its name, so there can't be an error here
if params[:labels] && can?(current_user, :admin_issue, user_project)
issue.remove_labels
attrs[:label_ids] = get_label_ids(params[:labels])
end
   
issue = ::Issues::UpdateService.new(user_project, current_user, attrs).execute(issue) issue = ::Issues::UpdateService.new(user_project, current_user, attrs).execute(issue)
   
Loading
Loading
Loading
@@ -647,7 +647,7 @@ describe API::API, api: true do
Loading
@@ -647,7 +647,7 @@ describe API::API, api: true do
end end
   
it "sends notifications for subscribers of newly added labels when issue is updated" do it "sends notifications for subscribers of newly added labels when issue is updated" do
label = project.labels.first label = create(:label, title: 'foo', color: '#FFAABB', project: project)
label.toggle_subscription(user2) label.toggle_subscription(user2)
   
perform_enqueued_jobs do perform_enqueued_jobs do
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment