2019-09-09 22:44:17 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Form::CustomEmojiBatch
|
|
|
|
include ActiveModel::Model
|
|
|
|
include Authorization
|
|
|
|
include AccountableConcern
|
|
|
|
|
|
|
|
attr_accessor :custom_emoji_ids, :action, :current_account,
|
|
|
|
:category_id, :category_name, :visible_in_picker
|
|
|
|
|
|
|
|
def save
|
|
|
|
case action
|
|
|
|
when 'update'
|
|
|
|
update!
|
|
|
|
when 'list'
|
|
|
|
list!
|
|
|
|
when 'unlist'
|
|
|
|
unlist!
|
|
|
|
when 'enable'
|
|
|
|
enable!
|
|
|
|
when 'disable'
|
|
|
|
disable!
|
|
|
|
when 'copy'
|
|
|
|
copy!
|
|
|
|
when 'delete'
|
|
|
|
delete!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def custom_emojis
|
2020-08-09 15:23:42 +02:00
|
|
|
@custom_emojis ||= CustomEmoji.where(id: custom_emoji_ids)
|
2019-09-09 22:44:17 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def update!
|
2023-10-16 16:36:28 +02:00
|
|
|
verify_authorization(:update?)
|
2019-09-09 22:44:17 +02:00
|
|
|
|
2023-02-18 23:09:40 +01:00
|
|
|
category = if category_id.present?
|
|
|
|
CustomEmojiCategory.find(category_id)
|
|
|
|
elsif category_name.present?
|
|
|
|
CustomEmojiCategory.find_or_create_by!(name: category_name)
|
|
|
|
end
|
2019-09-09 22:44:17 +02:00
|
|
|
|
|
|
|
custom_emojis.each do |custom_emoji|
|
|
|
|
custom_emoji.update(category_id: category&.id)
|
|
|
|
log_action :update, custom_emoji
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def list!
|
2023-10-16 16:36:28 +02:00
|
|
|
verify_authorization(:update?)
|
2019-09-09 22:44:17 +02:00
|
|
|
|
|
|
|
custom_emojis.each do |custom_emoji|
|
|
|
|
custom_emoji.update(visible_in_picker: true)
|
|
|
|
log_action :update, custom_emoji
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def unlist!
|
2023-10-16 16:36:28 +02:00
|
|
|
verify_authorization(:update?)
|
2019-09-09 22:44:17 +02:00
|
|
|
|
|
|
|
custom_emojis.each do |custom_emoji|
|
|
|
|
custom_emoji.update(visible_in_picker: false)
|
|
|
|
log_action :update, custom_emoji
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def enable!
|
2023-10-16 16:36:28 +02:00
|
|
|
verify_authorization(:enable?)
|
2019-09-09 22:44:17 +02:00
|
|
|
|
|
|
|
custom_emojis.each do |custom_emoji|
|
|
|
|
custom_emoji.update(disabled: false)
|
|
|
|
log_action :enable, custom_emoji
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def disable!
|
2023-10-16 16:36:28 +02:00
|
|
|
verify_authorization(:disable?)
|
2019-09-09 22:44:17 +02:00
|
|
|
|
|
|
|
custom_emojis.each do |custom_emoji|
|
|
|
|
custom_emoji.update(disabled: true)
|
|
|
|
log_action :disable, custom_emoji
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def copy!
|
2023-10-16 16:36:28 +02:00
|
|
|
verify_authorization(:copy?)
|
2019-09-09 22:44:17 +02:00
|
|
|
|
|
|
|
custom_emojis.each do |custom_emoji|
|
|
|
|
copied_custom_emoji = custom_emoji.copy!
|
|
|
|
log_action :create, copied_custom_emoji
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def delete!
|
2023-10-16 16:36:28 +02:00
|
|
|
verify_authorization(:destroy?)
|
2019-09-09 22:44:17 +02:00
|
|
|
|
|
|
|
custom_emojis.each do |custom_emoji|
|
|
|
|
custom_emoji.destroy
|
|
|
|
log_action :destroy, custom_emoji
|
|
|
|
end
|
|
|
|
end
|
2023-10-16 16:36:28 +02:00
|
|
|
|
|
|
|
def verify_authorization(permission)
|
|
|
|
custom_emojis.each { |custom_emoji| authorize(custom_emoji, permission) }
|
|
|
|
end
|
2019-09-09 22:44:17 +02:00
|
|
|
end
|