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