Module: Hyrax::WorksControllerBehavior

Extended by:
ActiveSupport::Concern
Includes:
Blacklight::AccessControls::Catalog, Blacklight::Base
Included in:
BatchUploadsController, CitationsController
Defined in:
app/controllers/concerns/hyrax/works_controller_behavior.rb

Instance Method Summary collapse

Instance Method Details

#createObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'app/controllers/concerns/hyrax/works_controller_behavior.rb', line 57

def create
  # Caching the original input params in case the form is not valid
  original_input_params_for_form = params[hash_key_for_curation_concern].deep_dup
  if create_work
    after_create_response
  else
    respond_to do |wants|
      wants.html do
        build_form
        # Creating a form object that can re-render most of the
        # submitted parameters
        @form = Hyrax::Forms::FailedSubmissionFormWrapper.new(form: @form, input_params: original_input_params_for_form)
        render 'new', status: :unprocessable_entity
      end
      wants.json { render_json_response(response_type: :unprocessable_entity, options: { errors: curation_concern.errors }) }
    end
  end
end

#destroyObject



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

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 })
      .call(curation_concern)
      .value!

    title = Array(curation_concern.title).first
  end

  after_destroy_response(title)
end

#editObject

rubocop:enable Metrics/AbcSize



98
99
100
101
# File 'app/controllers/concerns/hyrax/works_controller_behavior.rb', line 98

def edit
  @admin_set_options = available_admin_sets
  build_form
end

#file_managerObject



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

def file_manager
  @form = Forms::FileManagerForm.new(curation_concern, current_ability)
end

#inspect_workObject

Raises:

  • (Hydra::AccessDenied)


140
141
142
143
# File 'app/controllers/concerns/hyrax/works_controller_behavior.rb', line 140

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

#manifestObject



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

def manifest
  headers['Access-Control-Allow-Origin'] = '*'

  json = iiif_manifest_builder.manifest_for(presenter: iiif_manifest_presenter)

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

#newObject



49
50
51
52
53
54
55
# File 'app/controllers/concerns/hyrax/works_controller_behavior.rb', line 49

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 = admin_set_id_for_new
  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.



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'app/controllers/concerns/hyrax/works_controller_behavior.rb', line 79

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 = Hyrax.query_service.find_by_alternate_identifier(alternate_identifier: params[:id])
      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)
    wants.ttl { render body: presenter.export_as_ttl, mime_type: Mime[:ttl] }
    wants.jsonld { render body: presenter.export_as_jsonld, mime_type: Mime[:jsonld] }
    wants.nt { render body: presenter.export_as_nt, mime_type: Mime[:nt] }
  end
end

#updateObject



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

def update
  if update_work
    after_update_response
  else
    respond_to do |wants|
      wants.html do
        build_form
        render 'edit', status: :unprocessable_entity
      end
      wants.json { render_json_response(response_type: :unprocessable_entity, options: { errors: curation_concern.errors }) }
    end
  end
end