Module: Hyrax::WorksControllerBehavior

Extended by:
ActiveSupport::Concern
Includes:
Blacklight::AccessControls::Catalog, Blacklight::Configurable, Blacklight::SearchContext, EnsureMigratedBehavior, FlexibleSchemaBehavior, RedirectToDisplayUrl
Included in:
BatchUploadsController, CitationsController
Defined in:
app/controllers/concerns/hyrax/works_controller_behavior.rb

Instance Method Summary collapse

Instance Method Details

#createObject



71
72
73
74
75
76
77
78
79
# File 'app/controllers/concerns/hyrax/works_controller_behavior.rb', line 71

def create
  case curation_concern
  when ActiveFedora::Base
    original_input_params_for_form = params[hash_key_for_curation_concern].deep_dup
    actor.create(actor_environment) ? after_create_response : after_create_error(curation_concern.errors, original_input_params_for_form)
  else
    create_valkyrie_work
  end
end

#destroyObject



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'app/controllers/concerns/hyrax/works_controller_behavior.rb', line 114

def destroy
  case curation_concern
  when ActiveFedora::Base
    title = curation_concern.to_s
    env = Actors::Environment.new(curation_concern, current_ability, {})
    return unless actor.destroy(env)
    Hyrax.config.callback.run(:after_destroy, curation_concern.id, current_user, warn: false)
  else
    transactions['work_resource.destroy']
      .with_step_args('work_resource.delete' => { user: current_user },
                      'work_resource.delete_all_file_sets' => { user: current_user })
      .call(curation_concern).value!

    title = Array(curation_concern.title).first
  end

  after_destroy_response(title)
end

#editObject

rubocop:enable Metrics/AbcSize



100
101
102
103
# File 'app/controllers/concerns/hyrax/works_controller_behavior.rb', line 100

def edit
  @admin_set_options = available_admin_sets
  build_form
end

#file_managerObject



133
134
135
# File 'app/controllers/concerns/hyrax/works_controller_behavior.rb', line 133

def file_manager
  @form = presenter
end

#inspect_workObject

Raises:

  • (Hydra::AccessDenied)


137
138
139
140
# File 'app/controllers/concerns/hyrax/works_controller_behavior.rb', line 137

def inspect_work
  raise Hydra::AccessDenied unless current_ability.admin?
  presenter
end

#manifestObject



142
143
144
145
146
147
148
149
150
151
152
153
# File 'app/controllers/concerns/hyrax/works_controller_behavior.rb', line 142

def manifest
  locale = params[:locale] || current_user&.preferred_locale || I18n.default_locale
  I18n.with_locale(locale) do
    headers['Access-Control-Allow-Origin'] = '*'

    json = iiif_manifest_builder.manifest_for(presenter: iiif_manifest_presenter)

    respond_to do |wants|
      wants.any { render json: json }
    end
  end
end

#newObject



62
63
64
65
66
67
68
69
# File 'app/controllers/concerns/hyrax/works_controller_behavior.rb', line 62

def new
  @admin_set_options = available_admin_sets
  # TODO: move these lines to the work form builder in Hyrax
  curation_concern.depositor = current_user.user_key
  curation_concern.admin_set_id = params[:admin_set_id] || admin_set_id_for_new
  curation_concern.contexts = Hyrax.query_service.find_by(id: curation_concern.admin_set_id)&.contexts if curation_concern.flexible?
  build_form
end

#showObject

Finds a solr document matching the id and sets @presenter rubocop:disable Metrics/AbcSize

Raises:

  • CanCan::AccessDenied if the document is not found or the user doesn't have access to it.



84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'app/controllers/concerns/hyrax/works_controller_behavior.rb', line 84

def show
  @user_collections = user_collections

  respond_to do |wants|
    wants.html { presenter && parent_presenter }
    wants.json do
      # load @curation_concern manually because it's skipped for html
      @curation_concern = load_curation_concern
      curation_concern # This is here for authorization checks (we could add authorize! but let's use the same method for CanCanCan)
      render :show, status: :ok
    end
    additional_response_formats(wants)
  end
end

#updateObject



105
106
107
108
109
110
111
112
# File 'app/controllers/concerns/hyrax/works_controller_behavior.rb', line 105

def update
  case curation_concern
  when ActiveFedora::Base
    actor.update(actor_environment) ? after_update_response : after_update_error(curation_concern.errors)
  else
    update_valkyrie_work
  end
end