diff --git a/app/controllers/concerns/publisher_controller.rb b/app/controllers/concerns/publisher_controller.rb index dbfcd2f1ea4b2e3eb871a503fed4efb606874fe5..5199dca2fe3c0f7e14ea3425539bdaa8e35e962b 100644 --- a/app/controllers/concerns/publisher_controller.rb +++ b/app/controllers/concerns/publisher_controller.rb @@ -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) diff --git a/app/models/learning_object.rb b/app/models/learning_object.rb index 5b1e65ad55b4481d99e0fe58782812a6616fd85f..215295c7c27839db3598515b25e495c264637724 100644 --- a/app/models/learning_object.rb +++ b/app/models/learning_object.rb @@ -117,7 +117,7 @@ class LearningObject < ApplicationRecord end def default_attachment - return attachment unless attachment.nil? + #return attachment unless attachment.nil? unless attachments.blank? if object_type.try(:name) == 'VÃdeo' diff --git a/app/models/user.rb b/app/models/user.rb index 08be093e7129dbaaef3322d1c0f251f5815f4249..3dadf67c5e5f5bcfb1ed06654f19a784a949cd11 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -98,6 +98,10 @@ class User < ApplicationRecord validates :terms_of_service, acceptance: true + validates :dspace_url, presence: true, if: Proc.new {|u| !u.dspace_handle.blank? || !u.dspace_sets.blank?} + + validates :dspace_handle, presence: true, if: Proc.new {|u| !u.dspace_url.blank? || !u.dspace_sets.blank?} + enum submitter_request: { default: 0, requested: 1, accepted: 2, rejected: 3 } searchkick language: 'brazilian', match: :word_start, searchable: [:name], callbacks: :async diff --git a/app/policies/learning_object_policy.rb b/app/policies/learning_object_policy.rb index baa289bffe4c6b1359e661247c6120a22f5c91e5..c37f238e19568ce58d8d08065457361cbf1934fb 100644 --- a/app/policies/learning_object_policy.rb +++ b/app/policies/learning_object_policy.rb @@ -38,7 +38,7 @@ class LearningObjectPolicy < ApplicationPolicy end def create? - record if (user_exists? && user.is_submitter?) || (user_exists? && user.is_partner?) + record if (user_exists? && user.is_submitter?) end def update? @@ -46,7 +46,7 @@ class LearningObjectPolicy < ApplicationPolicy end def publish? - record if (user_can_curate? && record.submitted?) || user.is_partner? + record if (user_can_curate? && record.submitted?) end def destroy? diff --git a/app/policies/publisher_policy.rb b/app/policies/publisher_policy.rb index 631b5eccfb79d362773e6d120033a53d7932f1bd..5df13047229f9888c91ba76bca2937845f97258a 100644 --- a/app/policies/publisher_policy.rb +++ b/app/policies/publisher_policy.rb @@ -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 diff --git a/config/routes.rb b/config/routes.rb index 3a0d2f608a008b35eb4092826bbfcf78534704eb..6d447546019431034f88f0fedb5edd17b8747687 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -79,11 +79,11 @@ Rails.application.routes.draw do concern :submission do collection do - get :submissions + get :submissions + get 'submissions/:id', action: :show_submission end member do - post :submit - get :show_submission + post :submit end 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 diff --git a/db/seeds/licenses.rb b/db/seeds/licenses.rb index c81f3f188a088ebb1ef98ecb4307187ea851b67d..d423f517217f2bedb84956a219a99ef0cda611c7 100644 --- a/db/seeds/licenses.rb +++ b/db/seeds/licenses.rb @@ -27,3 +27,4 @@ License.create(name: 'MIT', description: 'MIT', url: 'https://opensource.org/lic License.create(name: 'GPL-2.0', description: 'GNU General Public License v2', url: 'https://opensource.org/licenses/GPL-2.0', image_url: '') License.create(name: 'GPL-3.0', description: 'GNU General Public License v3', url: 'https://opensource.org/licenses/GPL-3.0', image_url: '') License.create(name: 'Apache', description: 'Apache v2', url: 'https://www.apache.org/licenses/LICENSE-2.0', image_url: '') +License.create(name: 'No information available', description: 'No information available', url: '', image_url: '') diff --git a/spec/acceptance/learning_objects_spec.rb b/spec/acceptance/learning_objects_spec.rb index de43a4729992b711f6894c25fe2188eed4e9f8b1..44e7b5e57bf59cad3df21df09ff1667f4d82868a 100644 --- a/spec/acceptance/learning_objects_spec.rb +++ b/spec/acceptance/learning_objects_spec.rb @@ -234,7 +234,7 @@ resource 'Learning Objects' do end end - get '/v1/learning_objects/:id/show_submission' do + get '/v1/learning_objects/submissions/:id' do include_context "authenticate_user_curator" let(:id) { @learning_object.id } @@ -245,7 +245,7 @@ resource 'Learning Objects' do end example 'Show a submission' do - do_request + do_request expect(status).to eq(200) end end diff --git a/spec/acceptance/users_spec.rb b/spec/acceptance/users_spec.rb index e381d1b1400963e79233ece6798b7cd0483f7f3d..df0c1526f1e813a7667b85b19cd1b3e9f0b11c2a 100644 --- a/spec/acceptance/users_spec.rb +++ b/spec/acceptance/users_spec.rb @@ -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"