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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
db679788
Commit
db679788
authored
May 26, 2017
by
Toon Claes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add :owned param to ProjectFinder
And use it in the API.
parent
5654ac87
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
18 additions
and
9 deletions
+18
-9
app/finders/projects_finder.rb
app/finders/projects_finder.rb
+7
-2
lib/api/groups.rb
lib/api/groups.rb
+1
-1
lib/api/helpers.rb
lib/api/helpers.rb
+2
-5
lib/api/projects.rb
lib/api/projects.rb
+1
-1
spec/finders/projects_finder_spec.rb
spec/finders/projects_finder_spec.rb
+7
-0
No files found.
app/finders/projects_finder.rb
View file @
db679788
...
...
@@ -7,6 +7,7 @@
# project_ids_relation: int[] - project ids to use
# params:
# trending: boolean
# owned: boolean
# non_public: boolean
# starred: boolean
# sort: string
...
...
@@ -47,8 +48,12 @@ class ProjectsFinder < UnionFinder
def
init_collection
projects
=
[]
if
params
[
:owned
].
present?
projects
<<
current_user
.
owned_projects
if
current_user
else
projects
<<
current_user
.
authorized_projects
if
current_user
projects
<<
Project
.
unscoped
.
public_to_user
(
current_user
)
unless
params
[
:non_public
].
present?
end
projects
end
...
...
lib/api/groups.rb
View file @
db679788
...
...
@@ -152,7 +152,7 @@ module API
get
":id/projects"
do
group
=
find_group!
(
params
[
:id
])
projects
=
GroupProjectsFinder
.
new
(
group:
group
,
current_user:
current_user
,
params:
project_finder_params
).
execute
projects
=
filt
er_projects
(
projects
)
projects
=
reord
er_projects
(
projects
)
entity
=
params
[
:simple
]
?
Entities
::
BasicProjectDetails
:
Entities
::
Project
present
paginate
(
projects
),
with:
entity
,
current_user:
current_user
end
...
...
lib/api/helpers.rb
View file @
db679788
...
...
@@ -256,16 +256,13 @@ module API
# project helpers
def
filter_projects
(
projects
)
if
params
[
:owned
]
projects
=
projects
.
merge
(
current_user
.
owned_projects
)
end
def
reorder_projects
(
projects
)
projects
.
reorder
(
params
[
:order_by
]
=>
params
[
:sort
])
end
def
project_finder_params
finder_params
=
{}
finder_params
[
:owned
]
=
true
if
params
[
:owned
].
present?
finder_params
[
:non_public
]
=
true
if
params
[
:membership
].
present?
finder_params
[
:starred
]
=
true
if
params
[
:starred
].
present?
finder_params
[
:visibility_level
]
=
Gitlab
::
VisibilityLevel
.
level_value
(
params
[
:visibility
])
if
params
[
:visibility
]
...
...
lib/api/projects.rb
View file @
db679788
...
...
@@ -69,7 +69,7 @@ module API
def
present_projects
(
options
=
{})
projects
=
ProjectsFinder
.
new
(
current_user:
current_user
,
params:
project_finder_params
).
execute
projects
=
filt
er_projects
(
projects
)
projects
=
reord
er_projects
(
projects
)
projects
=
projects
.
with_statistics
if
params
[
:statistics
]
projects
=
projects
.
with_issues_enabled
if
params
[
:with_issues_enabled
]
projects
=
projects
.
with_merge_requests_enabled
if
params
[
:with_merge_requests_enabled
]
...
...
spec/finders/projects_finder_spec.rb
View file @
db679788
...
...
@@ -137,6 +137,13 @@ describe ProjectsFinder do
it
{
is_expected
.
to
eq
([
public_project
])
}
end
describe
'filter by owned'
do
let
(
:params
)
{
{
owned:
true
}
}
let!
(
:owned_project
)
{
create
(
:empty_project
,
:private
,
namespace:
current_user
.
namespace
)
}
it
{
is_expected
.
to
eq
([
owned_project
])
}
end
describe
'filter by non_public'
do
let
(
:params
)
{
{
non_public:
true
}
}
before
do
...
...
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