Files
danbooru/app/controllers/pools_controller.rb
evazion 7d503f088e posts: stop using pool_string attribute.
Stop using the pool_string attribute on posts:

* Stop updating it when adding or removing posts from pools.
* Stop returning pool_string in the /posts.json API.
* Stop including the `data-pools` attribute on thumbnails.

The pool_string attribute was used in the past to facilitate pool:X
searches. Posts had a hidden pool_string attribute that contained a list
of every pool the post belonged to. These pools were treated like fake
hidden tags on the post and a search for `pool:X` was treated like a tag
search.

The pool_string has no longer been used for this purpose for a long time
now, and was only maintained for API compatibility purposes. Getting rid
of it eliminates a bunch of legacy cruft relating to adding and removing
posts from pools.

If you need to see which pools a post belongs to, do this:

* https://danbooru.donmai.us/pools.json?search[post_ids_include_any]=318550

The `data-pools` attribute on thumbnails was used by some people to add
custom borders to pooled posts with custom CSS. This will no longer
work. This was already broken because it included things like collection
pools and deleted pools, which you probably didn't want. Use a
userscript to add this attribute back to thumbnails if you need it.
2021-10-07 05:55:43 -05:00

92 lines
2.3 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
@pool = authorize Pool.find(params[:id])
@pool.update(permitted_attributes(@pool))
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