diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-08-11 09:27:24 +0000 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-08-11 09:27:24 +0000 |
commit | d10ecacc47c1bb640621eef620eb3099ca81f0da (patch) | |
tree | 3854cdcb2a13c43c70a3af96ea35ef4ae5ac07fd | |
parent | 9d3e384ae6553fee85b7a1ed2b99a18a9884606e (diff) | |
parent | 37c4ba6f8d8b6be9f15bd0df701c64eea9c4d8e4 (diff) | |
download | gitlab-ce-d10ecacc47c1bb640621eef620eb3099ca81f0da.tar.gz |
Merge branch 'master' into 'master'
Let users limit by archived/not archived projects in GitLab API GET /projects
Adds a boolean parameter, archived, to the /projects endpoint.
See merge request !158
-rw-r--r-- | doc/api/projects.md | 8 | ||||
-rw-r--r-- | lib/api/helpers.rb | 4 | ||||
-rw-r--r-- | lib/api/projects.rb | 12 |
3 files changed, 20 insertions, 4 deletions
diff --git a/doc/api/projects.md b/doc/api/projects.md index e27f0c0226b..b8876e8e104 100644 --- a/doc/api/projects.md +++ b/doc/api/projects.md @@ -8,6 +8,10 @@ Get a list of projects accessible by the authenticated user. GET /projects ``` +Parameters: + ++ `archived` (optional) - if passed, limit by archived status + ```json [ { @@ -250,7 +254,7 @@ Parameters: + `description` (optional) - short project description + `issues_enabled` (optional) + `merge_requests_enabled` (optional) -+ `wiki_enabled` (optional) ++ `wiki_enabled` (optional) + `snippets_enabled` (optional) + `public` (optional) - if `true` same as setting visibility_level = 20 + `visibility_level` (optional) @@ -273,7 +277,7 @@ Parameters: + `default_branch` (optional) - 'master' by default + `issues_enabled` (optional) + `merge_requests_enabled` (optional) -+ `wiki_enabled` (optional) ++ `wiki_enabled` (optional) + `snippets_enabled` (optional) + `public` (optional) - if `true` same as setting visibility_level = 20 + `visibility_level` (optional) 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 88c73bff32d..4c0766482f3 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 |