Normally we skip doing page counts on index pages when there aren't any search filters. This is on the assumption that most index pages have more than 1000 pages (20,000 results), so it's not worth counting them exactly. This isn't always true, so here we turn on full counts on certain index pages known to be small.
63 lines
2.0 KiB
Ruby
63 lines
2.0 KiB
Ruby
class BulkUpdateRequestsController < ApplicationController
|
|
respond_to :html, :xml, :json, :js
|
|
before_action :member_only, :except => [:index, :show]
|
|
before_action :admin_only, :only => [:approve]
|
|
before_action :load_bulk_update_request, :except => [:new, :create, :index]
|
|
|
|
def new
|
|
@bulk_update_request = BulkUpdateRequest.new(bur_params(:create))
|
|
respond_with(@bulk_update_request)
|
|
end
|
|
|
|
def create
|
|
@bulk_update_request = BulkUpdateRequest.create(bur_params(:create))
|
|
respond_with(@bulk_update_request, :location => bulk_update_requests_path)
|
|
end
|
|
|
|
def show
|
|
@bulk_update_request = BulkUpdateRequest.find(params[:id])
|
|
respond_with(@bulk_update_request)
|
|
end
|
|
|
|
def edit
|
|
end
|
|
|
|
def update
|
|
raise User::PrivilegeError unless @bulk_update_request.editable?(CurrentUser.user)
|
|
|
|
@bulk_update_request.update(bur_params(:update))
|
|
respond_with(@bulk_update_request, location: bulk_update_requests_path, notice: "Bulk update request updated")
|
|
end
|
|
|
|
def approve
|
|
@bulk_update_request.approve!(CurrentUser.user)
|
|
respond_with(@bulk_update_request, :location => bulk_update_requests_path)
|
|
end
|
|
|
|
def destroy
|
|
raise User::PrivilegeError unless @bulk_update_request.rejectable?(CurrentUser.user)
|
|
|
|
@bulk_update_request.reject!(CurrentUser.user)
|
|
respond_with(@bulk_update_request, location: bulk_update_requests_path, notice: "Bulk update request rejected")
|
|
end
|
|
|
|
def index
|
|
@bulk_update_requests = BulkUpdateRequest.includes(:user, :approver, :forum_topic, forum_post: [:votes]).paginated_search(params, count_pages: true)
|
|
respond_with(@bulk_update_requests)
|
|
end
|
|
|
|
private
|
|
|
|
def load_bulk_update_request
|
|
@bulk_update_request = BulkUpdateRequest.find(params[:id])
|
|
end
|
|
|
|
def bur_params(context)
|
|
permitted_params = %i[script skip_secondary_validations]
|
|
permitted_params += %i[title reason forum_topic_id] if context == :create
|
|
permitted_params += %i[forum_topic_id forum_post_id] if context == :update && CurrentUser.is_admin?
|
|
|
|
params.fetch(:bulk_update_request, {}).permit(permitted_params)
|
|
end
|
|
end
|