Class: Admin::EmojisController
- Inherits:
-
AdminController
- Object
- AdminController
- Admin::EmojisController
- Defined in:
- app/controllers/admin/emojis_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
NOTE: This kind of custom logic also needs to be implemented to be run in the ExternalUploadManager when a direct S3 upload is completed, related to preventDirectS3Uploads in the UppyUploadMixin.
- #destroy ⇒ Object
- #index ⇒ Object
Instance Method Details
#create ⇒ Object
NOTE: This kind of custom logic also needs to be implemented to be run in the ExternalUploadManager when a direct S3 upload is completed, related to preventDirectS3Uploads in the UppyUploadMixin.
Until then, preventDirectS3Uploads is set to true in the UppyUploadMixin.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/controllers/admin/emojis_controller.rb', line 13 def create file = params[:file] || params[:files].first name = params[:name] || File.basename(file.original_filename, ".*") group = params[:group] ? params[:group].downcase : nil hijack do # fix the name name = File.basename(name, ".*") name = Emoji.sanitize_emoji_name(name) upload = UploadCreator.new(file.tempfile, file.original_filename, type: "custom_emoji").create_for( current_user.id, ) good = true data = if upload.persisted? custom_emoji = CustomEmoji.new(name: name, upload: upload, group: group, user: current_user) if custom_emoji.save StaffActionLogger.new(current_user).log_custom_emoji_create(name, group: group) Emoji.clear_cache { name: custom_emoji.name, url: custom_emoji.upload.url, group: group } else good = false failed_json.merge(errors: custom_emoji.errors.) end else good = false failed_json.merge(errors: upload.errors.) end render json: data.as_json, status: good ? 200 : 422 end end |
#destroy ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'app/controllers/admin/emojis_controller.rb', line 52 def destroy name = params.require(:id) # NOTE: the upload will automatically be removed by the 'clean_up_uploads' job emoji = CustomEmoji.find_by(name: name) if emoji.present? StaffActionLogger.new(current_user).log_custom_emoji_destroy(name) emoji.destroy! end Emoji.clear_cache Jobs.enqueue(:rebake_custom_emoji_posts, name: name) render json: success_json end |
#index ⇒ Object
4 5 6 |
# File 'app/controllers/admin/emojis_controller.rb', line 4 def index render_serialized(Emoji.custom, EmojiSerializer, root: false) end |