<commit_before>#!/usr/bin/env ruby

# Update the customRole collection, for reference please check us5865

# Run this script with no arguments to see usage:
#
#   ruby 90_update_custom_role.rb
#
# You can give one or more tenant IDs whose databases will be migrated, or "--all"
# for all tenants.  Also you can optionally give the MongoDB host/port.

require 'mongo'

############################################################
# Migration Script
############################################################

@conn = nil
DEBUG = true
CUSTOM_ROLE = "customRole"
NEW_RIGHT = "APP_AUTHORIZE"

#Update customRole collection,  add new right to "IT Administrator"
#US5865
def update_customRole(dbName)
  cusRole2Id = {}
  @conn[dbName][CUSTOM_ROLE].find({}).each do |cusRole|
     id = cusRole["_id"]
     cusRole2Id[id] = cusRole["body"]
  end
  cusRole2Id.each do |id, cusRole_body|
    puts id if DEBUG == true
    roles =  cusRole_body["roles"]
    if cusRole_body.has_key?("roles")
      update_IT_Admin(roles)
      @conn[dbName][CUSTOM_ROLE].update({"_id"=>id}, {"body"=>cusRole_body})
    end
  end
end

#Add new right to "IT Administrator"
def  update_IT_Admin(roles)
    roles.each do |group|
       if group["groupTitle"] == "IT Administrator"
         rights = group["rights"]
         rights.push(NEW_RIGHT).uniq!
       end
    end
end


# Example: this_script.rb --all host:myhost.com port:12345
#          this_script.rb host:myhost.com port:12345 db1 db2 db3
#
def parseArgs(argv)

  result = { "all" => false, "mongo_host" => "localhost", "mongo_port" => 27017, "tenants" => [] }

  for arg in argv
    if arg == "--all"
      result["all"] = true
    elsif arg.include?(":")
      host_port = arg.split(':')
      result["mongo_host"] = host_port[0]
      result["mongo_port"] = host_port[1]<commit_msg>us5865 add SECURITY_EVENT_VIEW to IT Administrator role to<commit_after>#!/usr/bin/env ruby

# Update the customRole collection, for reference please check us5865

# Run this script with no arguments to see usage:
#
#   ruby 90_update_custom_role.rb
#
# You can give one or more tenant IDs whose databases will be migrated, or "--all"
# for all tenants.  Also you can optionally give the MongoDB host/port.

require 'mongo'

############################################################
# Migration Script
############################################################

@conn = nil
DEBUG = true
CUSTOM_ROLE = "customRole"
NEW_RIGHT = "APP_AUTHORIZE"
SECURITY_EVENT_RIGHT = "SECURITY_EVENT_VIEW"

#Update customRole collection,  add new right to "IT Administrator"
#US5865
def update_customRole(dbName)
  cusRole2Id = {}
  @conn[dbName][CUSTOM_ROLE].find({}).each do |cusRole|
     id = cusRole["_id"]
     cusRole2Id[id] = cusRole["body"]
  end
  cusRole2Id.each do |id, cusRole_body|
    puts id if DEBUG == true
    roles =  cusRole_body["roles"]
    if cusRole_body.has_key?("roles")
      update_IT_Admin(roles)
      @conn[dbName][CUSTOM_ROLE].update({"_id"=>id}, {"body"=>cusRole_body})
    end
  end
end

#Add new right to "IT Administrator"
def  update_IT_Admin(roles)
    roles.each do |group|
       if group["groupTitle"] == "IT Administrator"
         rights = group["rights"]
         rights.push(NEW_RIGHT).uniq!
         rights.push(SECURITY_EVENT_RIGHT).uniq!
       end
    end
end


# Example: this_script.rb --all host:myhost.com port:12345
#          this_script.rb host:myhost.com port:12345 db1 db2 db3
#
def parseArgs(argv)

  result = { "all" => false, "mongo_host" => "localhost", "mongo_port" => 27017, "tenants" => [] }

  for arg in argv
    if arg == "--all"
      result["all"] = true
    elsif arg.include?(":")
      host_port = arg.split(':')
      result["mongo_host"] = host_port[0]
      result["mongo_port"] = host_port[1]
{'fraction_non_alphanumeric': 0.18234826398091705, 'fraction_numerical': 0.01855287569573284, 'mean_word_length': 3.907672301690507, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 15, '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': '6639146', 'n_tokens_mistral': 1343, 'n_tokens_neox': 1255, 'n_words': 327}