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
21919348
Commit
21919348
authored
Oct 19, 2011
by
Tim Assmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added support for a proc to set s3_permission with specs, still needs a
bit of work
parent
94d35f98
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
4 deletions
+56
-4
lib/paperclip/storage/s3.rb
+8
-4
test/storage/s3_test.rb
+48
-0
No files found.
lib/paperclip/storage/s3.rb
View file @
21919348
...
@@ -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
||
{}
...
@@ -184,7 +186,7 @@ module Paperclip
...
@@ -184,7 +186,7 @@ module Paperclip
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
...
@@ -212,11 +214,13 @@ module Paperclip
...
@@ -212,11 +214,13 @@ module Paperclip
@queued_for_write
.
each
do
|
style
,
file
|
@queued_for_write
.
each
do
|
style
,
file
|
begin
begin
log
(
"saving
#{
path
(
style
)
}
"
)
log
(
"saving
#{
path
(
style
)
}
"
)
s3_permission
=
@s3_permissions
[
style
]
||
@s3_permissions
[
:default
]
s3_permission
=
s3_permission
.
call
(
self
,
style
)
if
s3_permission
.
is_a?
(
Proc
)
AWS
::
S3
::
S3Object
.
store
(
path
(
style
),
AWS
::
S3
::
S3Object
.
store
(
path
(
style
),
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_permission
),
}.
merge
(
@s3_headers
))
}.
merge
(
@s3_headers
))
rescue
AWS
::
S3
::
NoSuchBucket
=>
e
rescue
AWS
::
S3
::
NoSuchBucket
=>
e
create_bucket
create_bucket
...
...
test/storage/s3_test.rb
View file @
21919348
...
@@ -632,5 +632,53 @@ class S3Test < Test::Unit::TestCase
...
@@ -632,5 +632,53 @@ 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
@dummy
.
avatar
.
url
()
=~
/^https:/
@dummy
.
avatar
.
url
(
:thumb
)
=~
/^http:/
assert
true
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