Skip to content

Update pagination parameters to use StrongParameters

Nick Malcolm requested to merge 467132-pagination-params into master

What does this MR do and why?

Update pagination parameters to use StrongParameters. Resolves StrongParams Rubocop: Update pagination params ... (#467132 - closed). There should be no behavioral changes, and I'm relying on existing specs continuing to pass to validate this.

In Add a RuboCop to enforce the use of StrongParam... (!155661 - merged) we introduced a RuboCop to flag usage of params without #permit or parameters during the request. This MR addresses the pagination-related ones and updates the RuboCop TODO - 21 files are removed from Exclude.

This MR only updates simple parameter reads, and excludes where params was being manipulated, e.g.

# app/controllers/admin/projects_controller.rb
  def index
    params[:sort] ||= 'latest_activity_desc'
    @sort = params[:sort]

I've introduced a Concern to make this logic easier to include in other concerns, and easier to test. (We could also add a gitlab-com-derisk FF here if needed).

The keys we permit are [:page, :per_page, :limit, :sort, :order_by, :pagination] based on https://docs.gitlab.com/ee/api/rest/#offset-based-pagination and https://docs.gitlab.com/ee/api/rest/#keyset-based-pagination. limit isn't in the pagination docs, but was added as it seems to be used in a few REST APIs too (e.g. UsersController#load_projects).

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Before After

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

Related to #467132 (closed)

Edited by Nick Malcolm

Merge request reports