Skip to content

Commit

Permalink
🎁 Contributions from PALNI/PALCI
Browse files Browse the repository at this point in the history
  • Loading branch information
5 people committed Dec 19, 2023
1 parent 9a6fe0e commit 707b447
Show file tree
Hide file tree
Showing 44 changed files with 738 additions and 178 deletions.
3 changes: 2 additions & 1 deletion app/assets/stylesheets/hyku.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
// allows full width if tabs are turned off with feature flipper
.home-content {
display: flex;
justify-content: normal;
padding: 0 20px;
}
.home-tabs-left {
min-width: 50%;
Expand Down Expand Up @@ -413,7 +415,6 @@ a.btn.btn-default.restore-default-color.with-color-hint {
nav.navbar.navbar-default.navbar-static-top .container-fluid .row {
margin-left: 0;
margin-right: 0;

nav.navbar-nav.col-sm-5 {
padding-right: 0;
}
Expand Down
8 changes: 5 additions & 3 deletions app/assets/stylesheets/viewer.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
.viewer {
height: 100%;
padding: 10px;
iframe {
// position: absolute;
}
}

#viewer-modal {
Expand All @@ -21,3 +18,8 @@
margin-bottom: 10px;
}
}

.video-embed-viewer {
aspect-ratio: 16 / 9;
width: 100%;
}
27 changes: 27 additions & 0 deletions app/controllers/admin/roles_service_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

module Admin
class RolesServiceController < ApplicationController
layout 'hyrax/dashboard'

def index
authorize! :update, RolesService
add_breadcrumb t(:'hyrax.controls.home'), root_path
add_breadcrumb t(:'hyrax.dashboard.breadcrumbs.admin'), hyrax.dashboard_path
add_breadcrumb t(:'hyrax.admin.sidebar.roles_service_jobs'), main_app.admin_roles_service_jobs_path
end

# post "admin/roles_service/:job_name_key
def update_roles
authorize! :update, RolesService
job = RolesService.valid_jobs.fetch(params[:job_name_key])

job.perform_later

respond_to do |wants|
wants.html { redirect_to main_app.admin_roles_service_jobs_path, notice: "#{job} has been submitted." }
wants.json { render json: { notice: "#{job} has been submitted." }, status: :ok }
end
end
end
end
17 changes: 17 additions & 0 deletions app/controllers/admin/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

module Admin
class UsersController < AdminController
before_action :ensure_admin!, except: [:remove_role]
before_action :load_user, only: [:destroy]

# NOTE: User creation/invitations handled by devise_invitable
Expand All @@ -26,6 +27,22 @@ def activate
end
end

def remove_role
authorize! :edit, User

user = User.find(params[:id])
role = Role.find(params[:role_id])

if user && role && user.roles.include?(role)
user.remove_role(role.name)
flash[:notice] = "Role '#{role.name}' was successfully removed from user #{user.email}."
else
flash[:alert] = "Failed to remove role from user #{user.email}."
end

redirect_back(fallback_location: root_path)
end

private

def load_user
Expand Down
9 changes: 9 additions & 0 deletions app/controllers/hyrax/dashboard/collections_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ def new
end

def show
configure_show_sort_fields

# unused assignment to be removed in 4.0.0
@banner_file = presenter.banner_file if collection_type.brandable?

Expand Down Expand Up @@ -732,6 +734,13 @@ def process_file_location(f)
end
end
## END OVERRIDE

def configure_show_sort_fields
# In the CollectionsControllerDecorator, we clear the sort fields and add our own to have
# the ability to sort the index with custom fields. However, this also affects the show page.
# Here we set the sort fields back to the defaults for the show page.
blacklight_config.sort_fields = CatalogController.blacklight_config.sort_fields
end
end
end
end
28 changes: 28 additions & 0 deletions app/controllers/hyrax/my/collections_controller_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true

module Hyrax
module My
module CollectionsControllerDecorator
def configure_facets
configure_blacklight do |config|
# clear facets copied from the CatalogController
config.sort_fields.clear
# Collections don't seem to have a date_uploaded_dtsi nor date_modified_dtsi
# we can at least use the system_modified_dtsi instead of date_modified_dtsi
# but we will omit date_uploaded_dtsi
config.add_sort_field "system_modified_dtsi desc", label: "date modified \u25BC"
config.add_sort_field "system_modified_dtsi asc", label: "date modified \u25B2"
config.add_sort_field "system_create_dtsi desc", label: "date created \u25BC"
config.add_sort_field "system_create_dtsi asc", label: "date created \u25B2"
config.add_sort_field "depositor_ssi asc, title_ssi asc", label: "depositor (A-Z)"
config.add_sort_field "depositor_ssi desc, title_ssi desc", label: "depositor (Z-A)"
config.add_sort_field "creator_ssi asc, title_ssi asc", label: "creator (A-Z)"
config.add_sort_field "creator_ssi desc, title_ssi desc", label: "creator (Z-A)"
end
end
end
end
end

Hyrax::My::CollectionsController.singleton_class.send(:prepend, Hyrax::My::CollectionsControllerDecorator)
Hyrax::My::CollectionsController.configure_facets
27 changes: 19 additions & 8 deletions app/controllers/hyrax/my/works_controller_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
# frozen_string_literal: true

##
# OVERRIDE Hyrax 3.5.0; when Hyrax hits v4.0.0 we can remove this.
# @see https://github.com/samvera/hyrax/pull/5972
# OVERRIDE Hyrax 3.6.0 to add custom sort fields while in the dashboard for works

module Hyrax
module My
module WorksControllerDecorator
def collections_service
cloned = clone
cloned.params = {}
Hyrax::CollectionsService.new(cloned)
def configure_facets
configure_blacklight do |config|
# clear facets copied from the CatalogController
config.sort_fields.clear
config.add_sort_field "date_uploaded_dtsi desc", label: "date uploaded \u25BC"
config.add_sort_field "date_uploaded_dtsi asc", label: "date uploaded \u25B2"
config.add_sort_field "date_modified_dtsi desc", label: "date modified \u25BC"
config.add_sort_field "date_modified_dtsi asc", label: "date modified \u25B2"
config.add_sort_field "system_create_dtsi desc", label: "date created \u25BC"
config.add_sort_field "system_create_dtsi asc", label: "date created \u25B2"
config.add_sort_field "depositor_ssi asc, title_ssi asc", label: "depositor (A-Z)"
config.add_sort_field "depositor_ssi desc, title_ssi desc", label: "depositor (Z-A)"
config.add_sort_field "creator_ssi asc, title_ssi asc", label: "creator (A-Z)"
config.add_sort_field "creator_ssi desc, title_ssi desc", label: "creator (Z-A)"
end
end
end
end
end

Hyrax::My::WorksController.prepend(Hyrax::My::WorksControllerDecorator)
Hyrax::My::WorksController.singleton_class.send(:prepend, Hyrax::My::WorksControllerDecorator)
Hyrax::My::WorksController.configure_facets
1 change: 1 addition & 0 deletions app/forms/hyrax/generic_work_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class GenericWorkForm < Hyrax::Forms::WorkForm
self.model_class = ::GenericWork
include HydraEditor::Form::Permissions
include PdfFormBehavior
include VideoEmbedFormBehavior

self.terms += %i[resource_type bibliographic_citation]
end
Expand Down
1 change: 1 addition & 0 deletions app/forms/hyrax/image_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class ImageForm < Hyrax::Forms::WorkForm
include Hyrax::FormTerms
self.model_class = ::Image
include PdfFormBehavior
include VideoEmbedFormBehavior

self.terms += %i[resource_type extent bibliographic_citation]
end
Expand Down
15 changes: 15 additions & 0 deletions app/forms/video_embed_form_behavior.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

# frozen_sting_literal: true

module VideoEmbedFormBehavior
extend ActiveSupport::Concern

included do
self.terms += %i[video_embed]
end

def secondary_terms
super.sort!
end
end
4 changes: 2 additions & 2 deletions app/helpers/blacklight/blacklight_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,10 @@ def document_index_view_type(query_params = params)
#
# @param [String] format suffix
# @yield
def with_format(format, _block)
def with_format(format)
old_formats = formats
self.formats = [format]
yield
yield if block_given?
self.formats = old_formats
nil
end
Expand Down
1 change: 1 addition & 0 deletions app/indexers/app_indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def generate_solr_document
super.tap do |solr_doc|
solr_doc['account_cname_tesim'] = Site.instance&.account&.cname
solr_doc['bulkrax_identifier_tesim'] = object.bulkrax_identifier if object.respond_to?(:bulkrax_identifier)
solr_doc['account_institution_name_ssim'] = Site.instance.institution_label
solr_doc['all_text_tsimv'] = full_text(object.file_sets.first&.id)
add_date(solr_doc)
end
Expand Down
2 changes: 2 additions & 0 deletions app/indexers/collection_indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ class CollectionIndexer < Hyrax::CollectionIndexer
# Uncomment this block if you want to add custom indexing behavior:
def generate_solr_document
super.tap do |solr_doc|
solr_doc['bulkrax_identifier_tesim'] = object.bulkrax_identifier if object.respond_to?(:bulkrax_identifier)
solr_doc["account_cname_tesim"] = Site.instance&.account&.cname
solr_doc['account_institution_name_ssim'] = Site.instance.institution_label
end
end
end
1 change: 1 addition & 0 deletions app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def admin_permissions

super
can [:manage], [Site, Role, User]
can [:update], RolesService

can [:read, :update], Account do |account|
account == Site.account
Expand Down
24 changes: 24 additions & 0 deletions app/models/concerns/video_embed_behavior.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

module VideoEmbedBehavior
extend ActiveSupport::Concern

included do
validates :video_embed,
format: {
with: %r{(http://|https://)(www\.)?(player\.vimeo\.com|youtube\.com/embed)},
message: lambda do |_object, _data|
I18n.t('errors.messages.valid_embed_url', default: 'must be a valid YouTube or Vimeo Embed URL.')
end
},
if: :video_embed?

property :video_embed, predicate: ::RDF::URI("https://atla.com/terms/video_embed"), multiple: false do |index|
index.as :stored_searchable
end
end

def video_embed?
video_embed.present?
end
end
3 changes: 2 additions & 1 deletion app/models/generic_work.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class GenericWork < ActiveFedora::Base
include ::Hyrax::WorkBehavior
include PdfBehavior
include ::Hyrax::BasicMetadata
include VideoEmbedBehavior

if ActiveModel::Type::Boolean.new.cast(ENV.fetch('HYKU_IIIF_PRINT', false))
include IiifPrint.model_configuration(
Expand All @@ -14,5 +14,6 @@ class GenericWork < ActiveFedora::Base

validates :title, presence: { message: 'Your work must have a title.' }

include ::Hyrax::BasicMetadata
self.indexer = GenericWorkIndexer
end
1 change: 1 addition & 0 deletions app/models/image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
class Image < ActiveFedora::Base
include ::Hyrax::WorkBehavior
include PdfBehavior
include VideoEmbedBehavior

if ActiveModel::Type::Boolean.new.cast(ENV.fetch('HYKU_IIIF_PRINT', false))
include IiifPrint.model_configuration(
Expand Down
4 changes: 3 additions & 1 deletion app/models/solr_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ class SolrDocument
# Do content negotiation for AF models.
use_extension(Hydra::ContentNegotiation)

attribute :account_cname, Solr::Array, 'account_cname_tesim'
attribute :account_institution_name, Solr::Array, 'account_institution_name_ssim'
attribute :extent, Solr::Array, 'extent_tesim'
attribute :rendering_ids, Solr::Array, 'hasFormat_ssim'
attribute :account_cname, Solr::Array, 'account_cname_tesim'
attribute :video_embed, Solr::String, 'video_embed_tesim'

field_semantics.merge!(
contributor: 'contributor_tesim',
Expand Down
46 changes: 33 additions & 13 deletions app/presenters/concerns/hyrax/iiif_av/displays_content_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ module IiifAv
# request.base_url => hostname
# also to remove #auth_service since it was not working for now
module DisplaysContentDecorator
private
def solr_document
defined?(super) ? super : object
end

def solr_document
defined?(super) ? super : object
end
def current_ability
defined?(super) ? super : @ability
end

def current_ability
defined?(super) ? super : @ability
end
private

Request = Struct.new(:base_url, keyword_init: true)

Expand All @@ -42,11 +42,18 @@ def video_display_content(_url, label = '')
height = solr_document.height&.try(:to_i) || 240
duration = conformed_duration_in_seconds
IIIFManifest::V3::DisplayContent.new(
Hyrax::IiifAv::Engine.routes.url_helpers.iiif_av_content_url(
solr_document.id,
label: label,
host: request.base_url
),
# Hyrax::IiifAv::Engine.routes.url_helpers.iiif_av_content_url(
# solr_document.id,
# label: label,
# host: request.base_url
# ),
# TODO: This is a hack to pull the download url from hyrax as the video resource.
# Ultimately we want to fix the processing times of the video derivatives so it doesn't take
# hours to days to complete. The draw back of doing it this way is that we're using the original
# video file which is fine if it's already processed, but if it's a raw, then it is not ideal for
# streaming purposes. The good thing is that PALs seem to be processing the video derivatives out
# of band first before ingesting so we shouldn't run into this issue.
Hyrax::Engine.routes.url_helpers.download_url(solr_document.id, host: request.base_url, protocol: 'https'),
label: label,
width: width,
height: height,
Expand All @@ -56,6 +63,17 @@ def video_display_content(_url, label = '')
)
end

def audio_content
streams = stream_urls
if streams.present?
streams.collect { |label, url| audio_display_content(url, label) }
else
# OVERRIDE, because we're hard coding `audio/mpeg`, it doesn't make sense to support `ogg`
# See: https://github.com/samvera-labs/hyrax-iiif_av/blob/6273f90016c153d2add33f85cc24285d51a25382/app/presenters/concerns/hyrax/iiif_av/displays_content.rb#L118
audio_display_content(download_path('mp3'), 'mp3')
end
end

def audio_display_content(_url, label = '')
duration = conformed_duration_in_seconds
IIIFManifest::V3::DisplayContent.new(
Expand All @@ -67,7 +85,9 @@ def audio_display_content(_url, label = '')
label: label,
duration: duration,
type: 'Sound',
format: solr_document.mime_type
# instead of relying on the mime type of the original file, we hard code it to `audio/mpeg`
# because this is pointing to the mp3 derivative, also UV doesn't support specifically `audio/x-wave`
format: 'audio/mpeg'
)
end

Expand Down
Loading

0 comments on commit 707b447

Please sign in to comment.