· 6 years ago · May 04, 2019, 12:24 AM
1# hrX Access: LCC + Employment Count Extract
2isFirst = true
3gcc = Gcc.first
4Lcc.find_each do |lcc|
5 country_code = lcc.country_code
6 code = lcc.code
7 count = lcc.employments.count
8 puts "Gcc, Country, LCC Code, Employement Count" if isFirst
9 isFirst = false
10 puts "#{gcc}, #{country_code}, #{code}, #{count}"
11end
12
13# Check FRID flag
14isFirst = true
15Lcc.find_each do |lcc|
16 puts "LCC Code, Create FG User, Send Payslips to HRIS" if isFirst
17 isFirst = false
18 puts "#{lcc.code}, #{lcc.create_fg_user}, #{lcc.send_payslips_to_hris}"
19end
20
21# Re-Synchronize User table records FRIDs
22[''].each do|em|
23 User.where(email: em).find_each do|user|
24 begin
25 puts "#{user.email};#{user.hrisid};#{user.status};#{user.last_sign_in_at};#{user.lccs.pluck(:code)}"
26 #user.status = 'ACTIVE'
27 Proxies::UserConnector.new(user, :update_roles, Fcs::FcsInstance.current_version, access_to_all: false).call
28 rescue => e
29 puts e
30 end
31 end
32end
33
34# hrx Access: create JWT Key
35# C:\Users\arvinfrancis.bien\Documents\pex-ror\app\controllers\conf\jwt_api_keys_controller.rb
36# C:\Users\arvinfrancis.bien\Documents\pex-ror\app\models\conf\jwt_api_key.rb
37# C:\Users\arvinfrancis.bien\Documents\pex-ror\spec\controllers\conf\jwt_api_key_controller_spec.rb
38def createJWTApiKey
39 begin
40 rsa_secret = OpenSSL::PKey::RSA.generate 2048
41 public_key = rsa_secret.public_key.to_s.split("\n")[1..-2].join
42 secret_key = rsa_secret.to_s
43 gcc = Gcc.first.code
44 client_id = "#{gcc} hrX Access" # make a unique client ID for each application
45
46 key = Conf::JWTApiKey.create! client_id: client_id,
47 public_key: public_key,
48 secret_key: secret_key
49
50 pub_key = OpenSSL::PKey::RSA.new(key.secret_key).public_key.to_s
51 puts "Client ID: #{key.client_id}"
52 puts "Public Key:", pub_key
53 puts "Secret Key:", key.secret_key.to_s
54 rescue => e
55 puts "#{e}".colorize(:yellow)
56 key = Conf::JWTApiKey.where('client_id = ?', client_id).first
57 pub_key = OpenSSL::PKey::RSA.new(key.secret_key).public_key.to_s
58 puts "Client ID: #{key.client_id}"
59 puts "Public Key:", pub_key
60 puts "Secret Key:", key.secret_key.to_s
61 end
62end
63# Function invocation
64createJWTApiKey
65
66# Activate hrX Access in Exchange
67gcc = Gcc.first
68user = User.where(email: 'arvinfrancis.bien@ngahr.com').first
69username = "#{user.given_name} #{user.family_name}"
70gcc.update_attributes(hrx_active: true, updated_at: Date.now, last_updated_by: username)