tb_media 1.3.0 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +1 -1
- data/Readme.markdown +3 -19
- data/app/assets/javascripts/admin/media/picker.js +4 -5
- data/app/assets/stylesheets/admin/media/application.css.scss +1 -12
- data/app/controllers/admin/media_controller.rb +7 -10
- data/app/controllers/admin/media_picker_controller.rb +1 -1
- data/app/models/spud_media.rb +12 -53
- 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 +3 -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 +1 -2
- data/lib/spud_media/engine.rb +3 -3
- data/lib/spud_media/version.rb +1 -1
- data/spec/controllers/admin/media_controller_spec.rb +4 -5
- data/spec/dummy/public/system/spud_media/1/small/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/small/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/small/test_img1.png +0 -0
- data/spec/models/spud_media_spec.rb +1 -1
- data/spec/rails_helper.rb +2 -2
- metadata +63 -65
- data/app/controllers/protected_media_controller.rb +0 -24
- data/app/helpers/protected_media_helper.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d20e9297b2866aad42576b7f895f7d881430b431
|
4
|
+
data.tar.gz: 7d1fa6cdb9389e466b7e89e213a9b7c1cfd07fe3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e7b4ac0a50b4922fa74b96a6b409dd9b1396b29d18b64e1da9cb3efe3fc81aa067923cda5f8b3f6658544146c843f4aedd3dbfdd009b1045dcd2ce00215938f
|
7
|
+
data.tar.gz: 5e847b6379638b6bb6b6a877ab8f40a091615e059784fafc944af4361ee4b6fa94e434fc5622f5914c98e219b7e3d30f5721dca83fe25b1d86d94bd4e7448934
|
data/Rakefile
CHANGED
@@ -20,7 +20,7 @@ RDoc::Task.new(:rdoc) do |rdoc|
|
|
20
20
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
21
|
end
|
22
22
|
|
23
|
-
APP_RAKEFILE = File.expand_path('
|
23
|
+
APP_RAKEFILE = File.expand_path('spec/dummy/Rakefile', __dir__)
|
24
24
|
load 'rails/tasks/engine.rake'
|
25
25
|
|
26
26
|
Bundler::GemHelper.install_tasks
|
data/Readme.markdown
CHANGED
@@ -21,35 +21,19 @@ TB Media is an engine for managing documents and other miscellaneous media files
|
|
21
21
|
TB Media accepts the following configuration options:
|
22
22
|
|
23
23
|
Spud::Media.configure do |config|
|
24
|
-
|
24
|
+
|
25
25
|
# s3 storage requires the 'aws-sdk' gem. defaults to filesystem
|
26
26
|
config.paperclip_storage = :s3
|
27
27
|
config.s3_credentials = "#{Rails.root}/config/s3.yml"
|
28
28
|
|
29
|
-
# see below for notes on 'storage_path_protected'
|
30
29
|
config.storage_path = "public/system/spud_media/:id/:style/:basename.:extension"
|
31
|
-
config.storage_path_protected = "public/system/spud_media_protected/:id/:style/:basename.:extension"
|
32
30
|
config.storage_url = "/system/spud_media/:id/:style/:basename.:extension"
|
33
31
|
config.max_upload_size = 15.megabytes
|
34
32
|
end
|
35
33
|
|
36
|
-
## File Protection
|
37
|
-
|
38
|
-
Spud Media allows for individual files to be marked as protected. How this is actually implemented depends on whether you are using the local file system or Amazon S3 for file storage.
|
39
|
-
|
40
34
|
### Filesystem
|
41
35
|
|
42
|
-
|
43
|
-
|
44
|
-
Protected files are moved to `public/system/spud_media_protected`. Note that the public-facing download URL should __not__ reflect the `protected` storage path. Instead the user will hit the same URL as before, but this time their request will hit the `show` action of the `ProtectedMedia` controller.
|
45
|
-
|
46
|
-
__It is up to the individual developer to make sure that the protected storage path is not accessible by the public.__ You may choose to protect this folder via server configurations, or you can move the folder out of the document root using `config.storage_path_protected`.
|
47
|
-
|
48
|
-
### Amazon S3
|
49
|
-
|
50
|
-
Files marked as unprotected will be uploaded to Amazon using the `public_read` ACL. These files are accessed directly - ie, calling `@media.attachment_url` will link directly to Amazon.
|
51
|
-
|
52
|
-
Files marked as protected are uploaded using the `private` ACL. In this case, calling `@media.attachment_url` will return a local URL that hits the show action of our `ProtectedMedia` controller. Once we have verified the user is logged in we generate a secure URL and redirect the user to it. The generated URL is good for 10 minutes.
|
36
|
+
Files are stored under `/public/system/spud_media` and are accessed directly by the web server. No further configuration is required, though you may customize the storage location if desired using `config.storage_path`.
|
53
37
|
|
54
38
|
Testing
|
55
39
|
-----------------
|
@@ -57,7 +41,7 @@ Testing
|
|
57
41
|
TB uses RSpec for testing. Get the tests running with a few short commands:
|
58
42
|
|
59
43
|
1. Create and migrate the databases:
|
60
|
-
|
44
|
+
|
61
45
|
rake db:create
|
62
46
|
rake db:migrate
|
63
47
|
|
@@ -107,15 +107,14 @@ spud.admin.mediapicker = new function(){
|
|
107
107
|
$('.spud_media_picker_details_name').text(element.attr('data-name'));
|
108
108
|
$('.spud_media_picker_details_size').text(element.attr('data-size'));
|
109
109
|
$('.spud_media_picker_details_lastmod').text(element.attr('data-lastmod'));
|
110
|
-
$('.spud_media_picker_details_protected').text(element.attr('data-protected'));
|
111
110
|
$('.spud_media_picker_details').show();
|
112
111
|
};
|
113
|
-
|
112
|
+
|
114
113
|
self.clickedCancel = function(e){
|
115
114
|
e.preventDefault();
|
116
115
|
parent.tinyMCE.activeEditor.windowManager.close();
|
117
116
|
};
|
118
|
-
|
117
|
+
|
119
118
|
self.clickedUseSelected = function(e){
|
120
119
|
e.preventDefault();
|
121
120
|
var $selected = $('.spud_media_picker_item_selected');
|
@@ -127,7 +126,7 @@ spud.admin.mediapicker = new function(){
|
|
127
126
|
};
|
128
127
|
self.goToTab('#spud_media_picker_tab_advanced');
|
129
128
|
};
|
130
|
-
|
129
|
+
|
131
130
|
self.submittedUpload = function(e){
|
132
131
|
if(!$('#spud_media_attachment').val()){
|
133
132
|
window.alert("Please select a file.");
|
@@ -307,4 +306,4 @@ spud.admin.mediapicker = new function(){
|
|
307
306
|
self.clickedInsert(e);
|
308
307
|
}
|
309
308
|
};
|
310
|
-
};
|
309
|
+
};
|
@@ -54,17 +54,6 @@ img.size-50-thumb {
|
|
54
54
|
border-top-right-radius: 8px;
|
55
55
|
border-top-left-radius: 8px;
|
56
56
|
background-image: linear-gradient(bottom, rgb(204,204,204) 33%, rgb(230,230,230) 66%);
|
57
|
-
background-image: -o-linear-gradient(bottom, rgb(204,204,204) 33%, rgb(230,230,230) 66%);
|
58
|
-
background-image: -moz-linear-gradient(bottom, rgb(204,204,204) 33%, rgb(230,230,230) 66%);
|
59
|
-
background-image: -webkit-linear-gradient(bottom, rgb(204,204,204) 33%, rgb(230,230,230) 66%);
|
60
|
-
background-image: -ms-linear-gradient(bottom, rgb(204,204,204) 33%, rgb(230,230,230) 66%);
|
61
|
-
background-image: -webkit-gradient(
|
62
|
-
linear,
|
63
|
-
left bottom,
|
64
|
-
left top,
|
65
|
-
color-stop(0.33, rgb(204,204,204)),
|
66
|
-
color-stop(0.66, rgb(230,230,230))
|
67
|
-
);
|
68
57
|
clear: both;
|
69
58
|
}
|
70
59
|
#spud_media_cropper_toolbar form{
|
@@ -100,4 +89,4 @@ user-select: none;
|
|
100
89
|
a[id^="spud_media_cropper_resize_"]:active{
|
101
90
|
position: relative;
|
102
91
|
top: 1px;
|
103
|
-
}
|
92
|
+
}
|
@@ -2,10 +2,10 @@ class Admin::MediaController < Admin::ApplicationController
|
|
2
2
|
layout 'admin/detail'
|
3
3
|
add_breadcrumb 'Media', :admin_media_path
|
4
4
|
belongs_to_app :media
|
5
|
-
before_action :load_media, only: [:edit, :update, :show, :destroy, :set_private
|
5
|
+
before_action :load_media, only: [:edit, :update, :show, :destroy, :set_private]
|
6
6
|
|
7
7
|
def index
|
8
|
-
@media = SpudMedia.order('created_at DESC').paginate
|
8
|
+
@media = SpudMedia.order('created_at DESC').paginate(page: params[:page])
|
9
9
|
respond_with @media
|
10
10
|
end
|
11
11
|
|
@@ -36,7 +36,7 @@ class Admin::MediaController < Admin::ApplicationController
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def update
|
39
|
-
@media.attachment.reprocess! if @media.
|
39
|
+
@media.attachment.reprocess! if @media.update(media_params)
|
40
40
|
respond_with @media, location: admin_media_path
|
41
41
|
end
|
42
42
|
|
@@ -45,12 +45,6 @@ class Admin::MediaController < Admin::ApplicationController
|
|
45
45
|
respond_with @media, location: admin_media_path
|
46
46
|
end
|
47
47
|
|
48
|
-
def set_access
|
49
|
-
is_protected = params[:protected] || false
|
50
|
-
@media.update_attribute(:is_protected, is_protected)
|
51
|
-
respond_with @media, location: admin_media_path
|
52
|
-
end
|
53
|
-
|
54
48
|
private
|
55
49
|
|
56
50
|
def load_media
|
@@ -62,7 +56,10 @@ class Admin::MediaController < Admin::ApplicationController
|
|
62
56
|
end
|
63
57
|
|
64
58
|
def media_params
|
65
|
-
params.require(:spud_media).permit(
|
59
|
+
params.require(:spud_media).permit(
|
60
|
+
:attachment_content_type, :attachment_file_name,
|
61
|
+
:attachment_file_size, :attachment,
|
62
|
+
:crop_x, :crop_y, :crop_w, :crop_h, :crop_s)
|
66
63
|
end
|
67
64
|
|
68
65
|
end
|
@@ -34,7 +34,7 @@ class Admin::MediaPickerController < Admin::ApplicationController
|
|
34
34
|
private
|
35
35
|
|
36
36
|
def media_params
|
37
|
-
params.require(:spud_media).permit(:attachment_content_type, :attachment_file_name, :attachment_file_size, :attachment, :
|
37
|
+
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)
|
38
38
|
end
|
39
39
|
|
40
40
|
end
|
data/app/models/spud_media.rb
CHANGED
@@ -3,12 +3,8 @@ class SpudMedia < ActiveRecord::Base
|
|
3
3
|
has_attached_file :attachment,
|
4
4
|
storage: Spud::Media.paperclip_storage,
|
5
5
|
s3_credentials: Spud::Media.s3_credentials,
|
6
|
-
s3_permissions:
|
7
|
-
|
8
|
-
},
|
9
|
-
path: Spud::Media.paperclip_storage == :s3 ? Spud::Media.storage_path : lambda { |attachment|
|
10
|
-
attachment.instance.is_protected ? Spud::Media.storage_path_protected : Spud::Media.storage_path
|
11
|
-
},
|
6
|
+
s3_permissions: 'public-read',
|
7
|
+
path: Spud::Media.storage_path,
|
12
8
|
url: Spud::Media.storage_url,
|
13
9
|
styles: ->(attachment) { attachment.instance.dynamic_styles }
|
14
10
|
|
@@ -26,10 +22,9 @@ class SpudMedia < ActiveRecord::Base
|
|
26
22
|
}
|
27
23
|
|
28
24
|
before_create :rename_file
|
29
|
-
before_update :validate_permissions
|
30
25
|
|
31
26
|
def rename_file
|
32
|
-
#
|
27
|
+
# Remove periods and other unsafe characters from file name to make routing easier
|
33
28
|
extension = File.extname(attachment_file_name)
|
34
29
|
filename = attachment_file_name.chomp(extension).parameterize
|
35
30
|
attachment.instance_write :file_name, filename + extension
|
@@ -104,56 +99,20 @@ class SpudMedia < ActiveRecord::Base
|
|
104
99
|
end
|
105
100
|
end
|
106
101
|
return styles
|
107
|
-
|
102
|
+
end
|
108
103
|
|
109
|
-
# if you are using S3, attachment.url will automatically point to the S3 url
|
110
|
-
# protected files need to hit the rails middle-man first
|
111
|
-
# this method will provide the correct url for either case
|
112
104
|
def attachment_url(style = nil)
|
113
105
|
# defaults to cropped style if that style exists, otherwise use original
|
114
|
-
style
|
115
|
-
|
116
|
-
return Paperclip::Interpolations.interpolate(Spud::Media.config.storage_url, attachment, style)
|
117
|
-
else
|
118
|
-
return attachment.url(style)
|
119
|
-
end
|
106
|
+
style ||= is_image? ? 'cropped' : 'original'
|
107
|
+
return attachment.url(style)
|
120
108
|
end
|
121
109
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
validate_permissions_s3
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
private
|
133
|
-
|
134
|
-
def validate_permissions_filesystem
|
135
|
-
if is_protected
|
136
|
-
old_path = Paperclip::Interpolations.interpolate(Spud::Media.config.storage_path, attachment, 'original')
|
137
|
-
new_path = Paperclip::Interpolations.interpolate(Spud::Media.config.storage_path_protected, attachment, 'original')
|
138
|
-
else
|
139
|
-
old_path = Paperclip::Interpolations.interpolate(Spud::Media.config.storage_path_protected, attachment, 'original')
|
140
|
-
new_path = Paperclip::Interpolations.interpolate(Spud::Media.config.storage_path, attachment, 'original')
|
141
|
-
end
|
142
|
-
new_base_dir = File.dirname(File.dirname(new_path))
|
143
|
-
old_base_dir = File.dirname(File.dirname(old_path))
|
144
|
-
FileUtils.mv(old_base_dir, new_base_dir) if File.directory?(old_base_dir)
|
145
|
-
end
|
146
|
-
|
147
|
-
def validate_permissions_s3
|
148
|
-
if is_protected
|
149
|
-
attachment.s3_object(:original).acl = :private
|
150
|
-
attachment.s3_object(:cropped).acl = :private if attachment.s3_object(:cropped).exists?
|
151
|
-
attachment.s3_object(:small).acl = :private if attachment.s3_object(:small).exists?
|
152
|
-
else
|
153
|
-
attachment.s3_object(:original).acl = :public_read
|
154
|
-
attachment.s3_object(:cropped).acl = :public_read if attachment.s3_object(:cropped).exists?
|
155
|
-
attachment.s3_object(:small).acl = :public_read if attachment.s3_object(:small).exists?
|
156
|
-
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
|
157
116
|
end
|
158
117
|
|
159
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,6 @@
|
|
1
1
|
Rails.application.routes.draw do
|
2
|
-
|
3
|
-
|
4
|
-
resources :media do
|
5
|
-
put 'set_access', :on => :member
|
6
|
-
end
|
2
|
+
namespace :admin do
|
3
|
+
resources :media
|
7
4
|
resources :media_picker, :only => [:index, :create]
|
8
|
-
|
9
|
-
|
10
|
-
get Spud::Media.config.storage_url => 'protected_media#show', :as => 'protected_media'
|
5
|
+
end
|
11
6
|
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,11 +2,10 @@ 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
8
|
self.storage_path = ':rails_root/public/system/spud_media/:id/:style/:basename.:extension'
|
9
|
-
self.storage_path_protected = ':rails_root/public/system/spud_media_protected/:id/:style/:basename.:extension'
|
10
9
|
self.storage_url = '/system/spud_media/:id/:style/:basename.:extension'
|
11
10
|
self.max_upload_size = 15.megabytes
|
12
11
|
end
|
data/lib/spud_media/engine.rb
CHANGED
@@ -10,9 +10,9 @@ module Spud
|
|
10
10
|
config.assets.precompile += ['admin/files_thumbs/*']
|
11
11
|
config.assets.precompile += ['admin/media_thumb.png']
|
12
12
|
config.assets.precompile += ['admin/media/picker.js']
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
TbCore.append_admin_javascripts('admin/media/application')
|
14
|
+
TbCore.append_admin_stylesheets('admin/media/application')
|
15
|
+
TbCore.configure do |config|
|
16
16
|
config.admin_applications += [{ name: 'Media', thumbnail: 'admin/media_thumb.png', url: '/admin/media', order: 3, retina: true }]
|
17
17
|
end
|
18
18
|
end
|
data/lib/spud_media/version.rb
CHANGED
@@ -12,9 +12,9 @@ describe Admin::MediaController, type: :controller do
|
|
12
12
|
|
13
13
|
describe 'index' do
|
14
14
|
it 'index page should return all media in descending order by create_at' do
|
15
|
-
@media1 =
|
16
|
-
@media2 =
|
17
|
-
@media3 =
|
15
|
+
@media1 = FactoryBot.create(:spud_media, created_at: 1.hour.ago)
|
16
|
+
@media2 = FactoryBot.create(:spud_media, created_at: 2.hours.ago)
|
17
|
+
@media3 = FactoryBot.create(:spud_media, created_at: 3.hours.ago)
|
18
18
|
get :index
|
19
19
|
@medias = assigns(:media)
|
20
20
|
expect(@medias.count).to eq(3)
|
@@ -34,9 +34,8 @@ describe Admin::MediaController, type: :controller do
|
|
34
34
|
|
35
35
|
describe 'create' do
|
36
36
|
it "should create a new media and returned the saved object's edit page" do
|
37
|
-
post :create, params: { spud_media: FactoryGirl.attributes_for(:spud_media) }
|
38
37
|
expect do
|
39
|
-
post :create, params: { spud_media:
|
38
|
+
post :create, params: { spud_media: FactoryBot.attributes_for(:spud_media) }
|
40
39
|
end.to change(SpudMedia, :count).by(1)
|
41
40
|
end
|
42
41
|
end
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -4,7 +4,7 @@ describe SpudMedia, type: :model do
|
|
4
4
|
|
5
5
|
describe 'attachment' do
|
6
6
|
it 'should require an attachment' do
|
7
|
-
media =
|
7
|
+
media = FactoryBot.build(:spud_media, attachment: nil)
|
8
8
|
expect(media.valid?).to eq(false)
|
9
9
|
expect(media.errors[:attachment].length).to eq(1)
|
10
10
|
end
|
data/spec/rails_helper.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
# This file is copied to spec/ when you run 'rails generate rspec:install'
|
2
2
|
ENV['RAILS_ENV'] ||= 'test'
|
3
3
|
|
4
|
-
require File.expand_path('
|
4
|
+
require File.expand_path('dummy/config/environment.rb', __dir__)
|
5
5
|
require 'spec_helper'
|
6
6
|
require 'rspec/rails'
|
7
7
|
require 'rails-controller-testing'
|
8
8
|
require 'database_cleaner'
|
9
9
|
require 'simplecov'
|
10
|
-
require '
|
10
|
+
require 'factory_bot_rails'
|
11
11
|
require 'tb_core/test_helper'
|
12
12
|
|
13
13
|
SimpleCov.start 'rails'
|
metadata
CHANGED
@@ -1,59 +1,59 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tb_media
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Moser Consulting
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-04-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: paperclip
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: rails
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 5.0.0.1
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 5.0.0.1
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: tb_core
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 1.4.4
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 1.4.4
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: database_cleaner
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
@@ -67,7 +67,7 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: factory_bot_rails
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
@@ -81,7 +81,7 @@ dependencies:
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: mysql2
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - ">="
|
@@ -95,7 +95,7 @@ dependencies:
|
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
98
|
+
name: rails-controller-testing
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - ">="
|
@@ -109,7 +109,7 @@ dependencies:
|
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
112
|
+
name: rspec-rails
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
115
|
- - ">="
|
@@ -123,7 +123,7 @@ dependencies:
|
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
|
-
name:
|
126
|
+
name: rubocop
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
129
|
- - ">="
|
@@ -137,7 +137,7 @@ dependencies:
|
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
|
-
name:
|
140
|
+
name: simplecov
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
142
142
|
requirements:
|
143
143
|
- - ">="
|
@@ -195,8 +195,6 @@ files:
|
|
195
195
|
- app/assets/stylesheets/admin/media/plugin.css
|
196
196
|
- app/controllers/admin/media_controller.rb
|
197
197
|
- app/controllers/admin/media_picker_controller.rb
|
198
|
-
- app/controllers/protected_media_controller.rb
|
199
|
-
- app/helpers/protected_media_helper.rb
|
200
198
|
- app/models/spud_media.rb
|
201
199
|
- app/views/admin/media/edit.html.erb
|
202
200
|
- app/views/admin/media/index.html.erb
|
@@ -306,69 +304,69 @@ signing_key:
|
|
306
304
|
specification_version: 4
|
307
305
|
summary: TB File upload/management module
|
308
306
|
test_files:
|
309
|
-
- spec/
|
307
|
+
- spec/spec_helper.rb
|
308
|
+
- spec/dummy/app/controllers/application_controller.rb
|
309
|
+
- spec/dummy/app/views/layouts/application.html.erb
|
310
310
|
- spec/dummy/app/assets/javascripts/application.js
|
311
311
|
- spec/dummy/app/assets/stylesheets/application.css
|
312
|
-
- spec/dummy/app/controllers/application_controller.rb
|
313
312
|
- spec/dummy/app/helpers/application_helper.rb
|
314
|
-
- spec/dummy/
|
315
|
-
- spec/dummy/config/
|
316
|
-
- spec/dummy/config/boot.rb
|
317
|
-
- spec/dummy/config/database.yml
|
318
|
-
- spec/dummy/config/environment.rb
|
319
|
-
- spec/dummy/config/environments/development.rb
|
313
|
+
- spec/dummy/config/routes.rb
|
314
|
+
- spec/dummy/config/locales/en.yml
|
320
315
|
- spec/dummy/config/environments/production.rb
|
316
|
+
- spec/dummy/config/environments/development.rb
|
321
317
|
- spec/dummy/config/environments/test.rb
|
318
|
+
- spec/dummy/config/environment.rb
|
319
|
+
- spec/dummy/config/application.rb
|
320
|
+
- spec/dummy/config/database.yml
|
321
|
+
- spec/dummy/config/boot.rb
|
322
322
|
- spec/dummy/config/initializers/backtrace_silencers.rb
|
323
|
-
- spec/dummy/config/initializers/inflections.rb
|
324
323
|
- spec/dummy/config/initializers/mime_types.rb
|
325
|
-
- spec/dummy/config/initializers/secret_token.rb
|
326
324
|
- spec/dummy/config/initializers/session_store.rb
|
327
325
|
- spec/dummy/config/initializers/wrap_parameters.rb
|
328
|
-
- spec/dummy/config/
|
329
|
-
- spec/dummy/config/
|
326
|
+
- spec/dummy/config/initializers/secret_token.rb
|
327
|
+
- spec/dummy/config/initializers/inflections.rb
|
330
328
|
- spec/dummy/config.ru
|
331
|
-
- spec/dummy/
|
332
|
-
- spec/dummy/
|
333
|
-
- spec/dummy/
|
334
|
-
- spec/dummy/db/migrate/20130904141444_add_scope_to_spud_admin_permissions.tb_core.rb
|
335
|
-
- spec/dummy/db/migrate/20130904141445_create_spud_user_settings.tb_core.rb
|
336
|
-
- spec/dummy/db/migrate/20130904141446_create_spud_media.tb_media.rb
|
337
|
-
- spec/dummy/db/migrate/20130904141447_add_protected_to_spud_media.tb_media.rb
|
338
|
-
- spec/dummy/db/migrate/20130904141448_add_cropping_to_spud_media.tb_media.rb
|
339
|
-
- spec/dummy/db/migrate/20151012194530_create_spud_roles.tb_core.rb
|
340
|
-
- spec/dummy/db/migrate/20151012194531_create_spud_permissions.tb_core.rb
|
341
|
-
- spec/dummy/db/migrate/20151012194532_create_spud_role_permissions.tb_core.rb
|
342
|
-
- spec/dummy/db/migrate/20151012194533_drop_spud_admin_permissions.tb_core.rb
|
343
|
-
- spec/dummy/db/migrate/20151012194534_add_requires_password_change_to_spud_users.tb_core.rb
|
344
|
-
- spec/dummy/db/schema.rb
|
345
|
-
- spec/dummy/public/404.html
|
329
|
+
- spec/dummy/script/rails
|
330
|
+
- spec/dummy/Rakefile
|
331
|
+
- spec/dummy/public/favicon.ico
|
346
332
|
- spec/dummy/public/422.html
|
347
333
|
- spec/dummy/public/500.html
|
348
|
-
- spec/dummy/public/
|
349
|
-
- spec/dummy/public/system/spud_media/1/cropped/test_img1.png
|
334
|
+
- spec/dummy/public/404.html
|
350
335
|
- spec/dummy/public/system/spud_media/1/original/test_img1.png
|
351
336
|
- spec/dummy/public/system/spud_media/1/small/test_img1.png
|
352
|
-
- spec/dummy/public/system/spud_media/
|
353
|
-
- spec/dummy/public/system/spud_media/2/original/test_img1.png
|
354
|
-
- spec/dummy/public/system/spud_media/2/small/test_img1.png
|
355
|
-
- spec/dummy/public/system/spud_media/3/cropped/test_img1.png
|
356
|
-
- spec/dummy/public/system/spud_media/3/original/test_img1.png
|
357
|
-
- spec/dummy/public/system/spud_media/3/small/test_img1.png
|
358
|
-
- spec/dummy/public/system/spud_media/4/cropped/test_img1.png
|
337
|
+
- spec/dummy/public/system/spud_media/1/cropped/test_img1.png
|
359
338
|
- spec/dummy/public/system/spud_media/4/original/test_img1.png
|
360
339
|
- spec/dummy/public/system/spud_media/4/small/test_img1.png
|
361
|
-
- spec/dummy/public/system/spud_media/
|
340
|
+
- spec/dummy/public/system/spud_media/4/cropped/test_img1.png
|
341
|
+
- spec/dummy/public/system/spud_media/3/original/test_img1.png
|
342
|
+
- spec/dummy/public/system/spud_media/3/small/test_img1.png
|
343
|
+
- spec/dummy/public/system/spud_media/3/cropped/test_img1.png
|
344
|
+
- spec/dummy/public/system/spud_media/2/original/test_img1.png
|
345
|
+
- spec/dummy/public/system/spud_media/2/small/test_img1.png
|
346
|
+
- spec/dummy/public/system/spud_media/2/cropped/test_img1.png
|
362
347
|
- spec/dummy/public/system/spud_media/5/original/test_img1.png
|
363
348
|
- spec/dummy/public/system/spud_media/5/small/test_img1.png
|
364
|
-
- spec/dummy/
|
349
|
+
- spec/dummy/public/system/spud_media/5/cropped/test_img1.png
|
350
|
+
- spec/dummy/db/schema.rb
|
351
|
+
- spec/dummy/db/migrate/20130904141441_create_spud_admin_permissions.tb_core.rb
|
352
|
+
- spec/dummy/db/migrate/20130904141443_add_time_zone_to_spud_user.tb_core.rb
|
353
|
+
- spec/dummy/db/migrate/20130904141448_add_cropping_to_spud_media.tb_media.rb
|
354
|
+
- spec/dummy/db/migrate/20130904141446_create_spud_media.tb_media.rb
|
355
|
+
- spec/dummy/db/migrate/20151012194532_create_spud_role_permissions.tb_core.rb
|
356
|
+
- spec/dummy/db/migrate/20130904141444_add_scope_to_spud_admin_permissions.tb_core.rb
|
357
|
+
- spec/dummy/db/migrate/20151012194533_drop_spud_admin_permissions.tb_core.rb
|
358
|
+
- spec/dummy/db/migrate/20151012194534_add_requires_password_change_to_spud_users.tb_core.rb
|
359
|
+
- spec/dummy/db/migrate/20151012194531_create_spud_permissions.tb_core.rb
|
360
|
+
- spec/dummy/db/migrate/20130904141442_create_spud_users.tb_core.rb
|
361
|
+
- spec/dummy/db/migrate/20151012194530_create_spud_roles.tb_core.rb
|
362
|
+
- spec/dummy/db/migrate/20130904141445_create_spud_user_settings.tb_core.rb
|
363
|
+
- spec/dummy/db/migrate/20130904141447_add_protected_to_spud_media.tb_media.rb
|
365
364
|
- spec/dummy/README.rdoc
|
366
|
-
- spec/dummy/script/rails
|
367
|
-
- spec/fixtures/images/test_img1.png
|
368
|
-
- spec/javascripts/helpers/setup_env.js
|
369
|
-
- spec/javascripts/spud/admin/media/application_spec.js
|
370
|
-
- spec/javascripts/support/jasmine.yml
|
371
|
-
- spec/javascripts/support/jasmine_helper.rb
|
372
365
|
- spec/models/spud_media_spec.rb
|
366
|
+
- spec/javascripts/support/jasmine_helper.rb
|
367
|
+
- spec/javascripts/support/jasmine.yml
|
368
|
+
- spec/javascripts/spud/admin/media/application_spec.js
|
369
|
+
- spec/javascripts/helpers/setup_env.js
|
370
|
+
- spec/fixtures/images/test_img1.png
|
371
|
+
- spec/controllers/admin/media_controller_spec.rb
|
373
372
|
- spec/rails_helper.rb
|
374
|
-
- spec/spec_helper.rb
|
@@ -1,24 +0,0 @@
|
|
1
|
-
class ProtectedMediaController < Spud::ApplicationController
|
2
|
-
|
3
|
-
before_action :require_user
|
4
|
-
|
5
|
-
def show
|
6
|
-
@media = SpudMedia.where(id: params[:id]).first
|
7
|
-
if @media.blank?
|
8
|
-
raise Spud::NotFoundError, item: 'media'
|
9
|
-
else
|
10
|
-
if Spud::Media.config.paperclip_storage == :s3
|
11
|
-
secure_url = @media.attachment.s3_object(params[:style]).url_for(:read, secure: true, expires: 10.minutes)
|
12
|
-
redirect_to(secure_url.to_s)
|
13
|
-
else
|
14
|
-
filepath = @media.attachment.path(params[:style])
|
15
|
-
if !File.exist?(filepath)
|
16
|
-
raise Spud::NotFoundError, item: 'media'
|
17
|
-
else
|
18
|
-
send_file(filepath, disposition: 'inline')
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|