Commit d134c725 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'use-pagination-helper' into 'master'

Use the pagination helper in the API

See merge request !7920
parents 9cbee6ec 74c8669b
module API
class AccessRequests < Grape::API
include PaginationParams
before { authenticate! }
helpers ::API::Helpers::MembersHelpers
......@@ -13,6 +15,9 @@ module API
detail 'This feature was introduced in GitLab 8.11.'
success Entities::AccessRequester
end
params do
use :pagination
end
get ":id/access_requests" do
source = find_source(source_type, params[:id])
......
module API
class AwardEmoji < Grape::API
include PaginationParams
before { authenticate! }
AWARDABLES = %w[issue merge_request snippet]
......@@ -21,6 +23,9 @@ module API
detail 'This feature was introduced in 8.9'
success Entities::AwardEmoji
end
params do
use :pagination
end
get endpoint do
if can_read_awardable?
awards = paginate(awardable.award_emoji)
......
module API
# Projects builds API
class Builds < Grape::API
include PaginationParams
before { authenticate! }
params do
......@@ -28,6 +29,7 @@ module API
end
params do
use :optional_scope
use :pagination
end
get ':id/builds' do
builds = user_project.builds.order('id DESC')
......@@ -43,6 +45,7 @@ module API
params do
requires :sha, type: String, desc: 'The SHA id of a commit'
use :optional_scope
use :pagination
end
get ':id/repository/commits/:sha/builds' do
authorize_read_builds!
......
require 'mime/types'
module API
# Project commit statuses API
class CommitStatuses < Grape::API
resource :projects do
include PaginationParams
before { authenticate! }
desc "Get a commit's statuses" do
......@@ -16,6 +17,7 @@ module API
optional :stage, type: String, desc: 'The stage'
optional :name, type: String, desc: 'The name'
optional :all, type: String, desc: 'Show all statuses, default: false'
use :pagination
end
get ':id/repository/commits/:sha/statuses' do
authorize!(:read_commit_status, user_project)
......
module API
class Groups < Grape::API
include PaginationParams
before { authenticate! }
helpers do
......@@ -21,6 +23,7 @@ module API
optional :search, type: String, desc: 'Search for a specific group'
optional :order_by, type: String, values: %w[name path], default: 'name', desc: 'Order by name or path'
optional :sort, type: String, values: %w[asc desc], default: 'asc', desc: 'Sort by asc (ascending) or desc (descending)'
use :pagination
end
get do
groups = if current_user.admin
......@@ -41,6 +44,9 @@ module API
desc 'Get list of owned groups for authenticated user' do
success Entities::Group
end
params do
use :pagination
end
get '/owned' do
groups = current_user.owned_groups
present paginate(groups), with: Entities::Group, user: current_user
......@@ -110,11 +116,13 @@ module API
desc 'Get a list of projects in this group.' do
success Entities::Project
end
params do
use :pagination
end
get ":id/projects" do
group = find_group!(params[:id])
projects = GroupProjectsFinder.new(group).execute(current_user)
projects = paginate projects
present projects, with: Entities::Project, user: current_user
present paginate(projects), with: Entities::Project, user: current_user
end
desc 'Transfer a project to the group namespace. Available only for admin.' do
......
module API
class Members < Grape::API
include PaginationParams
before { authenticate! }
helpers ::API::Helpers::MembersHelpers
......@@ -14,15 +16,15 @@ module API
end
params do
optional :query, type: String, desc: 'A query string to search for members'
use :pagination
end
get ":id/members" do
source = find_source(source_type, params[:id])
users = source.users
users = users.merge(User.search(params[:query])) if params[:query]
users = paginate(users)
present users, with: Entities::Member, source: source
present paginate(users), with: Entities::Member, source: source
end
desc 'Gets a member of a group or project.' do
......
module API
class MergeRequests < Grape::API
include PaginationParams
DEPRECATION_MESSAGE = 'This endpoint is deprecated and will be removed in GitLab 9.0.'.freeze
before { authenticate! }
......@@ -42,6 +44,7 @@ module API
optional :sort, type: String, values: %w[asc desc], default: 'desc',
desc: 'Return merge requests sorted in `asc` or `desc` order.'
optional :iid, type: Array[Integer], desc: 'The IID of the merge requests'
use :pagination
end
get ":id/merge_requests" do
authorize! :read_merge_request, user_project
......@@ -222,6 +225,9 @@ module API
detail 'Duplicate. DEPRECATED and WILL BE REMOVED in 9.0'
success Entities::MRNote
end
params do
use :pagination
end
get "#{path}/comments" do
merge_request = user_project.merge_requests.find(params[:merge_request_id])
......@@ -259,6 +265,9 @@ module API
desc 'List issues that will be closed on merge' do
success Entities::MRNote
end
params do
use :pagination
end
get "#{path}/closes_issues" do
merge_request = user_project.merge_requests.find(params[:merge_request_id])
issues = ::Kaminari.paginate_array(merge_request.closes_issues(current_user))
......
module API
# Milestones API
class Milestones < Grape::API
include PaginationParams
before { authenticate! }
helpers do
......@@ -30,6 +31,7 @@ module API
optional :state, type: String, values: %w[active closed all], default: 'all',
desc: 'Return "active", "closed", or "all" milestones'
optional :iid, type: Array[Integer], desc: 'The IID of the milestone'
use :pagination
end
get ":id/milestones" do
authorize! :read_milestone, user_project
......@@ -103,6 +105,7 @@ module API
end
params do
requires :milestone_id, type: Integer, desc: 'The ID of a project milestone'
use :pagination
end
get ":id/milestones/:milestone_id/issues" do
authorize! :read_milestone, user_project
......
module API
# namespaces API
class Namespaces < Grape::API
include PaginationParams
before { authenticate! }
resource :namespaces do
......@@ -9,6 +10,7 @@ module API
end
params do
optional :search, type: String, desc: "Search query for namespaces"
use :pagination
end
get do
namespaces = current_user.admin ? Namespace.all : current_user.namespaces
......
module API
# Notes API
class Notes < Grape::API
include PaginationParams
before { authenticate! }
NOTEABLE_TYPES = [Issue, MergeRequest, Snippet]
......@@ -17,6 +18,7 @@ module API
end
params do
requires :noteable_id, type: Integer, desc: 'The ID of the noteable'
use :pagination
end
get ":id/#{noteables_str}/:noteable_id/notes" do
noteable = user_project.send(noteables_str.to_sym).find(params[:noteable_id])
......
module API
# Projects API
class ProjectHooks < Grape::API
include PaginationParams
before { authenticate! }
before { authorize_admin_project }
helpers do
params :project_hook_properties do
requires :url, type: String, desc: "The URL to send the request to"
......@@ -17,9 +21,6 @@ module API
end
end
before { authenticate! }
before { authorize_admin_project }
params do
requires :id, type: String, desc: 'The ID of a project'
end
......@@ -27,6 +28,9 @@ module API
desc 'Get project hooks' do
success Entities::ProjectHook
end
params do
use :pagination
end
get ":id/hooks" do
hooks = paginate user_project.hooks
......
module API
# Projects API
class ProjectSnippets < Grape::API
include PaginationParams
before { authenticate! }
params do
......@@ -24,6 +25,9 @@ module API
desc 'Get all project snippets' do
success Entities::ProjectSnippet
end
params do
use :pagination
end
get ":id/snippets" do
present paginate(snippets_for_current_user), with: Entities::ProjectSnippet
end
......
module API
class Runners < Grape::API
include PaginationParams
before { authenticate! }
resource :runners do
......@@ -9,6 +11,7 @@ module API
params do
optional :scope, type: String, values: %w[active paused online],
desc: 'The scope of specific runners to show'
use :pagination
end
get do
runners = filter_runners(current_user.ci_authorized_runners, params[:scope], without: ['specific', 'shared'])
......@@ -21,6 +24,7 @@ module API
params do
optional :scope, type: String, values: %w[active paused online specific shared],
desc: 'The scope of specific runners to show'
use :pagination
end
get 'all' do
authenticated_as_admin!
......@@ -91,6 +95,7 @@ module API
params do
optional :scope, type: String, values: %w[active paused online specific shared],
desc: 'The scope of specific runners to show'
use :pagination
end
get ':id/runners' do
runners = filter_runners(Ci::Runner.owned_or_shared(user_project.id), params[:scope])
......
module API
# Todos API
class Todos < Grape::API
include PaginationParams
before { authenticate! }
ISSUABLE_TYPES = {
......@@ -44,10 +45,11 @@ module API
desc 'Get a todo list' do
success Entities::Todo
end
params do
use :pagination
end
get do
todos = find_todos
present paginate(todos), with: Entities::Todo, current_user: current_user
present paginate(find_todos), with: Entities::Todo, current_user: current_user
end
desc 'Mark a todo as done' do
......
module API
class Triggers < Grape::API
include PaginationParams
params do
requires :id, type: String, desc: 'The ID of a project'
end
......@@ -42,6 +44,9 @@ module API
desc 'Get triggers list' do
success Entities::Trigger
end
params do
use :pagination
end
get ':id/triggers' do
authenticate!
authorize! :admin_build, user_project
......
module API
# Users API
class Users < Grape::API
include PaginationParams
before { authenticate! }
resource :users, requirements: { uid: /[0-9]*/, id: /[0-9]*/ } do
......@@ -33,6 +34,7 @@ module API
optional :active, type: Boolean, default: false, desc: 'Filters only active users'
optional :external, type: Boolean, default: false, desc: 'Filters only external users'
optional :blocked, type: Boolean, default: false, desc: 'Filters only blocked users'
use :pagination
end
get do
unless can?(current_user, :read_users_list, nil)
......@@ -330,6 +332,7 @@ module API
end
params do
requires :id, type: Integer, desc: 'The ID of the user'
use :pagination
end
get ':id/events' do
user = User.find_by(id: params[:id])
......
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