diff --git a/app/models/application_record.rb b/app/models/application_record.rb index d36b82d6f7..6bfeb85c3a 100644 --- a/app/models/application_record.rb +++ b/app/models/application_record.rb @@ -10,4 +10,8 @@ class ApplicationRecord < ActiveRecord::Base include ArelHelpers::JoinAssociation self.abstract_class = true + + def self.image_service + ENV["S3_BUCKET"].present? ? :amazon_public : :local + end end diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index e7b81947ae..bd813f287f 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -87,10 +87,10 @@ class Enterprise < ApplicationRecord } accepts_nested_attributes_for :custom_tab - has_one_attached :logo - has_one_attached :promo_image + has_one_attached :logo, service: image_service + has_one_attached :promo_image, service: image_service has_one_attached :terms_and_conditions - has_one_attached :white_label_logo + has_one_attached :white_label_logo, service: image_service validates :logo, processable_image: true, diff --git a/app/models/enterprise_group.rb b/app/models/enterprise_group.rb index 9616c24722..4221776554 100644 --- a/app/models/enterprise_group.rb +++ b/app/models/enterprise_group.rb @@ -25,8 +25,8 @@ class EnterpriseGroup < ApplicationRecord delegate :phone, :address1, :address2, :city, :zipcode, :state, :country, to: :address - has_one_attached :logo - has_one_attached :promo_image + has_one_attached :logo, service: image_service + has_one_attached :promo_image, service: image_service validates :logo, processable_image: true, diff --git a/app/models/spree/image.rb b/app/models/spree/image.rb index e328eea790..8bdaeb65bb 100644 --- a/app/models/spree/image.rb +++ b/app/models/spree/image.rb @@ -9,7 +9,7 @@ module Spree large: { resize_to_limit: [600, 600] }, }.freeze - has_one_attached :attachment + has_one_attached :attachment, service: image_service validates :attachment, attached: true, diff --git a/config/storage.yml b/config/storage.yml index 255c8298d9..271782041f 100644 --- a/config/storage.yml +++ b/config/storage.yml @@ -19,3 +19,11 @@ amazon: secret_access_key: <%= ENV["S3_SECRET"] %> bucket: <%= ENV["S3_BUCKET"] %> region: <%= ENV.fetch("S3_REGION", "us-east-1") %> + +amazon_public: + service: S3 + public: true + access_key_id: <%= ENV["S3_ACCESS_KEY"] %> + secret_access_key: <%= ENV["S3_SECRET"] %> + bucket: <%= ENV["S3_BUCKET"] %> + region: <%= ENV.fetch("S3_REGION", "us-east-1") %>