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

Merge branch 'curator' of gitlab.c3sl.ufpr.br:portalmec/portalmec into user-profiles

parents b1813bf1 9f0b788b
No related branches found
No related tags found
No related merge requests found
module SubmissionController
extend ActiveSupport::Concern
include ::Paginator
included do
before_action :set_new_submission, only: :submit
before_action :authorize!
end
def submissions
learning_objects = paginate LearningObject.where(state: LearningObject.states[:submitted])
render json: learning_objects
end
def submit
return render status: :ok if @learning_object.submitted?
if @learning_object.update(state: LearningObject.states[:submitted])
render json: @learning_object, status: :ok
else
render json: @learning_object.errors, status: :unprocessable_entity
end
end
private
def submitted
return @learning_object.submitted?
end
def set_new_submission
@learning_object = LearningObject.find(params[:id])
end
end
......@@ -20,7 +20,7 @@ class V1::LearningObjects::PublishesController < ApplicationController
end
def authorize!
authorize(@learning_object || LearningObject.new, :update?)
authorize(@learning_object, :publish?)
end
# Never trust parameters from the scary internet, only allow the white list through.
......
......@@ -9,10 +9,12 @@ class V1::LearningObjectsController < ApplicationController
include ::HighlightsController
include ::SubjectableController
include ::StageableController
include ::SubmissionController
before_action :authenticate_user!, only: [:create, :update, :destroy, :tagging, :untagging]
before_action :authenticate_user!, only: [:create, :update, :destroy, :tagging, :untagging, :submit, :submission]
before_action :set_learning_object, only: [:show, :update, :destroy, :subjecting, :unsubjecting, :add_stages, :remove_stages]
before_action :set_new_learning_object, only: :index
before_action :set_new_learning_object, only: [:index, :submissions]
before_action :set_new_submission, only: :submit
before_action :authorize!, except: [:create, :tagging, :untagging, :download, :magnetlink]
before_action :set_paper_trail_whodunnit, except: [:index, :show]
......
......@@ -2,6 +2,6 @@ module Stateful
extend ActiveSupport::Concern
included do
enum state: { draft: 0, published: 1, suspended: 2 }
enum state: { draft: 0, published: 1, suspended: 2, submitted: 3 }
end
end
......@@ -99,6 +99,13 @@ class User < ApplicationRecord
false
end
def is_curator?
roles.each do |role|
return true if role.name == 'curator'
end
false
end
def is_moderator?
roles.each do |role|
return true if role.name == 'moderator'
......
......@@ -59,6 +59,10 @@ class ApplicationPolicy
user.is_admin? || user.is_moderator?
end
def user_can_curate?
user.is_curator?
end
class Scope < ApplicationPolicy
attr_reader :user, :scope
......
......@@ -4,6 +4,7 @@ class LearningObjectPolicy < ApplicationPolicy
include TaggablePolicy
include SubjectablePolicy
include StageablePolicy
include SubmissionPolicy
class Scope < Scope
def resolve
......@@ -25,6 +26,10 @@ class LearningObjectPolicy < ApplicationPolicy
record if owns?
end
def publish?
record if user_can_curate? && record.submitted?
end
def destroy?
record if owns?
end
......
module SubmissionPolicy
def submit?
record if owns?
end
def submissions?
return false if user.nil?
record if user_can_curate?
end
end
......@@ -58,6 +58,15 @@ Rails.application.routes.draw do
end
end
concern :submission do
collection do
get :submissions
end
member do
post :submit
end
end
concern :highlights do
collection do
get :this_week
......@@ -124,7 +133,7 @@ Rails.application.routes.draw do
end
end
resources :learning_objects, concerns: [:sociable, :downloadable, :reviewable, :taggable, :versionable, :deletable, :highlights, :subjectable, :stageable] do
resources :learning_objects, concerns: [:sociable, :downloadable, :reviewable, :taggable, :versionable, :deletable, :highlights, :subjectable, :stageable, :submission] do
member do
resource :chunk, module: 'learning_objects', only: [:create, :show]
resource :upload, module: 'learning_objects', only: :create
......
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