Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
paperclip
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ikcrm_common
paperclip
Commits
2483cd8c
Commit
2483cd8c
authored
Oct 21, 2011
by
Mike Burns
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
https://github.com/jovoto-team/paperclip
parents
7cc0921a
f4096934
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
72 additions
and
10 deletions
+72
-10
lib/paperclip/storage/s3.rb
+12
-4
test/helper.rb
+1
-0
test/storage/s3_test.rb
+59
-6
No files found.
lib/paperclip/storage/s3.rb
View file @
2483cd8c
...
@@ -80,8 +80,10 @@ module Paperclip
...
@@ -80,8 +80,10 @@ module Paperclip
@s3_options
=
@options
.
s3_options
||
{}
@s3_options
=
@options
.
s3_options
||
{}
@s3_permissions
=
set_permissions
(
@options
.
s3_permissions
)
@s3_permissions
=
set_permissions
(
@options
.
s3_permissions
)
@s3_protocol
=
@options
.
s3_protocol
||
@s3_protocol
=
@options
.
s3_protocol
||
Proc
.
new
do
|
style
|
Proc
.
new
do
|
style
,
attachment
|
(
@s3_permissions
[
style
.
to_sym
]
||
@s3_permissions
[
:default
])
==
:public_read
?
'http'
:
'https'
permission
=
(
@s3_permissions
[
style
.
to_sym
]
||
@s3_permissions
[
:default
])
permission
=
permission
.
call
(
attachment
,
style
)
if
permission
.
is_a?
(
Proc
)
(
permission
==
:public_read
)
?
'http'
:
'https'
end
end
@s3_headers
=
@options
.
s3_headers
||
{}
@s3_headers
=
@options
.
s3_headers
||
{}
...
@@ -182,9 +184,15 @@ module Paperclip
...
@@ -182,9 +184,15 @@ module Paperclip
end
end
end
end
def
s3_permissions
(
style
=
default_style
)
s3_permissions
=
@s3_permissions
[
style
]
||
@s3_permissions
[
:default
]
s3_permissions
=
s3_permissions
.
call
(
self
,
style
)
if
s3_permissions
.
is_a?
(
Proc
)
s3_permissions
end
def
s3_protocol
(
style
=
default_style
)
def
s3_protocol
(
style
=
default_style
)
if
@s3_protocol
.
is_a?
(
Proc
)
if
@s3_protocol
.
is_a?
(
Proc
)
@s3_protocol
.
call
(
style
)
@s3_protocol
.
call
(
style
,
self
)
else
else
@s3_protocol
@s3_protocol
end
end
...
@@ -216,7 +224,7 @@ module Paperclip
...
@@ -216,7 +224,7 @@ module Paperclip
file
,
file
,
bucket_name
,
bucket_name
,
{
:content_type
=>
file
.
content_type
.
to_s
.
strip
,
{
:content_type
=>
file
.
content_type
.
to_s
.
strip
,
:access
=>
(
@s3_permissions
[
style
]
||
@s3_permissions
[
:default
]
),
:access
=>
s3_permissions
(
style
),
}.
merge
(
@s3_headers
))
}.
merge
(
@s3_headers
))
rescue
AWS
::
S3
::
NoSuchBucket
=>
e
rescue
AWS
::
S3
::
NoSuchBucket
=>
e
create_bucket
create_bucket
...
...
test/helper.rb
View file @
2483cd8c
...
@@ -11,6 +11,7 @@ require 'active_record/version'
...
@@ -11,6 +11,7 @@ require 'active_record/version'
require
'active_support'
require
'active_support'
require
'mime/types'
require
'mime/types'
require
'pry'
require
'pry'
require
'pathname'
puts
"Testing against version
#{
ActiveRecord
::
VERSION
::
STRING
}
"
puts
"Testing against version
#{
ActiveRecord
::
VERSION
::
STRING
}
"
...
...
test/storage/s3_test.rb
View file @
2483cd8c
...
@@ -509,7 +509,7 @@ class S3Test < Test::Unit::TestCase
...
@@ -509,7 +509,7 @@ class S3Test < Test::Unit::TestCase
end
end
context
"S3 Permissions"
do
context
"S3 Permissions"
do
context
"defaults to
public-
read"
do
context
"defaults to
:public_
read"
do
setup
do
setup
do
rebuild_model
:storage
=>
:s3
,
rebuild_model
:storage
=>
:s3
,
:bucket
=>
"testing"
,
:bucket
=>
"testing"
,
...
@@ -556,7 +556,7 @@ class S3Test < Test::Unit::TestCase
...
@@ -556,7 +556,7 @@ class S3Test < Test::Unit::TestCase
'access_key_id'
=>
"12345"
,
'access_key_id'
=>
"12345"
,
'secret_access_key'
=>
"54321"
'secret_access_key'
=>
"54321"
},
},
:s3_permissions
=>
'private'
:s3_permissions
=>
:private
end
end
context
"when assigned"
do
context
"when assigned"
do
...
@@ -575,7 +575,7 @@ class S3Test < Test::Unit::TestCase
...
@@ -575,7 +575,7 @@ class S3Test < Test::Unit::TestCase
anything
,
anything
,
'testing'
,
'testing'
,
:content_type
=>
'image/png'
,
:content_type
=>
'image/png'
,
:access
=>
'private'
)
:access
=>
:private
)
@dummy
.
save
@dummy
.
save
end
end
...
@@ -599,8 +599,8 @@ class S3Test < Test::Unit::TestCase
...
@@ -599,8 +599,8 @@ class S3Test < Test::Unit::TestCase
'secret_access_key'
=>
"54321"
'secret_access_key'
=>
"54321"
},
},
:s3_permissions
=>
{
:s3_permissions
=>
{
:original
=>
'private'
,
:original
=>
:private
,
:thumb
=>
'public-read'
:thumb
=>
:public_read
}
}
end
end
...
@@ -621,7 +621,7 @@ class S3Test < Test::Unit::TestCase
...
@@ -621,7 +621,7 @@ class S3Test < Test::Unit::TestCase
anything
,
anything
,
'testing'
,
'testing'
,
:content_type
=>
'image/png'
,
:content_type
=>
'image/png'
,
:access
=>
style
==
:thumb
?
'public-read'
:
'private'
)
:access
=>
style
==
:thumb
?
:
public_read
:
:private
)
end
end
@dummy
.
save
@dummy
.
save
end
end
...
@@ -632,5 +632,58 @@ class S3Test < Test::Unit::TestCase
...
@@ -632,5 +632,58 @@ class S3Test < Test::Unit::TestCase
end
end
end
end
end
end
context
"proc permission set"
do
setup
do
rebuild_model
(
:storage
=>
:s3
,
:bucket
=>
"testing"
,
:path
=>
":attachment/:style/:basename.:extension"
,
:styles
=>
{
:thumb
=>
"80x80>"
},
:s3_credentials
=>
{
'access_key_id'
=>
"12345"
,
'secret_access_key'
=>
"54321"
},
:s3_permissions
=>
lambda
{
|
attachment
,
style
|
attachment
.
instance
.
private_attachment?
&&
style
.
to_sym
!=
:thumb
?
:
private
:
:public_read
}
)
end
context
"when assigned"
do
setup
do
@file
=
File
.
new
(
File
.
join
(
File
.
dirname
(
__FILE__
),
'..'
,
'fixtures'
,
'5k.png'
),
'rb'
)
@dummy
=
Dummy
.
new
@dummy
.
stubs
(
:private_attachment?
=>
true
)
@dummy
.
avatar
=
@file
end
teardown
{
@file
.
close
}
context
"and saved"
do
setup
do
AWS
::
S3
::
Base
.
stubs
(
:establish_connection!
)
[
:thumb
,
:original
].
each
do
|
style
|
AWS
::
S3
::
S3Object
.
expects
(
:store
).
with
(
"avatars/
#{
style
}
/5k.png"
,
anything
,
'testing'
,
:content_type
=>
'image/png'
,
:access
=>
style
==
:thumb
?
:
public_read
:
:private
)
end
@dummy
.
save
end
should
"succeed"
do
assert
@dummy
.
avatar
.
url
().
include?
"https://"
assert
@dummy
.
avatar
.
url
(
:thumb
).
include?
"http://"
end
end
end
end
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment