Skip to content

Conversation

@esoterik
Copy link
Member

This introduces a minor new user flow for image management in action center. Previously an admin could upload a banner while creating/editing an action; I've had to migrate/modernize almost everything to do with file uploads in this PR, so there's a new menu item in the admin nav just for gallery management.

The index page has a form which allows for one file upload, which is submitted asynchronously, and similarly images can be deleted from the gallery here.

after this is merged, we'll only need the following env variables for uploads:

amazon_access_key_id
amazon_secret_access_key
amazon_region
bucket_host
amazon_bucket

Draft until some file migration in our storage takes place and I confirm that everything's working as expected! (also just noticing that I have a few more things to remove/clean up and that I need to update the system tests -- will probably self-review this before I mark as ready to go)

@@ -0,0 +1,32 @@
class BaseUploader < CarrierWave::Uploader::Base
storage :fog
# cache_storage :file
Copy link
Member Author

Choose a reason for hiding this comment

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

TODO: figure out if we need to or should enable this

Copy link
Member

Choose a reason for hiding this comment

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

after reading about this, I'm still not sure of impact of setting or leaving it. seems file either way, since it's just temp storage before upload.

}
end

before(:each) do
Copy link
Member Author

Choose a reason for hiding this comment

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

to do: remove whole file and replace with gallery system test


config.before(:each, type: :system, js: true) do
stub_civicrm
StorageHelpers.mock_fog!
Copy link
Member Author

Choose a reason for hiding this comment

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

need to figure out if we should always be mocking this in tests or just when we need it

@esoterik esoterik force-pushed the migrate-srcfile-s3 branch 3 times, most recently from 8c22843 to 63ffb6c Compare July 24, 2025 20:28
Copy link
Member

@hartsick hartsick left a comment

Choose a reason for hiding this comment

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

looks good to me! sorry for not being able to give more substantive feedback. I think we should get this deployed to staging and see how it behaves. nice sleuthing!

end

def id_partition # mimics paperclips mapping function
("%09d" % model.id).scan(/\d{3}/).join("/")
Copy link
Member

Choose a reason for hiding this comment

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

fun

<%= f.label :image, "Upload new image" %>
<%= image_tag(@upload.image.try(:url)) if @upload.image? %>
<%= f.file_field :image %>
<%= f.hidden_field :image_cache %>
Copy link
Member

Choose a reason for hiding this comment

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

what does this field do? wondering if it's related to the cache_storage setting that was left unset

Copy link
Member Author

Choose a reason for hiding this comment

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

ah. this is supposed to keep the image in the field if the form fails, and absolutely isn't working at least partially because of this. just going to remove it for now

before do
end

it "uploads to the expected directory" do
Copy link
Member

Choose a reason for hiding this comment

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

think these are the specs you were talking about filling in after behavior was sorted, but flagging in case not!

@hartsick
Copy link
Member

Also, could you make a note in our deploy prep doc about changes we'll want to make to the deployed environment? (removal of env vars, etc)

@esoterik esoterik force-pushed the migrate-srcfile-s3 branch from 63ffb6c to 49ce0cd Compare July 28, 2025 17:38
stub_request(:get, %r{fakeimages/test.png}).to_return(status: 200, body: fixture_file_upload("test-image.png", "image/png").tempfile.to_io, headers: { content_type: "image/png" })
stub_request(:any, %r{/action_pages/featured_images/([0-9]+)/([0-9]+)/([0-9]+)/original/test.png}).to_return(status: 200, body: "", headers: {})
FactoryBot.create(:action_page, remote_featured_image_url: "https://example.com/fakeimages/test.png")
file_name = "test-image.png"
Copy link
Member Author

Choose a reason for hiding this comment

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

the tests i've updated in this file pass when run by themselves but not when in the entire suite

@esoterik esoterik force-pushed the migrate-srcfile-s3 branch from 49ce0cd to afcbbc7 Compare July 28, 2025 20:09
@esoterik esoterik force-pushed the migrate-srcfile-s3 branch from afcbbc7 to db37abb Compare July 28, 2025 20:14
@esoterik esoterik merged commit 04ebe1d into main Jul 28, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants