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



53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'app/controllers/concerns/hyrax/works_controller_behavior.rb', line 53

def create
  if actor.create(actor_environment)
    after_create_response
  else
    respond_to do |wants|
      wants.html do
        build_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



111
112
113
114
115
116
117
# File 'app/controllers/concerns/hyrax/works_controller_behavior.rb', line 111

def destroy
  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)
  after_destroy_response(title)
end

#editObject



93
94
95
# File 'app/controllers/concerns/hyrax/works_controller_behavior.rb', line 93

def edit
  build_form
end

#file_managerObject



119
120
121
# File 'app/controllers/concerns/hyrax/works_controller_behavior.rb', line 119

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

#inspect_workObject

Raises:

  • (Hydra::AccessDenied)


123
124
125
126
# File 'app/controllers/concerns/hyrax/works_controller_behavior.rb', line 123

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

#manifestObject



128
129
130
131
132
133
134
# File 'app/controllers/concerns/hyrax/works_controller_behavior.rb', line 128

def manifest
  headers['Access-Control-Allow-Origin'] = '*'
  respond_to do |wants|
    wants.json { render json: manifest_builder.to_h }
    wants.html { render json: manifest_builder.to_h }
  end
end

#newObject



46
47
48
49
50
51
# File 'app/controllers/concerns/hyrax/works_controller_behavior.rb', line 46

def new
  # 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

Raises:

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



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'app/controllers/concerns/hyrax/works_controller_behavior.rb', line 69

def show
  @user_collections = user_collections

  respond_to do |wants|
    wants.html { presenter && parent_presenter }
    wants.json do
      # load and authorize @curation_concern manually because it's skipped for html
      @curation_concern = _curation_concern_type.find(params[:id]) unless curation_concern
      authorize! :show, @curation_concern
      render :show, status: :ok
    end
    additional_response_formats(wants)
    wants.ttl do
      render body: presenter.export_as_ttl, content_type: 'text/turtle'
    end
    wants.jsonld do
      render body: presenter.export_as_jsonld, content_type: 'application/ld+json'
    end
    wants.nt do
      render body: presenter.export_as_nt, content_type: 'application/n-triples'
    end
  end
end

#updateObject



97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'app/controllers/concerns/hyrax/works_controller_behavior.rb', line 97

def update
  if actor.update(actor_environment)
    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