notifiably_audited 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +17 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +234 -0
- data/Rakefile +24 -0
- data/lib/notifiably_audited.rb +0 -0
- data/lib/notifiably_audited/version.rb +3 -0
- data/notifiably_audited.gemspec +30 -0
- metadata +155 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ODcwNjQ2YTAzNzU1ZmRmNTM5MWRlYjIyMWJkMjA5YzZhMzljMTU2Ng==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NGJiZWFlNTFkZDEzOWIxOTMyYjZlYzgyZjE4MTI2NTU3N2JhMzYzNg==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
NjUxZDhlZDNlZTY2OWVmNzI3MTY0ZTczN2E3ZGY3MjdkMzk5NTc3MWNkOTBj
|
10
|
+
NDUxNjA5NzQwNjNhOTBkZGMxNTZhYzAzMjBhMTNlNDZmZTMyZmM4YzVlN2Ew
|
11
|
+
MTM2YTRkYzIyZWI4MDljMmIxMDRhZTY3ZWY4ZDZiNjhiZjU4YmE=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
OTdlMGIxMmM0YTNiMDkxN2QwZWFjMjVkODc1M2Q1YmQ4ZWVmMWFkZjkyMmY5
|
14
|
+
ZmY5OWVlOTU5NGI5ZTE2MjU1MmM5MjJlNjg2MjJjNmQxMzFjOWUzMTUyYTFh
|
15
|
+
ZWI0ZTE5N2I5MWE3YjhmYzhlN2I0ZWY4YWJjODI4MmY3Mzc0NTY=
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 TODO: Write your name
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,234 @@
|
|
1
|
+
Audited [![Build Status](https://secure.travis-ci.org/collectiveidea/audited.png)](http://travis-ci.org/collectiveidea/audited) [![Dependency Status](https://gemnasium.com/collectiveidea/audited.png)](https://gemnasium.com/collectiveidea/audited)
|
2
|
+
=======
|
3
|
+
|
4
|
+
**Audited** (previously acts_as_audited) is an ORM extension that logs all changes to your models. Audited also allows you to record who made those changes, save comments and associate models related to the changes. Audited works with Rails 3.
|
5
|
+
|
6
|
+
## Supported Rubies
|
7
|
+
|
8
|
+
Audited supports and is [tested against](http://travis-ci.org/collectiveidea/audited) the following Ruby versions:
|
9
|
+
|
10
|
+
* 1.8.7
|
11
|
+
* 1.9.2
|
12
|
+
* 1.9.3
|
13
|
+
* Head
|
14
|
+
|
15
|
+
Audited may work just fine with a Ruby version not listed above, but we can't guarantee that it will. If you'd like to maintain a Ruby that isn't listed, please let us know with a [pull request](https://github.com/collectiveidea/audited/pulls).
|
16
|
+
|
17
|
+
## Supported ORMs
|
18
|
+
|
19
|
+
In a previous life, Audited was ActiveRecord-only. Audited will now audit models for the following backends:
|
20
|
+
|
21
|
+
* ActiveRecord
|
22
|
+
* MongoMapper
|
23
|
+
|
24
|
+
## Installation
|
25
|
+
|
26
|
+
The installation process depends on what ORM your app is using.
|
27
|
+
|
28
|
+
### ActiveRecord
|
29
|
+
|
30
|
+
Add the appropriate gem to your Gemfile:
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
gem "audited-activerecord", "~> 3.0"
|
34
|
+
```
|
35
|
+
|
36
|
+
Then, from your Rails app directory, create the `audits` table:
|
37
|
+
|
38
|
+
```bash
|
39
|
+
$ rails generate audited:install
|
40
|
+
$ rake db:migrate
|
41
|
+
```
|
42
|
+
|
43
|
+
#### Upgrading
|
44
|
+
|
45
|
+
If you're already using Audited (or acts_as_audited), your `audits` table may require additional columns. After every upgrade, please run:
|
46
|
+
|
47
|
+
```bash
|
48
|
+
$ rails generate audited:upgrade
|
49
|
+
$ rake db:migrate
|
50
|
+
```
|
51
|
+
|
52
|
+
Upgrading will only make changes if changes are needed.
|
53
|
+
|
54
|
+
### MongoMapper
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
gem "audited-mongo_mapper", "~> 3.0"
|
58
|
+
```
|
59
|
+
|
60
|
+
## Usage
|
61
|
+
|
62
|
+
Simply call `audited` on your models:
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
class User < ActiveRecord::Base
|
66
|
+
audited
|
67
|
+
end
|
68
|
+
```
|
69
|
+
|
70
|
+
By default, whenever a user is created, updated or destroyed, a new audit is created.
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
user = User.create!(:name => "Steve")
|
74
|
+
user.audits.count # => 1
|
75
|
+
user.update_attributes!(:name => "Ryan")
|
76
|
+
user.audits.count # => 2
|
77
|
+
user.destroy
|
78
|
+
user.audits.count # => 3
|
79
|
+
```
|
80
|
+
|
81
|
+
Audits contain information regarding what action was taken on the model and what changes were made.
|
82
|
+
|
83
|
+
```ruby
|
84
|
+
user.update_attributes!(:name => "Ryan")
|
85
|
+
audit = user.audits.last
|
86
|
+
audit.action # => "update"
|
87
|
+
audit.audited_changes # => {"name"=>["Steve", "Ryan"]}
|
88
|
+
```
|
89
|
+
|
90
|
+
### Specifying columns
|
91
|
+
|
92
|
+
By default, a new audit is created for any attribute changes. You can, however, limit the columns to be considered.
|
93
|
+
|
94
|
+
```ruby
|
95
|
+
class User < ActiveRecord::Base
|
96
|
+
# All fields
|
97
|
+
# audited
|
98
|
+
|
99
|
+
# Single field
|
100
|
+
# audited only: :name
|
101
|
+
|
102
|
+
# Multiple fields
|
103
|
+
# audited only: [:name, :address]
|
104
|
+
|
105
|
+
# All except certain fields
|
106
|
+
# audited except: :password
|
107
|
+
end
|
108
|
+
```
|
109
|
+
|
110
|
+
### Comments
|
111
|
+
|
112
|
+
You can attach comments to each audit using an `audit_comment` attribute on your model.
|
113
|
+
|
114
|
+
```ruby
|
115
|
+
user.update_attributes!(:name => "Ryan", :audit_comment => "Changing name, just because")
|
116
|
+
user.audits.last.comment # => "Changing name, just because"
|
117
|
+
```
|
118
|
+
|
119
|
+
You can optionally add the `:comment_required` option to your `audited` call to require comments for all audits.
|
120
|
+
|
121
|
+
```ruby
|
122
|
+
class User < ActiveRecord::Base
|
123
|
+
audited :comment_required => true
|
124
|
+
end
|
125
|
+
```
|
126
|
+
|
127
|
+
### Current User Tracking
|
128
|
+
|
129
|
+
If you're using Audited in a Rails application, all audited changes made within a request will automatically be attributed to the current user. By default, Audited uses the `current_user` method in your controller.
|
130
|
+
|
131
|
+
```
|
132
|
+
class PostsController < ApplicationController
|
133
|
+
def create
|
134
|
+
current_user # => #<User name: "Steve">
|
135
|
+
@post = Post.create(params[:post])
|
136
|
+
@post.audits.last.user # => #<User name: "Steve">
|
137
|
+
end
|
138
|
+
end
|
139
|
+
```
|
140
|
+
|
141
|
+
To use a method other than `current_user`, put the following in an intializer:
|
142
|
+
|
143
|
+
```ruby
|
144
|
+
Audited.current_user_method = :authenticated_user
|
145
|
+
```
|
146
|
+
|
147
|
+
Outside of a request, Audited can still record the user with the `as_user` method:
|
148
|
+
|
149
|
+
```ruby
|
150
|
+
Audit.as_user(User.find(1)) do
|
151
|
+
post.update_attribute!(:title => "Hello, world!")
|
152
|
+
end
|
153
|
+
post.audits.last.user # => #<User id: 1>
|
154
|
+
```
|
155
|
+
|
156
|
+
### Associated Audits
|
157
|
+
|
158
|
+
Sometimes it's useful to associate an audit with a model other than the one being changed. For instance, given the following models:
|
159
|
+
|
160
|
+
```ruby
|
161
|
+
class User < ActiveRecord::Base
|
162
|
+
belongs_to :company
|
163
|
+
audited
|
164
|
+
end
|
165
|
+
|
166
|
+
class Company < ActiveRecord::Base
|
167
|
+
has_many :users
|
168
|
+
end
|
169
|
+
```
|
170
|
+
|
171
|
+
Every change to a user is audited, but what if you want to grab all of the audits of users belonging to a particular company? You can add the `:associated_with` option to your `audited` call:
|
172
|
+
|
173
|
+
```ruby
|
174
|
+
class User < ActiveRecord::Base
|
175
|
+
belongs_to :company
|
176
|
+
audited :associated_with => :company
|
177
|
+
end
|
178
|
+
|
179
|
+
class Company < ActiveRecord::Base
|
180
|
+
has_many :users
|
181
|
+
has_associated_audits
|
182
|
+
end
|
183
|
+
```
|
184
|
+
|
185
|
+
Now, when a audit is created for a user, that user's company is also saved alongside the audit. This makes it much easier (and faster) to access audits indirectly related to a company.
|
186
|
+
|
187
|
+
```ruby
|
188
|
+
company = Company.create!(:name => "Collective Idea")
|
189
|
+
user = company.users.create!(:name => "Steve")
|
190
|
+
user.update_attribute!(:name => "Steve Richert")
|
191
|
+
user.audits.last.associated # => #<Company name: "Collective Idea">
|
192
|
+
company.associated_audits.last.auditable # => #<User name: "Steve Richert">
|
193
|
+
```
|
194
|
+
|
195
|
+
## Gotchas
|
196
|
+
|
197
|
+
### Accessible Attributes
|
198
|
+
|
199
|
+
Audited assumes you are using `attr_accessible`, however, if you are using `attr_protected` or just going at it unprotected you will have to set the `:allow_mass_assignment => true` option.
|
200
|
+
|
201
|
+
If using `attr_protected` be sure to add `audit_ids` to the list of protected attributes to prevent data loss.
|
202
|
+
|
203
|
+
```ruby
|
204
|
+
class User < ActiveRecord::Base
|
205
|
+
audited :allow_mass_assignment => true
|
206
|
+
end
|
207
|
+
```
|
208
|
+
|
209
|
+
```ruby
|
210
|
+
class User < ActiveRecord::Base
|
211
|
+
audited :allow_mass_assignment => true
|
212
|
+
attr_protected :logins, :audit_ids
|
213
|
+
end
|
214
|
+
```
|
215
|
+
|
216
|
+
### MongoMapper Embedded Documents
|
217
|
+
|
218
|
+
Currently, Audited does not track changes on embedded documents. Audited works by tracking a model's [dirty changes](http://api.rubyonrails.org/classes/ActiveModel/Dirty.html) but changes to embedded documents don't appear in dirty tracking.
|
219
|
+
|
220
|
+
## Support
|
221
|
+
|
222
|
+
You can find documentation at: http://rdoc.info/github/collectiveidea/audited
|
223
|
+
|
224
|
+
Or join the [mailing list](http://groups.google.com/group/audited) to get help or offer suggestions.
|
225
|
+
|
226
|
+
## Contributing
|
227
|
+
|
228
|
+
In the spirit of [free software](http://www.fsf.org/licensing/essays/free-sw.html), **everyone** is encouraged to help improve this project. Here are a few ways _you_ can pitch in:
|
229
|
+
|
230
|
+
* Use prerelease versions of Audited.
|
231
|
+
* [Report bugs](https://github.com/collectiveidea/audited/issues).
|
232
|
+
* Fix bugs and submit [pull requests](http://github.com/collectiveidea/audited/pulls).
|
233
|
+
* Write, clarify or fix documentation.
|
234
|
+
* Refactor code.
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
|
3
|
+
require 'bundler/gem_helper'
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
require 'appraisal'
|
6
|
+
|
7
|
+
Bundler::GemHelper.install_tasks(:name => 'audited')
|
8
|
+
Bundler::GemHelper.install_tasks(:name => 'audited-activerecord')
|
9
|
+
Bundler::GemHelper.install_tasks(:name => 'audited-mongo_mapper')
|
10
|
+
|
11
|
+
ADAPTERS = %w(active_record mongo_mapper)
|
12
|
+
|
13
|
+
ADAPTERS.each do |adapter|
|
14
|
+
desc "Run RSpec code examples for #{adapter} adapter"
|
15
|
+
RSpec::Core::RakeTask.new(adapter) do |t|
|
16
|
+
t.pattern = "spec/audited/adapters/#{adapter}/**/*_spec.rb"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
RSpec::Core::RakeTask.new(:spec => ADAPTERS) do |t|
|
21
|
+
t.pattern = 'spec/audited/*_spec.rb'
|
22
|
+
end
|
23
|
+
|
24
|
+
task :default => :spec
|
File without changes
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
#require 'notifiably_audited/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "notifiably_audited"
|
8
|
+
spec.version = NotifiablyAudited::VERSION
|
9
|
+
spec.authors = ["senthil kumar"]
|
10
|
+
spec.email = ["senthilkumar.hce@gmail.com"]
|
11
|
+
spec.summary = %q{It audits and notifies}
|
12
|
+
spec.description = %q{TODO}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
gem.add_development_dependency 'activerecord', '~> 3.0'
|
17
|
+
gem.add_development_dependency 'appraisal', '~> 0.4'
|
18
|
+
gem.add_development_dependency 'bson_ext', '~> 1.6'
|
19
|
+
gem.add_development_dependency 'mongo_mapper', '~> 0.11'
|
20
|
+
gem.add_development_dependency 'rails', '~> 3.0'
|
21
|
+
gem.add_development_dependency 'rspec-rails', '~> 2.0'
|
22
|
+
gem.add_development_dependency 'sqlite3', '~> 1.0'
|
23
|
+
|
24
|
+
gem.files = `git ls-files`.split($\).reject{|f| f =~ /(lib\/audited\-|adapters|generators)/ }
|
25
|
+
gem.test_files = gem.files.grep(/^spec\//)
|
26
|
+
gem.require_paths = ['lib']
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
|
metadata
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: notifiably_audited
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brandon Keepers
|
8
|
+
- Kenneth Kalmer
|
9
|
+
- Daniel Morrison
|
10
|
+
- Brian Ryckbost
|
11
|
+
- Steve Richert
|
12
|
+
- Ryan Glover
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
date: 2014-03-19 00:00:00.000000000 Z
|
17
|
+
dependencies:
|
18
|
+
- !ruby/object:Gem::Dependency
|
19
|
+
name: activerecord
|
20
|
+
requirement: !ruby/object:Gem::Requirement
|
21
|
+
requirements:
|
22
|
+
- - ~>
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: '3.0'
|
25
|
+
type: :development
|
26
|
+
prerelease: false
|
27
|
+
version_requirements: !ruby/object:Gem::Requirement
|
28
|
+
requirements:
|
29
|
+
- - ~>
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: '3.0'
|
32
|
+
- !ruby/object:Gem::Dependency
|
33
|
+
name: appraisal
|
34
|
+
requirement: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ~>
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0.4'
|
39
|
+
type: :development
|
40
|
+
prerelease: false
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0.4'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: bson_ext
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ~>
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '1.6'
|
53
|
+
type: :development
|
54
|
+
prerelease: false
|
55
|
+
version_requirements: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ~>
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '1.6'
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
name: mongo_mapper
|
62
|
+
requirement: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ~>
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0.11'
|
67
|
+
type: :development
|
68
|
+
prerelease: false
|
69
|
+
version_requirements: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ~>
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0.11'
|
74
|
+
- !ruby/object:Gem::Dependency
|
75
|
+
name: rails
|
76
|
+
requirement: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ~>
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '3.0'
|
81
|
+
type: :development
|
82
|
+
prerelease: false
|
83
|
+
version_requirements: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ~>
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '3.0'
|
88
|
+
- !ruby/object:Gem::Dependency
|
89
|
+
name: rspec-rails
|
90
|
+
requirement: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ~>
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '2.0'
|
95
|
+
type: :development
|
96
|
+
prerelease: false
|
97
|
+
version_requirements: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ~>
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '2.0'
|
102
|
+
- !ruby/object:Gem::Dependency
|
103
|
+
name: sqlite3
|
104
|
+
requirement: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ~>
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '1.0'
|
109
|
+
type: :development
|
110
|
+
prerelease: false
|
111
|
+
version_requirements: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ~>
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '1.0'
|
116
|
+
description: Log all changes to your models
|
117
|
+
email: info@collectiveidea.com
|
118
|
+
executables: []
|
119
|
+
extensions: []
|
120
|
+
extra_rdoc_files: []
|
121
|
+
files:
|
122
|
+
- .gitignore
|
123
|
+
- Gemfile
|
124
|
+
- LICENSE.txt
|
125
|
+
- README.md
|
126
|
+
- Rakefile
|
127
|
+
- lib/notifiably_audited.rb
|
128
|
+
- lib/notifiably_audited/version.rb
|
129
|
+
- notifiably_audited.gemspec
|
130
|
+
homepage: https://github.com/collectiveidea/audited
|
131
|
+
licenses:
|
132
|
+
- MIT
|
133
|
+
metadata: {}
|
134
|
+
post_install_message:
|
135
|
+
rdoc_options: []
|
136
|
+
require_paths:
|
137
|
+
- lib
|
138
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
139
|
+
requirements:
|
140
|
+
- - ! '>='
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
145
|
+
- - ! '>='
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '0'
|
148
|
+
requirements: []
|
149
|
+
rubyforge_project:
|
150
|
+
rubygems_version: 2.2.2
|
151
|
+
signing_key:
|
152
|
+
specification_version: 4
|
153
|
+
summary: Log all changes to your models
|
154
|
+
test_files: []
|
155
|
+
has_rdoc:
|