Move `pagination_params` into `API::BaseController` (#28845)
This commit is contained in:
parent
a0b525e50b
commit
85d9053b36
|
@ -60,8 +60,4 @@ class Api::V1::Accounts::FollowerAccountsController < Api::BaseController
|
||||||
def records_continue?
|
def records_continue?
|
||||||
@accounts.size == limit_param(DEFAULT_ACCOUNTS_LIMIT)
|
@accounts.size == limit_param(DEFAULT_ACCOUNTS_LIMIT)
|
||||||
end
|
end
|
||||||
|
|
||||||
def pagination_params(core_params)
|
|
||||||
params.slice(:limit).permit(:limit).merge(core_params)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -60,8 +60,4 @@ class Api::V1::Accounts::FollowingAccountsController < Api::BaseController
|
||||||
def records_continue?
|
def records_continue?
|
||||||
@accounts.size == limit_param(DEFAULT_ACCOUNTS_LIMIT)
|
@accounts.size == limit_param(DEFAULT_ACCOUNTS_LIMIT)
|
||||||
end
|
end
|
||||||
|
|
||||||
def pagination_params(core_params)
|
|
||||||
params.slice(:limit).permit(:limit).merge(core_params)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,8 +16,6 @@ class Api::V1::Admin::CanonicalEmailBlocksController < Api::BaseController
|
||||||
after_action :verify_authorized
|
after_action :verify_authorized
|
||||||
after_action :insert_pagination_headers, only: :index
|
after_action :insert_pagination_headers, only: :index
|
||||||
|
|
||||||
PAGINATION_PARAMS = %i(limit).freeze
|
|
||||||
|
|
||||||
def index
|
def index
|
||||||
authorize :canonical_email_block, :index?
|
authorize :canonical_email_block, :index?
|
||||||
render json: @canonical_email_blocks, each_serializer: REST::Admin::CanonicalEmailBlockSerializer
|
render json: @canonical_email_blocks, each_serializer: REST::Admin::CanonicalEmailBlockSerializer
|
||||||
|
@ -80,8 +78,4 @@ class Api::V1::Admin::CanonicalEmailBlocksController < Api::BaseController
|
||||||
def records_continue?
|
def records_continue?
|
||||||
@canonical_email_blocks.size == limit_param(LIMIT)
|
@canonical_email_blocks.size == limit_param(LIMIT)
|
||||||
end
|
end
|
||||||
|
|
||||||
def pagination_params(core_params)
|
|
||||||
params.slice(*PAGINATION_PARAMS).permit(*PAGINATION_PARAMS).merge(core_params)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -14,8 +14,6 @@ class Api::V1::Admin::DomainAllowsController < Api::BaseController
|
||||||
after_action :verify_authorized
|
after_action :verify_authorized
|
||||||
after_action :insert_pagination_headers, only: :index
|
after_action :insert_pagination_headers, only: :index
|
||||||
|
|
||||||
PAGINATION_PARAMS = %i(limit).freeze
|
|
||||||
|
|
||||||
def index
|
def index
|
||||||
authorize :domain_allow, :index?
|
authorize :domain_allow, :index?
|
||||||
render json: @domain_allows, each_serializer: REST::Admin::DomainAllowSerializer
|
render json: @domain_allows, each_serializer: REST::Admin::DomainAllowSerializer
|
||||||
|
@ -77,10 +75,6 @@ class Api::V1::Admin::DomainAllowsController < Api::BaseController
|
||||||
@domain_allows.size == limit_param(LIMIT)
|
@domain_allows.size == limit_param(LIMIT)
|
||||||
end
|
end
|
||||||
|
|
||||||
def pagination_params(core_params)
|
|
||||||
params.slice(*PAGINATION_PARAMS).permit(*PAGINATION_PARAMS).merge(core_params)
|
|
||||||
end
|
|
||||||
|
|
||||||
def resource_params
|
def resource_params
|
||||||
params.permit(:domain)
|
params.permit(:domain)
|
||||||
end
|
end
|
||||||
|
|
|
@ -14,8 +14,6 @@ class Api::V1::Admin::DomainBlocksController < Api::BaseController
|
||||||
after_action :verify_authorized
|
after_action :verify_authorized
|
||||||
after_action :insert_pagination_headers, only: :index
|
after_action :insert_pagination_headers, only: :index
|
||||||
|
|
||||||
PAGINATION_PARAMS = %i(limit).freeze
|
|
||||||
|
|
||||||
def index
|
def index
|
||||||
authorize :domain_block, :index?
|
authorize :domain_block, :index?
|
||||||
render json: @domain_blocks, each_serializer: REST::Admin::DomainBlockSerializer
|
render json: @domain_blocks, each_serializer: REST::Admin::DomainBlockSerializer
|
||||||
|
@ -93,10 +91,6 @@ class Api::V1::Admin::DomainBlocksController < Api::BaseController
|
||||||
@domain_blocks.size == limit_param(LIMIT)
|
@domain_blocks.size == limit_param(LIMIT)
|
||||||
end
|
end
|
||||||
|
|
||||||
def pagination_params(core_params)
|
|
||||||
params.slice(*PAGINATION_PARAMS).permit(*PAGINATION_PARAMS).merge(core_params)
|
|
||||||
end
|
|
||||||
|
|
||||||
def resource_params
|
def resource_params
|
||||||
params.permit(:domain, :severity, :reject_media, :reject_reports, :private_comment, :public_comment, :obfuscate)
|
params.permit(:domain, :severity, :reject_media, :reject_reports, :private_comment, :public_comment, :obfuscate)
|
||||||
end
|
end
|
||||||
|
|
|
@ -14,10 +14,6 @@ class Api::V1::Admin::EmailDomainBlocksController < Api::BaseController
|
||||||
after_action :verify_authorized
|
after_action :verify_authorized
|
||||||
after_action :insert_pagination_headers, only: :index
|
after_action :insert_pagination_headers, only: :index
|
||||||
|
|
||||||
PAGINATION_PARAMS = %i(
|
|
||||||
limit
|
|
||||||
).freeze
|
|
||||||
|
|
||||||
def index
|
def index
|
||||||
authorize :email_domain_block, :index?
|
authorize :email_domain_block, :index?
|
||||||
render json: @email_domain_blocks, each_serializer: REST::Admin::EmailDomainBlockSerializer
|
render json: @email_domain_blocks, each_serializer: REST::Admin::EmailDomainBlockSerializer
|
||||||
|
@ -73,8 +69,4 @@ class Api::V1::Admin::EmailDomainBlocksController < Api::BaseController
|
||||||
def records_continue?
|
def records_continue?
|
||||||
@email_domain_blocks.size == limit_param(LIMIT)
|
@email_domain_blocks.size == limit_param(LIMIT)
|
||||||
end
|
end
|
||||||
|
|
||||||
def pagination_params(core_params)
|
|
||||||
params.slice(*PAGINATION_PARAMS).permit(*PAGINATION_PARAMS).merge(core_params)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -14,10 +14,6 @@ class Api::V1::Admin::IpBlocksController < Api::BaseController
|
||||||
after_action :verify_authorized
|
after_action :verify_authorized
|
||||||
after_action :insert_pagination_headers, only: :index
|
after_action :insert_pagination_headers, only: :index
|
||||||
|
|
||||||
PAGINATION_PARAMS = %i(
|
|
||||||
limit
|
|
||||||
).freeze
|
|
||||||
|
|
||||||
def index
|
def index
|
||||||
authorize :ip_block, :index?
|
authorize :ip_block, :index?
|
||||||
render json: @ip_blocks, each_serializer: REST::Admin::IpBlockSerializer
|
render json: @ip_blocks, each_serializer: REST::Admin::IpBlockSerializer
|
||||||
|
@ -78,8 +74,4 @@ class Api::V1::Admin::IpBlocksController < Api::BaseController
|
||||||
def records_continue?
|
def records_continue?
|
||||||
@ip_blocks.size == limit_param(LIMIT)
|
@ip_blocks.size == limit_param(LIMIT)
|
||||||
end
|
end
|
||||||
|
|
||||||
def pagination_params(core_params)
|
|
||||||
params.slice(*PAGINATION_PARAMS).permit(*PAGINATION_PARAMS).merge(core_params)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -12,7 +12,6 @@ class Api::V1::Admin::TagsController < Api::BaseController
|
||||||
after_action :verify_authorized
|
after_action :verify_authorized
|
||||||
|
|
||||||
LIMIT = 100
|
LIMIT = 100
|
||||||
PAGINATION_PARAMS = %i(limit).freeze
|
|
||||||
|
|
||||||
def index
|
def index
|
||||||
authorize :tag, :index?
|
authorize :tag, :index?
|
||||||
|
@ -59,8 +58,4 @@ class Api::V1::Admin::TagsController < Api::BaseController
|
||||||
def records_continue?
|
def records_continue?
|
||||||
@tags.size == limit_param(LIMIT)
|
@tags.size == limit_param(LIMIT)
|
||||||
end
|
end
|
||||||
|
|
||||||
def pagination_params(core_params)
|
|
||||||
params.slice(*PAGINATION_PARAMS).permit(*PAGINATION_PARAMS).merge(core_params)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -12,8 +12,6 @@ class Api::V1::Admin::Trends::Links::PreviewCardProvidersController < Api::BaseC
|
||||||
after_action :verify_authorized
|
after_action :verify_authorized
|
||||||
after_action :insert_pagination_headers, only: :index
|
after_action :insert_pagination_headers, only: :index
|
||||||
|
|
||||||
PAGINATION_PARAMS = %i(limit).freeze
|
|
||||||
|
|
||||||
def index
|
def index
|
||||||
authorize :preview_card_provider, :index?
|
authorize :preview_card_provider, :index?
|
||||||
|
|
||||||
|
@ -57,8 +55,4 @@ class Api::V1::Admin::Trends::Links::PreviewCardProvidersController < Api::BaseC
|
||||||
def records_continue?
|
def records_continue?
|
||||||
@providers.size == limit_param(LIMIT)
|
@providers.size == limit_param(LIMIT)
|
||||||
end
|
end
|
||||||
|
|
||||||
def pagination_params(core_params)
|
|
||||||
params.slice(*PAGINATION_PARAMS).permit(*PAGINATION_PARAMS).merge(core_params)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -43,8 +43,4 @@ class Api::V1::BlocksController < Api::BaseController
|
||||||
def records_continue?
|
def records_continue?
|
||||||
paginated_blocks.size == limit_param(DEFAULT_ACCOUNTS_LIMIT)
|
paginated_blocks.size == limit_param(DEFAULT_ACCOUNTS_LIMIT)
|
||||||
end
|
end
|
||||||
|
|
||||||
def pagination_params(core_params)
|
|
||||||
params.slice(:limit).permit(:limit).merge(core_params)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -46,8 +46,4 @@ class Api::V1::BookmarksController < Api::BaseController
|
||||||
def records_continue?
|
def records_continue?
|
||||||
results.size == limit_param(DEFAULT_STATUSES_LIMIT)
|
results.size == limit_param(DEFAULT_STATUSES_LIMIT)
|
||||||
end
|
end
|
||||||
|
|
||||||
def pagination_params(core_params)
|
|
||||||
params.slice(:limit).permit(:limit).merge(core_params)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -72,8 +72,4 @@ class Api::V1::ConversationsController < Api::BaseController
|
||||||
def records_continue?
|
def records_continue?
|
||||||
@conversations.size == limit_param(LIMIT)
|
@conversations.size == limit_param(LIMIT)
|
||||||
end
|
end
|
||||||
|
|
||||||
def pagination_params(core_params)
|
|
||||||
params.slice(:limit).permit(:limit).merge(core_params)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -44,8 +44,4 @@ class Api::V1::Crypto::EncryptedMessagesController < Api::BaseController
|
||||||
def records_continue?
|
def records_continue?
|
||||||
@encrypted_messages.size == limit_param(LIMIT)
|
@encrypted_messages.size == limit_param(LIMIT)
|
||||||
end
|
end
|
||||||
|
|
||||||
def pagination_params(core_params)
|
|
||||||
params.slice(:limit).permit(:limit).merge(core_params)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -54,10 +54,6 @@ class Api::V1::DomainBlocksController < Api::BaseController
|
||||||
@blocks.size == limit_param(BLOCK_LIMIT)
|
@blocks.size == limit_param(BLOCK_LIMIT)
|
||||||
end
|
end
|
||||||
|
|
||||||
def pagination_params(core_params)
|
|
||||||
params.slice(:limit).permit(:limit).merge(core_params)
|
|
||||||
end
|
|
||||||
|
|
||||||
def domain_block_params
|
def domain_block_params
|
||||||
params.permit(:domain)
|
params.permit(:domain)
|
||||||
end
|
end
|
||||||
|
|
|
@ -48,10 +48,6 @@ class Api::V1::EndorsementsController < Api::BaseController
|
||||||
@accounts.size == limit_param(DEFAULT_ACCOUNTS_LIMIT)
|
@accounts.size == limit_param(DEFAULT_ACCOUNTS_LIMIT)
|
||||||
end
|
end
|
||||||
|
|
||||||
def pagination_params(core_params)
|
|
||||||
params.slice(:limit).permit(:limit).merge(core_params)
|
|
||||||
end
|
|
||||||
|
|
||||||
def unlimited?
|
def unlimited?
|
||||||
params[:limit] == '0'
|
params[:limit] == '0'
|
||||||
end
|
end
|
||||||
|
|
|
@ -46,8 +46,4 @@ class Api::V1::FavouritesController < Api::BaseController
|
||||||
def records_continue?
|
def records_continue?
|
||||||
results.size == limit_param(DEFAULT_STATUSES_LIMIT)
|
results.size == limit_param(DEFAULT_STATUSES_LIMIT)
|
||||||
end
|
end
|
||||||
|
|
||||||
def pagination_params(core_params)
|
|
||||||
params.slice(:limit).permit(:limit).merge(core_params)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -67,8 +67,4 @@ class Api::V1::FollowRequestsController < Api::BaseController
|
||||||
def records_continue?
|
def records_continue?
|
||||||
@accounts.size == limit_param(DEFAULT_ACCOUNTS_LIMIT)
|
@accounts.size == limit_param(DEFAULT_ACCOUNTS_LIMIT)
|
||||||
end
|
end
|
||||||
|
|
||||||
def pagination_params(core_params)
|
|
||||||
params.slice(:limit).permit(:limit).merge(core_params)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -37,8 +37,4 @@ class Api::V1::FollowedTagsController < Api::BaseController
|
||||||
def records_continue?
|
def records_continue?
|
||||||
@results.size == limit_param(TAGS_LIMIT)
|
@results.size == limit_param(TAGS_LIMIT)
|
||||||
end
|
end
|
||||||
|
|
||||||
def pagination_params(core_params)
|
|
||||||
params.slice(:limit).permit(:limit).merge(core_params)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -75,10 +75,6 @@ class Api::V1::Lists::AccountsController < Api::BaseController
|
||||||
@accounts.size == limit_param(DEFAULT_ACCOUNTS_LIMIT)
|
@accounts.size == limit_param(DEFAULT_ACCOUNTS_LIMIT)
|
||||||
end
|
end
|
||||||
|
|
||||||
def pagination_params(core_params)
|
|
||||||
params.slice(:limit).permit(:limit).merge(core_params)
|
|
||||||
end
|
|
||||||
|
|
||||||
def unlimited?
|
def unlimited?
|
||||||
params[:limit] == '0'
|
params[:limit] == '0'
|
||||||
end
|
end
|
||||||
|
|
|
@ -43,8 +43,4 @@ class Api::V1::MutesController < Api::BaseController
|
||||||
def records_continue?
|
def records_continue?
|
||||||
paginated_mutes.size == limit_param(DEFAULT_ACCOUNTS_LIMIT)
|
paginated_mutes.size == limit_param(DEFAULT_ACCOUNTS_LIMIT)
|
||||||
end
|
end
|
||||||
|
|
||||||
def pagination_params(core_params)
|
|
||||||
params.slice(:limit).permit(:limit).merge(core_params)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -43,10 +43,6 @@ class Api::V1::ScheduledStatusesController < Api::BaseController
|
||||||
params.permit(:scheduled_at)
|
params.permit(:scheduled_at)
|
||||||
end
|
end
|
||||||
|
|
||||||
def pagination_params(core_params)
|
|
||||||
params.slice(:limit).permit(:limit).merge(core_params)
|
|
||||||
end
|
|
||||||
|
|
||||||
def next_path
|
def next_path
|
||||||
api_v1_scheduled_statuses_url pagination_params(max_id: pagination_max_id) if records_continue?
|
api_v1_scheduled_statuses_url pagination_params(max_id: pagination_max_id) if records_continue?
|
||||||
end
|
end
|
||||||
|
|
|
@ -53,8 +53,4 @@ class Api::V1::Statuses::FavouritedByAccountsController < Api::V1::Statuses::Bas
|
||||||
def records_continue?
|
def records_continue?
|
||||||
@accounts.size == limit_param(DEFAULT_ACCOUNTS_LIMIT)
|
@accounts.size == limit_param(DEFAULT_ACCOUNTS_LIMIT)
|
||||||
end
|
end
|
||||||
|
|
||||||
def pagination_params(core_params)
|
|
||||||
params.slice(:limit).permit(:limit).merge(core_params)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -49,8 +49,4 @@ class Api::V1::Statuses::RebloggedByAccountsController < Api::V1::Statuses::Base
|
||||||
def records_continue?
|
def records_continue?
|
||||||
@accounts.size == limit_param(DEFAULT_ACCOUNTS_LIMIT)
|
@accounts.size == limit_param(DEFAULT_ACCOUNTS_LIMIT)
|
||||||
end
|
end
|
||||||
|
|
||||||
def pagination_params(core_params)
|
|
||||||
params.slice(:limit).permit(:limit).merge(core_params)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -188,8 +188,4 @@ class Api::V1::StatusesController < Api::BaseController
|
||||||
def serialized_accounts(accounts)
|
def serialized_accounts(accounts)
|
||||||
ActiveModel::Serializer::CollectionSerializer.new(accounts, serializer: REST::AccountSerializer)
|
ActiveModel::Serializer::CollectionSerializer.new(accounts, serializer: REST::AccountSerializer)
|
||||||
end
|
end
|
||||||
|
|
||||||
def pagination_params(core_params)
|
|
||||||
params.slice(:limit).permit(:limit).merge(core_params)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -34,10 +34,6 @@ class Api::V1::Trends::LinksController < Api::BaseController
|
||||||
scope
|
scope
|
||||||
end
|
end
|
||||||
|
|
||||||
def pagination_params(core_params)
|
|
||||||
params.slice(:limit).permit(:limit).merge(core_params)
|
|
||||||
end
|
|
||||||
|
|
||||||
def next_path
|
def next_path
|
||||||
api_v1_trends_links_url pagination_params(offset: offset_param + limit_param(DEFAULT_LINKS_LIMIT)) if records_continue?
|
api_v1_trends_links_url pagination_params(offset: offset_param + limit_param(DEFAULT_LINKS_LIMIT)) if records_continue?
|
||||||
end
|
end
|
||||||
|
|
|
@ -32,10 +32,6 @@ class Api::V1::Trends::StatusesController < Api::BaseController
|
||||||
scope
|
scope
|
||||||
end
|
end
|
||||||
|
|
||||||
def pagination_params(core_params)
|
|
||||||
params.slice(:limit).permit(:limit).merge(core_params)
|
|
||||||
end
|
|
||||||
|
|
||||||
def next_path
|
def next_path
|
||||||
api_v1_trends_statuses_url pagination_params(offset: offset_param + limit_param(DEFAULT_STATUSES_LIMIT)) if records_continue?
|
api_v1_trends_statuses_url pagination_params(offset: offset_param + limit_param(DEFAULT_STATUSES_LIMIT)) if records_continue?
|
||||||
end
|
end
|
||||||
|
|
|
@ -30,10 +30,6 @@ class Api::V1::Trends::TagsController < Api::BaseController
|
||||||
Trends.tags.query.allowed
|
Trends.tags.query.allowed
|
||||||
end
|
end
|
||||||
|
|
||||||
def pagination_params(core_params)
|
|
||||||
params.slice(:limit).permit(:limit).merge(core_params)
|
|
||||||
end
|
|
||||||
|
|
||||||
def next_path
|
def next_path
|
||||||
api_v1_trends_tags_url pagination_params(offset: offset_param + limit_param(DEFAULT_TAGS_LIMIT)) if records_continue?
|
api_v1_trends_tags_url pagination_params(offset: offset_param + limit_param(DEFAULT_TAGS_LIMIT)) if records_continue?
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
module Api::Pagination
|
module Api::Pagination
|
||||||
extend ActiveSupport::Concern
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
|
PAGINATION_PARAMS = %i(limit).freeze
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def pagination_max_id
|
def pagination_max_id
|
||||||
|
@ -24,6 +26,13 @@ module Api::Pagination
|
||||||
render json: { error: 'Pagination values for `offset` and `limit` must be positive' }, status: 400 if pagination_options_invalid?
|
render json: { error: 'Pagination values for `offset` and `limit` must be positive' }, status: 400 if pagination_options_invalid?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def pagination_params(core_params)
|
||||||
|
params
|
||||||
|
.slice(*PAGINATION_PARAMS)
|
||||||
|
.permit(*PAGINATION_PARAMS)
|
||||||
|
.merge(core_params)
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def insert_pagination_headers
|
def insert_pagination_headers
|
||||||
|
|
Loading…
Reference in New Issue