diff --git a/app/controllers/concerns/stageable_controller.rb b/app/controllers/concerns/stageable_controller.rb new file mode 100644 index 0000000000000000000000000000000000000000..c10593ebf6e364649f833ef678a0577dc327a171 --- /dev/null +++ b/app/controllers/concerns/stageable_controller.rb @@ -0,0 +1,28 @@ +module StageableController + extend ActiveSupport::Concern + + included do + before_action :authenticate_user!, only: [:add_stages, :remove_stages] + end + + # POST /v1/learning_objects/1/educational_stages + # POST /v1/learning_objects/1/educational_stages.json + def add_stages + stageable.add_educational_stages(ids: params[:educational_stages]) + render json: stageable.educational_stages, status: :created + end + + # DELETE /v1/learning_objects/1/educational_stages + # DELETE /v1/learning_objects/1/educational_stages.json + def remove_stages + stageable.remove_educational_stages(ids: params[:educational_stages]) + render json: stageable.educational_stages, status: :ok + end + + protected + + def stageable + raise NotImplementedError + end + +end diff --git a/app/controllers/concerns/subjectable_controller.rb b/app/controllers/concerns/subjectable_controller.rb new file mode 100644 index 0000000000000000000000000000000000000000..9e712be0faa1f91599f7f66e1f61cc3185a7a938 --- /dev/null +++ b/app/controllers/concerns/subjectable_controller.rb @@ -0,0 +1,28 @@ +module SubjectableController + extend ActiveSupport::Concern + + included do + before_action :authenticate_user!, only: [:subjecting, :unsubjecting] + end + + # POST /v1/learning_objects/1/subjects + # POST /v1/learning_objects/1/subjects.json + def subjecting + subjectable.add_subjects(ids: params[:subjects]) + render json: subjectable.subjects, status: :created + end + + # DELETE /v1/learning_objects/1/subjects + # DELETE /v1/learning_objects/1/subjects.json + def unsubjecting + subjectable.remove_subjects(ids: params[:subjects]) + render json: subjectable.subjects, status: :ok + end + + protected + + def subjectable + raise NotImplementedError + end + +end diff --git a/app/controllers/v1/collections_controller.rb b/app/controllers/v1/collections_controller.rb index 4c7a2fd58b1a0c8f8044fa1d29b4b9c339ff0227..b908899964e33658e5a23d95a254b5626c6106eb 100644 --- a/app/controllers/v1/collections_controller.rb +++ b/app/controllers/v1/collections_controller.rb @@ -5,9 +5,11 @@ class V1::CollectionsController < ApplicationController include ::DeletedObjectsController include ::HighlightsController include ::Paginator + include ::SubjectableController + include ::StageableController before_action :authenticate_user!, only: [:create, :update, :destroy] - before_action :set_collection, only: [:show, :update, :destroy, :add_object, :delete_object] + before_action :set_collection, only: [:show, :update, :destroy, :add_object, :delete_object, :subjecting, :unsubjecting, :add_stages, :remove_stages] before_action :set_new_collection, only: :index before_action :authorize!, except: [:create, :tagging, :untagging] @@ -81,6 +83,8 @@ class V1::CollectionsController < ApplicationController def followable; set_collection; end def taggable; set_collection; end def sociable; set_collection; end + def subjectable; set_collection; end + def stageable; set_collection; end def set_collection @collection ||= Collection.find(params[:id]) diff --git a/app/controllers/v1/learning_objects_controller.rb b/app/controllers/v1/learning_objects_controller.rb index 7df72a14dc186d85273f8603780652e4eb6c1fea..b42445adc219a22e3580ba2a69dd75118407ecba 100644 --- a/app/controllers/v1/learning_objects_controller.rb +++ b/app/controllers/v1/learning_objects_controller.rb @@ -6,9 +6,11 @@ class V1::LearningObjectsController < ApplicationController include ::Paginator include ::DeletedObjectsController include ::HighlightsController + include ::SubjectableController + include ::StageableController - before_action :authenticate_user!, except: [:create, :index, :show] - before_action :set_learning_object, only: [:show, :update, :destroy] + before_action :authenticate_user!, only: [:create, :update, :destroy] + 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 :authorize!, except: [:create, :tagging, :untagging] @@ -69,6 +71,8 @@ class V1::LearningObjectsController < ApplicationController def highlights_resource; LearningObject; end def sociable; set_learning_object; end def taggable; set_learning_object; end + def subjectable; set_learning_object; end + def stageable; set_learning_object; end # Use callbacks to share common setup or constraints between actions. def set_learning_object diff --git a/app/policies/collection_policy.rb b/app/policies/collection_policy.rb index a73da7457e7c1df2f574b9c478edd6eef216f8fc..8aeafcd2e3301106ac7b09318f47d12ce57b1593 100644 --- a/app/policies/collection_policy.rb +++ b/app/policies/collection_policy.rb @@ -2,6 +2,8 @@ class CollectionPolicy < ApplicationPolicy include SociablePolicy include FollowablePolicy include TaggablePolicy + include SubjectablePolicy + include StageablePolicy class Scope < Scope def initialize(user, user_id, scope) diff --git a/app/policies/learning_object_policy.rb b/app/policies/learning_object_policy.rb index fcf3fd3f217ebc992355628d3e74e3a1d173a9de..b35e77b0de8910086dc3d272455a2648d59ab8e9 100644 --- a/app/policies/learning_object_policy.rb +++ b/app/policies/learning_object_policy.rb @@ -2,6 +2,8 @@ class LearningObjectPolicy < ApplicationPolicy include SociablePolicy include ReportablePolicy include TaggablePolicy + include SubjectablePolicy + include StageablePolicy class Scope < Scope def resolve diff --git a/app/policies/stageable_policy.rb b/app/policies/stageable_policy.rb new file mode 100644 index 0000000000000000000000000000000000000000..62618be71f36d32a959a2eac874a3c30d17c5177 --- /dev/null +++ b/app/policies/stageable_policy.rb @@ -0,0 +1,11 @@ +module StageablePolicy + + def add_stages? + record if owns? + end + + def remove_stages? + record if owns? + end + +end diff --git a/app/policies/subjectable_policy.rb b/app/policies/subjectable_policy.rb new file mode 100644 index 0000000000000000000000000000000000000000..4133417c472573f927cd35e5e8a1d548b4ad5e56 --- /dev/null +++ b/app/policies/subjectable_policy.rb @@ -0,0 +1,11 @@ +module SubjectablePolicy + + def subjecting? + record if owns? + end + + def unsubjecting? + record if owns? + end + +end diff --git a/config/routes.rb b/config/routes.rb index 8f18a468949fa5def74f85f661490431443612a9..c799fa8d47ee6d0fa4e7c88aba4bfcde0bc5ad90 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -22,6 +22,20 @@ Rails.application.routes.draw do end end + concern :subjectable do + member do + post 'subjects', as: :subjecting, action: :subjecting + delete 'subjects', as: :unsubjecting, action: :unsubjecting + end + end + + concern :stageable do + member do + post 'educational_stages', as: :add_stages, action: :add_stages + delete 'educational_stages', as: :remove_stages, action: :remove_stages + end + end + concern :sociable do member do post 'like', as: :like, action: :like @@ -95,14 +109,14 @@ Rails.application.routes.draw do end end - resources :collections, concerns: [:followable, :sociable, :reviewable, :taggable, :versionable, :deletable, :highlights] do + resources :collections, concerns: [:followable, :sociable, :reviewable, :taggable, :versionable, :deletable, :highlights, :subjectable, :stageable] do member do post :items, to: 'collections#add_object' delete :items, to: 'collections#delete_object' end end - resources :learning_objects, concerns: [:sociable, :reviewable, :taggable, :versionable, :deletable, :highlights] do + resources :learning_objects, concerns: [:sociable, :reviewable, :taggable, :versionable, :deletable, :highlights, :subjectable, :stageable] do member do resource :chunk, module: 'learning_objects', only: [:create, :show] resource :upload, module: 'learning_objects', only: :create