Sha256: 33b5a4bba17b71fcb9c555ed69a35a1fd623b139e2b2b22ed744ffb945aebede

Contents?: true

Size: 1.36 KB

Versions: 12

Compression:

Stored size: 1.36 KB

Contents

module Hyrax
  module Actors
    # Adds membership to and removes membership from collections
    class CollectionsMembershipActor < AbstractActor
      # @param [Hyrax::Actors::Environment] env
      # @return [Boolean] true if create was successful
      def create(env)
        collection_ids = env.attributes.delete(:member_of_collection_ids)
        assign_collections(env, collection_ids) && next_actor.create(env)
      end

      # @param [Hyrax::Actors::Environment] env
      # @return [Boolean] true if update was successful
      def update(env)
        collection_ids = env.attributes.delete(:member_of_collection_ids)
        assign_collections(env, collection_ids) && next_actor.update(env)
      end

      private

        # Maps from collection ids to collection objects
        def assign_collections(env, collection_ids)
          return true unless collection_ids
          # grab/save collections this user has no edit access to
          other_collections = collections_without_edit_access(env)
          env.curation_concern.member_of_collections = ::Collection.find(collection_ids)
          env.curation_concern.member_of_collections.concat other_collections
        end

        def collections_without_edit_access(env)
          env.curation_concern.member_of_collections.select { |coll| env.current_ability.cannot?(:edit, coll) }
        end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
hyrax-2.0.3 app/actors/hyrax/actors/collections_membership_actor.rb
hyrax-2.0.2 app/actors/hyrax/actors/collections_membership_actor.rb
hyrax-2.0.1 app/actors/hyrax/actors/collections_membership_actor.rb
hyrax-2.0.0 app/actors/hyrax/actors/collections_membership_actor.rb
hyrax-2.0.0.rc3 app/actors/hyrax/actors/collections_membership_actor.rb
hyrax-2.0.0.rc2 app/actors/hyrax/actors/collections_membership_actor.rb
hyrax-2.0.0.rc1 app/actors/hyrax/actors/collections_membership_actor.rb
hyrax-2.0.0.beta5 app/actors/hyrax/actors/collections_membership_actor.rb
hyrax-2.0.0.beta4 app/actors/hyrax/actors/collections_membership_actor.rb
hyrax-2.0.0.beta3 app/actors/hyrax/actors/collections_membership_actor.rb
hyrax-2.0.0.beta2 app/actors/hyrax/actors/collections_membership_actor.rb
hyrax-2.0.0.beta1 app/actors/hyrax/actors/collections_membership_actor.rb