闭社主体 forked from https://github.com/tootsuite/mastodon
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.

99 lines
2.7 KiB

  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. authorize :custom_emoji, :index?
  7. @custom_emojis = filtered_custom_emojis.eager_load(:local_counterpart).page(params[:page])
  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 update
  24. authorize @custom_emoji, :update?
  25. if @custom_emoji.update(resource_params)
  26. log_action :update, @custom_emoji
  27. redirect_to admin_custom_emojis_path, notice: I18n.t('admin.custom_emojis.updated_msg')
  28. else
  29. redirect_to admin_custom_emojis_path, notice: I18n.t('admin.custom_emojis.update_failed_msg')
  30. end
  31. end
  32. def destroy
  33. authorize @custom_emoji, :destroy?
  34. @custom_emoji.destroy!
  35. log_action :destroy, @custom_emoji
  36. redirect_to admin_custom_emojis_path, notice: I18n.t('admin.custom_emojis.destroyed_msg')
  37. end
  38. def copy
  39. authorize @custom_emoji, :copy?
  40. emoji = CustomEmoji.find_or_initialize_by(domain: nil, shortcode: @custom_emoji.shortcode)
  41. emoji.image = @custom_emoji.image
  42. if emoji.save
  43. log_action :create, emoji
  44. flash[:notice] = I18n.t('admin.custom_emojis.copied_msg')
  45. else
  46. flash[:alert] = I18n.t('admin.custom_emojis.copy_failed_msg')
  47. end
  48. redirect_to admin_custom_emojis_path(page: params[:page])
  49. end
  50. def enable
  51. authorize @custom_emoji, :enable?
  52. @custom_emoji.update!(disabled: false)
  53. log_action :enable, @custom_emoji
  54. redirect_to admin_custom_emojis_path, notice: I18n.t('admin.custom_emojis.enabled_msg')
  55. end
  56. def disable
  57. authorize @custom_emoji, :disable?
  58. @custom_emoji.update!(disabled: true)
  59. log_action :disable, @custom_emoji
  60. redirect_to admin_custom_emojis_path, notice: I18n.t('admin.custom_emojis.disabled_msg')
  61. end
  62. private
  63. def set_custom_emoji
  64. @custom_emoji = CustomEmoji.find(params[:id])
  65. end
  66. def resource_params
  67. params.require(:custom_emoji).permit(:shortcode, :image, :visible_in_picker)
  68. end
  69. def filtered_custom_emojis
  70. CustomEmojiFilter.new(filter_params).results
  71. end
  72. def filter_params
  73. params.permit(
  74. :local,
  75. :remote
  76. )
  77. end
  78. end
  79. end