Skip to content
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
2 changes: 1 addition & 1 deletion .github/workflows/migrations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
bundle install --jobs 4 --retry 3
bundle exec rake db:create db:schema:load db:seed --trace
bundle exec rails runner '10.times { FactoryBot.create :exercise }'
git checkout -
git checkout --force -

# Retrieve gem cache for PR merge commit
- uses: actions/cache@v2
Expand Down
11 changes: 7 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ gem 'rinku'
# Sanitizes user content
gem 'sanitize'

# ActiveStorage variants
gem 'image_processing'

# ActiveStorage S3 support
gem 'aws-sdk-s3'

# Utilities for OpenStax websites
gem 'openstax_utilities'

Expand Down Expand Up @@ -76,14 +82,11 @@ gem 'fine_print'
# Keyword search
gem 'keyword_search'

# File uploads
# File uploads (old)
gem 'remotipart'
gem 'carrierwave'
gem 'mimemagic'

# Image editing
gem 'mini_magick'

# Read Excel xlsx spreadsheet files
gem 'roo'

Expand Down
17 changes: 15 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ GEM
aws-partitions (~> 1, >= 1.239.0)
aws-sigv4 (~> 1.1)
jmespath (~> 1.0)
aws-sdk-kms (1.41.0)
aws-sdk-core (~> 3, >= 3.109.0)
aws-sigv4 (~> 1.1)
aws-sdk-s3 (1.87.0)
aws-sdk-core (~> 3, >= 3.109.0)
aws-sdk-kms (~> 1)
aws-sigv4 (~> 1.1)
aws-sdk-secretsmanager (1.43.0)
aws-sdk-core (~> 3, >= 3.109.0)
aws-sigv4 (~> 1.1)
Expand Down Expand Up @@ -201,6 +208,9 @@ GEM
multi_xml (>= 0.5.2)
i18n (1.8.7)
concurrent-ruby (~> 1.0)
image_processing (1.12.1)
mini_magick (>= 4.9.5, < 5)
ruby-vips (>= 2.0.17, < 3)
ipaddress (0.8.3)
jaro_winkler (1.5.2)
jmespath (1.4.0)
Expand Down Expand Up @@ -245,7 +255,7 @@ GEM
mime-types-data (~> 3.2015)
mime-types-data (3.2019.0331)
mimemagic (0.3.5)
mini_magick (4.9.4)
mini_magick (4.11.0)
mini_mime (1.0.2)
mini_portile2 (2.5.0)
mini_racer (0.2.6)
Expand Down Expand Up @@ -427,6 +437,8 @@ GEM
rubocop (>= 0.70.0)
ruby-graphviz (1.2.4)
ruby-progressbar (1.10.1)
ruby-vips (2.0.17)
ffi (~> 1.9)
ruby_dep (1.5.0)
rubyzip (1.3.0)
sanitize (5.2.1)
Expand Down Expand Up @@ -507,6 +519,7 @@ DEPENDENCIES
addressable
apipie-rails
autoprefixer-rails
aws-sdk-s3
aws-sdk-secretsmanager
aws-sdk-ssm
bootsnap (~> 1.4.0)
Expand All @@ -528,6 +541,7 @@ DEPENDENCIES
fine_print
fog-aws
httparty
image_processing
jquery-rails
jquery-ui-rails
keyword_search
Expand All @@ -536,7 +550,6 @@ DEPENDENCIES
lograge
maruku
mimemagic
mini_magick
mini_racer
nifty-generators
oj
Expand Down
50 changes: 0 additions & 50 deletions app/controllers/api/v1/attachments_controller.rb

This file was deleted.

32 changes: 0 additions & 32 deletions app/representers/api/v1/attachment_representer.rb

This file was deleted.

17 changes: 17 additions & 0 deletions app/representers/api/v1/image_representer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module Api::V1
class ImageRepresenter < Roar::Decorator
include Roar::JSON

property :id,
type: String,
writeable: false,
readable: true

property :created_at,
type: String,
readable: true,
writeable: false,
getter: ->(*) { DateTimeUtilities.to_api_s(created_at) },
schema_info: { required: true }
end
end
6 changes: 4 additions & 2 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@
# config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX

# Store uploaded files on the local file system (see config/storage.yml for options).
config.active_storage.service = :local
# Store uploaded files on the local file system when precompiling assets and on S3 afterwards
config.active_storage.service = ActiveModel::Type::Boolean.new.cast(
ENV.fetch('DISABLE_S3', false)
) ? :local : :amazon

# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
# config.force_ssl = true
Expand Down
14 changes: 14 additions & 0 deletions config/initializers/active_storage.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Rails.application.config.active_storage.resolve_model_to_route = :rails_storage_proxy

Rails.application.config.after_initialize do
ActiveStorage::Blob.class_exec do
# To prevent problems with case-insensitive filesystems, especially in combination
# with databases which treat indices as case-sensitive, all blob keys generated are going
# to only contain the base-36 character alphabet and will therefore be lowercase. To maintain
# the same or higher amount of entropy as in the base-58 encoding used by `has_secure_token`
# the number of bytes used is increased to 28 from the standard 24
def self.generate_unique_secure_token(length: ActiveStorage::Blob::MINIMUM_TOKEN_LENGTH)
"#{Rails.application.secrets.environment_name}/#{SecureRandom.base36(length)}"
end
end
end
10 changes: 7 additions & 3 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
resources :exercises do
match :search, action: :index, via: [:get, :post], on: :collection

resource :attachments, only: [:create, :destroy]

publishable
# Not in V1
#has_logic
Expand Down Expand Up @@ -51,6 +49,7 @@

mount OpenStax::Accounts::Engine => :accounts
mount FinePrint::Engine => :fine_print
mount ActiveStorage::Engine, at: '/rails/active_storage'
mount OpenStax::Utilities::Engine => :status

use_doorkeeper do
Expand Down Expand Up @@ -92,5 +91,10 @@
end
end

get :'*path', controller: :webview, action: :index
# Catch-all frontend route, excluding active_storage
# https://github.com/rails/rails/issues/31228
get :'*path', controller: :webview, action: :index, constraints: ->(req) do
req.path.exclude? 'rails/active_storage'
end

end
1 change: 1 addition & 0 deletions config/secrets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ test:
aws:
s3:
region: us-east-1
exports_bucket_name: not-a-real-bucket
uploads_bucket_name: not-a-real-bucket
access_key_id: NOTAREALKEY
secret_access_key: NOTAREALSECRET
Expand Down
41 changes: 12 additions & 29 deletions config/storage.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,17 @@
test:
service: Disk
root: <%= Rails.root.join("tmp/storage") %>

local:
service: Disk
root: <%= Rails.root.join("storage") %>

# Use rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key)
# amazon:
# service: S3
# access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %>
# secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %>
# region: us-east-1
# bucket: your_own_bucket

# Remember not to checkin your GCS keyfile to a repository
# google:
# service: GCS
# project: your_project
# credentials: <%= Rails.root.join("path/to/gcs.keyfile") %>
# bucket: your_own_bucket

# Use rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key)
# microsoft:
# service: AzureStorage
# storage_account_name: your_account_name
# storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %>
# container: your_container_name
test:
service: Disk
root: <%= Rails.root.join("tmp/storage") %>

# mirror:
# service: Mirror
# primary: local
# mirrors: [ amazon, google, microsoft ]
amazon:
service: S3
access_key_id: <%= ENV['AWS_S3_ACCESS_KEY_ID'] %>
secret_access_key: <%= ENV['AWS_S3_SECRET_ACCESS_KEY'] %>
bucket: <%= ENV['AWS_S3_UPLOADS_BUCKET_NAME'] %>
region: <%= ENV['AWS_S3_REGION'] %>
http_open_timeout: <%= ENV.fetch('AWS_S3_OPEN_TIMEOUT', 60).to_i %>
http_read_timeout: <%= ENV.fetch('AWS_S3_READ_TIMEOUT', 60).to_i %>
retry_limit: <%= ENV.fetch('AWS_S3_RETRY_LIMIT', 3).to_i %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# This migration comes from active_storage (originally 20170806125915)
class CreateActiveStorageTables < ActiveRecord::Migration[5.2]
def change
create_table :active_storage_blobs do |t|
t.string :key, null: false
t.string :filename, null: false
t.string :content_type
t.text :metadata
t.string :service_name, null: false
t.bigint :byte_size, null: false
t.string :checksum, null: false
t.datetime :created_at, null: false

t.index [ :key ], unique: true
end

create_table :active_storage_attachments do |t|
t.string :name, null: false
t.references :record, null: false, polymorphic: true, index: false
t.references :blob, null: false

t.datetime :created_at, null: false

t.index [ :record_type, :record_id, :name, :blob_id ], name: "index_active_storage_attachments_uniqueness", unique: true
t.foreign_key :active_storage_blobs, column: :blob_id
end

create_table :active_storage_variant_records do |t|
t.belongs_to :blob, null: false, index: false
t.string :variation_digest, null: false

t.index %i[ blob_id variation_digest ], name: "index_active_storage_variant_records_uniqueness", unique: true
t.foreign_key :active_storage_blobs, column: :blob_id
end
end
end
Loading