Files
danbooru/app/controllers/pools_controller.rb
evazion 2eb89a8354 Fix #4601: Hide deleted pools by default in pool search.
* On /pools, hide deleted pools by default in HTML responses. Don't
  filter out deleted pools in API responses.

* API change: on /forum_topics, only hide deleted forum topics by
  default for HTML responses, not for API responses. Explicitly do
  https://danbooru.donmai.us/forum_topics.json?search[is_deleted]=false
  to filter out deleted topics.

* API change: on /tags, only hide empty tags by default for HTML
  responses, not for API responses. Explicitly do
  https://danbooru.donmai.us/tags.json?search[is_empty]=false to filter
  out empty tags.

* API change: on /pools, default to 20 posts per page for API responses,
  not 40.

* API change: add `search[is_empty]` param to /tags.json endpoint.
  `search[hide_empty]=true` is deprecated in favor of `search[is_empty]=false`.

* On /pools, add option to show/hide deleted pools in search form.

* Fix the /forum_topics page putting `search[order]=sticky&limit=40` in
  the URL when browsing past page 1.
2021-09-29 05:44:59 -05:00

95 lines
2.5 KiB
Ruby

class PoolsController < ApplicationController
respond_to :html, :xml, :json, :js
def new
@pool = authorize Pool.new(permitted_attributes(Pool))
respond_with(@pool)
end
def edit
@pool = authorize Pool.find(params[:id])
respond_with(@pool)
end
def index
if request.format.html?
@pools = authorize Pool.paginated_search(params, count_pages: true, defaults: { is_deleted: false })
else
@pools = authorize Pool.paginated_search(params, count_pages: true)
end
respond_with(@pools)
end
def gallery
limit = params[:limit].presence || CurrentUser.user.per_page
search = search_params.presence || ActionController::Parameters.new(category: "series")
@pools = authorize Pool.search(search).paginate(params[:page], limit: limit, search_count: params[:search])
respond_with(@pools)
end
def show
limit = params[:limit].presence || CurrentUser.user.per_page
@pool = authorize Pool.find(params[:id])
@posts = @pool.posts.paginate(params[:page], limit: limit, count: @pool.post_count)
respond_with(@pool)
end
def create
@pool = authorize Pool.new(permitted_attributes(Pool))
@pool.save
flash[:notice] = @pool.valid? ? "Pool created" : @pool.errors.full_messages.join("; ")
respond_with(@pool)
end
def update
# need to do this in order for synchronize! to work correctly
@pool = authorize Pool.find(params[:id])
@pool.attributes = permitted_attributes(@pool)
@pool.synchronize
@pool.save
unless @pool.errors.any?
flash[:notice] = "Pool updated"
end
respond_with(@pool)
end
def destroy
@pool = authorize Pool.find(params[:id])
@pool.update(is_deleted: true)
@pool.create_mod_action_for_delete
flash[:notice] = "Pool deleted"
respond_with(@pool)
end
def undelete
@pool = authorize Pool.find(params[:id])
@pool.update(is_deleted: false)
@pool.create_mod_action_for_undelete
flash[:notice] = "Pool undeleted"
respond_with(@pool)
end
def revert
@pool = authorize Pool.find(params[:id])
@version = @pool.versions.find(params[:version_id])
@pool.revert_to!(@version)
flash[:notice] = "Pool reverted"
respond_with(@pool) do |format|
format.js
end
end
private
def item_matches_params(pool)
if params[:search][:name_matches]
Pool.normalize_name_for_search(pool.name) == Pool.normalize_name_for_search(params[:search][:name_matches])
else
true
end
end
end