<commit_before>module MassassignmentSecurityForm
  module Extensions
    module Controller
      def self.included(base)
        base.class_eval do
          before_filter :remove_not_allowed_massassignment_fields_from_params, 
            :if => :allow_removing_massassignment_fields_from_params
        end
      end

      private
      def remove_not_allowed_massassignment_fields_from_params
        if allow_fields_encrypted = params[MassassignmentSecurityForm::Config::MASSASSIGNMENT_PARAMS_NAME]
          allowed_columns = MassassignmentSecurityForm::MassassignmentColumnsHash.parse_from(allow_fields_encrypted) 
          allowed_columns.remove_not_allowed_massassignments_from(params)
        else
          remove_all_massassignemnts_from_params
        end
        true
      end

      def remove_all_massassignemnts_from_params
        params.each do |key, value| 
          if value.is_a?(Hash)
            value.clear
          end
        end
      end

      # Für ActiveScaffold ist diese Aktion nicht nötig
      def allow_removing_massassignment_fields_from_params
        if self.class.respond_to?(:uses_active_scaffold?) && self.class.uses_active_scaffold?
          false
        else
          MassassignmentSecurityForm::Config.remove_not_allowed_massassignment_fields
        end
      end
    end
  end
end<commit_msg> * Permit for Rails 4<commit_after>module MassassignmentSecurityForm
  module Extensions
    module Controller
      def self.included(base)
        base.class_eval do
          before_filter :remove_not_allowed_massassignment_fields_from_params
        end
      end

      private
      def remove_not_allowed_massassignment_fields_from_params
        if allow_removing_massassignment_fields_from_params
          if allow_fields_encrypted = params[MassassignmentSecurityForm::Config::MASSASSIGNMENT_PARAMS_NAME]
            allowed_columns = MassassignmentSecurityForm::MassassignmentColumnsHash.parse_from(allow_fields_encrypted) 
            allowed_columns.remove_not_allowed_massassignments_from(params)
          else
            remove_all_massassignemnts_from_params
          end
        end
        
        params.respond_to?(:permit!) && params.permit!
        
        true
      end

      def remove_all_massassignemnts_from_params
        params.each do |key, value| 
          if value.is_a?(Hash)
            value.clear
          end
        end
      end

      # Für ActiveScaffold ist diese Aktion nicht nötig
      def allow_removing_massassignment_fields_from_params
        if self.class.respond_to?(:uses_active_scaffold?) && self.class.uses_active_scaffold?
          false
        else
          MassassignmentSecurityForm::Config.remove_not_allowed_massassignment_fields
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.040889526542324243, 'fraction_numerical': 0.0003586800573888092, 'mean_word_length': 2.728609625668449, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1368907', 'n_tokens_mistral': 792, 'n_tokens_neox': 776, 'n_words': 130}