Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
bf710b51
Commit
bf710b51
authored
Oct 13, 2016
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Validate label params against all labels available to project on the API
parent
033ea9d1
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
10 deletions
+9
-10
lib/api/helpers.rb
lib/api/helpers.rb
+9
-10
No files found.
lib/api/helpers.rb
View file @
bf710b51
...
@@ -71,6 +71,10 @@ module API
...
@@ -71,6 +71,10 @@ module API
@project
||=
find_project
(
params
[
:id
])
@project
||=
find_project
(
params
[
:id
])
end
end
def
available_labels
@available_labels
||=
LabelsFinder
.
new
(
current_user
,
project_id:
user_project
.
id
).
execute
end
def
find_project
(
id
)
def
find_project
(
id
)
project
=
Project
.
find_with_namespace
(
id
)
||
Project
.
find_by
(
id:
id
)
project
=
Project
.
find_with_namespace
(
id
)
||
Project
.
find_by
(
id:
id
)
...
@@ -118,7 +122,7 @@ module API
...
@@ -118,7 +122,7 @@ module API
end
end
def
find_project_label
(
id
)
def
find_project_label
(
id
)
label
=
user_project
.
labels
.
find_by_id
(
id
)
||
user_project
.
labels
.
find_by_title
(
id
)
label
=
available_labels
.
find_by_id
(
id
)
||
available_
labels
.
find_by_title
(
id
)
label
||
not_found!
(
'Label'
)
label
||
not_found!
(
'Label'
)
end
end
...
@@ -197,17 +201,12 @@ module API
...
@@ -197,17 +201,12 @@ module API
def
validate_label_params
(
params
)
def
validate_label_params
(
params
)
errors
=
{}
errors
=
{}
if
params
[
:labels
].
present?
params
[
:labels
].
to_s
.
split
(
','
).
each
do
|
label_name
|
params
[
:labels
].
split
(
','
).
each
do
|
label_name
|
label
=
available_labels
.
find_or_initialize_by
(
title:
label_name
.
strip
)
label
=
user_project
.
labels
.
create_with
(
next
if
label
.
valid?
color:
Label
::
DEFAULT_COLOR
).
find_or_initialize_by
(
title:
label_name
.
strip
)
if
label
.
invalid?
errors
[
label
.
title
]
=
label
.
errors
errors
[
label
.
title
]
=
label
.
errors
end
end
end
end
errors
errors
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment