Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix url & remove OriginPath #321

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .cloudformation/cloud_front.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Resources:
Principal:
AWS: !Sub "arn:aws:iam::cloudfront:user/CloudFront Origin Access Identity ${OriginAccessIdentity}"
Action: "s3:GetObject"
Resource: !Sub "arn:aws:s3:::${AppEnvironment}-cfj-decidim/uploads/decidim/*"
Resource: !Sub "arn:aws:s3:::${AppEnvironment}-cfj-decidim/*"


# ------------------------------------------------------------#
Expand Down Expand Up @@ -107,7 +107,6 @@ Resources:
OriginReadTimeout: 60
- Id: !Sub "${AppEnvironment}-cfj-decidim.s3.ap-northeast-1.amazonaws.com"
DomainName: !Sub "${AppEnvironment}-cfj-decidim.s3.ap-northeast-1.amazonaws.com"
OriginPath: /uploads/decidim
S3OriginConfig:
OriginAccessIdentity: !Sub "origin-access-identity/cloudfront/${OriginAccessIdentity}"
DefaultCacheBehavior:
Expand Down
18 changes: 13 additions & 5 deletions app/uploaders/decidim/application_uploader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,20 @@ def store_dir

# Overwrite: If the content block is in preview mode, then we show the
# URL using the asset_host domain
def url(*)
encoded_path = encode_path(path)
if asset_host.respond_to? :call
"#{asset_host.call(self)}/#{encoded_path}"
def url(*args)
if path.nil?
default_url(*args)
else
"#{asset_host}/#{encoded_path}"
encoded_path = encode_path(path.sub(File.expand_path(root), ""))
if (host = asset_host)
if host.respond_to? :call
"#{host.call(self)}/#{encoded_path}"
else
"#{host}/#{encoded_path}"
end
else
(base_path || "") + encoded_path
end
end
end

Expand Down