summaryrefslogtreecommitdiff
path: root/lib/api
diff options
context:
space:
mode:
authorSasha Joseph <sasha@fuzzproductions.com>2014-07-28 01:01:01 -0400
committerSasha Joseph <sasha@fuzzproductions.com>2014-07-28 12:48:13 -0400
commit37c4ba6f8d8b6be9f15bd0df701c64eea9c4d8e4 (patch)
treeecdc0db00ff1f15d49cc7456fd3d4ce17bf7f881 /lib/api
parent00c6723883671769f6efd692f935dc3203d7ccc6 (diff)
downloadgitlab-ce-37c4ba6f8d8b6be9f15bd0df701c64eea9c4d8e4.tar.gz
Add an option to GET /projects in the GitLab API to exclude archived projects
Diffstat (limited to 'lib/api')
-rw-r--r--lib/api/helpers.rb4
-rw-r--r--lib/api/projects.rb12
2 files changed, 14 insertions, 2 deletions
diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb
index d7d209e16f7..8189e433789 100644
--- a/lib/api/helpers.rb
+++ b/lib/api/helpers.rb
@@ -5,6 +5,10 @@ module API
SUDO_HEADER ="HTTP_SUDO"
SUDO_PARAM = :sudo
+ def parse_boolean(value)
+ [ true, 1, '1', 't', 'T', 'true', 'TRUE', 'on', 'ON' ].include?(value)
+ end
+
def current_user
private_token = (params[PRIVATE_TOKEN_PARAM] || env[PRIVATE_TOKEN_HEADER]).to_s
@current_user ||= User.find_by(authentication_token: private_token)
diff --git a/lib/api/projects.rb b/lib/api/projects.rb
index ab272426ce0..27869e49f71 100644
--- a/lib/api/projects.rb
+++ b/lib/api/projects.rb
@@ -7,7 +7,7 @@ module API
helpers do
def map_public_to_visibility_level(attrs)
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
end
@@ -15,10 +15,18 @@ module API
# Get a projects list for authenticated user
#
+ # Parameters:
+ # archived (optional) - if passed, limit by archived status
+ #
# Example Request:
# GET /projects
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
end