-
Notifications
You must be signed in to change notification settings - Fork 127
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
Fixing issues where Hyrax::FileSet resources are incorrectly cast to AF ::FileSet #7038
base: main
Are you sure you want to change the base?
Conversation
Test Results 13 files ±0 13 suites ±0 2h 48m 23s ⏱️ - 19m 38s For more details on these failures, see this check. Results for commit 8d2dc58. ± Comparison against base commit cf3f95e. This pull request removes 366 and adds 366 tests. Note that renamed tests count towards both.
|
before_action do | ||
# If Hyrax.config.file_set_class is set to ::FileSet, the load above will force-cast | ||
# the instance as a ::FileSet, even if it is a Hyrax::FileSet. Re-cast it back to | ||
# prevent method errors and nil objects later | ||
if @file_set.class == ::FileSet | ||
# We can tell if a Hyrax::FileSet was improperly cast because this AF method will | ||
# return nil since its parent is not a ActiveFedora work. | ||
@file_set = @file_set.valkyrie_resource if @file_set.parent&.id.nil? | ||
end | ||
end |
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.
before_action do | |
# If Hyrax.config.file_set_class is set to ::FileSet, the load above will force-cast | |
# the instance as a ::FileSet, even if it is a Hyrax::FileSet. Re-cast it back to | |
# prevent method errors and nil objects later | |
if @file_set.class == ::FileSet | |
# We can tell if a Hyrax::FileSet was improperly cast because this AF method will | |
# return nil since its parent is not a ActiveFedora work. | |
@file_set = @file_set.valkyrie_resource if @file_set.parent&.id.nil? | |
end | |
end | |
before_action :cast_file_set | |
def cast_file_set | |
# If Hyrax.config.file_set_class is set to ::FileSet, the load above will force-cast | |
# the instance as a ::FileSet, even if it is a Hyrax::FileSet. Re-cast it back to | |
# prevent method errors and nil objects later | |
if @file_set.class == ::FileSet | |
# We can tell if a Hyrax::FileSet was improperly cast because this AF method will | |
# return nil since its parent is not a ActiveFedora work. | |
@file_set = @file_set.valkyrie_resource if @file_set.parent&.id.nil? | |
end | |
end |
Move this to a method to allow easier overriding?
Fixes #7001
In the dassie test app, the value of
Hyrax.config.file
is set to be::FileSet
. This unintentionally causes all FileSets to be force-cast back to a ActiveFedora FileSet in theFileSetsController
, even if they should be a ValkyrieHyrax::FileSet
resource. That's because the class name passed toload_and_authorize_resource
uses that config value.The value of
Hyrax.config.file
needs to be left at::FileSet
for AF models to work, so this PR adds a conditional check in abefore_action
to see if it should cast a FileSet back with.valkyrie_resource
. Otherwise, nothing in the FileSetsController will work (i.e. versions, etc.)