rails-gdpr-export 1.0.2 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +6 -2
- data/lib/gdpr_exporter.rb +28 -8
- data/lib/gdpr_exporter/version.rb +1 -1
- data/rails-gdpr-export.gemspec +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad4eb505cc305ad42540e9e9ab33929f59a150efba6b9d06563dc6c740136b45
|
4
|
+
data.tar.gz: fb96f6b4c657d858cddf8ec3e9e79eb197f61b4a6962de4f5a9912093395540d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2252ca7bd625c33236d582a49444dd5e8a2362632a3c94f5fdc2dd67482f32092a2a5726d3139f5700cfc8cd27d718001d0bb9035139af6b1e93f6309d89efce
|
7
|
+
data.tar.gz: a31b4ed3fdfff06f7fbc0a99b69054b6024bda5a679c90711b1ec8d3c745f54f2446f86716fc152d4d0ad80a51c54228dd1dbb56a1f496f0a2bdf670fcd77118
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -41,23 +41,27 @@ The call target is a rails model and its arguments are:
|
|
41
41
|
renamed_fields: {<field_from_db> => <field_name_in_output>}
|
42
42
|
table_name: <the new table name in output>
|
43
43
|
description: <a comment>
|
44
|
-
|
44
|
+
joins: [<an array of associations>]}
|
45
45
|
```
|
46
|
+
When `joins` is specified, the fields of an association should be defined as `<association_name> <field_name>`.
|
46
47
|
|
47
48
|
#### Example
|
48
49
|
|
49
50
|
```ruby
|
50
51
|
User.gdpr_collect :email, :last_sign_in_at, :type, :forward_mailbox,
|
52
|
+
"program title",
|
51
53
|
{user_id: :id,
|
52
54
|
renamed_fields: {sign_in_count: "sign in count",
|
53
55
|
current_sign_in_at: "time of current sign in",
|
54
56
|
chosen_program_id: "chosen program",
|
55
57
|
current_sign_in_ip: "current IP address",
|
56
|
-
last_sign_in_ip: "previously used IP address"}
|
58
|
+
last_sign_in_ip: "previously used IP address"},
|
59
|
+
joins: [:program]}
|
57
60
|
```
|
58
61
|
|
59
62
|
From your `User` model, you want to retrieve the values of the fields `email, last_sign_in_at,
|
60
63
|
type, forward_mailbox`, in addition to the fields `sign_in_count, current_sign_in_at, chosen_program_id, current_sign_in_ip, last_sign_in_ip`. However for the latter you want their csv header to be renamed. And the field representing the user in the `User` model is `id`.
|
64
|
+
`User` has also an association with `program` and you want to value of its field `title`.
|
61
65
|
|
62
66
|
### Data export
|
63
67
|
Finally, call `GdprExporter.export(<user_id>)` to return a csv formatted output of all the fields you specified previously.
|
data/lib/gdpr_exporter.rb
CHANGED
@@ -18,7 +18,7 @@ module GdprExporter
|
|
18
18
|
# Collects data through all the tagged models and generates a csv
|
19
19
|
# formatted output
|
20
20
|
def self.export(user_id)
|
21
|
-
CSV.generate do |csv|
|
21
|
+
CSV.generate(force_quotes: true) do |csv|
|
22
22
|
get_klasses.each do |klass|
|
23
23
|
rows = klass.gdpr_query(user_id)
|
24
24
|
klass.gdpr_export(rows, csv)
|
@@ -91,12 +91,17 @@ module GdprExporter
|
|
91
91
|
# Adds the class method 'gdpr_query' to the eigenclass.
|
92
92
|
# It will execute the query.
|
93
93
|
self.define_singleton_method(:gdpr_query) do |_user_id|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
94
|
+
result = self.where(user_id_field => _user_id)
|
95
|
+
|
96
|
+
# When there are multiple joins defined, just keep calling 'joins'
|
97
|
+
# for each association.
|
98
|
+
if hash_params[:joins]
|
99
|
+
result = hash_params[:joins].inject(result) do | query, assoc |
|
100
|
+
query.send(:joins, assoc)
|
101
|
+
end
|
99
102
|
end
|
103
|
+
|
104
|
+
result
|
100
105
|
end
|
101
106
|
|
102
107
|
# Adds a method to export to csv to the eigenclass.
|
@@ -105,11 +110,26 @@ module GdprExporter
|
|
105
110
|
|
106
111
|
csv << (hash_params[:table_name] ? [hash_params[:table_name]] :
|
107
112
|
[self.to_s])
|
113
|
+
|
114
|
+
if hash_params[:desc]
|
115
|
+
csv << ['Description:', hash_params[:desc]]
|
116
|
+
end
|
117
|
+
|
108
118
|
csv << csv_headers
|
109
119
|
rows.each do |r|
|
110
|
-
csv << query_fields.map
|
120
|
+
csv << query_fields.map do |f|
|
121
|
+
f_splitted = f.to_s.split(' ')
|
122
|
+
if (f_splitted.size == 2)
|
123
|
+
# field f is coming from an assoc, i.e. field has been defined
|
124
|
+
# as "<tablename> <field>" in gdpr_collect then to get its value
|
125
|
+
# do r.<tablename>.<field>
|
126
|
+
f_splitted.inject(r) { |result, method| result.send(method) }
|
127
|
+
else
|
128
|
+
# No association involved, simply retrieve the field value.
|
129
|
+
r.send(f)
|
130
|
+
end
|
131
|
+
end
|
111
132
|
end
|
112
|
-
csv << ['Comment:', hash_params[:desc]] if hash_params[:desc]
|
113
133
|
csv << []
|
114
134
|
end
|
115
135
|
end
|
data/rails-gdpr-export.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["Chrislain Razafimahefa"]
|
10
10
|
spec.email = ["razafima@gmail.com"]
|
11
11
|
|
12
|
-
spec.summary = %q{A gem to export personal data in compliance with GDPR.}
|
12
|
+
spec.summary = %q{A rails gem to export personal data in compliance with GDPR.}
|
13
13
|
spec.homepage = "https://github.com/epfl-exts/rails-gdpr-export"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-gdpr-export
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chrislain Razafimahefa
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-05-
|
11
|
+
date: 2018-05-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -95,5 +95,5 @@ rubyforge_project:
|
|
95
95
|
rubygems_version: 2.7.6
|
96
96
|
signing_key:
|
97
97
|
specification_version: 4
|
98
|
-
summary: A gem to export personal data in compliance with GDPR.
|
98
|
+
summary: A rails gem to export personal data in compliance with GDPR.
|
99
99
|
test_files: []
|