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

Merge branch 'issue/321' into 'master'

Create a route to return lo's submitted by an user

See merge request portalmec/portalmec!485
parents 429bd874 7b0f623c
No related branches found
No related tags found
No related merge requests found
......@@ -21,9 +21,9 @@ module PublisherController
extend ActiveSupport::Concern
included do
before_action :authenticate, only: [:show_all_drafts, :show_liked_learning_objects, :show_liked_collections]
before_action :set_publisher, only: [:show_all_drafts, :show_all_learning_objects, :show_all_collections, :show_liked_learning_objects, :show_liked_collections]
before_action -> { authorize @publisher }, only: [:show_all_drafts, :show_liked_learning_objects, :show_liked_collections]
before_action :authenticate, only: [:show_all_drafts, :show_liked_learning_objects, :show_submitted_learning_objects, :show_liked_collections]
before_action :set_publisher, only: [:show_all_drafts, :show_all_learning_objects, :show_submitted_learning_objects, :show_all_collections, :show_liked_learning_objects, :show_liked_collections]
before_action -> { authorize @publisher }, only: [:show_all_drafts, :show_submitted_learning_objects, :show_liked_learning_objects, :show_liked_collections]
end
def show_all_drafts
......@@ -35,6 +35,10 @@ module PublisherController
render json: LearningObject.where(publisher: @publisher, state: LearningObject.states[:published])
end
def show_submitted_learning_objects
render json: LearningObject.where(publisher: @publisher, state: LearningObject.states[:submitted])
end
def show_all_collections
render json: ::UserPolicy::Scope.new(current_user, @publisher, Collection).resolve.where(owner: @publisher)
end
......@@ -59,7 +63,7 @@ module PublisherController
end
def set_publisher
user, id = request.path.split('/')[2, 3]
user, id = request.path.split('/')[2, 2]
return nil unless %w(users institutions).include? user
publisher_model = user.singularize.classify.constantize
@publisher = publisher_model.find(id)
......
......@@ -24,7 +24,7 @@ module PublisherPolicy
def initialize(user, record, scope)
@user = user
@record = user
@record = record
@scope = scope
end
......@@ -47,6 +47,10 @@ module PublisherPolicy
record if same_user? || user_can_edit?
end
def show_submitted_learning_objects?
record if same_user? || user_can_edit?
end
def show_liked_collections?
record if same_user? || user_can_edit?
end
......
......@@ -100,6 +100,7 @@ Rails.application.routes.draw do
get 'drafts', as: :get_drafts, action: :show_all_drafts
get 'learning_objects', as: :get_learning_objects, action: :show_all_learning_objects
get 'learning_objects/liked', as: :get_liked_learning_objects, action: :show_liked_learning_objects
get 'submissions', as: :get_submitted_learning_objects, action: :show_submitted_learning_objects
get 'collections', as: :get_collections, action: :show_all_collections
get 'collections/liked', as: :get_liked_collections, action: :show_liked_collections
end
......
......@@ -292,6 +292,21 @@ resource 'Users' do
end
end
get '/v1/users/:id/submissions' do
include_context "authenticate_user"
before do
create(:learning_object, publisher: @user, state: LearningObject.states[:submitted])
end
let(:id) { @user.id }
example 'Showing an user’s submissions' do
do_request
expect(status).to eq(200)
end
end
delete '/v1/auth' do
include_context "authenticate_user"
......
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