rails-gdpr-export 2.0.2 → 2.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7e7c5a2c6c437886d8ba018efc65665bc7ab380df9b35008ec6363f4f300f803
4
- data.tar.gz: d21fe4cc0b9601fda5577783c801182ec5d6f86a91c53790fecfeca21e5a9cc1
3
+ metadata.gz: d7e1487f84e939c9a7f248b70048d67246411119b2cca9fff7ead592c5ad12d1
4
+ data.tar.gz: c816136d3d5b279b9eef06b2143a6828c43f13a63c47b8e1f1cd6517d8544e32
5
5
  SHA512:
6
- metadata.gz: 8d29e71898e8a438dda05641a8ebeaa151ce0b47855155404847270c3e373585a696e609bf949529752e42ceb6fd9ba825fd52cb7e84d6c6dc8667d4f790b3ea
7
- data.tar.gz: 888a99343f67590dc13caba81f3006efdea18f582456db44abcf1e33859600b4035eec51970d3f265a10ef662e913eefdfa144dd4c580bada643691c09667f4e
6
+ metadata.gz: 5e53185e5aa0345dcfb9d81e711e36745c488e52f32e0622107a90b73ea7b792b455f839bba674655dd321bebae21613537247eff7bec5d62633ed6676201321
7
+ data.tar.gz: 2245352470f640050e5acdcde427a3d309af53f4087b4c4eefd5a46eb936c2cd95ada734839967161d2d817bdc9cdc397ca607c9d3f36468a4ce618a26db7b02
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rails-gdpr-export (2.0.2)
4
+ rails-gdpr-export (2.0.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -32,4 +32,4 @@ DEPENDENCIES
32
32
  rspec (~> 3.0)
33
33
 
34
34
  BUNDLED WITH
35
- 1.16.1
35
+ 1.16.5
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
- To initialize the gem usage, loads the GdprExporter module into activerecord classes. Do this at initialization time through an initializer. E.g. create a initializers/gdpr.rb file and add the following:
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 return to the user you need to call `gdpr_collect`.
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
- renamed_fields: {<field_from_db> => <field_name_in_output>}
42
- table_name: <the new table name in output>
43
- description: <a comment>
44
- joins: [<an array of associations>]}
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.gdpr_collect :email, :last_sign_in_at, :type, :forward_mailbox,
52
- "program title",
53
- {user_id: :id,
54
- renamed_fields: {sign_in_count: "sign in count",
55
- current_sign_in_at: "time of current sign in",
56
- chosen_program_id: "chosen program",
57
- current_sign_in_ip: "current IP address",
58
- last_sign_in_ip: "previously used IP address"},
59
- joins: [:program]}
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
- From your `User` model, you want to retrieve the values of the fields `email, last_sign_in_at,
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
- Finally, call `GdprExporter.export(<user_id>)` to return a csv formatted output of all the fields you specified previously.
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
@@ -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
- result = self.where(user_id_field => _user_id)
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.
@@ -1,5 +1,5 @@
1
1
  module Exts
2
2
  module Gdpr
3
- VERSION = "2.0.2"
3
+ VERSION = "2.0.3"
4
4
  end
5
5
  end
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.2
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: 2018-05-28 00:00:00.000000000 Z
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.6
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.