Forked from
PortalMEC / portalmec
1290 commits behind the upstream repository.
-
Mateus Rambo Strey authoredMateus Rambo Strey authored
attachment_controller.rb 864 B
class V1::LearningObjects::AttachmentController < ApplicationController
before_action :set_objects
before_action :authorize!
# DELETE /learning_objects/:learning_object_id/attachments/:attachment_id
def destroy
return render status: :not_found if @learning_object.nil? || @attachment.nil?
destroy_attachment_in_dspace(@attachment.id_dspace)
@attachment.destroy
render status: :ok
end
private
def attachment_params
params.permit(:learning_object_id, :id)
end
def set_objects
@learning_object = LearningObject.find(attachment_params[:learning_object_id])
@attachment = LearningObject.find(attachment_params[:id])
end
def authorize!
authorize(@learning_object, :destroy?)
end
def destroy_attachment_in_dspace(id)
client = DspaceService.create_client
client.bitstreams.delete(id: id)
end
end