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
8689ce1e
Commit
8689ce1e
authored
Jan 12, 2015
by
Marin Jankovski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add search filter option on project api for authorized projects.
parent
31bcd047
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
4 deletions
+31
-4
CHANGELOG
CHANGELOG
+1
-1
doc/api/projects.md
doc/api/projects.md
+1
-0
lib/api/projects.rb
lib/api/projects.rb
+4
-3
spec/requests/api/projects_spec.rb
spec/requests/api/projects_spec.rb
+25
-0
No files found.
CHANGELOG
View file @
8689ce1e
...
...
@@ -25,7 +25,7 @@ v 7.7.0
-
-
-
-
-
Add API project search filter option for authorized projects
-
-
- Fix File blame not respecting branch selection
...
...
doc/api/projects.md
View file @
8689ce1e
...
...
@@ -13,6 +13,7 @@ Parameters:
-
`archived`
(optional) - if passed, limit by archived status
-
`order_by`
(optional) - Return requests ordered by
`id`
,
`name`
,
`created_at`
or
`last_activity_at`
fields
-
`sort`
(optional) - Return requests sorted in
`asc`
or
`desc`
order
-
`search`
(optional) - Return list of authorized projects according to a search criteria
```
json
[
...
...
lib/api/projects.rb
View file @
8689ce1e
...
...
@@ -15,9 +15,6 @@ module API
# Get a projects list for authenticated user
#
# Parameters:
# archived (optional) - if passed, limit by archived status
#
# Example Request:
# GET /projects
get
do
...
...
@@ -37,6 +34,10 @@ module API
@projects
=
@projects
.
where
(
archived:
parse_boolean
(
params
[
:archived
]))
end
if
params
[
:search
].
present?
@projects
=
@projects
.
search
(
params
[
:search
])
end
@projects
=
paginate
@projects
present
@projects
,
with:
Entities
::
Project
end
...
...
spec/requests/api/projects_spec.rb
View file @
8689ce1e
...
...
@@ -7,6 +7,8 @@ describe API::API, api: true do
let
(
:user3
)
{
create
(
:user
)
}
let
(
:admin
)
{
create
(
:admin
)
}
let
(
:project
)
{
create
(
:project
,
creator_id:
user
.
id
,
namespace:
user
.
namespace
)
}
let
(
:project2
)
{
create
(
:project
,
path:
'project2'
,
creator_id:
user
.
id
,
namespace:
user
.
namespace
)
}
let
(
:project3
)
{
create
(
:project
,
path:
'project3'
,
creator_id:
user
.
id
,
namespace:
user
.
namespace
)
}
let
(
:snippet
)
{
create
(
:project_snippet
,
author:
user
,
project:
project
,
title:
'example'
)
}
let
(
:project_member
)
{
create
(
:project_member
,
user:
user
,
project:
project
,
access_level:
ProjectMember
::
MASTER
)
}
let
(
:project_member2
)
{
create
(
:project_member
,
user:
user3
,
project:
project
,
access_level:
ProjectMember
::
DEVELOPER
)
}
...
...
@@ -29,6 +31,29 @@ describe API::API, api: true do
json_response
.
first
[
'name'
].
should
==
project
.
name
json_response
.
first
[
'owner'
][
'username'
].
should
==
user
.
username
end
context
"and using search"
do
it
"should return searched project"
do
get
api
(
"/projects"
,
user
),
{
search:
project
.
name
}
response
.
status
.
should
eq
(
200
)
json_response
.
should
be_an
Array
json_response
.
length
.
should
eq
(
1
)
end
end
context
"and using sorting"
do
before
do
project2
project3
end
it
"should return the correct order when sorted by id"
do
get
api
(
"/projects"
,
user
),
{
order_by:
'id'
,
sort:
'desc'
}
response
.
status
.
should
eq
(
200
)
json_response
.
should
be_an
Array
json_response
.
first
[
'id'
].
should
eq
(
3
)
end
end
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