Sha256: cb609a2c8ec0d70b03e7e6a92fa035146f51ae6d731abcd7901f212a18f6b69a

Contents?: true

Size: 1.24 KB

Versions: 19

Compression:

Stored size: 1.24 KB

Contents

# frozen_string_literal: true

module Decidim::Cw
  # This class deals with uploading attachments to a participatory space.
  class AttachmentUploader < ApplicationUploader
    process :validate_dimensions
    process :strip

    def validable_dimensions
      true
    end

    set_variants do
      {
        thumbnail: { resize_to_fit: [nil, 237] },
        big: { resize_to_limit: [nil, 1000] }
      }
    end

    def max_image_height_or_width
      8000
    end

    protected

    # Strips out all embedded information from the image
    def strip
      return unless image?(self)

      manipulate! do |img|
        img.strip
        img
      end
    end

    def upload_context
      return :participant unless model.respond_to?(:context)

      model.context
    end

    # A simple check to avoid DoS with maliciously crafted images, or just to
    # avoid reckless users that upload gigapixels images.
    #
    # See https://hackerone.com/reports/390
    def validate_dimensions
      return unless image?(self)

      manipulate! do |image|
        raise CarrierWave::IntegrityError, I18n.t("carrierwave.errors.image_too_big") if image.dimensions.any? { |dimension| dimension > max_image_height_or_width }

        image
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
decidim-core-0.26.10 app/uploaders/decidim/cw/attachment_uploader.rb
decidim-core-0.26.9 app/uploaders/decidim/cw/attachment_uploader.rb
decidim-core-0.26.8 app/uploaders/decidim/cw/attachment_uploader.rb
decidim-core-0.26.7 app/uploaders/decidim/cw/attachment_uploader.rb
decidim-core-0.26.5 app/uploaders/decidim/cw/attachment_uploader.rb
decidim-core-0.26.4 app/uploaders/decidim/cw/attachment_uploader.rb
decidim-core-0.26.3 app/uploaders/decidim/cw/attachment_uploader.rb
decidim-core-0.26.2 app/uploaders/decidim/cw/attachment_uploader.rb
decidim-core-0.26.1 app/uploaders/decidim/cw/attachment_uploader.rb
decidim-core-0.26.0 app/uploaders/decidim/cw/attachment_uploader.rb
decidim-core-0.26.0.rc2 app/uploaders/decidim/cw/attachment_uploader.rb
decidim-core-0.26.0.rc1 app/uploaders/decidim/cw/attachment_uploader.rb
decidim-core-0.25.2 app/uploaders/decidim/cw/attachment_uploader.rb
decidim-core-0.25.1 app/uploaders/decidim/cw/attachment_uploader.rb
decidim-core-0.25.0 app/uploaders/decidim/cw/attachment_uploader.rb
decidim-core-0.25.0.rc4 app/uploaders/decidim/cw/attachment_uploader.rb
decidim-core-0.25.0.rc3 app/uploaders/decidim/cw/attachment_uploader.rb
decidim-core-0.25.0.rc2 app/uploaders/decidim/cw/attachment_uploader.rb
decidim-core-0.25.0.rc1 app/uploaders/decidim/cw/attachment_uploader.rb