The GDPR is forcing to use in mid of year 2017, I wanna have the tool out of the box to record the personal data accessing that can have some activity configuration.
User activity gem is a rails engine mountable gem working with "rails" and "rails admin". It's record all controller and action that user use into the database table itself.
Add this line to your application's Gemfile:
gem 'user_activity'
gem 'rails_admin', '~> 1.2 #the dependency gem
And then execute:
$ bundle
Or install it yourself as:
$ gem install user_activity
$ rails user_activity:install:migrations
And then execute:
$ rake db:migrate
Rails.application.routes.draw do
...
mount RailsAdmin::Engine => '/user_activity', as: 'user_activity'
...
end
In order to make the gem work, there is a few think to do following below.
##Configuration It is posible to config some data in this gem, to do that you can follow the example below:
In case you want to enable to all controller in your application, you can add code to ApplicationController.
class ApplicationController < ActionController::Base
...
before_action :log_user_activity
...
end
Override the method name 'user_for_user_activity'in controller which is return object of Struct with attribures 'name' and 'id'. For example in case using Devise.
class ApplicationController < ActionController::Base
...
def user_for_user_activity
Struct.new(:name, :id).new(current_user.email, current_user.id)
end
...
end
To define activity name and record to database, need to run the command below:
$ rails generate installer user_activity
That will create 2 files.
- config/initializers/user_activity.rb
- config/user_activity.yml
First is config/initializer/user_activity.rb configuration file that load yml to configuration attribute, the second is config/user_activity.yml this file store activity define and you can define the activity here.
Contribution directions go here.
The gem is available as open source under the terms of the MIT License.