Commit 37c4ba6f authored by Sasha Joseph's avatar Sasha Joseph

Add an option to GET /projects in the GitLab API to exclude archived projects

parent 00c67238
...@@ -8,6 +8,10 @@ Get a list of projects accessible by the authenticated user. ...@@ -8,6 +8,10 @@ Get a list of projects accessible by the authenticated user.
GET /projects GET /projects
``` ```
Parameters:
+ `archived` (optional) - if passed, limit by archived status
```json ```json
[ [
{ {
...@@ -250,7 +254,7 @@ Parameters: ...@@ -250,7 +254,7 @@ Parameters:
+ `description` (optional) - short project description + `description` (optional) - short project description
+ `issues_enabled` (optional) + `issues_enabled` (optional)
+ `merge_requests_enabled` (optional) + `merge_requests_enabled` (optional)
+ `wiki_enabled` (optional) + `wiki_enabled` (optional)
+ `snippets_enabled` (optional) + `snippets_enabled` (optional)
+ `public` (optional) - if `true` same as setting visibility_level = 20 + `public` (optional) - if `true` same as setting visibility_level = 20
+ `visibility_level` (optional) + `visibility_level` (optional)
...@@ -273,7 +277,7 @@ Parameters: ...@@ -273,7 +277,7 @@ Parameters:
+ `default_branch` (optional) - 'master' by default + `default_branch` (optional) - 'master' by default
+ `issues_enabled` (optional) + `issues_enabled` (optional)
+ `merge_requests_enabled` (optional) + `merge_requests_enabled` (optional)
+ `wiki_enabled` (optional) + `wiki_enabled` (optional)
+ `snippets_enabled` (optional) + `snippets_enabled` (optional)
+ `public` (optional) - if `true` same as setting visibility_level = 20 + `public` (optional) - if `true` same as setting visibility_level = 20
+ `visibility_level` (optional) + `visibility_level` (optional)
......
...@@ -5,6 +5,10 @@ module API ...@@ -5,6 +5,10 @@ module API
SUDO_HEADER ="HTTP_SUDO" SUDO_HEADER ="HTTP_SUDO"
SUDO_PARAM = :sudo SUDO_PARAM = :sudo
def parse_boolean(value)
[ true, 1, '1', 't', 'T', 'true', 'TRUE', 'on', 'ON' ].include?(value)
end
def current_user def current_user
private_token = (params[PRIVATE_TOKEN_PARAM] || env[PRIVATE_TOKEN_HEADER]).to_s private_token = (params[PRIVATE_TOKEN_PARAM] || env[PRIVATE_TOKEN_HEADER]).to_s
@current_user ||= User.find_by(authentication_token: private_token) @current_user ||= User.find_by(authentication_token: private_token)
......
...@@ -7,7 +7,7 @@ module API ...@@ -7,7 +7,7 @@ module API
helpers do helpers do
def map_public_to_visibility_level(attrs) def map_public_to_visibility_level(attrs)
publik = attrs.delete(:public) publik = attrs.delete(:public)
publik = [ true, 1, '1', 't', 'T', 'true', 'TRUE', 'on', 'ON' ].include?(publik) publik = parse_boolean(publik)
attrs[:visibility_level] = Gitlab::VisibilityLevel::PUBLIC if !attrs[:visibility_level].present? && publik == true attrs[:visibility_level] = Gitlab::VisibilityLevel::PUBLIC if !attrs[:visibility_level].present? && publik == true
attrs attrs
end end
...@@ -15,10 +15,18 @@ module API ...@@ -15,10 +15,18 @@ module API
# Get a projects list for authenticated user # Get a projects list for authenticated user
# #
# Parameters:
# archived (optional) - if passed, limit by archived status
#
# Example Request: # Example Request:
# GET /projects # GET /projects
get do get do
@projects = paginate current_user.authorized_projects @query = current_user.authorized_projects
# If the archived parameter is passed, limit results accordingly
if params[:archived].present?
@query = @query.where(archived: parse_boolean(params[:archived]))
end
@projects = paginate @query
present @projects, with: Entities::Project present @projects, with: Entities::Project
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment