forked from libremente/Portale
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_gdpr.rb
59 lines (46 loc) · 2.45 KB
/
check_gdpr.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# -*- encoding : utf-8 -*-
#!/bin/env /usr/local/rvm/rubies/ruby-1.8.7-p374/bin/ruby
#/opt/ruby-enterprise-1.8.7-2011.03/bin ruby
require 'rubygems'
require 'spiderfw/init'
#require 'debugger'
#require "mysql"
Spider.conf.set "log.level", :ERROR
#variabili
ore = "9"
destinatario = Spider.conf.get('portal.email_amministratore')
#destinatario = "[email protected]"
mittente = Spider.conf.get('portal.email_from')
#mittente = "[email protected]"
gdpr_attivo = Spider.conf.get('portal.abilita_gdpr_utente')
server = `hostname`.chomp.split('.')[0]
include Spider::Messenger::MessengerHelper rescue NameError
begin
if gdpr_attivo
con = Spider::Model::BaseModel.get_storage
dati = YAML.load_file('config/config.yml')
database = dati['storages']['default']['url'].split('/').last
rs = con.connection.query("SELECT nome, cognome, email, data_ora_cancellazione_gdpr, id FROM portal__utente WHERE data_ora_cancellazione_gdpr <= DATE_ADD(NOW(), INTERVAL -#{ore} HOUR) and richiesta_cancellazione_gdpr = '1'")
rs.each do |row|
nome = row[0]
cognome = row[1]
email = row[2]
data_ora_cancellazione_gdpr = row[3]
id_utente = row[4]
testo = "Cancellazione dati personali eseguita per l'utente (#{id_utente}) #{nome} #{cognome} email: #{email} come da sua richiesta del #{data_ora_cancellazione_gdpr}"
e1 = con.connection.query("delete from portal__utentelogin where utente_portale_id = #{id_utente}")
e2 = con.connection.query("delete from portal__utente__attributiaggiuntivi where utente_id = #{id_utente}")
e3 = con.connection.query("delete from portal__utente__gruppi where utente_id = #{id_utente}")
e4 = con.connection.query("delete from portal__utente__serviziprivati where utente_id = #{id_utente}")
e5 = con.connection.query("delete from portal__utente__utenteportalepermissionsjunction where utente_id = #{id_utente}")
e0 = con.connection.query("delete from portal__utente where id = #{id_utente}")
mail = Mail.new(testo)
mail[:to] = destinatario
mail[:from] = mittente
mail[:oggetto] = "#{ Spider.conf.get('ente.nome') } - Cancellazione dati personali"
mail_headers = {'Subject' => mail[:oggetto]}
#mando la mail
mailmandata = Spider::Messenger.email(mail[:from], mail[:to], mail_headers, testo)
end
end
end