tb_media 1.2.1 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
 - data/Rakefile +2 -2
 - data/Readme.markdown +3 -19
 - data/app/assets/javascripts/admin/media/application.js +2 -2
 - data/app/assets/javascripts/admin/media/picker.js +8 -5
 - data/app/assets/javascripts/admin/media/plugin.js.erb +86 -81
 - data/app/assets/stylesheets/admin/media/application.css.scss +1 -12
 - data/app/controllers/admin/media_controller.rb +54 -61
 - data/app/controllers/admin/media_picker_controller.rb +8 -16
 - data/app/models/spud_media.rb +63 -110
 - data/app/views/admin/media/index.html.erb +4 -12
 - data/app/views/admin/media/new.html.erb +0 -1
 - data/app/views/admin/media_picker/_media.html.erb +2 -7
 - data/app/views/admin/media_picker/index.html.erb +1 -2
 - data/config/locales/en.yml +0 -1
 - data/config/routes.rb +5 -8
 - data/db/migrate/20120101194256_create_spud_media.rb +2 -2
 - data/db/migrate/20120501203325_add_protected_to_spud_media.rb +1 -2
 - data/db/migrate/20120508132153_add_cropping_to_spud_media.rb +1 -1
 - data/lib/spud_media/configuration.rb +3 -4
 - data/lib/spud_media/content_types.rb +2 -2
 - data/lib/spud_media/engine.rb +21 -13
 - data/lib/spud_media/version.rb +3 -3
 - data/lib/tasks/spud_media_tasks.rake +4 -6
 - data/spec/controllers/admin/media_controller_spec.rb +23 -24
 - data/spec/dummy/config.ru +1 -1
 - data/spec/dummy/config/application.rb +2 -3
 - data/spec/dummy/config/boot.rb +1 -1
 - data/spec/dummy/config/environments/development.rb +0 -7
 - data/spec/dummy/config/environments/test.rb +3 -5
 - data/spec/dummy/config/routes.rb +2 -2
 - data/spec/dummy/db/migrate/20130904141442_create_spud_users.tb_core.rb +12 -12
 - data/spec/dummy/db/migrate/20130904141443_add_time_zone_to_spud_user.tb_core.rb +0 -1
 - data/spec/dummy/db/migrate/20130904141444_add_scope_to_spud_admin_permissions.tb_core.rb +0 -1
 - data/spec/dummy/db/migrate/20130904141446_create_spud_media.tb_media.rb +1 -1
 - data/spec/dummy/db/migrate/20130904141447_add_protected_to_spud_media.tb_media.rb +1 -1
 - data/spec/dummy/db/migrate/20130904141448_add_cropping_to_spud_media.tb_media.rb +3 -3
 - data/spec/dummy/db/migrate/20151012194531_create_spud_permissions.tb_core.rb +3 -3
 - data/spec/dummy/db/migrate/20151012194532_create_spud_role_permissions.tb_core.rb +2 -2
 - data/spec/dummy/db/migrate/20151012194534_add_requires_password_change_to_spud_users.tb_core.rb +1 -1
 - data/spec/dummy/db/schema.rb +63 -67
 - data/spec/dummy/public/system/spud_media/1/cropped/test_img1.png +0 -0
 - data/spec/dummy/public/system/spud_media/1/small/test_img1.png +0 -0
 - data/spec/dummy/public/system/spud_media/2/cropped/test_img1.png +0 -0
 - data/spec/dummy/public/system/spud_media/2/small/test_img1.png +0 -0
 - data/spec/dummy/public/system/spud_media/3/cropped/test_img1.png +0 -0
 - data/spec/dummy/public/system/spud_media/3/small/test_img1.png +0 -0
 - data/spec/dummy/public/system/spud_media/4/cropped/test_img1.png +0 -0
 - data/spec/dummy/public/system/spud_media/4/small/test_img1.png +0 -0
 - data/spec/dummy/public/system/spud_media/5/cropped/test_img1.png +0 -0
 - data/spec/dummy/public/system/spud_media/5/small/test_img1.png +0 -0
 - data/spec/dummy/script/rails +2 -2
 - data/spec/javascripts/support/jasmine_helper.rb +6 -7
 - data/spec/models/spud_media_spec.rb +2 -2
 - data/spec/rails_helper.rb +14 -7
 - data/spec/spec_helper.rb +42 -44
 - metadata +103 -104
 - data/app/controllers/protected_media_controller.rb +0 -24
 - data/app/helpers/protected_media_helper.rb +0 -3
 - data/spec/dummy/public/system/spud_media/1/cropped/test_img1.jpg +0 -0
 - data/spec/dummy/public/system/spud_media/2/cropped/test_img1.jpg +0 -0
 - data/spec/dummy/public/system/spud_media/3/cropped/test_img1.jpg +0 -0
 - data/spec/dummy/public/system/spud_media/4/cropped/test_img1.jpg +0 -0
 - data/spec/dummy/public/system/spud_media/5/cropped/test_img1.jpg +0 -0
 - data/spec/support/authlogic_helper.rb +0 -2
 
| 
         @@ -1,42 +1,34 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            class Admin::MediaPickerController < Admin::ApplicationController
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
     | 
    
         
            -
              include RespondsToParent
         
     | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
       5 
3 
     | 
    
         
             
              layout false
         
     | 
| 
       6 
4 
     | 
    
         
             
              respond_to :html
         
     | 
| 
       7 
5 
     | 
    
         | 
| 
       8 
6 
     | 
    
         
             
              def index
         
     | 
| 
       9 
     | 
    
         
            -
                @media = SpudMedia.order('attachment_file_name asc').paginate(: 
     | 
| 
      
 7 
     | 
    
         
            +
                @media = SpudMedia.order('attachment_file_name asc').paginate(page: params[:page], per_page: 30)
         
     | 
| 
       10 
8 
     | 
    
         
             
                respond_with @media do |format|
         
     | 
| 
       11 
     | 
    
         
            -
                  format.html 
     | 
| 
      
 9 
     | 
    
         
            +
                  format.html do
         
     | 
| 
       12 
10 
     | 
    
         
             
                    if params[:only_list]
         
     | 
| 
       13 
     | 
    
         
            -
                      render : 
     | 
| 
      
 11 
     | 
    
         
            +
                      render partial: 'media', collection: @media
         
     | 
| 
       14 
12 
     | 
    
         
             
                    else
         
     | 
| 
       15 
13 
     | 
    
         
             
                      render 'index'
         
     | 
| 
       16 
14 
     | 
    
         
             
                    end
         
     | 
| 
       17 
     | 
    
         
            -
                   
     | 
| 
      
 15 
     | 
    
         
            +
                  end
         
     | 
| 
       18 
16 
     | 
    
         
             
                end
         
     | 
| 
       19 
17 
     | 
    
         
             
              end
         
     | 
| 
       20 
18 
     | 
    
         | 
| 
       21 
19 
     | 
    
         
             
              def create
         
     | 
| 
       22 
20 
     | 
    
         
             
                @media = SpudMedia.new(media_params)
         
     | 
| 
       23 
21 
     | 
    
         
             
                if @media.save
         
     | 
| 
       24 
     | 
    
         
            -
                   
     | 
| 
       25 
     | 
    
         
            -
                    render 'create', :status => 200
         
     | 
| 
       26 
     | 
    
         
            -
                  else
         
     | 
| 
       27 
     | 
    
         
            -
                    respond_to_parent do
         
     | 
| 
       28 
     | 
    
         
            -
                      render 'create.js', :status => 200
         
     | 
| 
       29 
     | 
    
         
            -
                    end
         
     | 
| 
       30 
     | 
    
         
            -
                  end
         
     | 
| 
      
 22 
     | 
    
         
            +
                  render 'create', status: :ok
         
     | 
| 
       31 
23 
     | 
    
         
             
                else
         
     | 
| 
       32 
     | 
    
         
            -
                  render : 
     | 
| 
      
 24 
     | 
    
         
            +
                  render text: @media.errors.full_messages.first, status: :unprocessable_entity
         
     | 
| 
       33 
25 
     | 
    
         
             
                end
         
     | 
| 
       34 
26 
     | 
    
         
             
              end
         
     | 
| 
       35 
27 
     | 
    
         | 
| 
       36 
     | 
    
         
            -
            private
         
     | 
| 
      
 28 
     | 
    
         
            +
              private
         
     | 
| 
       37 
29 
     | 
    
         | 
| 
       38 
30 
     | 
    
         
             
              def media_params
         
     | 
| 
       39 
     | 
    
         
            -
                params.require(:spud_media).permit(:attachment_content_type 
     | 
| 
      
 31 
     | 
    
         
            +
                params.require(:spud_media).permit(:attachment_content_type, :attachment_file_name, :attachment_file_size, :attachment, :crop_x, :crop_y, :crop_w, :crop_h, :crop_s)
         
     | 
| 
       40 
32 
     | 
    
         
             
              end
         
     | 
| 
       41 
33 
     | 
    
         | 
| 
       42 
34 
     | 
    
         
             
            end
         
     | 
    
        data/app/models/spud_media.rb
    CHANGED
    
    | 
         @@ -1,82 +1,75 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            class SpudMedia < ActiveRecord::Base
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
       4 
     | 
    
         
            -
                : 
     | 
| 
       5 
     | 
    
         
            -
                : 
     | 
| 
       6 
     | 
    
         
            -
                : 
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
                 
     | 
| 
       9 
     | 
    
         
            -
                : 
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
                :url => Spud::Media.storage_url,
         
     | 
| 
       13 
     | 
    
         
            -
                :styles => lambda { |attachment| attachment.instance.dynamic_styles }
         
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
              validates_numericality_of :crop_x, :crop_y, :crop_w, :crop_h, :crop_s, :allow_nil => true
         
     | 
| 
      
 3 
     | 
    
         
            +
              has_attached_file :attachment,
         
     | 
| 
      
 4 
     | 
    
         
            +
                storage: Spud::Media.paperclip_storage,
         
     | 
| 
      
 5 
     | 
    
         
            +
                s3_credentials: Spud::Media.s3_credentials,
         
     | 
| 
      
 6 
     | 
    
         
            +
                s3_permissions: 'public-read',
         
     | 
| 
      
 7 
     | 
    
         
            +
                path: Spud::Media.storage_path,
         
     | 
| 
      
 8 
     | 
    
         
            +
                url: Spud::Media.storage_url,
         
     | 
| 
      
 9 
     | 
    
         
            +
                styles: ->(attachment) { attachment.instance.dynamic_styles }
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
              validates :crop_x, :crop_y, :crop_w, :crop_h, :crop_s, numericality: { allow_nil: true }
         
     | 
| 
       16 
12 
     | 
    
         | 
| 
       17 
13 
     | 
    
         
             
              extend ActionView::Helpers::NumberHelper
         
     | 
| 
       18 
14 
     | 
    
         | 
| 
       19 
15 
     | 
    
         
             
              validates_attachment :attachment,
         
     | 
| 
       20 
     | 
    
         
            -
                : 
     | 
| 
       21 
     | 
    
         
            -
                : 
     | 
| 
       22 
     | 
    
         
            -
                : 
     | 
| 
       23 
     | 
    
         
            -
                  : 
     | 
| 
       24 
     | 
    
         
            -
                  : 
     | 
| 
       25 
     | 
    
         
            -
                  : 
     | 
| 
      
 16 
     | 
    
         
            +
                presence: true,
         
     | 
| 
      
 17 
     | 
    
         
            +
                content_type: { content_type: Spud::Media::CONTENT_TYPES },
         
     | 
| 
      
 18 
     | 
    
         
            +
                size: {
         
     | 
| 
      
 19 
     | 
    
         
            +
                  less_than: Spud::Media.max_upload_size,
         
     | 
| 
      
 20 
     | 
    
         
            +
                  message: 'size cannot exceed ' + number_to_human_size(Spud::Media.max_upload_size),
         
     | 
| 
      
 21 
     | 
    
         
            +
                  if: proc { |_p| Spud::Media.max_upload_size.positive? }
         
     | 
| 
       26 
22 
     | 
    
         
             
                }
         
     | 
| 
       27 
23 
     | 
    
         | 
| 
       28 
24 
     | 
    
         
             
              before_create :rename_file
         
     | 
| 
       29 
     | 
    
         
            -
              #after_create :validate_permissions
         
     | 
| 
       30 
     | 
    
         
            -
              before_update :validate_permissions
         
     | 
| 
       31 
25 
     | 
    
         | 
| 
       32 
26 
     | 
    
         
             
              def rename_file
         
     | 
| 
       33 
     | 
    
         
            -
                #  
     | 
| 
      
 27 
     | 
    
         
            +
                # Remove periods and other unsafe characters from file name to make routing easier
         
     | 
| 
       34 
28 
     | 
    
         
             
                extension = File.extname(attachment_file_name)
         
     | 
| 
       35 
29 
     | 
    
         
             
                filename = attachment_file_name.chomp(extension).parameterize
         
     | 
| 
       36 
30 
     | 
    
         
             
                attachment.instance_write :file_name, filename + extension
         
     | 
| 
       37 
31 
     | 
    
         
             
              end
         
     | 
| 
       38 
32 
     | 
    
         | 
| 
       39 
33 
     | 
    
         
             
              def image_from_type
         
     | 
| 
      
 34 
     | 
    
         
            +
                if is_image?
         
     | 
| 
      
 35 
     | 
    
         
            +
                  return attachment_url(:small)
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
                elsif attachment_content_type.blank?
         
     | 
| 
      
 38 
     | 
    
         
            +
                  return 'admin/files_thumbs/dat_thumb.png'
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
                elsif attachment_content_type =~ /jpeg|jpg/
         
     | 
| 
      
 41 
     | 
    
         
            +
                  return 'admin/files_thumbs/jpg_thumb.png'
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
                elsif attachment_content_type =~ /png/
         
     | 
| 
      
 44 
     | 
    
         
            +
                  return 'admin/files_thumbs/png_thumb.png'
         
     | 
| 
      
 45 
     | 
    
         
            +
             
     | 
| 
      
 46 
     | 
    
         
            +
                elsif attachment_content_type =~ /zip|tar|tar\.gz|gz/
         
     | 
| 
      
 47 
     | 
    
         
            +
                  return 'admin/files_thumbs/zip_thumb.png'
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
                elsif attachment_content_type =~ /xls|xlsx/
         
     | 
| 
      
 50 
     | 
    
         
            +
                  return 'admin/files_thumbs/xls_thumb.png'
         
     | 
| 
      
 51 
     | 
    
         
            +
             
     | 
| 
      
 52 
     | 
    
         
            +
                elsif attachment_content_type =~ /doc|docx/
         
     | 
| 
      
 53 
     | 
    
         
            +
                  return 'admin/files_thumbs/doc_thumb.png'
         
     | 
| 
       40 
54 
     | 
    
         | 
| 
       41 
     | 
    
         
            -
                 
     | 
| 
       42 
     | 
    
         
            -
                  return  
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
                elsif  
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
       47 
     | 
    
         
            -
                elsif  
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
                elsif  
     | 
| 
       51 
     | 
    
         
            -
             
     | 
| 
       52 
     | 
    
         
            -
                
         
     | 
| 
       53 
     | 
    
         
            -
                elsif self.attachment_content_type.match(/zip|tar|tar\.gz|gz/)
         
     | 
| 
       54 
     | 
    
         
            -
                	return "admin/files_thumbs/zip_thumb.png"
         
     | 
| 
       55 
     | 
    
         
            -
                
         
     | 
| 
       56 
     | 
    
         
            -
                elsif self.attachment_content_type.match(/xls|xlsx/)
         
     | 
| 
       57 
     | 
    
         
            -
                	return "admin/files_thumbs/xls_thumb.png"
         
     | 
| 
       58 
     | 
    
         
            -
                
         
     | 
| 
       59 
     | 
    
         
            -
                elsif self.attachment_content_type.match(/doc|docx/)
         
     | 
| 
       60 
     | 
    
         
            -
                	return "admin/files_thumbs/doc_thumb.png"
         
     | 
| 
       61 
     | 
    
         
            -
                
         
     | 
| 
       62 
     | 
    
         
            -
                elsif self.attachment_content_type.match(/ppt|pptx/)
         
     | 
| 
       63 
     | 
    
         
            -
                	return "admin/files_thumbs/ppt_thumb.png"
         
     | 
| 
       64 
     | 
    
         
            -
                
         
     | 
| 
       65 
     | 
    
         
            -
                elsif self.attachment_content_type.match(/txt|text/)
         
     | 
| 
       66 
     | 
    
         
            -
                	return "admin/files_thumbs/txt_thumb.png"
         
     | 
| 
       67 
     | 
    
         
            -
                
         
     | 
| 
       68 
     | 
    
         
            -
                elsif self.attachment_content_type.match(/pdf|ps/)
         
     | 
| 
       69 
     | 
    
         
            -
                	return "admin/files_thumbs/pdf_thumb.png"
         
     | 
| 
       70 
     | 
    
         
            -
                
         
     | 
| 
       71 
     | 
    
         
            -
                elsif self.attachment_content_type.match(/mp3|wav|aac/)
         
     | 
| 
       72 
     | 
    
         
            -
                	return "admin/files_thumbs/mp3_thumb.png"
         
     | 
| 
      
 55 
     | 
    
         
            +
                elsif attachment_content_type =~ /ppt|pptx/
         
     | 
| 
      
 56 
     | 
    
         
            +
                  return 'admin/files_thumbs/ppt_thumb.png'
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
      
 58 
     | 
    
         
            +
                elsif attachment_content_type =~ /txt|text/
         
     | 
| 
      
 59 
     | 
    
         
            +
                  return 'admin/files_thumbs/txt_thumb.png'
         
     | 
| 
      
 60 
     | 
    
         
            +
             
     | 
| 
      
 61 
     | 
    
         
            +
                elsif attachment_content_type =~ /pdf|ps/
         
     | 
| 
      
 62 
     | 
    
         
            +
                  return 'admin/files_thumbs/pdf_thumb.png'
         
     | 
| 
      
 63 
     | 
    
         
            +
             
     | 
| 
      
 64 
     | 
    
         
            +
                elsif attachment_content_type =~ /mp3|wav|aac/
         
     | 
| 
      
 65 
     | 
    
         
            +
                  return 'admin/files_thumbs/mp3_thumb.png'
         
     | 
| 
       73 
66 
     | 
    
         
             
                end
         
     | 
| 
       74 
     | 
    
         
            -
             
     | 
| 
       75 
     | 
    
         
            -
                return  
     | 
| 
      
 67 
     | 
    
         
            +
             
     | 
| 
      
 68 
     | 
    
         
            +
                return 'admin/files_thumbs/dat_thumb.png'
         
     | 
| 
       76 
69 
     | 
    
         
             
              end
         
     | 
| 
       77 
70 
     | 
    
         | 
| 
       78 
71 
     | 
    
         
             
              def is_image?
         
     | 
| 
       79 
     | 
    
         
            -
                if  
     | 
| 
      
 72 
     | 
    
         
            +
                if attachment_content_type =~ /jpeg|jpg|png/
         
     | 
| 
       80 
73 
     | 
    
         
             
                  return true
         
     | 
| 
       81 
74 
     | 
    
         
             
                else
         
     | 
| 
       82 
75 
     | 
    
         
             
                  return false
         
     | 
| 
         @@ -84,7 +77,7 @@ class SpudMedia < ActiveRecord::Base 
     | 
|
| 
       84 
77 
     | 
    
         
             
              end
         
     | 
| 
       85 
78 
     | 
    
         | 
| 
       86 
79 
     | 
    
         
             
              def is_pdf?
         
     | 
| 
       87 
     | 
    
         
            -
                if  
     | 
| 
      
 80 
     | 
    
         
            +
                if attachment_content_type =~ /pdf/
         
     | 
| 
       88 
81 
     | 
    
         
             
                  return true
         
     | 
| 
       89 
82 
     | 
    
         
             
                else
         
     | 
| 
       90 
83 
     | 
    
         
             
                  return false
         
     | 
| 
         @@ -97,69 +90,29 @@ class SpudMedia < ActiveRecord::Base 
     | 
|
| 
       97 
90 
     | 
    
         | 
| 
       98 
91 
     | 
    
         
             
              def dynamic_styles
         
     | 
| 
       99 
92 
     | 
    
         
             
                styles = {}
         
     | 
| 
       100 
     | 
    
         
            -
                if is_image?  
     | 
| 
      
 93 
     | 
    
         
            +
                if is_image? # || is_pdf?
         
     | 
| 
       101 
94 
     | 
    
         
             
                  styles[:small] = '50'
         
     | 
| 
       102 
95 
     | 
    
         
             
                  if has_custom_crop?
         
     | 
| 
       103 
     | 
    
         
            -
                    styles[:cropped] = {: 
     | 
| 
      
 96 
     | 
    
         
            +
                    styles[:cropped] = { geometry: '', convert_options: "-strip -resize #{crop_s}% -crop #{crop_w}x#{crop_h}+#{crop_x}+#{crop_y}" }
         
     | 
| 
       104 
97 
     | 
    
         
             
                  else
         
     | 
| 
       105 
     | 
    
         
            -
                    styles[:cropped] = {: 
     | 
| 
      
 98 
     | 
    
         
            +
                    styles[:cropped] = { geometry: '1280x1280>', convert_options: '-strip -quality 85', source_file_options: '-density 72' }
         
     | 
| 
       106 
99 
     | 
    
         
             
                  end
         
     | 
| 
       107 
100 
     | 
    
         
             
                end
         
     | 
| 
       108 
101 
     | 
    
         
             
                return styles
         
     | 
| 
       109 
102 
     | 
    
         
             
              end
         
     | 
| 
       110 
103 
     | 
    
         | 
| 
       111 
     | 
    
         
            -
               
     | 
| 
       112 
     | 
    
         
            -
              # protected files need to hit the rails middle-man first
         
     | 
| 
       113 
     | 
    
         
            -
              # this method will provide the correct url for either case
         
     | 
| 
       114 
     | 
    
         
            -
              def attachment_url(style=nil)
         
     | 
| 
      
 104 
     | 
    
         
            +
              def attachment_url(style = nil)
         
     | 
| 
       115 
105 
     | 
    
         
             
                # defaults to cropped style if that style exists, otherwise use original
         
     | 
| 
       116 
     | 
    
         
            -
                 
     | 
| 
       117 
     | 
    
         
            -
             
     | 
| 
       118 
     | 
    
         
            -
                end
         
     | 
| 
       119 
     | 
    
         
            -
                if Spud::Media.paperclip_storage == :s3 && is_protected
         
     | 
| 
       120 
     | 
    
         
            -
                  return Paperclip::Interpolations.interpolate(Spud::Media.config.storage_url, attachment, style)
         
     | 
| 
       121 
     | 
    
         
            -
                else
         
     | 
| 
       122 
     | 
    
         
            -
                  return attachment.url(style)
         
     | 
| 
       123 
     | 
    
         
            -
                end
         
     | 
| 
       124 
     | 
    
         
            -
              end
         
     | 
| 
       125 
     | 
    
         
            -
             
     | 
| 
       126 
     | 
    
         
            -
              # If is_protected has changed, we need to make sure we are setting the appropriate permissions
         
     | 
| 
       127 
     | 
    
         
            -
              # This means either moving the file in the filesystem or setting the appropriate ACL in S3
         
     | 
| 
       128 
     | 
    
         
            -
              def validate_permissions
         
     | 
| 
       129 
     | 
    
         
            -
                if Spud::Media.config.paperclip_storage == :filesystem
         
     | 
| 
       130 
     | 
    
         
            -
                  validate_permissions_filesystem
         
     | 
| 
       131 
     | 
    
         
            -
                elsif Spud::Media.config.paperclip_storage == :s3
         
     | 
| 
       132 
     | 
    
         
            -
                  validate_permissions_s3
         
     | 
| 
       133 
     | 
    
         
            -
                end
         
     | 
| 
       134 
     | 
    
         
            -
              end
         
     | 
| 
       135 
     | 
    
         
            -
             
     | 
| 
       136 
     | 
    
         
            -
            private
         
     | 
| 
       137 
     | 
    
         
            -
             
     | 
| 
       138 
     | 
    
         
            -
              def validate_permissions_filesystem
         
     | 
| 
       139 
     | 
    
         
            -
                if is_protected
         
     | 
| 
       140 
     | 
    
         
            -
                  old_path = Paperclip::Interpolations.interpolate(Spud::Media.config.storage_path, attachment, 'original')
         
     | 
| 
       141 
     | 
    
         
            -
                  new_path = Paperclip::Interpolations.interpolate(Spud::Media.config.storage_path_protected, attachment, 'original')
         
     | 
| 
       142 
     | 
    
         
            -
                else
         
     | 
| 
       143 
     | 
    
         
            -
                  old_path = Paperclip::Interpolations.interpolate(Spud::Media.config.storage_path_protected, attachment, 'original')
         
     | 
| 
       144 
     | 
    
         
            -
                  new_path = Paperclip::Interpolations.interpolate(Spud::Media.config.storage_path, attachment, 'original') 
         
     | 
| 
       145 
     | 
    
         
            -
                end
         
     | 
| 
       146 
     | 
    
         
            -
                new_base_dir = File.dirname(File.dirname(new_path))
         
     | 
| 
       147 
     | 
    
         
            -
                old_base_dir = File.dirname(File.dirname(old_path))
         
     | 
| 
       148 
     | 
    
         
            -
                if File.directory?(old_base_dir)
         
     | 
| 
       149 
     | 
    
         
            -
                  FileUtils.mv(old_base_dir, new_base_dir)
         
     | 
| 
       150 
     | 
    
         
            -
                end
         
     | 
| 
      
 106 
     | 
    
         
            +
                style ||= is_image? ? 'cropped' : 'original'
         
     | 
| 
      
 107 
     | 
    
         
            +
                return attachment.url(style)
         
     | 
| 
       151 
108 
     | 
    
         
             
              end
         
     | 
| 
       152 
109 
     | 
    
         | 
| 
       153 
     | 
    
         
            -
              def  
     | 
| 
       154 
     | 
    
         
            -
                 
     | 
| 
       155 
     | 
    
         
            -
                   
     | 
| 
       156 
     | 
    
         
            -
                   
     | 
| 
       157 
     | 
    
         
            -
             
     | 
| 
       158 
     | 
    
         
            -
                 
     | 
| 
       159 
     | 
    
         
            -
                  attachment.s3_object(:original).acl = :public_read
         
     | 
| 
       160 
     | 
    
         
            -
                  attachment.s3_object(:cropped).acl = :public_read if attachment.s3_object(:cropped).exists?
         
     | 
| 
       161 
     | 
    
         
            -
                  attachment.s3_object(:small).acl = :public_read if attachment.s3_object(:small).exists?
         
     | 
| 
       162 
     | 
    
         
            -
                end
         
     | 
| 
      
 110 
     | 
    
         
            +
              def is_protected
         
     | 
| 
      
 111 
     | 
    
         
            +
                ActiveSupport::Deprecation.warn(
         
     | 
| 
      
 112 
     | 
    
         
            +
                  'SpudMedia#is_protected is deprecated and will soon be removed',
         
     | 
| 
      
 113 
     | 
    
         
            +
                  caller
         
     | 
| 
      
 114 
     | 
    
         
            +
                )
         
     | 
| 
      
 115 
     | 
    
         
            +
                false
         
     | 
| 
       163 
116 
     | 
    
         
             
              end
         
     | 
| 
       164 
117 
     | 
    
         | 
| 
       165 
118 
     | 
    
         
             
            end
         
     | 
| 
         @@ -9,27 +9,19 @@ 
     | 
|
| 
       9 
9 
     | 
    
         
             
            				<% @media.each do |media| %>
         
     | 
| 
       10 
10 
     | 
    
         
             
            					<tr>
         
     | 
| 
       11 
11 
     | 
    
         
             
            						<td>
         
     | 
| 
       12 
     | 
    
         
            -
            							 
     | 
| 
       13 
     | 
    
         
            -
            								<img src="<%= media.image_from_type %>" class="size-50-thumb" />
         
     | 
| 
       14 
     | 
    
         
            -
            							<% else %>
         
     | 
| 
       15 
     | 
    
         
            -
            								<%= image_tag(media.image_from_type, :class => "size-50-thumb") %>
         
     | 
| 
       16 
     | 
    
         
            -
            							<% end %>
         
     | 
| 
      
 12 
     | 
    
         
            +
            							<%= image_tag(media.image_from_type, :class => "size-50-thumb") %>
         
     | 
| 
       17 
13 
     | 
    
         
             
            							<%= link_to media.attachment_file_name, media.attachment_url %>
         
     | 
| 
       18 
14 
     | 
    
         
             
            						</td>
         
     | 
| 
       19 
15 
     | 
    
         
             
            						<td class="table-actions">
         
     | 
| 
       20 
16 
     | 
    
         
             
            							<% if media.is_image? %>
         
     | 
| 
       21 
17 
     | 
    
         
             
            								<%= link_to 'Crop', edit_admin_medium_path(media.id), :class => 'btn btn-sm btn-default' %>
         
     | 
| 
       22 
18 
     | 
    
         
             
            							<% end %>
         
     | 
| 
       23 
     | 
    
         
            -
            							 
     | 
| 
       24 
     | 
    
         
            -
            								<%= link_to raw('<i class="icon-lock"></i> Protected'), set_access_admin_medium_path(media.id, :protected => false), :method => :put, :class => 'btn btn-sm btn-default' %>
         
     | 
| 
       25 
     | 
    
         
            -
            							<% else %>
         
     | 
| 
       26 
     | 
    
         
            -
            								<%= link_to 'Public', set_access_admin_medium_path(media.id, :protected => true), :method => :put, :class => 'btn btn-sm btn-default' %>
         
     | 
| 
       27 
     | 
    
         
            -
            							<% end %>
         
     | 
| 
       28 
     | 
    
         
            -
            							<%= link_to "Remove", admin_medium_path(media), :method => :delete, :class => 'btn btn-sm btn-danger', :data => {:confirm => "Are you sure you want to remove this file?"} %>
         
     | 
| 
      
 19 
     | 
    
         
            +
            							<%= link_to 'Remove', admin_medium_path(media), :method => :delete, :class => 'btn btn-sm btn-danger', :data => {:confirm => "Are you sure you want to remove this file?"} %>
         
     | 
| 
       29 
20 
     | 
    
         
             
            						</td>
         
     | 
| 
       30 
21 
     | 
    
         
             
            					</tr>
         
     | 
| 
       31 
22 
     | 
    
         
             
            				<% end %>
         
     | 
| 
       32 
23 
     | 
    
         
             
            			</tbody>
         
     | 
| 
       33 
24 
     | 
    
         
             
            		</table>
         
     | 
| 
       34 
     | 
    
         
            -
            	</div> 
     | 
| 
      
 25 
     | 
    
         
            +
            	</div>
         
     | 
| 
      
 26 
     | 
    
         
            +
            	<%= will_paginate @media, :renderer => BootstrapPagination::Rails %>
         
     | 
| 
       35 
27 
     | 
    
         
             
            <% end %>
         
     | 
| 
         @@ -1,6 +1,5 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            <%=form_for @media, :url => admin_media_path, :builder => TbCore::FormBuilder, :html => {:class => "form-horizontal", :multipart => true} do |f|%>
         
     | 
| 
       2 
2 
     | 
    
         
             
              <%= tb_form_error_header(@media) %>
         
     | 
| 
       3 
3 
     | 
    
         
             
              <%= f.tb_file_field :attachment %>
         
     | 
| 
       4 
     | 
    
         
            -
              <%= f.tb_check_box :is_protected %>
         
     | 
| 
       5 
4 
     | 
    
         
             
              <%= f.tb_save_buttons('File', admin_media_path) %>
         
     | 
| 
       6 
5 
     | 
    
         
             
            <% end %>
         
     | 
| 
         @@ -4,14 +4,9 @@ 
     | 
|
| 
       4 
4 
     | 
    
         
             
              'data-url' => media.attachment_url,
         
     | 
| 
       5 
5 
     | 
    
         
             
              'data-name' => media.attachment_file_name,
         
     | 
| 
       6 
6 
     | 
    
         
             
              'data-size' => media.attachment_file_size,
         
     | 
| 
       7 
     | 
    
         
            -
              'data-lastmod' => media.attachment_updated_at.blank? == false ? media.attachment_updated_at.strftime("%l:%M %p, %D") : '' 
     | 
| 
       8 
     | 
    
         
            -
              'data-protected' => (media.is_protected ? 'Yes' : 'No') do %>
         
     | 
| 
      
 7 
     | 
    
         
            +
              'data-lastmod' => media.attachment_updated_at.blank? == false ? media.attachment_updated_at.strftime("%l:%M %p, %D") : '' do %>
         
     | 
| 
       9 
8 
     | 
    
         
             
              <span class="spud_media_picker_item_thumb">
         
     | 
| 
       10 
     | 
    
         
            -
                 
     | 
| 
       11 
     | 
    
         
            -
                  <img src="<%= media.image_from_type %>"/>
         
     | 
| 
       12 
     | 
    
         
            -
                <% else %>
         
     | 
| 
       13 
     | 
    
         
            -
                  <%= image_tag(media.image_from_type) %>
         
     | 
| 
       14 
     | 
    
         
            -
                <% end %>
         
     | 
| 
      
 9 
     | 
    
         
            +
                <%= image_tag(media.image_from_type) %>
         
     | 
| 
       15 
10 
     | 
    
         
             
              </span>
         
     | 
| 
       16 
11 
     | 
    
         
             
              <span class="spud_media_picker_item_filename">
         
     | 
| 
       17 
12 
     | 
    
         
             
                <%= media.attachment_file_name %>
         
     | 
| 
         @@ -40,7 +40,6 @@ 
     | 
|
| 
       40 
40 
     | 
    
         
             
                      <li>File Name: <span class="spud_media_picker_details_name"></span></li>
         
     | 
| 
       41 
41 
     | 
    
         
             
                      <li>File Size: <span class="spud_media_picker_details_size"></span></li>
         
     | 
| 
       42 
42 
     | 
    
         
             
                      <li>Last Modified: <span class="spud_media_picker_details_lastmod"></span></li>
         
     | 
| 
       43 
     | 
    
         
            -
                      <li>Protected: <span class="spud_media_picker_details_protected"></span></li>
         
     | 
| 
       44 
43 
     | 
    
         
             
                    </ul>
         
     | 
| 
       45 
44 
     | 
    
         
             
                  </div>
         
     | 
| 
       46 
45 
     | 
    
         
             
                  <div class="spud_media_picker_buttons">
         
     | 
| 
         @@ -104,4 +103,4 @@ 
     | 
|
| 
       104 
103 
     | 
    
         
             
              </script>
         
     | 
| 
       105 
104 
     | 
    
         | 
| 
       106 
105 
     | 
    
         
             
            </body>
         
     | 
| 
       107 
     | 
    
         
            -
            </html>
         
     | 
| 
      
 106 
     | 
    
         
            +
            </html>
         
     | 
    
        data/config/locales/en.yml
    CHANGED
    
    
    
        data/config/routes.rb
    CHANGED
    
    | 
         @@ -1,11 +1,8 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            Rails.application.routes.draw do
         
     | 
| 
      
 2 
     | 
    
         
            +
              namespace :admin do
         
     | 
| 
      
 3 
     | 
    
         
            +
                resources :media
         
     | 
| 
       2 
4 
     | 
    
         | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
       6 
     | 
    
         
            -
                end
         
     | 
| 
       7 
     | 
    
         
            -
                resources :media_picker, :only => [:index, :create]
         
     | 
| 
       8 
     | 
    
         
            -
            	end
         
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
              get Spud::Media.config.storage_url => 'protected_media#show', :as => 'protected_media'
         
     | 
| 
      
 5 
     | 
    
         
            +
                # picker plugin not currently used
         
     | 
| 
      
 6 
     | 
    
         
            +
                # resources :media_picker, :only => [:index, :create]
         
     | 
| 
      
 7 
     | 
    
         
            +
              end
         
     | 
| 
       11 
8 
     | 
    
         
             
            end
         
     | 
| 
         @@ -1,4 +1,4 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            class CreateSpudMedia < ActiveRecord::Migration
         
     | 
| 
      
 1 
     | 
    
         
            +
            class CreateSpudMedia < ActiveRecord::Migration[4.2]
         
     | 
| 
       2 
2 
     | 
    
         
             
              def change
         
     | 
| 
       3 
3 
     | 
    
         
             
                create_table :spud_media do |t|
         
     | 
| 
       4 
4 
     | 
    
         
             
                  t.string :attachment_content_type
         
     | 
| 
         @@ -8,4 +8,4 @@ class CreateSpudMedia < ActiveRecord::Migration 
     | 
|
| 
       8 
8 
     | 
    
         
             
                  t.timestamps
         
     | 
| 
       9 
9 
     | 
    
         
             
                end
         
     | 
| 
       10 
10 
     | 
    
         
             
              end
         
     | 
| 
       11 
     | 
    
         
            -
            end
         
     | 
| 
      
 11 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -1,6 +1,5 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            class AddProtectedToSpudMedia < ActiveRecord::Migration
         
     | 
| 
      
 1 
     | 
    
         
            +
            class AddProtectedToSpudMedia < ActiveRecord::Migration[4.2]
         
     | 
| 
       2 
2 
     | 
    
         
             
              def change
         
     | 
| 
       3 
     | 
    
         
            -
                add_column :spud_media, :is_protected, :boolean, :default => false
         
     | 
| 
       4 
3 
     | 
    
         
             
                add_column :spud_media, :attachment_updated_at, :datetime
         
     | 
| 
       5 
4 
     | 
    
         
             
              end
         
     | 
| 
       6 
5 
     | 
    
         
             
            end
         
     | 
| 
         @@ -2,12 +2,11 @@ module Spud 
     | 
|
| 
       2 
2 
     | 
    
         
             
              module Media
         
     | 
| 
       3 
3 
     | 
    
         
             
                include ActiveSupport::Configurable
         
     | 
| 
       4 
4 
     | 
    
         
             
                require 'active_support/core_ext/numeric/bytes'
         
     | 
| 
       5 
     | 
    
         
            -
                config_accessor :paperclip_storage, :s3_credentials, :storage_path, : 
     | 
| 
      
 5 
     | 
    
         
            +
                config_accessor :paperclip_storage, :s3_credentials, :storage_path, :storage_url, :max_upload_size
         
     | 
| 
       6 
6 
     | 
    
         
             
                self.paperclip_storage = :filesystem
         
     | 
| 
       7 
7 
     | 
    
         
             
                self.s3_credentials = "#{Rails.root}/config/s3.yml"
         
     | 
| 
       8 
     | 
    
         
            -
                self.storage_path =  
     | 
| 
       9 
     | 
    
         
            -
                self. 
     | 
| 
       10 
     | 
    
         
            -
                self.storage_url = "/system/spud_media/:id/:style/:basename.:extension"
         
     | 
| 
      
 8 
     | 
    
         
            +
                self.storage_path = ':rails_root/public/system/spud_media/:id/:style/:basename.:extension'
         
     | 
| 
      
 9 
     | 
    
         
            +
                self.storage_url = '/system/spud_media/:id/:style/:basename.:extension'
         
     | 
| 
       11 
10 
     | 
    
         
             
                self.max_upload_size = 15.megabytes
         
     | 
| 
       12 
11 
     | 
    
         
             
              end
         
     | 
| 
       13 
12 
     | 
    
         
             
            end
         
     | 
| 
         @@ -8,7 +8,7 @@ module Spud 
     | 
|
| 
       8 
8 
     | 
    
         
             
                  'application/msword',
         
     | 
| 
       9 
9 
     | 
    
         
             
                  'application/vnd.ms-excel',
         
     | 
| 
       10 
10 
     | 
    
         
             
                  'application/vnd.ms-powerpoint',
         
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
       12 
12 
     | 
    
         
             
                  # Documents
         
     | 
| 
       13 
13 
     | 
    
         
             
                  'application/pdf',
         
     | 
| 
       14 
14 
     | 
    
         
             
                  'text/html',
         
     | 
| 
         @@ -57,6 +57,6 @@ module Spud 
     | 
|
| 
       57 
57 
     | 
    
         
             
                  'image/vnd.adobe.photoshop',
         
     | 
| 
       58 
58 
     | 
    
         
             
                  'application/postscript',
         
     | 
| 
       59 
59 
     | 
    
         
             
                  'application/x-shockwave-flash'
         
     | 
| 
       60 
     | 
    
         
            -
                ]
         
     | 
| 
      
 60 
     | 
    
         
            +
                ].freeze
         
     | 
| 
       61 
61 
     | 
    
         
             
              end
         
     | 
| 
       62 
62 
     | 
    
         
             
            end
         
     | 
    
        data/lib/spud_media/engine.rb
    CHANGED
    
    | 
         @@ -2,17 +2,25 @@ require 'tb_core' 
     | 
|
| 
       2 
2 
     | 
    
         
             
            require 'paperclip'
         
     | 
| 
       3 
3 
     | 
    
         | 
| 
       4 
4 
     | 
    
         
             
            module Spud
         
     | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
      
 5 
     | 
    
         
            +
              module Media
         
     | 
| 
      
 6 
     | 
    
         
            +
                class Engine < Rails::Engine
         
     | 
| 
      
 7 
     | 
    
         
            +
                  engine_name :tb_media
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
                  initializer :admin do
         
     | 
| 
      
 10 
     | 
    
         
            +
                    config.assets.precompile += ['admin/files_thumbs/*']
         
     | 
| 
      
 11 
     | 
    
         
            +
                    config.assets.precompile += ['admin/media_thumb.png']
         
     | 
| 
      
 12 
     | 
    
         
            +
                    # config.assets.precompile += ['admin/media/picker.js'] <- Picker not currently used
         
     | 
| 
      
 13 
     | 
    
         
            +
                    TbCore.append_admin_javascripts('admin/media/application')
         
     | 
| 
      
 14 
     | 
    
         
            +
                    TbCore.append_admin_stylesheets('admin/media/application')
         
     | 
| 
      
 15 
     | 
    
         
            +
                    TbCore.configure do |config|
         
     | 
| 
      
 16 
     | 
    
         
            +
                      config.admin_applications += [{ name: 'Media', thumbnail: 'admin/media_thumb.png', url: '/admin/media', order: 3, retina: true }]
         
     | 
| 
      
 17 
     | 
    
         
            +
                    end
         
     | 
| 
      
 18 
     | 
    
         
            +
                  end
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
                  initializer 'tb_media.assets' do
         
     | 
| 
      
 21 
     | 
    
         
            +
                    Rails.application.config.assets.precompile += ['admin/media_thumb.png']
         
     | 
| 
      
 22 
     | 
    
         
            +
                  end
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
                end
         
     | 
| 
      
 25 
     | 
    
         
            +
              end
         
     | 
| 
       18 
26 
     | 
    
         
             
            end
         
     |