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
Tatuya Kamada
gitlab-ce
Commits
398ab263
Commit
398ab263
authored
Sep 19, 2016
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow users to apply group labels on Issues/MRs
parent
d5a595b5
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
60 additions
and
20 deletions
+60
-20
app/controllers/dashboard/labels_controller.rb
app/controllers/dashboard/labels_controller.rb
+4
-1
app/controllers/projects/issues_controller.rb
app/controllers/projects/issues_controller.rb
+6
-3
app/controllers/projects/labels_controller.rb
app/controllers/projects/labels_controller.rb
+1
-1
app/controllers/projects/merge_requests_controller.rb
app/controllers/projects/merge_requests_controller.rb
+4
-1
app/finders/issuable_finder.rb
app/finders/issuable_finder.rb
+3
-1
app/models/label.rb
app/models/label.rb
+5
-1
app/services/issuable_base_service.rb
app/services/issuable_base_service.rb
+10
-5
app/services/projects/autocomplete_service.rb
app/services/projects/autocomplete_service.rb
+1
-1
app/views/shared/issuable/_filter.html.haml
app/views/shared/issuable/_filter.html.haml
+4
-5
app/views/shared/issuable/_form.html.haml
app/views/shared/issuable/_form.html.haml
+1
-1
spec/services/issues/create_service_spec.rb
spec/services/issues/create_service_spec.rb
+21
-0
No files found.
app/controllers/dashboard/labels_controller.rb
View file @
398ab263
class
Dashboard::LabelsController
<
Dashboard
::
ApplicationController
def
index
labels
=
Label
.
where
(
project_id:
projects
).
select
(
:id
,
:title
,
:color
).
uniq
(
:title
)
labels
=
LabelsFinder
.
new
(
current_user
,
project_id:
projects
)
.
execute
.
select
(
:id
,
:title
,
:color
)
.
uniq
(
:title
)
respond_to
do
|
format
|
format
.
json
{
render
json:
labels
}
...
...
app/controllers/projects/issues_controller.rb
View file @
398ab263
...
...
@@ -25,8 +25,7 @@ class Projects::IssuesController < Projects::ApplicationController
def
index
@issues
=
issues_collection
@issues
=
@issues
.
page
(
params
[
:page
])
@labels
=
@project
.
labels
.
where
(
title:
params
[
:label_name
])
@labels
=
LabelsFinder
.
new
(
current_user
,
project_id:
@project
.
id
,
title:
params
[
:label_name
]).
execute
if
params
[
:label_name
].
presence
respond_to
do
|
format
|
format
.
html
...
...
@@ -45,11 +44,15 @@ class Projects::IssuesController < Projects::ApplicationController
assignee_id:
""
)
@issue
=
@noteable
=
@project
.
issues
.
new
(
issue_params
)
@issue
=
@noteable
=
@project
.
issues
.
new
(
issue_params
)
@labels
=
LabelsFinder
.
new
(
current_user
,
project_id:
@project
.
id
).
execute
respond_with
(
@issue
)
end
def
edit
@labels
=
LabelsFinder
.
new
(
current_user
,
project_id:
@project
.
id
).
execute
respond_with
(
@issue
)
end
...
...
app/controllers/projects/labels_controller.rb
View file @
398ab263
...
...
@@ -17,7 +17,7 @@ class Projects::LabelsController < Projects::ApplicationController
respond_to
do
|
format
|
format
.
html
format
.
json
do
render
json:
@project
.
labels
render
json:
LabelsFinder
.
new
(
current_user
,
project_id:
@project
.
id
).
execute
end
end
end
...
...
app/controllers/projects/merge_requests_controller.rb
View file @
398ab263
...
...
@@ -40,7 +40,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
@merge_requests
=
@merge_requests
.
page
(
params
[
:page
])
@merge_requests
=
@merge_requests
.
preload
(
:target_project
)
@labels
=
@project
.
labels
.
where
(
title:
params
[
:label_name
])
@labels
=
LabelsFinder
.
new
(
current_user
,
project_id:
@project
.
id
,
title:
params
[
:label_name
]).
execute
if
params
[
:label_name
].
presence
respond_to
do
|
format
|
format
.
html
...
...
@@ -263,6 +263,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
@source_project
=
@merge_request
.
source_project
@target_project
=
@merge_request
.
target_project
@target_branches
=
@merge_request
.
target_project
.
repository
.
branch_names
@labels
=
LabelsFinder
.
new
(
current_user
,
project_id:
@project
.
id
).
execute
end
def
update
...
...
@@ -575,6 +576,8 @@ class Projects::MergeRequestsController < Projects::ApplicationController
@note_counts
=
Note
.
where
(
commit_id:
@commits
.
map
(
&
:id
)).
group
(
:commit_id
).
count
@labels
=
LabelsFinder
.
new
(
current_user
,
project_id:
@project
.
id
).
execute
define_pipelines_vars
end
...
...
app/finders/issuable_finder.rb
View file @
398ab263
...
...
@@ -274,8 +274,10 @@ class IssuableFinder
items
=
items
.
without_label
else
items
=
items
.
with_label
(
label_names
,
params
[
:sort
])
if
projects
items
=
items
.
where
(
labels:
{
project_id:
projects
})
label_ids
=
LabelsFinder
.
new
(
current_user
,
project_id:
projects
).
execute
.
select
(
:id
)
items
=
items
.
where
(
labels:
{
id:
label_ids
})
end
end
end
...
...
app/models/label.rb
View file @
398ab263
...
...
@@ -23,7 +23,7 @@ class Label < ActiveRecord::Base
has_many
:merge_requests
,
through: :label_links
,
source: :target
,
source_type:
'MergeRequest'
validates
:color
,
color:
true
,
allow_blank:
false
validates
:project
,
presence:
true
,
unless:
Proc
.
new
{
|
service
|
service
.
template?
}
validates
:project
,
presence:
true
,
if: :project_label?
# Don't allow ',' for label titles
validates
:title
,
...
...
@@ -127,6 +127,10 @@ class Label < ActiveRecord::Base
private
def
project_label?
type
.
blank?
&&
!
template?
end
def
label_format_reference
(
format
=
:id
)
raise
StandardError
,
'Unknown format'
unless
[
:id
,
:name
].
include?
(
format
)
...
...
app/services/issuable_base_service.rb
View file @
398ab263
...
...
@@ -80,17 +80,18 @@ class IssuableBaseService < BaseService
def
filter_labels_in_param
(
key
)
return
if
params
[
key
].
to_a
.
empty?
params
[
key
]
=
project
.
labels
.
where
(
id:
params
[
key
]).
pluck
(
:id
)
params
[
key
]
=
available_
labels
.
where
(
id:
params
[
key
]).
pluck
(
:id
)
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
params
[
:label_ids
]
=
labels
.
split
(
','
).
map
do
|
label_name
|
label
=
available_labels
.
find_by
(
title:
title
).
select
(
:id
)
label
||=
project
.
labels
.
create
(
title:
label_name
.
strip
,
color:
Label
::
DEFAULT_COLOR
)
label
.
id
end
end
...
...
@@ -111,6 +112,10 @@ class IssuableBaseService < BaseService
new_label_ids
end
def
available_labels
LabelsFinder
.
new
(
current_user
,
project_id:
@project
.
id
).
execute
end
def
merge_slash_commands_into_params!
(
issuable
)
description
,
command_params
=
SlashCommands
::
InterpretService
.
new
(
project
,
current_user
).
...
...
app/services/projects/autocomplete_service.rb
View file @
398ab263
...
...
@@ -13,7 +13,7 @@ module Projects
end
def
labels
@project
.
labels
.
select
([
:title
,
:color
])
LabelsFinder
.
new
(
current_user
,
project_id:
project
.
id
).
execute
.
select
([
:title
,
:color
])
end
def
commands
(
noteable
,
type
)
...
...
app/views/shared/issuable/_filter.html.haml
View file @
398ab263
...
...
@@ -77,11 +77,10 @@
=
hidden_field_tag
:state_event
,
params
[
:state_event
]
.filter-item.inline
=
button_tag
"Update
#{
type
.
to_s
.
humanize
(
capitalize:
false
)
}
"
,
class:
"btn update_selected_issues btn-save"
-
if
!
@labels
.
nil?
.row-content-block.second-block.filtered-labels
{
class:
(
"hidden"
if
!
@labels
.
any?
)
}
-
if
@labels
.
any?
=
render
"shared/labels_row"
,
labels:
@labels
-
has_labels
=
@labels
&&
@labels
.
any?
.row-content-block.second-block.filtered-labels
{
class:
(
"hidden"
unless
has_labels
)
}
-
if
has_labels
=
render
'shared/labels_row'
,
labels:
@labels
:javascript
new
UsersSelect
();
...
...
app/views/shared/issuable/_form.html.haml
View file @
398ab263
...
...
@@ -95,7 +95,7 @@
.issuable-form-select-holder
=
render
"shared/issuable/milestone_dropdown"
,
selected:
issuable
.
milestone
,
name:
"
#{
issuable
.
class
.
model_name
.
param_key
}
[milestone_id]"
,
show_any:
false
,
show_menu_above:
true
,
show_upcoming:
false
,
extra_class:
"js-issuable-form-dropdown js-dropdown-keep-input"
,
dropdown_title:
"Select milestone"
.form-group
-
has_labels
=
issuable
.
project
.
labels
.
any?
-
has_labels
=
@labels
&&
@
labels
.
any?
=
f
.
label
:label_ids
,
"Labels"
,
class:
"control-label
#{
"col-lg-4"
if
has_due_date
}
"
=
f
.
hidden_field
:label_ids
,
multiple:
true
,
value:
''
.col-sm-10
{
class:
"#{"
col
-
lg
-
8
" if has_due_date} #{'issuable-form-padding-top' if !has_labels}"
}
...
...
spec/services/issues/create_service_spec.rb
View file @
398ab263
...
...
@@ -67,6 +67,27 @@ describe Issues::CreateService, services: true do
expect
(
Todo
.
where
(
attributes
).
count
).
to
eq
1
end
context
'when label belongs to project group'
do
let
(
:group
)
{
create
(
:group
)
}
let
(
:group_labels
)
{
create_pair
(
:group_label
,
group:
group
)
}
let
(
:opts
)
do
{
title:
'Title'
,
description:
'Description'
,
label_ids:
group_labels
.
map
(
&
:id
)
}
end
before
do
project
.
update
(
group:
group
)
end
it
'assigns group labels'
do
expect
(
issue
.
labels
).
to
match_array
group_labels
end
end
context
'when label belongs to different project'
do
let
(
:label
)
{
create
(
:label
)
}
...
...
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