Skip to content
Snippets Groups Projects
Commit 9e30ed42 authored by Clarissa's avatar Clarissa
Browse files

SCRUM#275: adding attachments index, to get easier to check

parent 6934ae8f
No related branches found
No related tags found
No related merge requests found
......@@ -19,10 +19,15 @@
class V1::LearningObjects::AttachmentController < ApplicationController
before_action :set_objects
before_action :authenticate_user!, only: :update
before_action :authenticate_user!, only: [:update, :index]
before_action :authorize!, only: :destroy
before_action :authorize_update_attachment!, only: :update
# GET /learning_objects/:learning_object_id/attachment
def index
render json: @attachment
end
# DELETE /learning_objects/:learning_object_id/attachments/:id
def destroy
return render status: :not_found if @learning_object.nil? || @attachment.nil?
......@@ -32,7 +37,7 @@ class V1::LearningObjects::AttachmentController < ApplicationController
render status: :ok
end
# PUT /learning_objects/:learning_object_id/attachments/:id
def update
return render status: :not_found if @learning_object.nil? || @attachment.nil?
......@@ -55,7 +60,11 @@ class V1::LearningObjects::AttachmentController < ApplicationController
def set_objects
@learning_object = LearningObject.find(attachment_params[:learning_object_id])
@attachment = LearningObject::Attachment.find(attachment_params[:id])
if ( attachment_params[:id].blank? )
@attachment = @learning_object.attachment
else
@attachment = LearningObject::Attachment.find(attachment_params[:id])
end
end
def authorize!
......
......@@ -168,7 +168,7 @@ Rails.application.routes.draw do
collection do
get 'validate'
end
resources :attachment, module: 'learning_objects', only: [:destroy, :update], on: :member
resources :attachment, module: 'learning_objects', only: [:destroy, :update, :index], on: :member
end
resources :institutions, concerns: :deletable do
......
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