-
Notifications
You must be signed in to change notification settings - Fork 124
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
Conversation
0e31bfd
to
e5897ef
Compare
There was a problem hiding this 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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! |
There was a problem hiding this comment.
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.
def process_banner_input(collection_id:, banner_unchanged_indicator:, update_banner_file_ids:) | ||
return if banner_unchanged_indicator == "true" |
There was a problem hiding this comment.
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.
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:) |
There was a problem hiding this 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 |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
spec/controllers/hyrax/dashboard/collections_controller_with_resource_spec.rb
Show resolved
Hide resolved
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) |
There was a problem hiding this comment.
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?
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
7279983
to
e48fb18
Compare
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
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 toprocess_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. :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.
Then, you can test the uploading and creation of banner and logo:
@samvera/hyrax-code-reviewers