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

[#161102] Adds active_storage_for_images_only feature flag #3348

Merged
merged 7 commits into from
Jan 30, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
4 changes: 4 additions & 0 deletions app/lib/settings_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ def self.relays_enabled_for_reservation?
setting "relays.#{Rails.env}.reservation_enabled"
end

def self.active_storage_enabled?
feature_on?(:active_storage) || feature_on?(:active_storage_for_images_only)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'm leaning towards letting each feature flag do its own thing - what's your thinking about intertwining here?

If we keep this logic I'd vote for renaming to active_storage_for_images_enabled?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of how the flags are named, it seemed like active_storage could/would be a superset of active_storage_for_images_only. Also doing it this way would mean no change in OSU's settings.yml. Neither of these may be interesting enough reasons, don't have a strong opinion.

end

#
# Used to query the +Settings+ under feature:
# [_feature_]
Expand Down
2 changes: 1 addition & 1 deletion app/models/concerns/active_storage_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module ActiveStorageFile
has_one_attached :file

def assign_attributes(new_attributes)
if SettingsHelper.feature_on?(:active_storage)
if SettingsHelper.active_storage_enabled?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this feature flag here? I can't recall if we need it for some reason or perhaps it was left over from a previous iteration of the code, before we separated things into modules

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also can't recall. It passes CI with it removed though, so I suppose it's fine to leave it out. I recall this method causing a lot of problems, so likely extra stuff was left in it while working up to a solution.

# Ensure the file name and file_type are set first when attaching a StringIO
# see #file= method below
assign_first = new_attributes.extract!(:name, :file_type)
Expand Down
15 changes: 12 additions & 3 deletions app/models/concerns/downloadable_files/image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,35 @@ module DownloadableFiles
module Image

extend ActiveSupport::Concern
include DownloadableFile

if SettingsHelper.active_storage_enabled?
include ActiveStorageFile
else
include PaperclipFile
end

included do
attr_reader :remove_file

before_validation { delete_file if remove_file }

if SettingsHelper.feature_on?(:active_storage)
if SettingsHelper.active_storage_enabled?
validates :file, content_type: ["image/jpg", "image/jpeg", "image/png", "image/gif"]
else
validates_attachment :file, content_type: { content_type: ["image/jpg", "image/jpeg", "image/png", "image/gif"] }
end
end

def file_present?
file.present?
end

def remove_file=(value)
@remove_file = !value.to_i.zero?
end

def padded_image(width: 400, height: 200, background_color: "rgb(231, 231, 231)")
if SettingsHelper.feature_on?(:active_storage)
if SettingsHelper.active_storage_enabled?
download_url.variant(resize_and_pad: [width, height, { background: background_color }])
else
download_url
Expand Down
3 changes: 2 additions & 1 deletion config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ feature:
bypass_kiosk_auth: false
revenue_account_editable: false
active_storage: false
facility_tile_list: false
active_storage_for_images_only: false
facility_tile_list: <%= ENV.fetch("FACILITY_TILE_LIST", false) %>
facility_tile_list_admin: false
po_require_affiliate_account: true

Expand Down
1 change: 1 addition & 0 deletions doc/HOWTO_feature_flags.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,4 @@
* `kiosk_view` Kiosk mode - display a list of actionable reservations without logging in (optionally allow acting w/o auth)
* `reservations: grace_period`, `reservations: timeout_period`, `occupancies: timeout_period`, `billing: review_period` various grace periods, time periods, and review periods
* `active_storage` use `ActiveStorage` if `true`, or `Paperclip` if `false`
* `active_storage_for_images_only` enables `ActiveStorage` for the `DownloadableFiles::Image` module. This flag does not need to be enabled if `active_storage` is