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
# File 'app/controllers/concerns/hyrax/works_controller_behavior.rb', line 57

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



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

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



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

def edit
  build_form
end

#file_managerObject



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

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

#inspect_workObject

Raises:

  • (Hydra::AccessDenied)


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

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

#newObject



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

def new
  # TODO: move these lines to the work form builder in Hyrax
  curation_concern.depositor = current_user.user_key

  # admin_set_id is required on the client, otherwise simple_form renders a blank option.
  # however it isn't a required field for someone to submit via json.
  # Set the first admin_set they have access to.
  admin_set = Hyrax::AdminSetService.new(self).search_results(:deposit).first
  curation_concern.admin_set_id = admin_set && admin_set.id
  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.



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

def show
  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



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

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