rails-gdpr-export 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6f339f58d2851865fc9ecbb780ed5561a9f692bc60341325d14b2e18c6378733
4
+ data.tar.gz: a3f0b834ec32842050baa81fab905d6a75bf6364edaf2583c843a124568dcb01
5
+ SHA512:
6
+ metadata.gz: 6b3b5df225578771d630115f3a47455b1e72a79d239236fc892c505a34bf390fb567d7fa86a102b09e52aa631f2825c81dfc5c98704fe3b302d90bb1a5cd81f5
7
+ data.tar.gz: f91fcb3f52b6da7ad6ef2bd75bb2dca3984075fd94f3aa56f8b4bb73b7d54d706659121ecf655002f0a0c726a574e70d944f3e4979bf4b60370a84086ed20177
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.0
5
+ before_install: gem install bundler -v 1.16.1
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in rails-gdpr-export.gemspec
6
+ gemspec
@@ -0,0 +1,35 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rails-gdpr-export (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.3)
10
+ rake (10.5.0)
11
+ rspec (3.7.0)
12
+ rspec-core (~> 3.7.0)
13
+ rspec-expectations (~> 3.7.0)
14
+ rspec-mocks (~> 3.7.0)
15
+ rspec-core (3.7.1)
16
+ rspec-support (~> 3.7.0)
17
+ rspec-expectations (3.7.0)
18
+ diff-lcs (>= 1.2.0, < 2.0)
19
+ rspec-support (~> 3.7.0)
20
+ rspec-mocks (3.7.0)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.7.0)
23
+ rspec-support (3.7.1)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ bundler (~> 1.16)
30
+ rails-gdpr-export!
31
+ rake (< 11.0)
32
+ rspec (~> 3.0)
33
+
34
+ BUNDLED WITH
35
+ 1.16.1
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Chrislain Razafimahefa
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,70 @@
1
+ # Rails::Gdpr::Export
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rails/gdpr/export`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'rails-gdpr-export'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install rails-gdpr-export
22
+
23
+ ## Usage
24
+
25
+ - Add the following code in a initializer file (e.g. initializers/gdpr.rb):
26
+
27
+ ```ruby
28
+ require 'exts/gdpr'
29
+
30
+ # Loads the Gdpr module into activerecord classes.
31
+ ActiveRecord::Base.send :include, Gdpr
32
+
33
+
34
+ # Defines gdpr data collection throughout the model classes
35
+ #
36
+ User.gdpr_collect :email, :last_sign_in_at, :stripe_customer_id,
37
+ :type, :forward_mailbox,
38
+ {user_id: :id,
39
+ renamed_fields: {sign_in_count: "sign in count",
40
+ current_sign_in_at: "time of current sign in",
41
+ chosen_program_id: "chosen program",
42
+ current_sign_in_ip: "current IP address",
43
+ last_sign_in_ip: "previously used IP address"}}
44
+
45
+
46
+ Subscription.gdpr_collect :stripe_id, :stripe_plan_id,
47
+ :exmatriculated_at, :current_period_end, :status,
48
+ :notified_at, :pause_reason, :pause_error,
49
+ :start_at, :initial_start_at, :completed_at,
50
+ :amount, :paused_at, :rules_accepted_at,
51
+ {user_id: :user_id,
52
+ join: :program,
53
+ renamed_fields: {title: "program title"}}
54
+ ```
55
+
56
+ - call Gdpr.export(<user_id>) and it will return a csv formatted output
57
+
58
+ ## Development
59
+
60
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
61
+
62
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
63
+
64
+ ## Contributing
65
+
66
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rails-gdpr-export.
67
+
68
+ ## License
69
+
70
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rails/gdpr/export"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,114 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "exts/gdpr/version"
4
+ require 'csv'
5
+
6
+ module Exts
7
+ module Gdpr
8
+ # Stores all the classes that have been tagged for gdpr collection
9
+ @@klasses = []
10
+
11
+ def self.get_klasses
12
+ @@klasses
13
+ end
14
+
15
+ def self.add_klass(klass)
16
+ @@klasses << klass
17
+ end
18
+
19
+ # Collects data through all the tagged models and generates a csv
20
+ # formatted output
21
+ def self.export(user_id)
22
+ CSV.generate do |csv|
23
+ get_klasses.each do |klass|
24
+ rows = klass.gdpr_query(user_id)
25
+ klass.gdpr_export(rows, csv)
26
+ end
27
+ end
28
+ end
29
+
30
+ # Instruments the classes implementing this module with instance and class
31
+ # methods.
32
+ def self.included base
33
+ base.send :include, InstanceMethods
34
+ base.extend ClassMethods
35
+ end
36
+
37
+ module InstanceMethods
38
+ end
39
+
40
+ module ClassMethods
41
+ # Declared in each model class with interest in collecting gdpr data.
42
+ # Instruments the singleton of those classes so that gdpr data can be
43
+ # collected and exported to csv.
44
+ #
45
+ # Arguments are:
46
+ # - set of simple fields: i.e. fields that will be output as is
47
+ # - a hash of params:
48
+ # {renamed_fields: {<field_from_db> => <field_name_in_output>}
49
+ # table_name: <the new table name in output>
50
+ # description: <a comment>
51
+ # join: <an association>}
52
+ def gdpr_collect(*args)
53
+ # Params handling
54
+ if args.class == Hash # when user provides the hash_params only
55
+ simple_fields, hash_params = [[], args]
56
+ else
57
+ simple_fields, hash_params = [args[0..-2], args.last]
58
+ end
59
+
60
+ unless hash_params.class == Hash
61
+ raise "Gdpr fields collection error: last argument must be a hash!"
62
+ end
63
+
64
+ unless hash_params.key?(:user_id)
65
+ raise "Gdpr fields collection error: the field aliasing user_id is not declared for '#{self}'!"
66
+ end
67
+
68
+ # Adds the eigen class to the set of classes eligible for gdpr data collection.
69
+ Gdpr.add_klass(self)
70
+
71
+ # Adds instance fields to the eigenclass. They store
72
+ # all the fields and info we are interested in.
73
+ @gdpr_simple_fields = simple_fields
74
+ @gdpr_hash_params = hash_params
75
+ # Add readers for the instance vars declared above (for testing reasons)
76
+ self.class.send :attr_reader, :gdpr_simple_fields
77
+ self.class.send :attr_reader, :gdpr_hash_params
78
+
79
+ # Build the csv header and prepare the fields used for querying
80
+ user_id_field = hash_params[:user_id]
81
+ csv_headers = [:user_id].concat @gdpr_simple_fields
82
+ query_fields = [user_id_field].concat @gdpr_simple_fields
83
+
84
+ if hash_params[:renamed_fields]
85
+ csv_headers.concat hash_params[:renamed_fields].values
86
+ query_fields.concat hash_params[:renamed_fields].keys
87
+ end
88
+
89
+ # Adds the class method 'gdpr_query' to the eigenclass.
90
+ # It will execute the query.
91
+ self.define_singleton_method(:gdpr_query) do |_user_id|
92
+ if hash_params[:join]
93
+ self.select(query_fields).where(user_id_field => _user_id).
94
+ joins(hash_params[:join])
95
+ else
96
+ self.select(query_fields).where(user_id_field => _user_id)
97
+ end
98
+ end
99
+
100
+ # Adds a method to export to csv to the eigenclass.
101
+ self.define_singleton_method(:gdpr_export) do |rows, csv|
102
+ csv << (hash_params[:table_name] ? [hash_params[:table_name]] :
103
+ [self.to_s])
104
+ csv << csv_headers
105
+ rows.each do |r|
106
+ csv << query_fields.map{ |f| r.send(f) }
107
+ end
108
+ csv << ['Comment:', hash_params[:desc]] if hash_params[:desc]
109
+ csv << []
110
+ end
111
+ end
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,5 @@
1
+ module Exts
2
+ module Gdpr
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,35 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "exts/gdpr/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rails-gdpr-export"
8
+ spec.version = Exts::Gdpr::VERSION
9
+ spec.authors = ["Chrislain Razafimahefa"]
10
+ spec.email = ["razafima@gmail.com"]
11
+
12
+ spec.summary = %q{A gem to export personal data in compliance with GDPR.}
13
+ spec.homepage = "https://github.com/epfl-exts/rails-gdpr-export"
14
+ spec.license = "MIT"
15
+
16
+ # # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ # if spec.respond_to?(:metadata)
19
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
20
+ # else
21
+ # raise "RubyGems 2.0 or newer is required to protect against " \
22
+ # "public gem pushes."
23
+ # end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
+ f.match(%r{^(test|spec|features)/})
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_development_dependency "bundler", "~> 1.16"
33
+ spec.add_development_dependency "rake", "< 11.0"
34
+ spec.add_development_dependency "rspec", "~> 3.0"
35
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails-gdpr-export
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Chrislain Razafimahefa
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-05-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "<"
32
+ - !ruby/object:Gem::Version
33
+ version: '11.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "<"
39
+ - !ruby/object:Gem::Version
40
+ version: '11.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description:
56
+ email:
57
+ - razafima@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - Gemfile
66
+ - Gemfile.lock
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - bin/console
71
+ - bin/setup
72
+ - lib/exts/gdpr.rb
73
+ - lib/exts/gdpr/version.rb
74
+ - rails-gdpr-export.gemspec
75
+ homepage: https://github.com/epfl-exts/rails-gdpr-export
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.7.6
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: A gem to export personal data in compliance with GDPR.
99
+ test_files: []