app/actors/hyrax/actors/collections_membership_actor.rb
##
# Attaches any unattached members.  Deletes those that are marked _delete
#
# @param env [Hyrax::Actors::Enviornment]
# @return [Boolean]
#
# rubocop:disable Metrics/MethodLength
# rubocop:disable Metrics/PerceivedComplexity
# rubocop:disable Metrics/CyclomaticComplexity
Attaches any unattached members.  Deletes those that are marked _delete
Attaches any unattached members . Deletes those that are marked _delete
def assign_nested_attributes_for_collection(env)
        attributes_collection = env.attributes.delete(:member_of_collections_attributes)
        return true unless attributes_collection
        return false unless
          valid_membership?(env, collection_ids: attributes_collection.map { |_, attributes| attributes['id'] })
        attributes_collection = attributes_collection.sort_by { |i, _| i.to_i }.map { |_, attributes| attributes }
        existing_collections = env.curation_concern.member_of_collection_ids
        boolean_type_caster = ActiveModel::Type::Boolean.new
        attributes_collection.each do |attributes|
          next if attributes['id'].blank?
          if boolean_type_caster.cast(attributes['_destroy'])
            next unless existing_collections.include?(attributes['id'])
            remove(env.curation_concern, attributes['id'])
          else
            next if existing_collections.include?(attributes['id'])
            add(env, attributes['id'])
          end
        end
        true
      end
def assign_nested_attributes_for_collection ( env ) attributes_collection = env . attributes . delete ( :member_of_collections_attributes ) return true unless attributes_collection return false unless valid_membership? ( env , collection_ids : attributes_collection . map { | _ , attributes | attributes [ 'id' ] } ) attributes_collection = attributes_collection . sort_by { | i , _ | i . to_i } . map { | _ , attributes | attributes } existing_collections = env . curation_concern . member_of_collection_ids boolean_type_caster = ActiveModel :: Type :: Boolean . new attributes_collection . each do | attributes | next if attributes [ 'id' ] . blank? if boolean_type_caster . cast ( attributes [ '_destroy' ] ) next unless existing_collections . include? ( attributes [ 'id' ] ) remove ( env . curation_concern , attributes [ 'id' ] ) else next if existing_collections . include? ( attributes [ 'id' ] ) add ( env , attributes [ 'id' ] ) end end true end
Attaches any unattached members.
Attaches any unattached members .
# checking for existing works to avoid rewriting/loading works that are already attached # Likely someone in the UI sought to add the collection, then # changed their mind and checked the "delete" checkbox and posted # their update. # Let's not try to add an item already
disable Metrics/MethodLength rubocop:disable Metrics/PerceivedComplexity rubocop:disable Metrics/CyclomaticComplexity
disable Metrics / MethodLength rubocop : disable Metrics / PerceivedComplexity rubocop : disable Metrics / CyclomaticComplexity
Boolean
env
None