2024-02-25 12:15:55 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2010-03-10 18:21:43 -05:00
|
|
|
class PoolsController < ApplicationController
|
2020-02-14 01:39:57 -05:00
|
|
|
respond_to :html, :json
|
2024-12-08 22:28:31 -05:00
|
|
|
before_action :member_only, except: %i[index show gallery]
|
|
|
|
before_action :janitor_only, only: %i[destroy]
|
|
|
|
before_action :ensure_lockdown_disabled, except: %i[index show gallery]
|
2011-01-20 18:30:36 -05:00
|
|
|
|
2010-03-10 18:21:43 -05:00
|
|
|
def new
|
2011-01-20 18:30:36 -05:00
|
|
|
@pool = Pool.new
|
|
|
|
respond_with(@pool)
|
2010-03-10 18:21:43 -05:00
|
|
|
end
|
2013-03-19 08:10:10 -04:00
|
|
|
|
2010-03-10 18:21:43 -05:00
|
|
|
def edit
|
2011-01-20 18:30:36 -05:00
|
|
|
@pool = Pool.find(params[:id])
|
|
|
|
respond_with(@pool)
|
2010-03-10 18:21:43 -05:00
|
|
|
end
|
2013-03-19 08:10:10 -04:00
|
|
|
|
2010-03-10 18:21:43 -05:00
|
|
|
def index
|
2018-04-02 13:51:26 -04:00
|
|
|
@pools = Pool.search(search_params).paginate(params[:page], :limit => params[:limit], :search_count => params[:search])
|
2013-03-29 15:37:28 -04:00
|
|
|
respond_with(@pools) do |format|
|
2018-05-16 19:39:31 -04:00
|
|
|
format.json do
|
2018-05-24 13:18:16 -04:00
|
|
|
render json: @pools.to_json
|
2018-05-22 17:57:46 -04:00
|
|
|
expires_in params[:expiry].to_i.days if params[:expiry]
|
2018-05-16 19:39:31 -04:00
|
|
|
end
|
2013-03-29 15:37:28 -04:00
|
|
|
end
|
2010-03-10 18:21:43 -05:00
|
|
|
end
|
2013-03-19 08:10:10 -04:00
|
|
|
|
2014-08-25 19:41:27 -04:00
|
|
|
def gallery
|
2024-04-04 16:52:49 -04:00
|
|
|
@pools = Pool.search(search_params).paginate_posts(params[:page], limit: params[:limit], search_count: params[:search])
|
2014-08-25 19:41:27 -04:00
|
|
|
end
|
|
|
|
|
2010-03-10 18:21:43 -05:00
|
|
|
def show
|
2011-01-20 18:30:36 -05:00
|
|
|
@pool = Pool.find(params[:id])
|
2024-02-25 05:38:55 -05:00
|
|
|
respond_with(@pool) do |format|
|
|
|
|
format.html do
|
2024-04-04 16:52:49 -04:00
|
|
|
@posts = @pool.posts.paginate_posts(params[:page], limit: params[:limit], total_count: @pool.post_ids.count)
|
2024-02-25 05:38:55 -05:00
|
|
|
end
|
|
|
|
end
|
2010-03-10 18:21:43 -05:00
|
|
|
end
|
2013-03-19 08:10:10 -04:00
|
|
|
|
2010-03-10 18:21:43 -05:00
|
|
|
def create
|
2018-04-02 13:51:26 -04:00
|
|
|
@pool = Pool.create(pool_params)
|
2017-08-10 19:16:50 -04:00
|
|
|
flash[:notice] = @pool.valid? ? "Pool created" : @pool.errors.full_messages.join("; ")
|
2013-07-11 21:14:18 -04:00
|
|
|
respond_with(@pool)
|
2010-03-10 18:21:43 -05:00
|
|
|
end
|
2013-03-19 08:10:10 -04:00
|
|
|
|
2010-03-10 18:21:43 -05:00
|
|
|
def update
|
2011-09-15 19:15:10 -04:00
|
|
|
# need to do this in order for synchronize! to work correctly
|
2011-01-20 18:30:36 -05:00
|
|
|
@pool = Pool.find(params[:id])
|
2018-04-02 13:51:26 -04:00
|
|
|
@pool.attributes = pool_params
|
2011-09-15 19:15:10 -04:00
|
|
|
@pool.save
|
2015-05-02 11:12:30 -04:00
|
|
|
unless @pool.errors.any?
|
|
|
|
flash[:notice] = "Pool updated"
|
|
|
|
end
|
2013-07-11 21:14:18 -04:00
|
|
|
respond_with(@pool)
|
2010-03-10 18:21:43 -05:00
|
|
|
end
|
2013-03-19 08:10:10 -04:00
|
|
|
|
2010-03-10 18:21:43 -05:00
|
|
|
def destroy
|
2011-01-20 18:30:36 -05:00
|
|
|
@pool = Pool.find(params[:id])
|
2011-10-15 22:36:43 -04:00
|
|
|
if !@pool.deletable_by?(CurrentUser.user)
|
|
|
|
raise User::PrivilegeError
|
|
|
|
end
|
2013-05-20 08:42:15 -04:00
|
|
|
@pool.create_mod_action_for_delete
|
2020-09-17 19:40:21 -04:00
|
|
|
@pool.destroy
|
2013-07-11 21:14:18 -04:00
|
|
|
flash[:notice] = "Pool deleted"
|
|
|
|
respond_with(@pool)
|
2010-03-10 18:21:43 -05:00
|
|
|
end
|
2013-03-19 08:10:10 -04:00
|
|
|
|
2010-03-10 18:21:43 -05:00
|
|
|
def revert
|
2011-01-20 18:30:36 -05:00
|
|
|
@pool = Pool.find(params[:id])
|
2016-10-10 06:24:49 -04:00
|
|
|
@version = @pool.versions.find(params[:version_id])
|
2011-01-20 18:30:36 -05:00
|
|
|
@pool.revert_to!(@version)
|
2013-09-04 20:34:33 -04:00
|
|
|
flash[:notice] = "Pool reverted"
|
2013-04-30 19:54:00 -04:00
|
|
|
respond_with(@pool) do |format|
|
|
|
|
format.js
|
|
|
|
end
|
2010-03-10 18:21:43 -05:00
|
|
|
end
|
2018-04-02 13:51:26 -04:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def pool_params
|
2018-11-13 17:25:45 -05:00
|
|
|
permitted_params = %i[name description category is_active post_ids post_ids_string]
|
2018-11-08 12:32:58 -05:00
|
|
|
params.require(:pool).permit(*permitted_params, post_ids: [])
|
2018-04-02 13:51:26 -04:00
|
|
|
end
|
2024-12-08 22:28:31 -05:00
|
|
|
|
|
|
|
def ensure_lockdown_disabled
|
|
|
|
access_denied if Security::Lockdown.pools_disabled? && !CurrentUser.is_staff?
|
|
|
|
end
|
2010-03-10 18:21:43 -05:00
|
|
|
end
|