Project

General

Profile

Defect #39803 » itgn_module.rb

Guus Teley, 2023-12-12 15:15

 
1
module ItgnModule
2
    #AES Encryption key
3
    Rails.configuration.itgn_consent_library_key = "redacted"
4
    @@seckey = Rails.configuration.itgn_consent_library_key
5
    require 'openssl'
6
    require 'digest'
7

    
8

    
9
    def access_level
10
        if User.current.admin?
11
            access_level = 3
12
        else
13
            if User.current.groups.where(:lastname=>"ITGN Consent Library Editor").count == 1
14
                access_level = 2
15
            else
16
                if User.current.groups.where(:lastname=>"ITGN Consent Library Query").count == 1
17
                    access_level = 1
18
                else
19
                    access_level = 0
20
                end
21
            end
22
        end
23
        access_level
24
    end
25

    
26
    def encrypt (val)
27
        cipher_encrypt = OpenSSL::Cipher::AES.new(256, :CBC).encrypt
28
        cipher_encrypt.key = (Digest::SHA1.hexdigest @@seckey)[0..31]
29
        rv = cipher_encrypt.update(val) + cipher_encrypt.final
30
        rv
31
    end
32
    def decrypt(val)
33
        return val if val.nil?
34
        cipher_decrypt = OpenSSL::Cipher::AES.new(256, :CBC).decrypt
35
        cipher_decrypt.key = (Digest::SHA1.hexdigest @@seckey)[0..31]
36
        rv = cipher_decrypt.update(val) + cipher_decrypt.final
37
        rv
38
    end
39
end
(2-2/3)