<commit_before># frozen_string_literal: true
module Hyrax
  module Dashboard
    ## Shows a list of all collections to the admins
    class CollectionMembersController < Hyrax::My::CollectionsController
      before_action :filter_docs_with_read_access!

      include Hyrax::Collections::AcceptsBatches

      load_resource only: :update_members,
                    instance_name: :collection,
                    class: Hyrax.config.collection_model

      def after_update
        respond_to do |format|
          format.html { redirect_to success_return_path, notice: t('hyrax.dashboard.my.action.collection_update_success') }
          format.json { render json: @collection, status: :updated, location: dashboard_collection_path(@collection) }
        end
      end

      def after_update_error(err_msg)
        respond_to do |format|
          format.html { redirect_to err_return_path, alert: err_msg }
          format.json { render json: @collection.errors, status: :unprocessable_entity }
        end
      end

      def update_members # rubocop:disable Metrics/MethodLength
        err_msg = validate
        after_update_error(err_msg) if err_msg.present?
        return if err_msg.present?

        @collection.reindex_extent = Hyrax::Adapters::NestingIndexAdapter::LIMITED_REINDEX
        begin
          Hyrax::Collections::CollectionMemberService.add_members_by_ids(collection_id: collection_id,
                                                                         new_member_ids: batch_ids,
                                                                         user: current_user)
          after_update
        rescue Hyrax::SingleMembershipError => err
          messages = JSON.parse(err.message)
          if messages.size == batch_ids.size
            after_update_error(messages.uniq.join(', '))
          elsif messages.present?<commit_msg>only set reindex-extent on AF collections<commit_after># frozen_string_literal: true
module Hyrax
  module Dashboard
    ## Shows a list of all collections to the admins
    class CollectionMembersController < Hyrax::My::CollectionsController
      before_action :filter_docs_with_read_access!

      include Hyrax::Collections::AcceptsBatches

      load_resource only: :update_members,
                    instance_name: :collection,
                    class: Hyrax.config.collection_model

      def after_update
        respond_to do |format|
          format.html { redirect_to success_return_path, notice: t('hyrax.dashboard.my.action.collection_update_success') }
          format.json { render json: @collection, status: :updated, location: dashboard_collection_path(@collection) }
        end
      end

      def after_update_error(err_msg)
        respond_to do |format|
          format.html { redirect_to err_return_path, alert: err_msg }
          format.json { render json: @collection.errors, status: :unprocessable_entity }
        end
      end

      def update_members # rubocop:disable Metrics/MethodLength
        err_msg = validate
        after_update_error(err_msg) if err_msg.present?
        return if err_msg.present?

        @collection.try(:reindex_extent=, Hyrax::Adapters::NestingIndexAdapter::LIMITED_REINDEX)
        begin
          Hyrax::Collections::CollectionMemberService.add_members_by_ids(collection_id: collection_id,
                                                                         new_member_ids: batch_ids,
                                                                         user: current_user)
          after_update
        rescue Hyrax::SingleMembershipError => err
          messages = JSON.parse(err.message)
          if messages.size == batch_ids.size
            after_update_error(messages.uniq.join(', '))
          elsif messages.present?
{'fraction_non_alphanumeric': 0.06897463002114165, 'fraction_numerical': 0.0, 'mean_word_length': 2.291304347826087, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2014236', 'n_tokens_mistral': 984, 'n_tokens_neox': 947, 'n_words': 206}