From 71f4d0ba4474ef8064f58c96d5a8284a410149cd Mon Sep 17 00:00:00 2001 From: Mason Ballengee Date: Thu, 14 Nov 2024 13:47:30 -0500 Subject: [PATCH] Use SpeedyAF when loading edit pages --- app/controllers/media_objects_controller.rb | 6 ++--- .../speedy_af/proxy/admin/collection.rb | 8 +++++++ .../speedy_af/proxy/media_object.rb | 12 ++++++++++ config/initializers/workflow_steps.rb | 22 +++++++++++++++++++ 4 files changed, 45 insertions(+), 3 deletions(-) diff --git a/app/controllers/media_objects_controller.rb b/app/controllers/media_objects_controller.rb index 8ed6e67940..b10602f256 100644 --- a/app/controllers/media_objects_controller.rb +++ b/app/controllers/media_objects_controller.rb @@ -24,9 +24,9 @@ class MediaObjectsController < ApplicationController include SecurityHelper before_action :authenticate_user!, except: [:show, :set_session_quality, :show_stream_details, :manifest] - before_action :load_resource, except: [:create, :destroy, :update_status, :set_session_quality, :tree, :deliver_content, :confirm_remove, :show_stream_details, :add_to_playlist, :intercom_collections, :manifest, :move_preview, :edit, :update, :json_update] - load_and_authorize_resource except: [:create, :destroy, :update_status, :set_session_quality, :tree, :deliver_content, :confirm_remove, :show_stream_details, :add_to_playlist, :intercom_collections, :manifest, :move_preview, :show_progress] - authorize_resource only: [:create] + before_action :load_resource, except: [:create, :destroy, :update_status, :set_session_quality, :tree, :deliver_content, :confirm_remove, :show_stream_details, :add_to_playlist, :intercom_collections, :manifest, :move_preview, :update, :json_update] + load_and_authorize_resource except: [:create, :destroy, :update_status, :set_session_quality, :tree, :deliver_content, :confirm_remove, :show_stream_details, :add_to_playlist, :intercom_collections, :manifest, :move_preview, :show_progress, :edit] + authorize_resource only: [:create, :edit] before_action :inject_workflow_steps, only: [:edit, :update], unless: proc { request.format.json? } before_action :load_player_context, only: [:show] diff --git a/app/presenters/speedy_af/proxy/admin/collection.rb b/app/presenters/speedy_af/proxy/admin/collection.rb index 173cdcc53e..99ceccaa69 100644 --- a/app/presenters/speedy_af/proxy/admin/collection.rb +++ b/app/presenters/speedy_af/proxy/admin/collection.rb @@ -31,6 +31,14 @@ def to_model self end + def dropbox + Avalon::Dropbox.new( dropbox_absolute_path, self ) + end + + def dropbox_absolute_path( name = nil ) + File.join(Settings.dropbox.path, name || dropbox_directory_name) + end + def persisted? id.present? end diff --git a/app/presenters/speedy_af/proxy/media_object.rb b/app/presenters/speedy_af/proxy/media_object.rb index 308d1ddd4a..8b2c08d693 100644 --- a/app/presenters/speedy_af/proxy/media_object.rb +++ b/app/presenters/speedy_af/proxy/media_object.rb @@ -12,7 +12,11 @@ # specific language governing permissions and limitations under the License. # --- END LICENSE_HEADER BLOCK --- +require 'active_model' + class SpeedyAF::Proxy::MediaObject < SpeedyAF::Base + extend ActiveModel::Translation + SINGULAR_FIELDS = [:title, :statement_of_responsibility, :date_created, :date_issued, :copyright_date, :abstract, :terms_of_use, :rights_statement] HASH_FIELDS = [:note, :other_identifier, :related_item_url] @@ -44,8 +48,12 @@ def initialize(solr_document, instance_defaults = {}) end # Convert empty strings to nil @attrs.transform_values! { |value| value == "" ? nil : value } + @errors = ActiveModel::Errors.new(self) end + attr_accessor :name + attr_accessor :errors + def to_model self end @@ -152,6 +160,10 @@ def permalink_with_query(query_vars = {}) val ? val.to_s : nil end + def workflow + WorkflowDatastream.find("#{id}/workflow") + end + protected # Overrides from SpeedyAF::Base diff --git a/config/initializers/workflow_steps.rb b/config/initializers/workflow_steps.rb index 4d83323c93..26519201b5 100644 --- a/config/initializers/workflow_steps.rb +++ b/config/initializers/workflow_steps.rb @@ -3,4 +3,26 @@ ResourceDescriptionStep.new, StructureStep.new, AccessControlStep.new) + + # Override context building so edit page rendering skips fedora + Avalon::Workflow::WorkflowControllerBehavior.class_eval do + def model_object + @model_object = if params[:action] == "edit" + SpeedyAF::Base.find(params[:id]) + else + ActiveFedora::Base.find(params[:id], cast: true) + end + end + + # def perform_step_action action + # context = if action == :before_step + # HYDRANT_STEPS.get_step(@active_step).send(action, params.merge!({ user: user_key })) + # else + # HYDRANT_STEPS.get_step(@active_step).send(action, build_context) + # end + + # context_to_instance_variables context + # context + # end + end end