From cbc90565b55d89704d64bc48db323b82b739a873 Mon Sep 17 00:00:00 2001 From: Robert Schilling Date: Thu, 14 Aug 2014 10:17:52 +0200 Subject: Do label validation for issues/merge requests API --- lib/api/helpers.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'lib/api/helpers.rb') diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb index 8189e433789..d36b29a00b1 100644 --- a/lib/api/helpers.rb +++ b/lib/api/helpers.rb @@ -112,6 +112,21 @@ module API ActionController::Parameters.new(attrs).permit! end + # Helper method for validating all labels against its names + def validate_label_params(params) + if params[:labels].present? + params[:labels].split(',').each do |label_name| + label = user_project.labels.create_with( + color: Label::DEFAULT_COLOR).find_or_initialize_by( + title: label_name.strip) + if label.invalid? + return true + end + end + end + false + end + # error helpers def forbidden! -- cgit v1.2.1