rails-gdpr-export 2.0.2 → 2.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/README.md +31 -23
- data/lib/gdpr_exporter.rb +13 -1
- data/lib/gdpr_exporter/version.rb +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: d7e1487f84e939c9a7f248b70048d67246411119b2cca9fff7ead592c5ad12d1
|
4
|
+
data.tar.gz: c816136d3d5b279b9eef06b2143a6828c43f13a63c47b8e1f1cd6517d8544e32
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e53185e5aa0345dcfb9d81e711e36745c488e52f32e0622107a90b73ea7b792b455f839bba674655dd321bebae21613537247eff7bec5d62633ed6676201321
|
7
|
+
data.tar.gz: 2245352470f640050e5acdcde427a3d309af53f4087b4c4eefd5a46eb936c2cd95ada734839967161d2d817bdc9cdc397ca607c9d3f36468a4ce618a26db7b02
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -24,47 +24,55 @@ This gem allows you to specify fields that you want to retrieve from your models
|
|
24
24
|
|
25
25
|
### Initialization
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
```ruby
|
30
|
-
ActiveRecord::Base.send :include, GdprExporter
|
31
|
-
```
|
27
|
+
First start by importing `gdpr_exporter` into your application, i.e., add `require "gdpr_exporter"` to your `Application.rb` file.
|
32
28
|
|
33
29
|
### Data collection
|
34
30
|
|
35
|
-
In order to specify the fields you want to
|
31
|
+
In order to specify the fields you want to collect you need to call `gdpr_collect`.
|
36
32
|
The call target is a rails model and its arguments are:
|
37
33
|
* a set of simple fields, i.e. fields that will be output as is,
|
38
34
|
* followed by a hash of params:
|
35
|
+
|
39
36
|
```ruby
|
40
|
-
{user_id: <the field in the model used as alias for the user_id field>
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
37
|
+
{ user_id: <the field in the model used as alias for the user_id field>
|
38
|
+
renamed_fields: { <field_from_db> => <field_name_in_output> }
|
39
|
+
table_name: <the new table name in output>
|
40
|
+
description: <a comment>
|
41
|
+
joins: [<an array of associations>] }
|
45
42
|
```
|
43
|
+
|
46
44
|
When `joins` is specified, the fields of an association should be defined as `<association_name> <field_name>`.
|
47
45
|
|
46
|
+
For `user_id`, you can also use a string with a chain of associations. For instance, if my model is indirectly linked to user through an `belongs_to: :account` association, you can specify `user_id: "account user_id"`. Currently, the gem support only to levels of nested associations.
|
47
|
+
|
48
48
|
#### Example
|
49
49
|
|
50
|
+
Suppose you have a `User` model, then in its class you should `include Gdprexporter` and call `gdpr_collect`.
|
51
|
+
And you should do something similar for all other models you are interested in in your application.
|
52
|
+
|
50
53
|
```ruby
|
51
|
-
User
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
54
|
+
class User
|
55
|
+
include GdprExporter
|
56
|
+
|
57
|
+
gdpr_collect :email, :last_sign_in_at, :type, :forward_mailbox,
|
58
|
+
"program title",
|
59
|
+
{ user_id: :id,
|
60
|
+
renamed_fields: { sign_in_count: "sign in count",
|
61
|
+
current_sign_in_at: "time of current sign in",
|
62
|
+
chosen_program_id: "chosen program",
|
63
|
+
current_sign_in_ip: "current IP address",
|
64
|
+
last_sign_in_ip: "previously used IP address" },
|
65
|
+
joins: [:program] }
|
66
|
+
end
|
60
67
|
```
|
61
68
|
|
62
|
-
|
69
|
+
Here from your `User` model, you want to retrieve the values of the fields `email, last_sign_in_at,
|
63
70
|
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
|
71
|
+
`User` has also an association with `program` and you want to value of its field `title` (hence the presence of `"program title"` in the list of fields).
|
65
72
|
|
66
73
|
### Data export
|
67
|
-
|
74
|
+
|
75
|
+
Finally, call `GdprExporter.export(<user_id>)` (from a controller in your application) to return a csv formatted output of all the fields you specified previously.
|
68
76
|
|
69
77
|
|
70
78
|
## Contributing
|
data/lib/gdpr_exporter.rb
CHANGED
@@ -91,7 +91,19 @@ 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
|
-
|
94
|
+
decomposed_user_id_field = user_id_field.to_s.split(" ")
|
95
|
+
result = case
|
96
|
+
when decomposed_user_id_field.size == 3
|
97
|
+
self
|
98
|
+
.includes(decomposed_user_id_field.first.to_sym => decomposed_user_id_field.second.to_sym)
|
99
|
+
.where(decomposed_user_id_field.second.pluralize.to_sym => { decomposed_user_id_field.last.to_sym => _user_id })
|
100
|
+
when decomposed_user_id_field.size == 2
|
101
|
+
self
|
102
|
+
.includes(decomposed_user_id_field.first.to_sym)
|
103
|
+
.where(decomposed_user_id_field.first.pluralize.to_sym => { decomposed_user_id_field.last.to_sym => _user_id })
|
104
|
+
else
|
105
|
+
self.where(user_id_field => _user_id)
|
106
|
+
end
|
95
107
|
|
96
108
|
# When there are multiple joins defined, just keep calling 'joins'
|
97
109
|
# for each association.
|
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: 2.0.
|
4
|
+
version: 2.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chrislain Razafimahefa
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-08-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -92,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
92
|
version: '0'
|
93
93
|
requirements: []
|
94
94
|
rubyforge_project:
|
95
|
-
rubygems_version: 2.7.
|
95
|
+
rubygems_version: 2.7.3
|
96
96
|
signing_key:
|
97
97
|
specification_version: 4
|
98
98
|
summary: A rails gem to export personal data in compliance with GDPR.
|