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
Boxiang Sun
gitlab-ce
Commits
209fd864
Commit
209fd864
authored
Jul 11, 2018
by
Marko, Peter
Committed by
Peter Marko
Jul 16, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix archived parameter for projects API
parent
c7c630f1
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
48 additions
and
3 deletions
+48
-3
app/finders/projects_finder.rb
app/finders/projects_finder.rb
+2
-1
changelogs/unreleased/fix-project-api-archived.yml
changelogs/unreleased/fix-project-api-archived.yml
+5
-0
lib/api/helpers.rb
lib/api/helpers.rb
+7
-1
lib/api/projects.rb
lib/api/projects.rb
+1
-1
spec/requests/api/projects_spec.rb
spec/requests/api/projects_spec.rb
+33
-0
No files found.
app/finders/projects_finder.rb
View file @
209fd864
...
@@ -16,6 +16,7 @@
...
@@ -16,6 +16,7 @@
# personal: boolean
# personal: boolean
# search: string
# search: string
# non_archived: boolean
# non_archived: boolean
# archived: 'only' or boolean
#
#
class
ProjectsFinder
<
UnionFinder
class
ProjectsFinder
<
UnionFinder
include
CustomAttributesFilter
include
CustomAttributesFilter
...
@@ -130,7 +131,7 @@ class ProjectsFinder < UnionFinder
...
@@ -130,7 +131,7 @@ class ProjectsFinder < UnionFinder
def
by_archived
(
projects
)
def
by_archived
(
projects
)
if
params
[
:non_archived
]
if
params
[
:non_archived
]
projects
.
non_archived
projects
.
non_archived
elsif
params
.
key?
(
:archived
)
# Back-compatibility with the places where `params[:archived]` can be set explicitly to `false`
elsif
params
.
key?
(
:archived
)
if
params
[
:archived
]
==
'only'
if
params
[
:archived
]
==
'only'
projects
.
archived
projects
.
archived
elsif
Gitlab
::
Utils
.
to_boolean
(
params
[
:archived
])
elsif
Gitlab
::
Utils
.
to_boolean
(
params
[
:archived
])
...
...
changelogs/unreleased/fix-project-api-archived.yml
0 → 100644
View file @
209fd864
---
title
:
Fix archived parameter for projects API
merge_request
:
20566
author
:
Peter Marko
type
:
fixed
lib/api/helpers.rb
View file @
209fd864
...
@@ -385,7 +385,7 @@ module API
...
@@ -385,7 +385,7 @@ module API
finder_params
[
:non_public
]
=
true
if
params
[
:membership
].
present?
finder_params
[
:non_public
]
=
true
if
params
[
:membership
].
present?
finder_params
[
:starred
]
=
true
if
params
[
:starred
].
present?
finder_params
[
:starred
]
=
true
if
params
[
:starred
].
present?
finder_params
[
:visibility_level
]
=
Gitlab
::
VisibilityLevel
.
level_value
(
params
[
:visibility
])
if
params
[
:visibility
]
finder_params
[
:visibility_level
]
=
Gitlab
::
VisibilityLevel
.
level_value
(
params
[
:visibility
])
if
params
[
:visibility
]
finder_params
[
:archived
]
=
params
[
:archived
]
finder_params
[
:archived
]
=
archived_param
unless
params
[
:archived
].
nil?
finder_params
[
:search
]
=
params
[
:search
]
if
params
[
:search
]
finder_params
[
:search
]
=
params
[
:search
]
if
params
[
:search
]
finder_params
[
:user
]
=
params
.
delete
(
:user
)
if
params
[
:user
]
finder_params
[
:user
]
=
params
.
delete
(
:user
)
if
params
[
:user
]
finder_params
[
:custom_attributes
]
=
params
[
:custom_attributes
]
if
params
[
:custom_attributes
]
finder_params
[
:custom_attributes
]
=
params
[
:custom_attributes
]
if
params
[
:custom_attributes
]
...
@@ -496,5 +496,11 @@ module API
...
@@ -496,5 +496,11 @@ module API
exception
.
status
==
500
exception
.
status
==
500
end
end
def
archived_param
return
'only'
if
params
[
:archived
]
params
[
:archived
]
end
end
end
end
end
lib/api/projects.rb
View file @
209fd864
...
@@ -30,7 +30,7 @@ module API
...
@@ -30,7 +30,7 @@ module API
end
end
params
:filter_params
do
params
:filter_params
do
optional
:archived
,
type:
Boolean
,
de
fault:
false
,
de
sc:
'Limit by archived status'
optional
:archived
,
type:
Boolean
,
desc:
'Limit by archived status'
optional
:visibility
,
type:
String
,
values:
Gitlab
::
VisibilityLevel
.
string_values
,
optional
:visibility
,
type:
String
,
values:
Gitlab
::
VisibilityLevel
.
string_values
,
desc:
'Limit by visibility'
desc:
'Limit by visibility'
optional
:search
,
type:
String
,
desc:
'Return list of projects matching the search criteria'
optional
:search
,
type:
String
,
desc:
'Return list of projects matching the search criteria'
...
...
spec/requests/api/projects_spec.rb
View file @
209fd864
...
@@ -237,6 +237,39 @@ describe API::Projects do
...
@@ -237,6 +237,39 @@ describe API::Projects do
end
end
end
end
context
'and using archived'
do
let!
(
:archived_project
)
{
create
(
:project
,
creator_id:
user
.
id
,
namespace:
user
.
namespace
,
archived:
true
)
}
it
'returns archived projects'
do
get
api
(
'/projects?archived=true'
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
include_pagination_headers
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
Project
.
public_or_visible_to_user
(
user
).
where
(
archived:
true
).
size
)
expect
(
json_response
.
map
{
|
project
|
project
[
'id'
]
}).
to
include
(
archived_project
.
id
)
end
it
'returns non-archived projects'
do
get
api
(
'/projects?archived=false'
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
include_pagination_headers
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
Project
.
public_or_visible_to_user
(
user
).
where
(
archived:
false
).
size
)
expect
(
json_response
.
map
{
|
project
|
project
[
'id'
]
}).
not_to
include
(
archived_project
.
id
)
end
it
'returns every project'
do
get
api
(
'/projects'
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
include_pagination_headers
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
map
{
|
project
|
project
[
'id'
]
}).
to
contain_exactly
(
*
Project
.
public_or_visible_to_user
(
user
).
pluck
(
:id
))
end
end
context
'and using search'
do
context
'and using search'
do
it_behaves_like
'projects response'
do
it_behaves_like
'projects response'
do
let
(
:filter
)
{
{
search:
project
.
name
}
}
let
(
:filter
)
{
{
search:
project
.
name
}
}
...
...
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