Initial commit

This commit is contained in:
Yaser
2026-08-13 19:42:08 +03:30
commit d59bf30ef0
173 changed files with 11702 additions and 0 deletions

99
bin/seed_test_users.rb Normal file
View File

@@ -0,0 +1,99 @@
# frozen_string_literal: true
# Creates / updates Fibitex test users in Barong (Dalan).
# Run: bundle exec rails runner lib/seed_test_users.rb
# Guard: set FIBITEX_SEED_TEST_USERS=false to skip.
require 'yaml'
require 'json'
def test_seed_enabled?
ENV.fetch('FIBITEX_SEED_TEST_USERS', 'true') != 'false'
end
unless test_seed_enabled?
puts 'SKIP seed_test_users (FIBITEX_SEED_TEST_USERS=false)'
exit 0
end
config_path = ENV.fetch(
'TEST_USERS_CONFIG',
File.expand_path('../config/test_users.yml', __dir__)
)
unless File.exist?(config_path)
puts "ERR missing config: #{config_path}"
exit 1
end
config = YAML.safe_load(File.read(config_path))
fiat_ids = %w[irt cad]
def apply_kyc_labels!(user, kyc_mode)
Label.where(user_id: user.id, scope: 'private').delete_all
case kyc_mode.to_s
when 'zero'
bound = Level::LEVEL_ID_BOUNDS['0'].to_i
when 'full'
bound = Level::LEVEL_ID_BOUNDS[user.level.to_s].to_i
else
bound = Level::LEVEL_ID_BOUNDS[user.level.to_s].to_i
end
Level.where(id: 1..bound).find_each do |level|
user.labels.create!(key: level.key, value: level.value, scope: 'private')
end
user.update!(level: Level.what_level(user.kyc_info[:points])) if kyc_mode.to_s == 'full'
end
def sync_user_level!(user, target_level)
return if target_level.nil?
user.update!(level: target_level.to_i)
end
def remove_user!(email)
user = User.find_by(email: email)
return unless user
Label.where(user_id: user.id).delete_all
User.where(id: user.id).delete_all
puts "REMOVED #{email}"
end
(config['remove_emails'] || []).each do |email|
remove_user!(email)
end
(config['users'] || []).each do |entry|
email = entry['email']
user = User.find_or_initialize_by(email: email)
user.uid = entry['uid'] if entry['uid'].present? && user.uid.blank?
user.password = entry['password']
user.role = entry['role']
user.state = entry['state'] || 'active'
user.level = entry['level'] || 0
user.otp = false
if user.save
apply_kyc_labels!(user, entry['kyc'])
sync_user_level!(user, entry['level'])
puts "OK #{email} uid=#{user.uid} role=#{user.role} level=#{user.level} kyc=#{entry['kyc']}"
else
puts "ERR #{email}: #{user.errors.full_messages.join(', ')}"
exit 1
end
end
File.write(
File.join(Dir.tmpdir, 'fibitex_test_user_uids.json'),
JSON.pretty_generate(
(config['users'] || []).map { |u| { 'email' => u['email'], 'uid' => User.find_by!(email: u['email']).uid } }
)
)
puts 'DONE seed_test_users'