<commit_before># utf-8
require 'open-uri'
require 'csv'
require 'gooddata'

module GoodData::Bricks

  class UserBrick < GoodData::Bricks::Brick
    def version
      "0.0.1"
    end

    def call(params)

      domain_name = params['domain']
      project = params['gdc_project']
      csv_path = params['csv_path']
      only_domain = params['add_only_to_domain'] == 'true' || params['add_only_to_domain'] == true ? true : false
      # Check mandatory columns and parameters
      mandatory_params = [domain_name, csv_path]

      mandatory_params.each do |param|
        fail param+' is required in the block parameters.' unless param
      end

      domain = GoodData::Domain[domain_name]

      first_name_column = params[:first_name_column] || 'first_name'
      last_name_column  = params[:last_name_column] || 'last_name'
      login_column      = params[:login_column] || 'login'
      password_column   = params[:password_column] || 'password'
      email_column      = params[:email_column] || 'email' || default_login
      role_column       = params[:role_column] || 'role'

      new_users = []
      CSV.foreach(csv_path, :headers => true, :return_headers => false) do |row|
      pp row
        json = {
          'user' => {
            'content' => {
              'firstname' => row[first_name_column],
              'lastname' => row[last_name_column],
              'login' => row[login_column],
              'password' => <PASSWORD>],
              'email' => row[email_column],
              'role' => row[role_column],
              'domain' => domain_name
            },
            'meta' => {}
          }
        }
        new_users << GoodData::Membership.new(json)
      end

      if only_domain
        domain.users_create(new_users)
      else
        project.users_import(new_users, domain)
      end
    end
  end
end
<commit_msg>Adding whitelists<commit_after># utf-8
require 'open-uri'
require 'csv'
require 'gooddata'

module GoodData::Bricks

  class UserBrick < GoodData::Bricks::Brick
    def version
      "0.0.1"
    end

    def call(params)

      domain_name = params['domain']
      project = params['gdc_project']
      csv_path = params['csv_path']
      only_domain = params['add_only_to_domain'] == 'true' || params['add_only_to_domain'] == true ? true : false
      whitelists = params['whitelists']

      # Check mandatory columns and parameters
      mandatory_params = [domain_name, csv_path]

      mandatory_params.each do |param|
        fail param+' is required in the block parameters.' unless param
      end

      domain = GoodData::Domain[domain_name]

      first_name_column = params[:first_name_column] || 'first_name'
      last_name_column  = params[:last_name_column] || 'last_name'
      login_column      = params[:login_column] || 'login'
      password_column   = params[:password_column] || 'password'
      email_column      = params[:email_column] || 'email' || default_login
      role_column       = params[:role_column] || 'role'

      new_users = []
      CSV.foreach(csv_path, :headers => true, :return_headers => false) do |row|
      pp row
        json = {
          'user' => {
            'content' => {
              'firstname' => row[first_name_column],
              'lastname' => row[last_name_column],
              'login' => row[login_column],
              'password' => row[<PASSWORD>],
              'email' => row[email_column],
              'role' => row[role_column],
              'domain' => domain_name
            },
            'meta' => {}
          }
        }
        new_users << GoodData::Membership.new(json)
      end

      if only_domain
        domain.users_create(new_users)
      else
        project.users_import(new_users, domain: domain, :whitelists => whitelists)
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.1206806282722513, 'fraction_numerical': 0.0020942408376963353, 'mean_word_length': 2.3458844133099825, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 30, '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': '943581', 'n_tokens_mistral': 1154, 'n_tokens_neox': 1140, 'n_words': 238}