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
3db22610
Commit
3db22610
authored
Sep 29, 2016
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reuse LabelsFinder on Banzai::Filter::LabelReferenceFilter
parent
723e5767
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
44 additions
and
15 deletions
+44
-15
app/finders/issuable_finder.rb
app/finders/issuable_finder.rb
+2
-3
app/finders/labels_finder.rb
app/finders/labels_finder.rb
+33
-5
app/models/project.rb
app/models/project.rb
+4
-0
lib/banzai/filter/label_reference_filter.rb
lib/banzai/filter/label_reference_filter.rb
+5
-7
No files found.
app/finders/issuable_finder.rb
View file @
3db22610
...
...
@@ -128,8 +128,7 @@ class IssuableFinder
@labels
=
Label
.
where
(
title:
label_names
)
if
projects
label_ids
=
LabelsFinder
.
new
(
current_user
,
project_id:
projects
).
execute
.
select
(
:id
)
@labels
=
@labels
.
where
(
labels:
{
id:
label_ids
})
@labels
=
LabelsFinder
.
new
(
current_user
,
project_ids:
projects
,
title:
label_names
).
execute
end
else
@labels
=
Label
.
none
...
...
@@ -277,7 +276,7 @@ class IssuableFinder
items
=
items
.
with_label
(
label_names
,
params
[
:sort
])
if
projects
label_ids
=
LabelsFinder
.
new
(
current_user
,
project_id:
projects
).
execute
.
select
(
:id
)
label_ids
=
LabelsFinder
.
new
(
current_user
,
project_id
s
:
projects
).
execute
.
select
(
:id
)
items
=
items
.
where
(
labels:
{
id:
label_ids
})
end
end
...
...
app/finders/labels_finder.rb
View file @
3db22610
...
...
@@ -16,8 +16,16 @@ class LabelsFinder < UnionFinder
def
label_ids
label_ids
=
[]
label_ids
<<
Label
.
where
(
group_id:
projects
.
joins
(
:namespace
).
where
(
namespaces:
{
type:
'Group'
}).
select
(
:namespace_id
)).
select
(
:id
)
label_ids
<<
Label
.
where
(
project_id:
projects
.
select
(
:id
)).
select
(
:id
)
if
project
label_ids
<<
project
.
group
.
labels
if
project
.
group
.
present?
label_ids
<<
project
.
labels
else
label_ids
<<
Label
.
where
(
group_id:
projects
.
group_ids
)
label_ids
<<
Label
.
where
(
project_id:
projects
.
select
(
:id
))
end
label_ids
end
def
sort
(
items
)
...
...
@@ -37,18 +45,38 @@ class LabelsFinder < UnionFinder
params
[
:project_id
].
presence
end
def
project_ids
params
[
:project_ids
].
presence
end
def
title
params
[
:title
].
presence
end
def
project
return
@project
if
defined?
(
@project
)
if
project_id
@project
=
available_projects
.
find
(
project_id
)
rescue
nil
else
@project
=
nil
end
@project
end
def
projects
return
@projects
if
defined?
(
@projects
)
@projects
=
ProjectsFinder
.
new
.
execute
(
current_user
)
@projects
=
@projects
.
joins
(
:namespace
).
where
(
namespaces:
{
id:
group_id
,
type:
'Group'
}
)
if
group_id
@projects
=
@projects
.
where
(
id:
project_id
)
if
project_id
@projects
=
available_projects
@projects
=
@projects
.
in_namespace
(
group_id
)
if
group_id
@projects
=
@projects
.
where
(
id:
project_id
s
)
if
project_ids
@projects
=
@projects
.
reorder
(
nil
)
@projects
end
def
available_projects
@available_projects
||=
ProjectsFinder
.
new
.
execute
(
current_user
)
end
end
app/models/project.rb
View file @
3db22610
...
...
@@ -388,6 +388,10 @@ class Project < ActiveRecord::Base
Project
.
count
end
end
def
group_ids
joins
(
:namespace
).
where
(
namespaces:
{
type:
'Group'
}).
pluck
(
:namespace_id
)
end
end
def
lfs_enabled?
...
...
lib/banzai/filter/label_reference_filter.rb
View file @
3db22610
...
...
@@ -39,13 +39,7 @@ module Banzai
end
def
find_labels
(
project
)
label_ids
=
[]
label_ids
<<
project
.
group
.
labels
.
select
(
:id
)
if
project
.
group
.
present?
label_ids
<<
project
.
labels
.
select
(
:id
)
union
=
Gitlab
::
SQL
::
Union
.
new
(
label_ids
)
object_class
.
where
(
"labels.id IN (
#{
union
.
to_sql
}
)"
)
LabelsFinder
.
new
(
user
,
project_id:
project
.
id
).
execute
end
# Parameters to pass to `Label.find_by` based on the given arguments
...
...
@@ -91,6 +85,10 @@ module Banzai
object
.
is_a?
(
ProjectLabel
)
&&
object
.
project
==
project
end
def
user
context
[
:current_user
]
||
context
[
:author
]
end
def
project
context
[
:project
]
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