diff --git a/app/controllers/concerns/submission_controller.rb b/app/controllers/concerns/submission_controller.rb index 3bb83748a7f7e4aa38768f79fcb1171ea56b2c66..72481197cdd61dfc99497301c94f427f2cc0dc94 100644 --- a/app/controllers/concerns/submission_controller.rb +++ b/app/controllers/concerns/submission_controller.rb @@ -4,6 +4,7 @@ module SubmissionController included do before_action :set_new_submission, only: :submit + before_action :set_submission, only: :show_submission before_action :authorize! end @@ -22,6 +23,11 @@ module SubmissionController end end + def show_submission + return render status: :ok if @learning_object.draft? || @learning_object.published? + render json: @learning_object + end + private def submitted @@ -32,4 +38,8 @@ module SubmissionController @learning_object = LearningObject.find(params[:id]) end + def set_submission + @learning_object ||= LearningObject.find(params[:id]) + end + end diff --git a/app/controllers/v1/learning_objects_controller.rb b/app/controllers/v1/learning_objects_controller.rb index 739e9489a62ef5c4d7fc991f196357327e754892..1639ae3566e9cec14357c7589cddf84d66777728 100644 --- a/app/controllers/v1/learning_objects_controller.rb +++ b/app/controllers/v1/learning_objects_controller.rb @@ -11,10 +11,11 @@ class V1::LearningObjectsController < ApplicationController include ::StageableController include ::SubmissionController - before_action :authenticate_user!, only: [:create, :update, :destroy, :tagging, :untagging, :submit, :submission] + before_action :authenticate_user!, only: [:create, :update, :destroy, :tagging, :untagging, :submit, :submission, :show_submission] before_action :set_learning_object, only: [:show, :update, :destroy, :subjecting, :unsubjecting, :add_stages, :remove_stages] before_action :set_new_learning_object, only: [:index, :submissions] before_action :set_new_submission, only: :submit + before_action :set_submission, only: :show_submission before_action :authorize!, except: [:create, :tagging, :untagging, :download, :magnetlink] before_action :set_paper_trail_whodunnit, except: [:index, :show] diff --git a/app/policies/submission_policy.rb b/app/policies/submission_policy.rb index 9018431be275b2acec87f27e937fb1922e2679f8..345ec5e5f610d7c5fe360bac19e1b5f88a61ca67 100644 --- a/app/policies/submission_policy.rb +++ b/app/policies/submission_policy.rb @@ -9,4 +9,9 @@ module SubmissionPolicy record if user_can_moderate? end + def show_submission? + return false if user.nil? + record if user_can_moderate? + end + end diff --git a/config/routes.rb b/config/routes.rb index d86ea9a09846c36fd51537e1845cac8a7b20eba3..0f1be12739d4bd907828bc5e6580340541c46afc 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -64,6 +64,7 @@ Rails.application.routes.draw do end member do post :submit + get :show_submission end end