From 6155c52462482a64ac27c1021bf4d496121f01cc Mon Sep 17 00:00:00 2001 From: pabois <pierreandre.boissinot@noesya.coop> Date: Fri, 22 Oct 2021 16:05:05 +0200 Subject: [PATCH] creating a new scaleway service extending s3 to resolve the direct upload acl problem --- .../communication/website/posts/show.html.erb | 2 ++ .../max_login_attempts_reached.html.erb | 2 +- config/storage.yml | 2 +- lib/active_storage/service/scaleway_service.rb | 16 ++++++++++++++++ 4 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 lib/active_storage/service/scaleway_service.rb diff --git a/app/views/admin/communication/website/posts/show.html.erb b/app/views/admin/communication/website/posts/show.html.erb index 62ab87330..4b39d1f82 100644 --- a/app/views/admin/communication/website/posts/show.html.erb +++ b/app/views/admin/communication/website/posts/show.html.erb @@ -54,6 +54,8 @@ </div> <div class="card-body"> <%= image_tag @post.featured_image.variant(resize: '400'), class: 'img-fluid' %> + <%= @post.featured_image.url %> + <%= @post.featured_image.variant(resize: '400').url %> </div> </div> <% end %> diff --git a/app/views/devise/two_factor_authentication/max_login_attempts_reached.html.erb b/app/views/devise/two_factor_authentication/max_login_attempts_reached.html.erb index 32d0b6cef..b0e613863 100644 --- a/app/views/devise/two_factor_authentication/max_login_attempts_reached.html.erb +++ b/app/views/devise/two_factor_authentication/max_login_attempts_reached.html.erb @@ -1,4 +1,4 @@ <div class="alert alert-danger" role="alert"> <%= t('devise.two_factor_authentication.max_login_attempts_reached').html_safe %> </div> -<%= link_to t('devise.shared.links.sign_out'), destroy_user_session_path, class: "btn btn-danger" %> +<%= link_to t('devise.shared.links.sign_out'), destroy_user_session_path, method: :delete, class: "btn btn-danger" %> diff --git a/config/storage.yml b/config/storage.yml index 66f3ff1fa..6b5af23d9 100644 --- a/config/storage.yml +++ b/config/storage.yml @@ -7,7 +7,7 @@ local: root: <%= Rails.root.join("storage") %> scaleway: - service: S3 + service: Scaleway access_key_id: <%= ENV['SCALEWAY_OS_ACCESS_KEY_ID'] %> secret_access_key: <%= ENV['SCALEWAY_OS_SECRET_ACCESS_KEY'] %> region: <%= ENV['SCALEWAY_OS_REGION'] %> diff --git a/lib/active_storage/service/scaleway_service.rb b/lib/active_storage/service/scaleway_service.rb new file mode 100644 index 000000000..1caadf668 --- /dev/null +++ b/lib/active_storage/service/scaleway_service.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +require 'active_storage/service/s3_service.rb' + +module ActiveStorage + class Service::ScalewayService < Service::S3Service + + def headers_for_direct_upload(key, content_type:, checksum:, filename: nil, disposition: nil, **) + content_disposition = content_disposition_with(type: disposition, filename: filename) if filename + + headers = public? ? { "x-amz-acl" => "public-read" } : {} + + headers.merge({ "Content-Type" => content_type, "Content-MD5" => checksum, "Content-Disposition" => content_disposition }) + end + end +end -- GitLab