Skip to content
Snippets Groups Projects
Commit 975fb34b authored by Marcela Ribeiro de Oliveira's avatar Marcela Ribeiro de Oliveira
Browse files

Merge branch 'revert-ee12496c' into 'master'

Revert "Merge branch 'issue/275' into 'master'"

See merge request portalmec/portalmec!473
parents ee12496c 34cce86b
No related branches found
No related tags found
No related merge requests found
......@@ -27,7 +27,7 @@ class V1::LearningObjects::AttachmentController < ApplicationController
# GET /learning_objects/:learning_object_id/attachment
def index
@attachment = paginate @attachment
@attachment = paginate LearningObject::Attachment.includes(:attachment)
render json: @attachment
end
......@@ -68,18 +68,13 @@ class V1::LearningObjects::AttachmentController < ApplicationController
end
def update_params
params.permit(:learning_object_attachment_id, :learning_object_attachment_id_son, :infohash)
params.permit(:attachment_id, :infohash)
end
def set_objects
if current_user.try(:is_admin?)
@learning_object = LearningObject.unscoped.find(attachment_params[:learning_object_id])
else
@learning_object = LearningObject.find(attachment_params[:learning_object_id])
end
@learning_object = LearningObject.find(attachment_params[:learning_object_id])
if ( attachment_params[:id].blank? )
@attachment = @learning_object.attachments
@attachment = @learning_object.attachment
else
@attachment = LearningObject::Attachment.find(attachment_params[:id])
end
......
......@@ -45,9 +45,10 @@ class LearningObject::Attachment < ApplicationRecord
include ::Thumbnailable
belongs_to :learning_object
scope :unknown_mime_type, ->() { where(format: 'Unknown') }
has_one :learning_object_attachment, as: :learning_object_attachment_id_son
belongs_to :learning_object_attachment
has_one :attachment, class_name: 'LearningObject::Attachment'
belongs_to :attachment, class_name: 'LearningObject::Attachment'
# has_and_belongs_to_many
# belongs_to
def retrieve_url
"#{DspaceService.link}/rest#{retrieve_link}"
......
......@@ -34,6 +34,5 @@ class LearningObject::AttachmentSerializer < ActiveModel::Serializer
:id_dspace,
:thumbnail,
:cache_link,
:learning_object_attachment_id,
:learning_object_attachment_id_son
:attachment_id
end
class RemoveAttachmentIdForLearningObjectAttachments < ActiveRecord::Migration[5.0]
class UpdateLearningObjectAttachmentsForeignKey < ActiveRecord::Migration[5.0]
def change
remove_index :learning_object_attachments, :attachment_id
remove_foreign_key :learning_object_attachments, :learning_object_attachments
remove_column :learning_object_attachments, :attachment_id
add_foreign_key :learning_object_attachments, :learning_object_attachments, column: :attachment_id, on_delete: :cascade
end
end
class RemoveLearningObjectAttachmentsForeignKeyOnCascade < ActiveRecord::Migration[5.0]
def change
remove_foreign_key :learning_object_attachments, :learning_object_attachments
end
end
class AddForeignKeyToLearningObjectAttachments < ActiveRecord::Migration[5.0]
def change
add_column :learning_object_attachments, :learning_object_attachment_id, :integer
add_column :learning_object_attachments, :learning_object_attachment_id_son, :integer
add_foreign_key :learning_object_attachments, :learning_object_attachments, on_delete: :cascade
add_foreign_key :learning_object_attachments, :learning_object_attachments, column: :learning_object_attachment_id_son, on_delete: :nullify
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment