You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
2.0 KiB

  1. # frozen_string_literal: true
  2. module Admin
  3. class CustomEmojisController < BaseController
  4. def index
  5. authorize :custom_emoji, :index?
  6. @custom_emojis = filtered_custom_emojis.eager_load(:local_counterpart).page(params[:page])
  7. @form = Form::CustomEmojiBatch.new
  8. end
  9. def new
  10. authorize :custom_emoji, :create?
  11. @custom_emoji = CustomEmoji.new
  12. end
  13. def create
  14. authorize :custom_emoji, :create?
  15. @custom_emoji = CustomEmoji.new(resource_params)
  16. if @custom_emoji.save
  17. log_action :create, @custom_emoji
  18. redirect_to admin_custom_emojis_path, notice: I18n.t('admin.custom_emojis.created_msg')
  19. else
  20. render :new
  21. end
  22. end
  23. def batch
  24. @form = Form::CustomEmojiBatch.new(form_custom_emoji_batch_params.merge(current_account: current_account, action: action_from_button))
  25. @form.save
  26. rescue ActionController::ParameterMissing
  27. flash[:alert] = I18n.t('admin.accounts.no_account_selected')
  28. rescue Mastodon::NotPermittedError
  29. flash[:alert] = I18n.t('admin.custom_emojis.not_permitted')
  30. ensure
  31. redirect_to admin_custom_emojis_path(filter_params)
  32. end
  33. private
  34. def resource_params
  35. params.require(:custom_emoji).permit(:shortcode, :image, :visible_in_picker)
  36. end
  37. def filtered_custom_emojis
  38. CustomEmojiFilter.new(filter_params).results
  39. end
  40. def filter_params
  41. params.slice(:page, *CustomEmojiFilter::KEYS).permit(:page, *CustomEmojiFilter::KEYS)
  42. end
  43. def action_from_button
  44. if params[:update]
  45. 'update'
  46. elsif params[:list]
  47. 'list'
  48. elsif params[:unlist]
  49. 'unlist'
  50. elsif params[:enable]
  51. 'enable'
  52. elsif params[:disable]
  53. 'disable'
  54. elsif params[:copy]
  55. 'copy'
  56. elsif params[:delete]
  57. 'delete'
  58. end
  59. end
  60. def form_custom_emoji_batch_params
  61. params.require(:form_custom_emoji_batch).permit(:action, :category_id, :category_name, custom_emoji_ids: [])
  62. end
  63. end
  64. end