user_activity 0.1.0
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 +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +42 -0
- data/Rakefile +36 -0
- data/app/assets/config/user_activity_manifest.js +2 -0
- data/app/assets/javascripts/user_activity/application.js +13 -0
- data/app/assets/stylesheets/user_activity/application.css +15 -0
- data/app/controllers/user_activity/application_controller.rb +5 -0
- data/app/helpers/user_activity/application_helper.rb +4 -0
- data/app/jobs/user_activity/application_job.rb +4 -0
- data/app/mailers/user_activity/application_mailer.rb +6 -0
- data/app/models/user_activity/application_record.rb +5 -0
- data/app/models/user_activity/user_activity_log.rb +5 -0
- data/app/views/layouts/user_activity/application.html.erb +14 -0
- data/config/initializers/rails_admin.rb +57 -0
- data/config/routes.rb +3 -0
- data/db/migrate/20171107030047_add_user_logs_table.rb +15 -0
- data/lib/tasks/user_activity_tasks.rake +4 -0
- data/lib/user_activity.rb +42 -0
- data/lib/user_activity/engine.rb +5 -0
- data/lib/user_activity/version.rb +3 -0
- metadata +108 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 570aafea45f410b73687c1369cad33444d88050a
|
4
|
+
data.tar.gz: 5b51b03da704c47f3d434ed769cc05b043f696c7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9c8aa9f7a8097d7dd04b717836b1ff8a3dde4072aec9721c5c9f19d358f1843562624e1426c7aef9eccf18d5c5a980519cd4ce8e4b1be4af7058bcaaf22ab807
|
7
|
+
data.tar.gz: 0c584653f8d72004d0fd57b9bb5e4d21c390648a93556f9ec1f65a5ab39a3546902d56a81682c247fff8ed7e59fa431ee3649a017c360d4d1777ac2936d1f2f0
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2017 Kraiyanat Tee
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# UserActivity
|
2
|
+
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.
|
3
|
+
|
4
|
+
## Usage
|
5
|
+
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.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'user_activity'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
```bash
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
```bash
|
21
|
+
$ gem install user_activity
|
22
|
+
```
|
23
|
+
|
24
|
+
### Generate database table:
|
25
|
+
```bash
|
26
|
+
$ rails user_activity:install:migrations
|
27
|
+
```
|
28
|
+
|
29
|
+
### Mount route to application:
|
30
|
+
```ruby
|
31
|
+
Rails.application.routes.draw do
|
32
|
+
...
|
33
|
+
mount RailsAdmin::Engine => '/user_activity', as: 'user_activity'
|
34
|
+
...
|
35
|
+
end
|
36
|
+
```
|
37
|
+
|
38
|
+
## Contributing
|
39
|
+
Contribution directions go here.
|
40
|
+
|
41
|
+
## License
|
42
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'UserActivity'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
|
18
|
+
load 'rails/tasks/engine.rake'
|
19
|
+
|
20
|
+
|
21
|
+
load 'rails/tasks/statistics.rake'
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
require 'bundler/gem_tasks'
|
26
|
+
|
27
|
+
require 'rake/testtask'
|
28
|
+
|
29
|
+
Rake::TestTask.new(:test) do |t|
|
30
|
+
t.libs << 'test'
|
31
|
+
t.pattern = 'test/**/*_test.rb'
|
32
|
+
t.verbose = false
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
task default: :test
|
@@ -0,0 +1,13 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file. JavaScript code in this file should be added after the last require_* statement.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require_tree .
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
|
10
|
+
* files in this directory. Styles in this file should be added after the last require_* statement.
|
11
|
+
* It is generally better to create a new file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>User activity</title>
|
5
|
+
<%= stylesheet_link_tag "user_activity/application", media: "all" %>
|
6
|
+
<%= javascript_include_tag "user_activity/application" %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<%= yield %>
|
12
|
+
|
13
|
+
</body>
|
14
|
+
</html>
|
@@ -0,0 +1,57 @@
|
|
1
|
+
RailsAdmin.config do |config|
|
2
|
+
|
3
|
+
### Popular gems integration
|
4
|
+
|
5
|
+
## == Devise ==
|
6
|
+
# config.authenticate_with do
|
7
|
+
# warden.authenticate! scope: :user
|
8
|
+
# end
|
9
|
+
# config.current_user_method(&:current_user)
|
10
|
+
|
11
|
+
## == Cancan ==
|
12
|
+
# config.authorize_with :cancan
|
13
|
+
|
14
|
+
## == Pundit ==
|
15
|
+
# config.authorize_with :pundit
|
16
|
+
|
17
|
+
## == PaperTrail ==
|
18
|
+
# config.audit_with :paper_trail, 'User', 'PaperTrail::Version' # PaperTrail >= 3.0.0
|
19
|
+
|
20
|
+
### More at https://github.com/sferik/rails_admin/wiki/Base-configuration
|
21
|
+
|
22
|
+
## == Gravatar integration ==
|
23
|
+
## To disable Gravatar integration in Navigation Bar set to false
|
24
|
+
# config.show_gravatar = true
|
25
|
+
|
26
|
+
config.actions do
|
27
|
+
dashboard do
|
28
|
+
only UserActivity::UserActivityLog
|
29
|
+
end
|
30
|
+
|
31
|
+
index do
|
32
|
+
only UserActivity::UserActivityLog
|
33
|
+
end
|
34
|
+
|
35
|
+
export do
|
36
|
+
only UserActivity::UserActivityLog
|
37
|
+
end
|
38
|
+
|
39
|
+
# new
|
40
|
+
# bulk_delete
|
41
|
+
|
42
|
+
show do
|
43
|
+
only UserActivity::UserActivityLog
|
44
|
+
end
|
45
|
+
|
46
|
+
# edit
|
47
|
+
# delete
|
48
|
+
|
49
|
+
show_in_app do
|
50
|
+
only UserActivity::UserActivityLog
|
51
|
+
end
|
52
|
+
|
53
|
+
## With an audit adapter, you can add:
|
54
|
+
# history_index
|
55
|
+
# history_show
|
56
|
+
end
|
57
|
+
end
|
data/config/routes.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
class AddUserLogsTable < ActiveRecord::Migration[5.1]
|
2
|
+
def change
|
3
|
+
create_table :user_activity_logs do |t|
|
4
|
+
t.integer :user_id
|
5
|
+
t.string :user_name
|
6
|
+
t.string :object_id
|
7
|
+
t.string :controller
|
8
|
+
t.string :action
|
9
|
+
t.string :activity
|
10
|
+
t.string :http_request
|
11
|
+
|
12
|
+
t.timestamps
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require "active_support"
|
2
|
+
require "user_activity/engine"
|
3
|
+
|
4
|
+
module UserActivity
|
5
|
+
def tee_method
|
6
|
+
"Kraiyanat"
|
7
|
+
end
|
8
|
+
|
9
|
+
def user_for_user_activity
|
10
|
+
@current_user || Struct.new(:name, :id).new("anonymus", "")
|
11
|
+
end
|
12
|
+
|
13
|
+
def activity_for_user_activity(controller, method)
|
14
|
+
activity_hash = {}
|
15
|
+
activity_hash[["aa", "bb"]] = "cc"
|
16
|
+
|
17
|
+
activity_hash[[controller.to_s, method.to_s]].to_s
|
18
|
+
end
|
19
|
+
|
20
|
+
def log_user_activity
|
21
|
+
UserActivityLog.create(
|
22
|
+
user_id: user_for_user_activity.id,
|
23
|
+
user_name: user_for_user_activity.name,
|
24
|
+
action: params[:action],
|
25
|
+
controller: params[:controller],
|
26
|
+
activity: activity_for_user_activity("aa", "bb"),
|
27
|
+
http_request: "#{request.method} #{request.url} #{request.params}"
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.included(klass)
|
32
|
+
klass.extend ClassMethods
|
33
|
+
end
|
34
|
+
|
35
|
+
module ClassMethods
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
ActiveSupport.on_load(:action_controller) do
|
40
|
+
include UserActivity
|
41
|
+
before_action :log_user_activity
|
42
|
+
end
|
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: user_activity
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kraiyanat Chomchumpol
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-11-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 5.1.4
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 5.1.4
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rails_admin
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.2'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.2'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: sqlite3
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: 'Easy to use gem, tracking all activity that user done and come with
|
56
|
+
the modern user interface ''rails admin'' '
|
57
|
+
email:
|
58
|
+
- kraiyanat@gmail.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- MIT-LICENSE
|
64
|
+
- README.md
|
65
|
+
- Rakefile
|
66
|
+
- app/assets/config/user_activity_manifest.js
|
67
|
+
- app/assets/javascripts/user_activity/application.js
|
68
|
+
- app/assets/stylesheets/user_activity/application.css
|
69
|
+
- app/controllers/user_activity/application_controller.rb
|
70
|
+
- app/helpers/user_activity/application_helper.rb
|
71
|
+
- app/jobs/user_activity/application_job.rb
|
72
|
+
- app/mailers/user_activity/application_mailer.rb
|
73
|
+
- app/models/user_activity/application_record.rb
|
74
|
+
- app/models/user_activity/user_activity_log.rb
|
75
|
+
- app/views/layouts/user_activity/application.html.erb
|
76
|
+
- config/initializers/rails_admin.rb
|
77
|
+
- config/routes.rb
|
78
|
+
- db/migrate/20171107030047_add_user_logs_table.rb
|
79
|
+
- lib/tasks/user_activity_tasks.rake
|
80
|
+
- lib/user_activity.rb
|
81
|
+
- lib/user_activity/engine.rb
|
82
|
+
- lib/user_activity/version.rb
|
83
|
+
homepage: ''
|
84
|
+
licenses:
|
85
|
+
- MIT
|
86
|
+
metadata: {}
|
87
|
+
post_install_message:
|
88
|
+
rdoc_options: []
|
89
|
+
require_paths:
|
90
|
+
- lib
|
91
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
requirements: []
|
102
|
+
rubyforge_project:
|
103
|
+
rubygems_version: 2.6.11
|
104
|
+
signing_key:
|
105
|
+
specification_version: 4
|
106
|
+
summary: Rails engine mountable gem to tracking user activities
|
107
|
+
test_files: []
|
108
|
+
has_rdoc:
|