<commit_before>require 'yaml'

namespace :check do
  desc "clean private data from the database"
  task cleandb: :environment do
    begin
      cleandb_config = YAML.load(File.open(File.join(File.dirname(__FILE__), '..', '..', 'config', 'cleandb.yml')))
      exceptions = cleandb_config["email_exceptions"] if cleandb_config.has_key?("email_exceptions")
      slack_settings = cleandb_config["slack_settings"] if cleandb_config.has_key?("slack_settings")
      bot_urls = cleandb_config["bot_urls"] if cleandb_config.has_key?("bot_urls")
      bot_settings = cleandb_config["bot_settings"] if cleandb_config.has_key?("bot_settings")
    rescue Exception => e
      puts e.message
    end
    exceptions ||= []
    slack_settings ||= {}
    bot_urls ||= {}
    bot_settings ||= {}

    Team.find_each do |t|
      if !t.settings.blank? && t.get_slack_notifications_enabled == "1"
        slack_settings.each do |k, v|
          t.send("set_#{k}", v)
        end
      end
      t.reset_slack_notifications_enabled if slack_settings.blank?
      t.private = false
      t.save(:validate => false)
    end

    User.find_each do |u|
      unless u.email =~ /@meedan\./ || exceptions.include?(u.email)
        u.update_columns(email: '', encrypted_password: '')
      end
    end

    Project.find_each do |p|
      if !p.settings.blank? && p.get_slack_notifications_enabled == "1"
        slack_settings.each do |k, v|
          p.send("set_#{k}", v)
        end
        p.reset_slack_notifications_enabled if slack_settings.blank?
        p.save(:validate => false)
      end
    end

    bot_urls.each do |id, url|<commit_msg>Ticket #7684 - fix errbit error related to 2FA encrypted<commit_after>require 'yaml'

namespace :check do
  desc "clean private data from the database"
  task cleandb: :environment do
    begin
      cleandb_config = YAML.load(File.open(File.join(File.dirname(__FILE__), '..', '..', 'config', 'cleandb.yml')))
      exceptions = cleandb_config["email_exceptions"] if cleandb_config.has_key?("email_exceptions")
      slack_settings = cleandb_config["slack_settings"] if cleandb_config.has_key?("slack_settings")
      bot_urls = cleandb_config["bot_urls"] if cleandb_config.has_key?("bot_urls")
      bot_settings = cleandb_config["bot_settings"] if cleandb_config.has_key?("bot_settings")
    rescue Exception => e
      puts e.message
    end
    exceptions ||= []
    slack_settings ||= {}
    bot_urls ||= {}
    bot_settings ||= {}

    Team.find_each do |t|
      if !t.settings.blank? && t.get_slack_notifications_enabled == "1"
        slack_settings.each do |k, v|
          t.send("set_#{k}", v)
        end
      end
      t.reset_slack_notifications_enabled if slack_settings.blank?
      t.private = false
      t.save(:validate => false)
    end

    User.find_each do |u|
      # reset encrypted for 2FA
      u.update_columns(encrypted_otp_secret: '', encrypted_otp_secret_iv: '', encrypted_otp_secret_salt: '')
      unless u.email =~ /@meedan\./ || exceptions.include?(u.email)
        u.update_columns(email: '', encrypted_password: '')
      end
    end

    Project.find_each do |p|
      if !p.settings.blank? && p.get_slack_notifications_enabled == "1"
        slack_settings.each do |k, v|
          p.send("set_#{k}", v)
        end
        p.reset_slack_notifications_enabled if slack_settings.blank?
        p.save(:validate => false)
      end
    end

    bot_urls.each do |id, url|
{'fraction_non_alphanumeric': 0.12885398487492727, 'fraction_numerical': 0.0029086678301337987, 'mean_word_length': 3.0602125147579695, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '217725', 'n_tokens_mistral': 1181, 'n_tokens_neox': 1176, 'n_words': 226}