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

allow branding info to be processed with Hyrax::PcdmCollectionForm #5458

Merged
merged 1 commit into from
May 3, 2022

Conversation

blancoj
Copy link
Contributor

@blancoj blancoj commented Feb 23, 2022

Fixes #5330

This PR will allow the user to update the branding files: banner, and logo, for the Hyrax::PcdmCollectionForm.

In order to test this, you will need configure the collection model:

Edit /config/initializers/hyrax.rb and set:

config.collection_model = "Hyrax::PcdmCollection"

I want to point out that in order to get the Prepopulators to work, I had to add this line of code in the form method in collection_controller.rb. Perhaps there may be a better way to do this in the future.
form.prepopulate!

Also, in the update method of the collection_controller.rb file, I added a call to process_branding, and in there I check what model is being used. You don't want to do any processing in the method if the model is Pcdm, since that will be taken care by the ChangeSet and steps defined further down in that file. Not sure this is the best way to do this. :

def process_branding
  if Hyrax.config.collection_model.present? && Hyrax.config.collection_model == "Hyrax::PcdmCollection"
  elsif !params[:update_collection].nil?
    process_banner_input
    process_logo_input
  end
end

Guidance for testing, such as acceptance criteria or new user interface behaviors:
First
To isolate issues in other tabs, create a collection_type with all options off except Branding.

  1. navigate to Dashboard -> Settings -> Collection Types
  2. click button: Create new collection type
  3. set Type name: Brandable only (or other meaningful name)
  4. click button: Save
  5. click tab: Settings
  6. uncheck all but Branding (as seen below)
  7. click button: Save changes

Then, you can test the uploading and creation of banner and logo:

  1. navigate to Dashboard -> Collections
  2. click button: New Collection
  3. select type: Brandable only (or the name you used when creating the collection type)
  4. click button: Create Collection
  5. set Title: My Branded Collection (or other meaningful name)
  6. Update a banner and logo. You can do a couple of logos if you'd like.
  7. click Save

@samvera/hyrax-code-reviewers

@blancoj blancoj force-pushed the issue-5330 branch 3 times, most recently from 0e31bfd to e5897ef Compare March 2, 2022 03:01
Copy link
Contributor

@elrayle elrayle left a comment

Choose a reason for hiding this comment

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

A few pre-final review comments.

@@ -234,10 +237,20 @@ def valkyrie_create
end

def valkyrie_update
# To handle the update of the Branding Tab, Edit collection page
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this comment is needed. This method handles more than just the branding.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree. I put it in there as I was debugging.

@@ -498,7 +514,9 @@ def form
@form ||=
case @collection
when Valkyrie::Resource
Hyrax::Forms::ResourceForm.for(@collection)
form = Hyrax::Forms::ResourceForm.for(@collection)
form.prepopulate!
Copy link
Contributor

Choose a reason for hiding this comment

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

I'll have to double check this, but I thought prepopulate! happened automatically.

Comment on lines 29 to 30
def process_banner_input(collection_id:, banner_unchanged_indicator:, update_banner_file_ids:)
return if banner_unchanged_indicator == "true"
Copy link
Contributor

Choose a reason for hiding this comment

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

This check of banner_unchanged_indicator here isn't needed anymore if the check is made in #call.

Suggested change
def process_banner_input(collection_id:, banner_unchanged_indicator:, update_banner_file_ids:)
return if banner_unchanged_indicator == "true"
def process_banner_input(collection_id:, update_banner_file_ids:)

Copy link
Contributor

@elrayle elrayle left a comment

Choose a reason for hiding this comment

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

It really is nice having the processing of banner and logos, each in their own transaction step. Makes it easier to tell what is happening.

I have a few suggestions and questions, but overall, this looks really good. For some suggestions, you should be able to click the Commit suggestion button if the change looks good to you.

process_banner_input
process_logo_input
end
process_branding
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a minor suggestion. If you move process_branding after the return, then you won't have to check the model in the process_branding method.

      def update
        process_member_changes
        return valkyrie_update if @collection.is_a?(Valkyrie::Resource)

        process_branding
        ... # remainder of AF processing
      end

@@ -163,6 +160,12 @@ def update
end
end

def process_branding
return if Hyrax.config.collection_model == "Hyrax::PcdmCollection"
Copy link
Contributor

Choose a reason for hiding this comment

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

If you continue to need to check this here, it needs to be a more general to check if @collection.is_a?(Valkyrie::Resource). If you take the suggestion in the update method, then this check can be removed.

@@ -17,6 +17,41 @@
end
end

describe '#banner_info' do
let(:banner_info) do
Copy link
Contributor

Choose a reason for hiding this comment

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

This and the logo_info test are great to have.

Comment on lines 61 to 65
logo_info = CollectionBrandingInfo.where(collection_id: collection_id).where(role: "logo").where(local_path: uploaded_file_id.to_s)
logo_info.first.alt_text = alttext
logo_info.first.target_url = linkurl
logo_info.first.local_path = uploaded_file_id
logo_info.first.save(uploaded_file_id, false)
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it work to set logo_info to the first result to avoid calling first multiple times?

Suggested change
logo_info = CollectionBrandingInfo.where(collection_id: collection_id).where(role: "logo").where(local_path: uploaded_file_id.to_s)
logo_info.first.alt_text = alttext
logo_info.first.target_url = linkurl
logo_info.first.local_path = uploaded_file_id
logo_info.first.save(uploaded_file_id, false)
logo_info = CollectionBrandingInfo.where(collection_id: collection_id).where(role: "logo").where(local_path: uploaded_file_id.to_s).first
logo_info.alt_text = alttext
logo_info.target_url = linkurl
logo_info.local_path = uploaded_file_id
logo_info.save(uploaded_file_id, false)

# During the update collection process this step is called to update the file
# to be used as a the banner for the collection.
#
class SaveCollectionBanner
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs tests. You might be able to copy in the tests from the controller and make some minor adjustments for them to work for the transaction code.

# During the update collection process this step is called to update the file(s)
# to be used as logo(s) for the collection.
#
class SaveCollectionLogo
Copy link
Contributor

Choose a reason for hiding this comment

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

Same for this step. It needs tests. You might be able to copy in the tests from the controller and make some minor adjustments for them to work for the transaction code.

end

it 'does not save linkurl containing html; target_url is empty' do
expect(step.call(collection, update_logo_file_ids: [uploaded.id.to_s], alttext_values: ["Logo alt Text"], linkurl_values: ["<script>remove_me</script>"])).to be_success
Copy link
Contributor

Choose a reason for hiding this comment

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

Good to have the negative tests included too to catch edge cases.

Copy link
Contributor

@elrayle elrayle left a comment

Choose a reason for hiding this comment

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

Thanks for pushing this all the way through, especially in time for Virtual Connect. All release tests pass for nurax-pg with this PR.

@elrayle elrayle merged commit 3ce78e7 into main May 3, 2022
@elrayle elrayle deleted the issue-5330 branch May 3, 2022 14:29
@dlpierce dlpierce added the notes-bugfix Release Notes: Fixed a bug label Jun 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
notes-bugfix Release Notes: Fixed a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hyrax::PcdmCollectionForm fails to load branding tab
3 participants