Skip to content

Commit

Permalink
Replace ApplicationController::MAX_START with max_start()
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Dolski committed Jan 18, 2024
1 parent b7e374c commit c22b7d8
Show file tree
Hide file tree
Showing 14 changed files with 29 additions and 27 deletions.
6 changes: 4 additions & 2 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
#
class ApplicationController < ActionController::Base

MAX_START = 10000

protect_from_forgery with: :exception
helper_method :current_user, :current_user_is_sysadmin?, :logged_in?,
:request_context, :to_do_list
Expand Down Expand Up @@ -217,6 +215,10 @@ def ensure_logged_out
redirect_to root_path if logged_in?
end

def max_start
10000 - window_size
end

def rescue_gone
respond_to do |format|
format.html { render "errors/error410", status: :gone }
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/collections_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def index
end
@permitted_params = params.permit(Search::RESULTS_PARAMS +
Search::SIMPLE_SEARCH_PARAMS)
@start = [@permitted_params[:start].to_i.abs, MAX_START].min
@start = [@permitted_params[:start].to_i.abs, max_start].min
@window = window_size
@collections = Collection.search.
institution(current_institution).
Expand Down Expand Up @@ -432,7 +432,7 @@ def show_statistics
#
def show_submissions_in_progress
@permitted_params = params.permit(Search::RESULTS_PARAMS)
@start = [@permitted_params[:start].to_i.abs, MAX_START].min
@start = [@permitted_params[:start].to_i.abs, max_start].min
@window = window_size
@items = submissions_in_progress(@start, @window)
@count = @items.count
Expand Down Expand Up @@ -652,7 +652,7 @@ def redirect_scope

def set_item_results_ivars
@permitted_params = params.permit(RESULTS_PARAMS + [:collection_id])
@start = [@permitted_params[:start].to_i.abs, MAX_START].min
@start = [@permitted_params[:start].to_i.abs, max_start].min
@window = window_size
@items = Item.search.
institution(@collection.institution).
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def setup_index(institution = nil)
@permitted_params = params.permit(Search::RESULTS_PARAMS +
Search::SIMPLE_SEARCH_PARAMS +
[:status_text, :status])
@start = [@permitted_params[:start].to_i.abs, MAX_START].min
@start = [@permitted_params[:start].to_i.abs, max_start].min
@window = window_size
@events = Event.
where.not(event_type: Event::Type::DOWNLOAD).
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/imports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def index
authorize Import
@permitted_params = params.permit(Search::RESULTS_PARAMS +
Search::SIMPLE_SEARCH_PARAMS)
@start = [@permitted_params[:start].to_i.abs, MAX_START].min
@start = [@permitted_params[:start].to_i.abs, max_start].min
@window = window_size
@imports = Import.
where(institution: current_institution).
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/index_pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def new
#
def show
@permitted_params = params.permit(:letter, :q, :start)
@start = [@permitted_params[:start].to_i.abs, MAX_START].min
@start = [@permitted_params[:start].to_i.abs, max_start].min
@window = 50
reg_e_ids = @index_page.registered_element_ids
if reg_e_ids.any?
Expand Down
12 changes: 6 additions & 6 deletions app/controllers/institutions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ def show_authentication
#
def show_buried_items
@permitted_params = params.permit(RESULTS_PARAMS)
@start = [@permitted_params[:start].to_i.abs, MAX_START].min
@start = [@permitted_params[:start].to_i.abs, max_start].min
@window = window_size
@items = buried_items(@start, @window)
@count = @items.count
Expand Down Expand Up @@ -446,7 +446,7 @@ def show_imports
authorize Import
@permitted_params = params.permit(Search::RESULTS_PARAMS +
Search::SIMPLE_SEARCH_PARAMS)
@start = [@permitted_params[:start].to_i.abs, MAX_START].min
@start = [@permitted_params[:start].to_i.abs, max_start].min
@window = window_size
@imports = Import.
where(institution: @institution).
Expand Down Expand Up @@ -476,7 +476,7 @@ def show_invitees
@permitted_params = params.permit(Search::RESULTS_PARAMS +
Search::SIMPLE_SEARCH_PARAMS +
[:approval_state, :institution_id])
@start = [@permitted_params[:start].to_i.abs, MAX_START].min
@start = [@permitted_params[:start].to_i.abs, max_start].min
@window = window_size
@invitees = Invitee.
where(institution: @institution).
Expand Down Expand Up @@ -583,7 +583,7 @@ def show_submission_profiles
#
def show_submissions_in_progress
@permitted_params = params.permit(Search::RESULTS_PARAMS)
@start = [@permitted_params[:start].to_i.abs, MAX_START].min
@start = [@permitted_params[:start].to_i.abs, max_start].min
@window = window_size
@items = submissions_in_progress(@start, @window)
@count = @items.count
Expand Down Expand Up @@ -665,7 +665,7 @@ def show_vocabularies
@permitted_params = params.permit(Search::RESULTS_PARAMS +
Search::SIMPLE_SEARCH_PARAMS +
[:institution_id])
@start = [@permitted_params[:start].to_i.abs, MAX_START].min
@start = [@permitted_params[:start].to_i.abs, max_start].min
@window = window_size
@vocabularies = Vocabulary.
where(institution: @institution).
Expand All @@ -683,7 +683,7 @@ def show_vocabularies
#
def show_withdrawn_items
@permitted_params = params.permit(RESULTS_PARAMS)
@start = [@permitted_params[:start].to_i.abs, MAX_START].min
@start = [@permitted_params[:start].to_i.abs, max_start].min
@window = window_size
@items = withdrawn_items(@start, @window)
@count = @items.count
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/invitees_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def setup_index(institution)
@permitted_params = params.permit(Search::RESULTS_PARAMS +
Search::SIMPLE_SEARCH_PARAMS +
[:approval_state, :institution_id])
@start = [@permitted_params[:start].to_i.abs, MAX_START].min
@start = [@permitted_params[:start].to_i.abs, max_start].min
@window = window_size
@invitees = Invitee.
where("LOWER(email) LIKE ?", "%#{@permitted_params[:q]&.downcase}%").
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ def process_review
#
def recent
@permitted_params = params.permit(:start)
@start = [@permitted_params[:start].to_i.abs, MAX_START].min
@start = [@permitted_params[:start].to_i.abs, max_start].min
@window = window_size
@items = Item.search.
institution(current_institution).
Expand Down Expand Up @@ -327,7 +327,7 @@ def reject
def review
authorize Item
@permitted_params = params.permit(Search::RESULTS_PARAMS)
@start = [@permitted_params[:start].to_i.abs, MAX_START].min
@start = [@permitted_params[:start].to_i.abs, max_start].min
@window = window_size
@items = Item.search.
institution(current_institution).
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/messages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class MessagesController < ApplicationController
#
def index
@permitted_params = results_params
@start = [@permitted_params[:start].to_i.abs, MAX_START].min
@start = [@permitted_params[:start].to_i.abs, max_start].min
@window = window_size
@messages = Message.all.order(updated_at: :desc)
if @permitted_params[:key].present?
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/search_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def index
@permitted_params = params.permit(Search::SIMPLE_SEARCH_PARAMS +
Search::advanced_search_params +
Search::RESULTS_PARAMS)
@start = [@permitted_params[:start].to_i.abs, MAX_START].min
@start = [@permitted_params[:start].to_i.abs, max_start].min
@window = window_size
@items = EntityRelation.new.
aggregations(true).
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/tasks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def setup_index(institution = nil)
@permitted_params = params.permit(Search::RESULTS_PARAMS +
Search::SIMPLE_SEARCH_PARAMS +
[:institution_id, :queue, :status, :status_text])
@start = [@permitted_params[:start].to_i.abs, MAX_START].min
@start = [@permitted_params[:start].to_i.abs, max_start].min
@window = window_size
@tasks = Task.all.order(created_at: :desc)
if institution
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/units_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ def show_statistics
#
def show_submissions_in_progress
@permitted_params = params.permit(Search::RESULTS_PARAMS)
@start = [@permitted_params[:start].to_i.abs, MAX_START].min
@start = [@permitted_params[:start].to_i.abs, max_start].min
@window = window_size
@items = submissions_in_progress(@start, @window)
@count = @items.count
Expand Down Expand Up @@ -565,7 +565,7 @@ def review_items(start, limit)

def set_item_results_ivars
@permitted_params = params.permit(RESULTS_PARAMS + [:unit_id])
@start = [@permitted_params[:start].to_i.abs, MAX_START].min
@start = [@permitted_params[:start].to_i.abs, max_start].min
@window = window_size
@items = Item.search.
institution(@unit.institution).
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def set_submissions_in_progress_ivars
end

def set_submittable_collections_ivars(apply_window: true)
@start = [params[:collections_start].to_i.abs, MAX_START].min
@start = [params[:collections_start].to_i.abs, max_start].min
@window = window_size
@permitted_params = params.permit(:collections_start, :items_start, :window)
@submittable_collections = @user.effective_institution_admin?(@user.institution,
Expand All @@ -218,7 +218,7 @@ def set_submittable_collections_ivars(apply_window: true)

def set_submitted_items_ivars
@permitted_params = params.permit(:direction, :q, :sort, :start)
@start = [@permitted_params[:start].to_i.abs, MAX_START].min
@start = [@permitted_params[:start].to_i.abs, max_start].min
@window = window_size
@items = Item.search.
institution(current_institution).
Expand Down Expand Up @@ -256,7 +256,7 @@ def setup_index(institution)
@permitted_params = params.permit(Search::RESULTS_PARAMS +
Search::SIMPLE_SEARCH_PARAMS +
[:institution_id])
@start = [@permitted_params[:start].to_i.abs, MAX_START].min
@start = [@permitted_params[:start].to_i.abs, max_start].min
@window = window_size
q = "%#{@permitted_params[:q]&.downcase}%"
@users = User.
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/vocabularies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def index
@permitted_params = params.permit(Search::RESULTS_PARAMS +
Search::SIMPLE_SEARCH_PARAMS +
[:institution_id])
@start = [@permitted_params[:start].to_i.abs, MAX_START].min
@start = [@permitted_params[:start].to_i.abs, max_start].min
@window = window_size
@vocabularies = Vocabulary.
where(institution: current_institution).
Expand Down Expand Up @@ -96,7 +96,7 @@ def new
def show
@permitted_params = params.permit(Search::RESULTS_PARAMS +
Search::SIMPLE_SEARCH_PARAMS)
@start = [@permitted_params[:start].to_i.abs, MAX_START].min
@start = [@permitted_params[:start].to_i.abs, max_start].min
@window = window_size
q = "%#{@permitted_params[:q]&.downcase}%"
@terms = @vocabulary.vocabulary_terms.
Expand Down

0 comments on commit c22b7d8

Please sign in to comment.