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



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

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



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

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



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

def edit
  build_form
end

#file_managerObject



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

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

#inspect_workObject

Raises:

  • (Hydra::AccessDenied)


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

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

#manifestObject



129
130
131
132
133
134
135
136
137
138
# File 'app/controllers/concerns/hyrax/works_controller_behavior.rb', line 129

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



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

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.



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

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



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

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