app/controllers/curate/collections_controller.rb in curate-0.5.4 vs app/controllers/curate/collections_controller.rb in curate-0.5.5

- old
+ new

@@ -1,6 +1,18 @@ class Curate::CollectionsController < ApplicationController + class CollectionsControllerResource < CanCan::ControllerResource + def initialize(*args) + super + if @controller.params['add_to_profile'].present? + @options[:class] = 'ProfileSection' + end + end + end + def self.cancan_resource_class + CollectionsControllerResource + end + include Blacklight::Catalog # Hydra::CollectionsControllerBehavior must come after Blacklight::Catalog # so that the update method is overridden. include Hydra::CollectionsControllerBehavior include Hydra::AccessControlsEnforcement @@ -61,11 +73,11 @@ end redirect_to params.fetch(:redirect_to) { catalog_index_path } end def remove_member - @collection = Collection.find(params[:id]) + @collection = ActiveFedora::Base.find(params[:id], cast: true) item = ActiveFedora::Base.find(params[:item_id], cast:true) @collection.remove_member(item) redirect_to params.fetch(:redirect_to) { collection_path(params[:id]) } end @@ -80,11 +92,11 @@ def load_and_authorize_collection id = id_from_params(:collection_id) id ||= id_from_params(:profile_collection_id) return nil unless id - @collection = Collection.find(id) + @collection = ActiveFedora::Base.find(id, cast: true) authorize! :update, @collection end def id_from_params(key) if params[key] && !params[key].empty? @@ -99,13 +111,20 @@ end end def after_create add_to_profile - respond_to do |format| - format.html { redirect_to collections_path, notice: 'Collection was successfully created.' } - format.json { render json: @collection, status: :created, location: @collection } + if @collection.is_a?(ProfileSection) + respond_to do |format| + format.html { redirect_to person_path(current_user.person), notice: "#{@collection.human_readable_type} was successfully created." } + format.json { render json: @collection, status: :created, location: @collection } + end + else + respond_to do |format| + format.html { redirect_to collections_path, notice: "#{@collection.human_readable_type} was successfully created." } + format.json { render json: @collection, status: :created, location: @collection } + end end end ### Turn off this filter query if it's the index action def include_collection_ids(solr_parameters, user_parameters) @@ -127,7 +146,7 @@ # Proxy engine (collections) routes to the local routes # e.g. collections.collection_path(@collection) def collections self end -end +end