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

Fixing issues where Hyrax::FileSet resources are incorrectly cast to AF ::FileSet #7038

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all 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
10 changes: 10 additions & 0 deletions app/controllers/hyrax/file_sets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ class FileSetsController < ApplicationController

before_action :authenticate_user!, except: [:show, :citation, :stats]
load_and_authorize_resource class: Hyrax.config.file_set_class
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
Comment on lines +12 to +21
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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?

before_action :build_breadcrumbs, only: [:show, :edit, :stats]
before_action do
blacklight_config.track_search_session = false
Expand Down
Loading