Coder Social home page Coder Social logo

rails-gdpr-export's Introduction

rails-gdpr-export

A gem for exporting user personal data in compliance with GDPR.

Installation

Add this line to your application's Gemfile:

gem 'rails-gdpr-export'

And then execute:

$ bundle

Or install it yourself as:

$ gem install rails-gdpr-export

Usage

This gem allows you to specify fields that you want to retrieve from your models and to export them in a csv format.

Initialization

First start by importing gdpr_exporter into your application, i.e., add require "gdpr_exporter" to your Application.rb file.

Data collection

In order to specify the fields you want to collect you need to call gdpr_collect. The call target is a rails model and its arguments are:

  • a set of simple fields, i.e. fields that will be output as is,
  • followed by a hash of params:
 { user_id:        <the field in the model used as alias for the user_id field>
   renamed_fields: { <field_from_db> => <field_name_in_output> }
   table_name:     <the new table name in output>
   description:    <a comment>
   joins:          [<an array of associations>] }

When joins is specified, the fields of an association should be defined as <association_name> <field_name>.

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.

Example

Suppose you have a User model, then in its class you should include Gdprexporter and call gdpr_collect. And you should do something similar for all other models you are interested in in your application.

class User
    include GdprExporter

    gdpr_collect :email, :last_sign_in_at, :type, :forward_mailbox,
        "program title",
        { user_id: :id,
          renamed_fields: { sign_in_count: "sign in count",
                            current_sign_in_at: "time of current sign in",
                            chosen_program_id: "chosen program",
                            current_sign_in_ip: "current IP address",
                            last_sign_in_ip: "previously used IP address" },
          joins:          [:program] }
end

Here from your User model, you want to retrieve the values of the fields email, last_sign_in_at, 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. 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).

Data export

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.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/epfl-exts/rails-gdpr-export.

License

The gem is available as open source under the terms of the MIT License.

rails-gdpr-export's People

Contributors

grischoun avatar yannis avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.