1
0

custom_emojis_controller.rb 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # frozen_string_literal: true
  2. module Admin
  3. class CustomEmojisController < BaseController
  4. before_action :set_custom_emoji, except: [:index, :new, :create]
  5. def index
  6. @custom_emojis = filtered_custom_emojis.page(params[:page])
  7. end
  8. def new
  9. @custom_emoji = CustomEmoji.new
  10. end
  11. def create
  12. @custom_emoji = CustomEmoji.new(resource_params)
  13. if @custom_emoji.save
  14. redirect_to admin_custom_emojis_path, notice: I18n.t('admin.custom_emojis.created_msg')
  15. else
  16. render :new
  17. end
  18. end
  19. def destroy
  20. @custom_emoji.destroy
  21. redirect_to admin_custom_emojis_path, notice: I18n.t('admin.custom_emojis.destroyed_msg')
  22. end
  23. def copy
  24. emoji = @custom_emoji.dup
  25. emoji.domain = nil
  26. if emoji.save
  27. redirect_to admin_custom_emojis_path, notice: I18n.t('admin.custom_emojis.copied_msg')
  28. else
  29. redirect_to admin_custom_emojis_path, alert: I18n.t('admin.custom_emojis.copy_failed_msg')
  30. end
  31. end
  32. def enable
  33. @custom_emoji.update!(disabled: false)
  34. redirect_to admin_custom_emojis_path, notice: I18n.t('admin.custom_emojis.enabled_msg')
  35. end
  36. def disable
  37. @custom_emoji.update!(disabled: true)
  38. redirect_to admin_custom_emojis_path, notice: I18n.t('admin.custom_emojis.disabled_msg')
  39. end
  40. private
  41. def set_custom_emoji
  42. @custom_emoji = CustomEmoji.find(params[:id])
  43. end
  44. def resource_params
  45. params.require(:custom_emoji).permit(:shortcode, :image)
  46. end
  47. def filtered_custom_emojis
  48. CustomEmojiFilter.new(filter_params).results
  49. end
  50. def filter_params
  51. params.permit(
  52. :local,
  53. :remote
  54. )
  55. end
  56. end
  57. end