transcript 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.codeclimate.yml +27 -0
- data/.gitignore +13 -0
- data/.rspec +2 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +170 -0
- data/LICENSE +21 -0
- data/README.md +174 -0
- data/Rakefile +7 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/circle.yml +8 -0
- data/config.ru +7 -0
- data/lib/generators/transcript/USAGE +17 -0
- data/lib/generators/transcript/install_generator.rb +33 -0
- data/lib/generators/transcript/templates/transcript.rb.erb +3 -0
- data/lib/transcript/actor.rb +13 -0
- data/lib/transcript/configuration.rb +5 -0
- data/lib/transcript/controller.rb +11 -0
- data/lib/transcript/job.rb +16 -0
- data/lib/transcript/model.rb +20 -0
- data/lib/transcript/receiver.rb +11 -0
- data/lib/transcript/version.rb +3 -0
- data/lib/transcript.rb +21 -0
- data/spec/audit_entry_spec.rb +66 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/config/manifest.js +4 -0
- data/spec/dummy/app/assets/images/.keep +0 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/javascripts/cable.js +13 -0
- data/spec/dummy/app/assets/javascripts/channels/.keep +0 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
- data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/controllers/concerns/.keep +0 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/jobs/application_job.rb +2 -0
- data/spec/dummy/app/mailers/application_mailer.rb +4 -0
- data/spec/dummy/app/models/application_record.rb +3 -0
- data/spec/dummy/app/models/audit_entry.rb +3 -0
- data/spec/dummy/app/models/concerns/.keep +0 -0
- data/spec/dummy/app/models/post.rb +3 -0
- data/spec/dummy/app/models/user.rb +3 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
- data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/bin/setup +34 -0
- data/spec/dummy/bin/update +29 -0
- data/spec/dummy/config/application.rb +15 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/cable.yml +9 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +54 -0
- data/spec/dummy/config/environments/production.rb +86 -0
- data/spec/dummy/config/environments/test.rb +42 -0
- data/spec/dummy/config/initializers/application_controller_renderer.rb +6 -0
- data/spec/dummy/config/initializers/assets.rb +11 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +5 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/new_framework_defaults.rb +24 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/transcript.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/puma.rb +47 -0
- data/spec/dummy/config/routes.rb +3 -0
- data/spec/dummy/config/secrets.yml +22 -0
- data/spec/dummy/config/spring.rb +6 -0
- data/spec/dummy/config.ru +5 -0
- data/spec/dummy/db/migrate/20160822202506_create_users.rb +8 -0
- data/spec/dummy/db/migrate/20160822202519_create_posts.rb +8 -0
- data/spec/dummy/db/migrate/20160823152659_create_audit_entries.rb +12 -0
- data/spec/dummy/db/schema.rb +38 -0
- data/spec/dummy/lib/assets/.keep +0 -0
- data/spec/dummy/log/.keep +0 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
- data/spec/dummy/public/apple-touch-icon.png +0 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/test/factories/audit_entries.rb +9 -0
- data/spec/dummy/test/fixtures/audit_entries.yml +19 -0
- data/spec/dummy/test/fixtures/posts.yml +11 -0
- data/spec/dummy/test/fixtures/users.yml +11 -0
- data/spec/dummy/test/models/audit_entry_test.rb +7 -0
- data/spec/dummy/test/models/post_test.rb +7 -0
- data/spec/dummy/test/models/user_test.rb +7 -0
- data/spec/factories.rb +16 -0
- data/spec/generators/install_generator_spec.rb +65 -0
- data/spec/post_spec.rb +17 -0
- data/spec/spec_helper.rb +53 -0
- data/spec/support/active_job.rb +1 -0
- data/spec/support/application_controller.rb +2 -0
- data/spec/support/factory_girl.rb +3 -0
- data/spec/support/shoulda.rb +11 -0
- data/spec/transcript/configuration_spec.rb +7 -0
- data/spec/transcript/controller_spec.rb +49 -0
- data/spec/transcript/job_spec.rb +14 -0
- data/spec/transcript/transcript_spec.rb +5 -0
- data/spec/user_spec.rb +17 -0
- data/transcript.gemspec +32 -0
- metadata +383 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9b20d6d6f59ef113036dddfa9739d4fc16dc10b0
|
4
|
+
data.tar.gz: ea8aa8e46168e4dbddaa027f2820f6e83e7373ec
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c58484693521b8da900784752ba56c334b7141d2af4163ce68b345b4010457fd43450eb2a9d307754dda9dc23ebafda1a7ec173d1a82999a360a4800778e66a0
|
7
|
+
data.tar.gz: 931079903ab30d12e4a52d9701120e22613d2dbe51a7be57764582d34b64df65b2b3f5f319e1af6c98976216ab8a8d6ff5f3620fc32a1c0faeb7c86c7d6fb2c8
|
data/.codeclimate.yml
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
---
|
2
|
+
engines:
|
3
|
+
bundler-audit:
|
4
|
+
enabled: true
|
5
|
+
duplication:
|
6
|
+
enabled: true
|
7
|
+
config:
|
8
|
+
languages:
|
9
|
+
- ruby
|
10
|
+
fixme:
|
11
|
+
enabled: true
|
12
|
+
rubocop:
|
13
|
+
enabled: true
|
14
|
+
markdownlint:
|
15
|
+
enabled: true
|
16
|
+
checks:
|
17
|
+
MD013:
|
18
|
+
enabled: false
|
19
|
+
shellcheck:
|
20
|
+
enabled: true
|
21
|
+
ratings:
|
22
|
+
paths:
|
23
|
+
- Gemfile.lock
|
24
|
+
- "**.erb"
|
25
|
+
- "**.rb"
|
26
|
+
exclude_paths:
|
27
|
+
- spec/
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at logan@loganleger.com. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,170 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
transcript (0.1.0)
|
5
|
+
rails (~> 5.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
actioncable (5.0.0.1)
|
11
|
+
actionpack (= 5.0.0.1)
|
12
|
+
nio4r (~> 1.2)
|
13
|
+
websocket-driver (~> 0.6.1)
|
14
|
+
actionmailer (5.0.0.1)
|
15
|
+
actionpack (= 5.0.0.1)
|
16
|
+
actionview (= 5.0.0.1)
|
17
|
+
activejob (= 5.0.0.1)
|
18
|
+
mail (~> 2.5, >= 2.5.4)
|
19
|
+
rails-dom-testing (~> 2.0)
|
20
|
+
actionpack (5.0.0.1)
|
21
|
+
actionview (= 5.0.0.1)
|
22
|
+
activesupport (= 5.0.0.1)
|
23
|
+
rack (~> 2.0)
|
24
|
+
rack-test (~> 0.6.3)
|
25
|
+
rails-dom-testing (~> 2.0)
|
26
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
27
|
+
actionview (5.0.0.1)
|
28
|
+
activesupport (= 5.0.0.1)
|
29
|
+
builder (~> 3.1)
|
30
|
+
erubis (~> 2.7.0)
|
31
|
+
rails-dom-testing (~> 2.0)
|
32
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
33
|
+
activejob (5.0.0.1)
|
34
|
+
activesupport (= 5.0.0.1)
|
35
|
+
globalid (>= 0.3.6)
|
36
|
+
activemodel (5.0.0.1)
|
37
|
+
activesupport (= 5.0.0.1)
|
38
|
+
activerecord (5.0.0.1)
|
39
|
+
activemodel (= 5.0.0.1)
|
40
|
+
activesupport (= 5.0.0.1)
|
41
|
+
arel (~> 7.0)
|
42
|
+
activesupport (5.0.0.1)
|
43
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
44
|
+
i18n (~> 0.7)
|
45
|
+
minitest (~> 5.1)
|
46
|
+
tzinfo (~> 1.1)
|
47
|
+
ammeter (1.1.3)
|
48
|
+
activesupport (>= 3.0)
|
49
|
+
railties (>= 3.0)
|
50
|
+
rspec-rails (>= 2.2)
|
51
|
+
arel (7.1.1)
|
52
|
+
builder (3.2.2)
|
53
|
+
codeclimate-test-reporter (0.6.0)
|
54
|
+
simplecov (>= 0.7.1, < 1.0.0)
|
55
|
+
concurrent-ruby (1.0.2)
|
56
|
+
diff-lcs (1.2.5)
|
57
|
+
docile (1.1.5)
|
58
|
+
erubis (2.7.0)
|
59
|
+
factory_girl (4.7.0)
|
60
|
+
activesupport (>= 3.0.0)
|
61
|
+
factory_girl_rails (4.7.0)
|
62
|
+
factory_girl (~> 4.7.0)
|
63
|
+
railties (>= 3.0.0)
|
64
|
+
globalid (0.3.7)
|
65
|
+
activesupport (>= 4.1.0)
|
66
|
+
i18n (0.7.0)
|
67
|
+
json (2.0.1)
|
68
|
+
loofah (2.0.3)
|
69
|
+
nokogiri (>= 1.5.9)
|
70
|
+
mail (2.6.4)
|
71
|
+
mime-types (>= 1.16, < 4)
|
72
|
+
method_source (0.8.2)
|
73
|
+
mime-types (3.1)
|
74
|
+
mime-types-data (~> 3.2015)
|
75
|
+
mime-types-data (3.2016.0521)
|
76
|
+
mini_portile2 (2.1.0)
|
77
|
+
minitest (5.9.0)
|
78
|
+
nio4r (1.2.1)
|
79
|
+
nokogiri (1.6.8)
|
80
|
+
mini_portile2 (~> 2.1.0)
|
81
|
+
pkg-config (~> 1.1.7)
|
82
|
+
pkg-config (1.1.7)
|
83
|
+
rack (2.0.1)
|
84
|
+
rack-test (0.6.3)
|
85
|
+
rack (>= 1.0)
|
86
|
+
rails (5.0.0.1)
|
87
|
+
actioncable (= 5.0.0.1)
|
88
|
+
actionmailer (= 5.0.0.1)
|
89
|
+
actionpack (= 5.0.0.1)
|
90
|
+
actionview (= 5.0.0.1)
|
91
|
+
activejob (= 5.0.0.1)
|
92
|
+
activemodel (= 5.0.0.1)
|
93
|
+
activerecord (= 5.0.0.1)
|
94
|
+
activesupport (= 5.0.0.1)
|
95
|
+
bundler (>= 1.3.0, < 2.0)
|
96
|
+
railties (= 5.0.0.1)
|
97
|
+
sprockets-rails (>= 2.0.0)
|
98
|
+
rails-dom-testing (2.0.1)
|
99
|
+
activesupport (>= 4.2.0, < 6.0)
|
100
|
+
nokogiri (~> 1.6.0)
|
101
|
+
rails-html-sanitizer (1.0.3)
|
102
|
+
loofah (~> 2.0)
|
103
|
+
railties (5.0.0.1)
|
104
|
+
actionpack (= 5.0.0.1)
|
105
|
+
activesupport (= 5.0.0.1)
|
106
|
+
method_source
|
107
|
+
rake (>= 0.8.7)
|
108
|
+
thor (>= 0.18.1, < 2.0)
|
109
|
+
rake (10.5.0)
|
110
|
+
rspec (3.5.0)
|
111
|
+
rspec-core (~> 3.5.0)
|
112
|
+
rspec-expectations (~> 3.5.0)
|
113
|
+
rspec-mocks (~> 3.5.0)
|
114
|
+
rspec-core (3.5.2)
|
115
|
+
rspec-support (~> 3.5.0)
|
116
|
+
rspec-expectations (3.5.0)
|
117
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
118
|
+
rspec-support (~> 3.5.0)
|
119
|
+
rspec-mocks (3.5.0)
|
120
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
121
|
+
rspec-support (~> 3.5.0)
|
122
|
+
rspec-rails (3.5.1)
|
123
|
+
actionpack (>= 3.0)
|
124
|
+
activesupport (>= 3.0)
|
125
|
+
railties (>= 3.0)
|
126
|
+
rspec-core (~> 3.5.0)
|
127
|
+
rspec-expectations (~> 3.5.0)
|
128
|
+
rspec-mocks (~> 3.5.0)
|
129
|
+
rspec-support (~> 3.5.0)
|
130
|
+
rspec-support (3.5.0)
|
131
|
+
shoulda-matchers (3.1.1)
|
132
|
+
activesupport (>= 4.0.0)
|
133
|
+
simplecov (0.12.0)
|
134
|
+
docile (~> 1.1.0)
|
135
|
+
json (>= 1.8, < 3)
|
136
|
+
simplecov-html (~> 0.10.0)
|
137
|
+
simplecov-html (0.10.0)
|
138
|
+
sprockets (3.7.0)
|
139
|
+
concurrent-ruby (~> 1.0)
|
140
|
+
rack (> 1, < 3)
|
141
|
+
sprockets-rails (3.1.1)
|
142
|
+
actionpack (>= 4.0)
|
143
|
+
activesupport (>= 4.0)
|
144
|
+
sprockets (>= 3.0.0)
|
145
|
+
sqlite3 (1.3.11)
|
146
|
+
thor (0.19.1)
|
147
|
+
thread_safe (0.3.5)
|
148
|
+
tzinfo (1.2.2)
|
149
|
+
thread_safe (~> 0.1)
|
150
|
+
websocket-driver (0.6.4)
|
151
|
+
websocket-extensions (>= 0.1.0)
|
152
|
+
websocket-extensions (0.1.2)
|
153
|
+
|
154
|
+
PLATFORMS
|
155
|
+
ruby
|
156
|
+
|
157
|
+
DEPENDENCIES
|
158
|
+
ammeter (~> 1.1)
|
159
|
+
bundler (~> 1.12)
|
160
|
+
codeclimate-test-reporter (~> 0.6)
|
161
|
+
factory_girl_rails (~> 4.2)
|
162
|
+
rake (~> 10.0)
|
163
|
+
rspec (~> 3.0)
|
164
|
+
shoulda-matchers (~> 3.1)
|
165
|
+
simplecov (~> 0.12)
|
166
|
+
sqlite3 (~> 1.3)
|
167
|
+
transcript!
|
168
|
+
|
169
|
+
BUNDLED WITH
|
170
|
+
1.12.5
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2009 NewAperio, LLC.
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,174 @@
|
|
1
|
+
# Transcript
|
2
|
+
|
3
|
+
Simple ActiveRecord auditing.
|
4
|
+
|
5
|
+
[![CircleCI](https://circleci.com/gh/newaperio/transcript.svg?style=svg)](https://circleci.com/gh/newaperio/transcript)
|
6
|
+
[![Code Climate](https://codeclimate.com/github/newaperio/transcript/badges/gpa.svg)](https://codeclimate.com/github/newaperio/transcript)
|
7
|
+
[![Test Coverage](https://codeclimate.com/github/newaperio/transcript/badges/coverage.svg)](https://codeclimate.com/github/newaperio/transcript/coverage)
|
8
|
+
|
9
|
+
Transcript is a simple audit library. It provides a clean interface for recording changes to a given record, including metadata about the change itself. At its core, Transcript is simply a set of concerns that expose functionality in the controller to create the log and in the model to setup relationships between the data.
|
10
|
+
|
11
|
+
Transcript differs from other auditing libraries in two ways. First, it values explicitness, exposing audit log creation near where the action takes place. Secondly, Transcript values simplicity. The core classes are only a few lines each.
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
Transcript is a set of Rails concerns and generators. It's intended to be used with Rails 5.0+ and Ruby 1.9.3+. It currently only works with PostgreSQL.
|
16
|
+
|
17
|
+
Add this line to your application's Gemfile:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
gem 'transcript'
|
21
|
+
```
|
22
|
+
|
23
|
+
And then execute:
|
24
|
+
|
25
|
+
```sh
|
26
|
+
$ bundle
|
27
|
+
```
|
28
|
+
|
29
|
+
Next, run the generator to install:
|
30
|
+
|
31
|
+
```sh
|
32
|
+
$ rails generate transcript:install NAME
|
33
|
+
```
|
34
|
+
|
35
|
+
This generates a Transcript model, which can be called anything, and an initializer, specifying some configuration.
|
36
|
+
|
37
|
+
## Using Transcript
|
38
|
+
|
39
|
+
### Models
|
40
|
+
|
41
|
+
Transcript has notions of three types of models:
|
42
|
+
|
43
|
+
- the actor, which is the object taking action;
|
44
|
+
- the receiver, or the object that the actor is taking action on;
|
45
|
+
- and the Transcript model, which records these actions.
|
46
|
+
|
47
|
+
#### Actor
|
48
|
+
|
49
|
+
An actor can be any individual model. Because this is configured as a polymorphic association, any number of individual models can be configured as actors. To add a new actor, include the concern in the model. For example, you might have a `User` model that you want to make an actor:
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
class User < ActiveRecord::Base
|
53
|
+
include Transcript::Actor
|
54
|
+
end
|
55
|
+
```
|
56
|
+
|
57
|
+
This interface sets up relationships to the log. To get a list of all the entries created by a particular actor, call the `audit_entries_by` relationship:
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
@user.audit_entries_by # => [#<AuditEntry>, ...]
|
61
|
+
```
|
62
|
+
|
63
|
+
#### Receiver
|
64
|
+
|
65
|
+
The receiver, similar to the actor, can be any individual model, and as many models as required. To add a new receiver, include the concern:
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
class Post < ActiveRecord::Post
|
69
|
+
include Transcript::Receiver
|
70
|
+
end
|
71
|
+
```
|
72
|
+
|
73
|
+
This will setup the relationships to get a list of the activities on a particular receiver:
|
74
|
+
|
75
|
+
```ruby
|
76
|
+
@post.audit_entries # => [#<AuditEntry>, ...]
|
77
|
+
```
|
78
|
+
|
79
|
+
Sometimes you may want to have a single model that is both an actor and a receiver. For example, you may want to track changes on your user model. You can do this by including both concerns:
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
class User < ActiveRecord::Base
|
83
|
+
include Transcript::Actor
|
84
|
+
include Transcript::Receiver
|
85
|
+
end
|
86
|
+
```
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
@user.audit_entries_by # => [#<AuditEntry>, ...]
|
90
|
+
@user.audit_entries # => [#<AuditEntry>, ...]
|
91
|
+
```
|
92
|
+
|
93
|
+
#### Model
|
94
|
+
|
95
|
+
The Transcript model is generated by the installer. The primary functionality is included as a concern to provide the most amount of flexibility. Since it's a module, you can override or extend the functionality in the model itself.
|
96
|
+
|
97
|
+
The generator will give you something like this:
|
98
|
+
|
99
|
+
```ruby
|
100
|
+
class AuditEntry < ActiveRecord::Base
|
101
|
+
include Transcript::Model
|
102
|
+
end
|
103
|
+
```
|
104
|
+
|
105
|
+
The concern also includes a convenience method to get the latest audit entry:
|
106
|
+
|
107
|
+
```ruby
|
108
|
+
@post.audit_entries.latest # => #<AuditEntry>
|
109
|
+
```
|
110
|
+
|
111
|
+
### Metadata
|
112
|
+
|
113
|
+
Transcript tracks some metadata about the audit entry. It logs the receiver at the top of the entry to `receiver_serialized`. This is a JSONB column in PostgreSQL, which can be indexed and queried.
|
114
|
+
|
115
|
+
### Controller
|
116
|
+
|
117
|
+
The controller concern provides an easy controller helper to create the Transcript record. The installation generator should inject the concern automatically:
|
118
|
+
|
119
|
+
```ruby
|
120
|
+
class ApplicationController < ActionController::Base
|
121
|
+
include Transcript::Controller
|
122
|
+
end
|
123
|
+
```
|
124
|
+
|
125
|
+
Now, in any action, make a call to the helper. The method expects an object representing the actor and the object that is being acted upon. You can optionally pass a custom action name as a third argument as a string representing the verb (e.g. `create`, `delete`, or `export`). If no custom action is provided Transcript will infer from the controller action it's being called in.
|
126
|
+
|
127
|
+
**Implied action:**
|
128
|
+
```ruby
|
129
|
+
def create
|
130
|
+
audit_action current_user, @comment
|
131
|
+
# ...
|
132
|
+
end
|
133
|
+
```
|
134
|
+
|
135
|
+
**Custom action:**
|
136
|
+
```ruby
|
137
|
+
def send_password_reset
|
138
|
+
audit_action current_user, @user, "password_reset"
|
139
|
+
# ...
|
140
|
+
end
|
141
|
+
```
|
142
|
+
|
143
|
+
## Known Issues
|
144
|
+
|
145
|
+
### UUIDs
|
146
|
+
|
147
|
+
If you use UUIDs as the primary key, you have to manually edit the migration before running it. This is a [known issue](https://github.com/rails/rails/issues/23422) with Rails migrations using `references` calls, which doesn't respect the configured primary key setting. Doing so would create something like this:
|
148
|
+
|
149
|
+
```ruby
|
150
|
+
class CreateAuditEntries < ActiveRecord::Migration[5.0]
|
151
|
+
def change
|
152
|
+
create_table :audit_entries do |t|
|
153
|
+
t.string :action
|
154
|
+
t.references :actor, polymorphic: true, type: :uuid
|
155
|
+
t.references :receiver, polymorphic: true, type: :uuid
|
156
|
+
t.jsonb :receiver_serialized
|
157
|
+
|
158
|
+
t.timestamps
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
```
|
163
|
+
|
164
|
+
## Contributing
|
165
|
+
|
166
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/newaperio/transcript. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
167
|
+
|
168
|
+
## License
|
169
|
+
|
170
|
+
Transcript is copyright © 2016 NewAperio. It is free software and may be redistributed under the terms specified in the [`LICENSE`](/LICENSE) file.
|
171
|
+
|
172
|
+
## NewAperio
|
173
|
+
|
174
|
+
Transcript was developed and is maintained by [NewAperio](http://newaperio.com), a web and mobile engineering firm based in Baton Rouge, LA.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "transcript"
|
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
|
data/bin/setup
ADDED
data/circle.yml
ADDED
data/config.ru
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
Description:
|
2
|
+
Installs Transcript. Creates a new audit model with the passed model name.
|
3
|
+
Creates a configuration file. Injects the Transcript concerns into
|
4
|
+
ApplicationController and the newly created model.
|
5
|
+
|
6
|
+
Example:
|
7
|
+
rails generate transcript audit_entry
|
8
|
+
|
9
|
+
This will create:
|
10
|
+
|
11
|
+
Configuration: config/initializers/transcript.rb
|
12
|
+
Model: app/models/audit_entry.rb
|
13
|
+
|
14
|
+
This will modify:
|
15
|
+
|
16
|
+
Controller: app/controllers/application_controller.rb
|
17
|
+
Model: app/models/audit_entry.rb
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
|
3
|
+
module Transcript
|
4
|
+
class InstallGenerator < Rails::Generators::NamedBase
|
5
|
+
source_root File.expand_path('../templates', __FILE__)
|
6
|
+
|
7
|
+
def generate_model
|
8
|
+
invoke "active_record:model", [
|
9
|
+
name,
|
10
|
+
"action:string",
|
11
|
+
"actor:references{polymorphic}",
|
12
|
+
"receiver:references{polymorphic}",
|
13
|
+
"receiver_serialized:jsonb",
|
14
|
+
]
|
15
|
+
end
|
16
|
+
|
17
|
+
def generate_configuration_initializer
|
18
|
+
template "transcript.rb.erb", "config/initializers/transcript.rb"
|
19
|
+
end
|
20
|
+
|
21
|
+
def add_model_concern
|
22
|
+
inject_into_class "app/models/#{file_path}.rb",
|
23
|
+
class_name,
|
24
|
+
" include Transcript::Model\n\n"
|
25
|
+
end
|
26
|
+
|
27
|
+
def add_controller_concern
|
28
|
+
inject_into_class "app/controllers/application_controller.rb",
|
29
|
+
"ApplicationController",
|
30
|
+
" include Transcript::Controller\n\n"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "active_job"
|
2
|
+
|
3
|
+
module Transcript
|
4
|
+
class Job < ActiveJob::Base
|
5
|
+
queue_as :default
|
6
|
+
|
7
|
+
def perform(actor, receiver, action)
|
8
|
+
Transcript.configuration.audit_model.create(
|
9
|
+
actor: actor,
|
10
|
+
action: action,
|
11
|
+
receiver: receiver,
|
12
|
+
receiver_serialized: receiver,
|
13
|
+
)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "active_support/concern"
|
2
|
+
|
3
|
+
module Transcript
|
4
|
+
module Model
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
belongs_to :actor, polymorphic: true
|
9
|
+
belongs_to :receiver, polymorphic: true
|
10
|
+
|
11
|
+
validates :actor, presence: true
|
12
|
+
end
|
13
|
+
|
14
|
+
module ClassMethods
|
15
|
+
def latest
|
16
|
+
order('created_at DESC').first
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|