2017-09-18 18:52:38 -07:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Admin
|
|
|
|
class CustomEmojisController < BaseController
|
|
|
|
def index
|
2017-11-11 11:23:33 -08:00
|
|
|
authorize :custom_emoji, :index?
|
2019-09-09 13:44:17 -07:00
|
|
|
|
2017-11-07 05:49:32 -08:00
|
|
|
@custom_emojis = filtered_custom_emojis.eager_load(:local_counterpart).page(params[:page])
|
2019-09-09 13:44:17 -07:00
|
|
|
@form = Form::CustomEmojiBatch.new
|
2017-09-18 18:52:38 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
2017-11-11 11:23:33 -08:00
|
|
|
authorize :custom_emoji, :create?
|
2019-09-09 13:44:17 -07:00
|
|
|
|
2017-09-18 18:52:38 -07:00
|
|
|
@custom_emoji = CustomEmoji.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2017-11-11 11:23:33 -08:00
|
|
|
authorize :custom_emoji, :create?
|
|
|
|
|
2017-09-18 18:52:38 -07:00
|
|
|
@custom_emoji = CustomEmoji.new(resource_params)
|
|
|
|
|
|
|
|
if @custom_emoji.save
|
2017-11-23 17:05:53 -08:00
|
|
|
log_action :create, @custom_emoji
|
2017-09-18 18:52:38 -07:00
|
|
|
redirect_to admin_custom_emojis_path, notice: I18n.t('admin.custom_emojis.created_msg')
|
|
|
|
else
|
|
|
|
render :new
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-09-09 13:44:17 -07:00
|
|
|
def batch
|
2022-07-04 17:41:40 -07:00
|
|
|
authorize :custom_emoji, :index?
|
|
|
|
|
2019-09-09 13:44:17 -07:00
|
|
|
@form = Form::CustomEmojiBatch.new(form_custom_emoji_batch_params.merge(current_account: current_account, action: action_from_button))
|
|
|
|
@form.save
|
|
|
|
rescue ActionController::ParameterMissing
|
2022-10-14 15:20:54 -07:00
|
|
|
flash[:alert] = I18n.t('admin.custom_emojis.no_emoji_selected')
|
2020-06-05 06:23:27 -07:00
|
|
|
rescue Mastodon::NotPermittedError
|
|
|
|
flash[:alert] = I18n.t('admin.custom_emojis.not_permitted')
|
2022-03-14 09:34:53 -07:00
|
|
|
rescue ActiveRecord::RecordInvalid => e
|
|
|
|
error_message = action_from_button == 'copy' ? 'admin.custom_emojis.batch_copy_error' : 'admin.custom_emojis.batch_error'
|
|
|
|
flash[:alert] = I18n.t(error_message, message: e.message)
|
2019-09-09 13:44:17 -07:00
|
|
|
ensure
|
|
|
|
redirect_to admin_custom_emojis_path(filter_params)
|
2017-10-05 14:42:05 -07:00
|
|
|
end
|
|
|
|
|
2017-09-18 18:52:38 -07:00
|
|
|
private
|
|
|
|
|
|
|
|
def resource_params
|
2017-10-27 07:11:30 -07:00
|
|
|
params.require(:custom_emoji).permit(:shortcode, :image, :visible_in_picker)
|
2017-09-18 18:52:38 -07:00
|
|
|
end
|
2017-10-05 14:42:05 -07:00
|
|
|
|
|
|
|
def filtered_custom_emojis
|
|
|
|
CustomEmojiFilter.new(filter_params).results
|
|
|
|
end
|
|
|
|
|
|
|
|
def filter_params
|
2020-01-20 06:55:03 -08:00
|
|
|
params.slice(:page, *CustomEmojiFilter::KEYS).permit(:page, *CustomEmojiFilter::KEYS)
|
2019-09-09 13:44:17 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
def action_from_button
|
|
|
|
if params[:update]
|
|
|
|
'update'
|
|
|
|
elsif params[:list]
|
|
|
|
'list'
|
|
|
|
elsif params[:unlist]
|
|
|
|
'unlist'
|
|
|
|
elsif params[:enable]
|
|
|
|
'enable'
|
|
|
|
elsif params[:disable]
|
|
|
|
'disable'
|
|
|
|
elsif params[:copy]
|
|
|
|
'copy'
|
|
|
|
elsif params[:delete]
|
|
|
|
'delete'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def form_custom_emoji_batch_params
|
|
|
|
params.require(:form_custom_emoji_batch).permit(:action, :category_id, :category_name, custom_emoji_ids: [])
|
2017-10-05 14:42:05 -07:00
|
|
|
end
|
2017-09-18 18:52:38 -07:00
|
|
|
end
|
|
|
|
end
|