mongoid-audit 0.3.2 → 1.0.0.alpha.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/.ruby-version +1 -1
- data/Gemfile.lock +74 -0
- data/README.md +38 -171
- data/Rakefile +0 -12
- data/config/mongoid.yml +0 -0
- data/lib/mongoid-audit.rb +14 -27
- data/lib/mongoid-audit/history_tracker.rb +6 -0
- data/lib/mongoid-audit/rails_admin.rb +119 -108
- data/lib/mongoid-audit/railtie.rb +6 -16
- data/lib/mongoid-audit/trackable.rb +12 -262
- data/lib/mongoid-audit/version.rb +1 -1
- data/mongoid-audit.gemspec +7 -8
- metadata +41 -85
- data/.coveralls.yml +0 -1
- data/.rspec +0 -1
- data/.travis.yml +0 -15
- data/lib/mongoid-audit/mongoid_observer.rb +0 -172
- data/lib/mongoid-audit/sweeper.rb +0 -46
- data/lib/mongoid-audit/tracker.rb +0 -170
- data/spec/integration/integration_spec.rb +0 -666
- data/spec/spec_helper.rb +0 -28
- data/spec/support/database_cleaner.rb +0 -11
- data/spec/support/mongoid.rb +0 -16
- data/spec/trackable_spec.rb +0 -134
- data/spec/tracker_spec.rb +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0057de0bc4b8086ede177d4e62f00f2afe911a9c
|
4
|
+
data.tar.gz: a3bc47897234907ac0febea43b6d7062f04be122
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ced31227b1dbdb9bd575ee5d48e03642e2574aa3b1df4836a54f08709cf42e4b24bb6c6c148ad822a442e22372f59bb5bb0180b013a95f82422aff0411f138d
|
7
|
+
data.tar.gz: b6decdc95280890a88824fc4ec47e3fc8c7c6b08cc488ada2e9208b0eb81240f9cd1796e758118f5b2cd8d74ab235c97b8f97592ec89cf6f908198eae493356c
|
data/.gitignore
CHANGED
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
2.1.2
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
mongoid-audit (1.0.0.alpha.1)
|
5
|
+
activesupport
|
6
|
+
glebtv_mongoid_userstamp
|
7
|
+
kaminari
|
8
|
+
mongoid (~> 4.0.0)
|
9
|
+
mongoid-history (~> 0.4.4)
|
10
|
+
|
11
|
+
GEM
|
12
|
+
remote: https://rubygems.org/
|
13
|
+
specs:
|
14
|
+
actionpack (4.1.4)
|
15
|
+
actionview (= 4.1.4)
|
16
|
+
activesupport (= 4.1.4)
|
17
|
+
rack (~> 1.5.2)
|
18
|
+
rack-test (~> 0.6.2)
|
19
|
+
actionview (4.1.4)
|
20
|
+
activesupport (= 4.1.4)
|
21
|
+
builder (~> 3.1)
|
22
|
+
erubis (~> 2.7.0)
|
23
|
+
activemodel (4.1.4)
|
24
|
+
activesupport (= 4.1.4)
|
25
|
+
builder (~> 3.1)
|
26
|
+
activesupport (4.1.4)
|
27
|
+
i18n (~> 0.6, >= 0.6.9)
|
28
|
+
json (~> 1.7, >= 1.7.7)
|
29
|
+
minitest (~> 5.1)
|
30
|
+
thread_safe (~> 0.1)
|
31
|
+
tzinfo (~> 1.1)
|
32
|
+
bson (2.3.0)
|
33
|
+
builder (3.2.2)
|
34
|
+
connection_pool (2.0.0)
|
35
|
+
easy_diff (0.0.3)
|
36
|
+
erubis (2.7.0)
|
37
|
+
glebtv_mongoid_userstamp (0.4.1)
|
38
|
+
mongoid (~> 4.0.0.beta1)
|
39
|
+
i18n (0.6.11)
|
40
|
+
json (1.8.1)
|
41
|
+
kaminari (0.16.1)
|
42
|
+
actionpack (>= 3.0.0)
|
43
|
+
activesupport (>= 3.0.0)
|
44
|
+
minitest (5.4.0)
|
45
|
+
mongoid (4.0.0)
|
46
|
+
activemodel (~> 4.0)
|
47
|
+
moped (~> 2.0.0)
|
48
|
+
origin (~> 2.1)
|
49
|
+
tzinfo (>= 0.3.37)
|
50
|
+
mongoid-history (0.4.4)
|
51
|
+
activesupport
|
52
|
+
easy_diff
|
53
|
+
mongoid (>= 3.0)
|
54
|
+
moped (2.0.0)
|
55
|
+
bson (~> 2.2)
|
56
|
+
connection_pool (~> 2.0)
|
57
|
+
optionable (~> 0.2.0)
|
58
|
+
optionable (0.2.0)
|
59
|
+
origin (2.1.1)
|
60
|
+
rack (1.5.2)
|
61
|
+
rack-test (0.6.2)
|
62
|
+
rack (>= 1.0)
|
63
|
+
rake (10.3.2)
|
64
|
+
thread_safe (0.3.4)
|
65
|
+
tzinfo (1.2.2)
|
66
|
+
thread_safe (~> 0.1)
|
67
|
+
|
68
|
+
PLATFORMS
|
69
|
+
ruby
|
70
|
+
|
71
|
+
DEPENDENCIES
|
72
|
+
bundler
|
73
|
+
mongoid-audit!
|
74
|
+
rake
|
data/README.md
CHANGED
@@ -1,31 +1,32 @@
|
|
1
|
-
Mongoid::Audit
|
2
|
-
==============
|
1
|
+
## Mongoid::Audit
|
3
2
|
|
4
|
-
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/mongoid-audit.png)](http://badge.fury.io/rb/mongoid-audit)
|
4
|
+
[![Dependency Status](https://www.versioneye.com/user/projects/53ea131f8b6db55f150000b7/badge.svg)](https://www.versioneye.com/user/projects/53ea131f8b6db55f150000b7)
|
5
|
+
[![Issues](http://img.shields.io/github/issues/rs-pro/mongoid-audit.svg)](https://github.com/rs-pro/mongoid-audit/issues)
|
6
|
+
[![License](http://img.shields.io/:license-mit-blue.svg)](https://github.com/rs-pro/mongoid-audit/blob/master/MIT-LICENSE.txt)
|
5
7
|
|
6
|
-
|
7
|
-
* Rails 4 support
|
8
|
-
* Built in rails_admin auditing support
|
9
|
-
* Properly setting user (modifier) all the time
|
8
|
+
**MongoidAudit 1.0 is a complete rewrite and might break backwards compatibility**
|
10
9
|
|
11
|
-
|
10
|
+
Since 1.0.0, mongoid_audit is no longer a fork, but a wrapper of [mongoid-history](https://github.com/aq1018/mongoid-history), providing
|
11
|
+
out-of-the-box Userstamp, RailsAdmin integration and easier setup and configuration.
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
Database storage format for user / modifier in 1.0.0 was changed, since now glebtv_mongoid_userstamp gem is used to store
|
14
|
+
modifier.
|
15
|
+
|
16
|
+
To migrate your data do:
|
17
|
+
|
18
|
+
HistoryTracker.all.each{|ht| ht.rename(:modifier_id, :updater_id)
|
17
19
|
|
18
|
-
|
20
|
+
This gem includes storing modifier, but it is done via ```glebtv_mongoid_userstamp``` and not directly.
|
19
21
|
|
20
|
-
|
22
|
+
RailsAdmin history is fully supported.
|
21
23
|
|
22
|
-
Installation
|
23
|
-
____________
|
24
|
+
## Installation
|
24
25
|
|
25
26
|
Add this line to your application's Gemfile:
|
26
27
|
|
27
28
|
# must be after rails_admin, if you use it
|
28
|
-
gem 'mongoid-audit'
|
29
|
+
gem 'mongoid-audit', '~> 1.0.0.alpha.1'
|
29
30
|
|
30
31
|
And then execute:
|
31
32
|
|
@@ -33,173 +34,39 @@ And then execute:
|
|
33
34
|
|
34
35
|
Or install it yourself as:
|
35
36
|
|
36
|
-
$ gem install mongoid-audit
|
37
|
-
|
38
|
-
Usage
|
39
|
-
-----
|
40
|
-
|
41
|
-
**Rails Admin Integration**
|
42
|
-
|
43
|
-
# note that instead of a user class, you pass in history tracker table name as second argument
|
44
|
-
config.audit_with :mongoid_audit, 'HistoryTracker'
|
45
|
-
|
46
|
-
|
47
|
-
**Create a history tracker**
|
48
|
-
|
49
|
-
Create a new class to track histories. All histories are stored in this tracker. The name of the class can be anything you like. The only requirement is that it includes `Mongoid::Audit::Tracker`
|
50
|
-
|
51
|
-
```ruby
|
52
|
-
# app/models/history_tracker.rb
|
53
|
-
class HistoryTracker
|
54
|
-
include Mongoid::Audit::Tracker
|
55
|
-
end
|
56
|
-
```
|
57
|
-
|
58
|
-
**Set tracker class name**
|
59
|
-
|
60
|
-
Manually set the tracker class name to make sure your tracker can be found and loaded properly. You can skip this step if you manually require your tracker before using any trackables.
|
61
|
-
|
62
|
-
The following example sets the tracker class name using a Rails initializer.
|
63
|
-
|
64
|
-
```ruby
|
65
|
-
# config/initializers/mongoid-audit.rb
|
66
|
-
# initializer for mongoid-audit
|
67
|
-
# assuming HistoryTracker is your tracker class
|
68
|
-
Mongoid::Audit.tracker_class_name = :history_tracker
|
69
|
-
```
|
70
|
-
|
71
|
-
**Set `#current_user` method name**
|
72
|
-
|
73
|
-
You can set the name of the method that returns currently logged in user if you don't want to set `modifier` explicitly on every update.
|
74
|
-
|
75
|
-
The following example sets the `current_user_method` using a Rails initializer
|
76
|
-
|
77
|
-
```ruby
|
78
|
-
# config/initializers/mongoid-audit.rb
|
79
|
-
# initializer for mongoid-audit
|
80
|
-
# assuming you're using devise/authlogic
|
81
|
-
Mongoid::Audit.current_user_method = :current_user
|
82
|
-
```
|
83
|
-
|
84
|
-
**IMPORTANT**
|
85
|
-
for this to work in development environment, add
|
86
|
-
```ruby
|
87
|
-
require_dependency 'history_tracker.rb' if Rails.env == "development"
|
88
|
-
```
|
89
|
-
to the initializer so controller filter would be installed
|
90
|
-
|
37
|
+
$ gem install mongoid-audit --pre
|
91
38
|
|
92
|
-
|
39
|
+
## Usage
|
93
40
|
|
94
|
-
```
|
95
|
-
# assume that current_user return #<User _id: 1>
|
96
|
-
post = Post.first
|
97
|
-
post.update_attributes(:title => 'New title')
|
41
|
+
Include ```Trackable``` in your models. That's it, you are done!
|
98
42
|
|
99
|
-
|
100
|
-
```
|
43
|
+
include Trackable
|
101
44
|
|
102
|
-
|
45
|
+
## Advanced usage
|
103
46
|
|
104
|
-
|
105
|
-
|
106
|
-
include Mongoid::Document
|
107
|
-
include Mongoid::Timestamps
|
47
|
+
Identical to Mongoid::History.
|
48
|
+
See https://github.com/aq1018/mongoid-history
|
108
49
|
|
109
|
-
|
110
|
-
|
111
|
-
|
50
|
+
include Mongoid::History::Trackable
|
51
|
+
track_history({
|
52
|
+
track_create: true,
|
53
|
+
track_destroy: true,
|
54
|
+
track_update: true,
|
55
|
+
modifier_field: :updater,
|
56
|
+
except: ["created_at", "updated_at", "c_at", "u_at"],
|
57
|
+
})
|
112
58
|
|
113
|
-
|
114
|
-
field :body
|
115
|
-
field :rating
|
116
|
-
embeds_many :comments
|
59
|
+
### Rails Admin Integration
|
117
60
|
|
118
|
-
|
119
|
-
track_history :on => [:title, :body], # track title and body fields only, default is :all
|
120
|
-
:modifier_field => :modifier, # adds "referenced_in :modifier" to track who made the change, default is :modifier
|
121
|
-
:version_field => :version, # adds "field :version, :type => Integer" to track current version, default is :version
|
122
|
-
:track_create => false, # track document creation, default is false
|
123
|
-
:track_update => true, # track document updates, default is true
|
124
|
-
:track_destroy => false # track document destruction, default is false
|
125
|
-
end
|
61
|
+
Add
|
126
62
|
|
127
|
-
|
128
|
-
include Mongoid::Document
|
129
|
-
include Mongoid::Timestamps
|
63
|
+
config.audit_with :mongoid_audit
|
130
64
|
|
131
|
-
|
132
|
-
include Mongoid::Audit::Trackable
|
133
|
-
|
134
|
-
field :title
|
135
|
-
field :body
|
136
|
-
embedded_in :post, :inverse_of => :comments
|
137
|
-
|
138
|
-
# track title and body for all comments, scope it to post (the parent)
|
139
|
-
# also track creation and destruction
|
140
|
-
track_history :on => [:title, :body], :scope => :post, :track_create => true, :track_destroy => true
|
141
|
-
end
|
142
|
-
|
143
|
-
# the modifier class
|
144
|
-
class User
|
145
|
-
include Mongoid::Document
|
146
|
-
include Mongoid::Timestamps
|
147
|
-
|
148
|
-
field :name
|
149
|
-
end
|
150
|
-
|
151
|
-
user = User.create(:name => "Aaron")
|
152
|
-
post = Post.create(:title => "Test", :body => "Post", :modifier => user)
|
153
|
-
comment = post.comments.create(:title => "test", :body => "comment", :modifier => user)
|
154
|
-
comment.history_tracks.count # should be 1
|
155
|
-
|
156
|
-
comment.update_attributes(:title => "Test 2")
|
157
|
-
comment.history_tracks.count # should be 2
|
158
|
-
|
159
|
-
track = comment.history_tracks.last
|
160
|
-
|
161
|
-
track.undo! user # comment title should be "Test"
|
162
|
-
|
163
|
-
track.redo! user # comment title should be "Test 2"
|
164
|
-
|
165
|
-
# undo last change
|
166
|
-
comment.undo! user
|
167
|
-
|
168
|
-
# undo versions 1 - 4
|
169
|
-
comment.undo! user, :from => 4, :to => 1
|
170
|
-
|
171
|
-
# undo last 3 versions
|
172
|
-
comment.undo! user, :last => 3
|
173
|
-
|
174
|
-
# redo versions 1 - 4
|
175
|
-
comment.redo! user, :from => 1, :to => 4
|
176
|
-
|
177
|
-
# redo last 3 versions
|
178
|
-
comment.redo! user, :last => 3
|
179
|
-
|
180
|
-
# delete post
|
181
|
-
post.destroy
|
182
|
-
|
183
|
-
# undelete post
|
184
|
-
post.undo! user
|
185
|
-
|
186
|
-
# disable tracking for comments within a block
|
187
|
-
Comment.disable_tracking do
|
188
|
-
comment.update_attributes(:title => "Test 3")
|
189
|
-
end
|
190
|
-
```
|
191
|
-
For more examples, check out [spec/integration/integration_spec.rb](https://github.com/aq1018/mongoid-history/blob/master/spec/integration/integration_spec.rb).
|
65
|
+
in ```config/initializers/rails_admin.rb```
|
192
66
|
|
193
67
|
## Credits
|
194
68
|
|
195
|
-
|
196
|
-
|
197
|
-
The original gem didn't work correctly for us, when not setting modifier manually, so we rewrote it a bit.
|
198
|
-
Seems to work fully now, including manually setting modifier
|
199
|
-
|
200
|
-
Mongoid-history Copyright (c) 2011-2012 Aaron Qian. MIT License. See [LICENSE.txt](https://github.com/aq1018/mongoid-history/blob/master/LICENSE.txt) for further details.
|
201
|
-
|
202
|
-
Mongoid-audit Copyright (c) 2013 http://rocketscience.pro MIT License.
|
69
|
+
(c) 2013-2014 http://rocketscience.pro MIT License.
|
203
70
|
|
204
71
|
## Contributing
|
205
72
|
|
data/Rakefile
CHANGED
@@ -1,14 +1,2 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
2
|
|
3
|
-
# Get your spec rake tasks working in RSpec 2.0
|
4
|
-
|
5
|
-
require 'rspec/core/rake_task'
|
6
|
-
|
7
|
-
desc 'Default: run specs.'
|
8
|
-
task :default => :spec
|
9
|
-
|
10
|
-
desc "Run specs"
|
11
|
-
RSpec::Core::RakeTask.new do |t|
|
12
|
-
t.pattern = "./spec/**/*_spec.rb" # don't need this, it's default.
|
13
|
-
# Put spec opts in a file named .rspec in root
|
14
|
-
end
|
data/config/mongoid.yml
CHANGED
File without changes
|
data/lib/mongoid-audit.rb
CHANGED
@@ -1,34 +1,21 @@
|
|
1
|
-
require 'mongoid-audit/version'
|
2
|
-
require 'easy_diff'
|
3
1
|
require 'mongoid'
|
4
|
-
require '
|
5
|
-
require '
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
mattr_accessor :tracker_class_name
|
10
|
-
mattr_accessor :trackable_class_options
|
11
|
-
mattr_accessor :modifier_class_name
|
12
|
-
mattr_accessor :current_user_method
|
13
|
-
|
14
|
-
def self.tracker_class
|
15
|
-
@tracker_class ||= tracker_class_name.to_s.classify.constantize
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
2
|
+
require 'mongoid-history'
|
3
|
+
require 'mongoid_userstamp'
|
4
|
+
require 'kaminari'
|
5
|
+
require 'kaminari/hooks'
|
6
|
+
require 'kaminari/models/mongoid_extension'
|
19
7
|
|
20
|
-
|
21
|
-
|
22
|
-
|
8
|
+
require 'mongoid-audit/version'
|
9
|
+
require 'mongoid-audit/trackable'
|
10
|
+
require 'mongoid-audit/history_tracker'
|
11
|
+
require 'mongoid-audit/railtie'
|
23
12
|
|
24
|
-
|
13
|
+
begin; require 'rails_admin'; rescue LoadError; end
|
14
|
+
if defined? ::RailsAdmin
|
25
15
|
require "mongoid-audit/rails_admin"
|
26
16
|
end
|
27
17
|
|
28
|
-
|
29
|
-
|
30
|
-
|
18
|
+
Mongoid::History.tracker_class_name = :history_tracker
|
19
|
+
Mongoid::History.current_user_method = :current_user
|
20
|
+
Mongoid::History.modifier_class_name = "User"
|
31
21
|
|
32
|
-
Mongoid::Audit.modifier_class_name = "User"
|
33
|
-
Mongoid::Audit.trackable_class_options = {}
|
34
|
-
Mongoid::Audit.current_user_method ||= :current_user
|
@@ -1,108 +1,119 @@
|
|
1
|
-
module RailsAdmin
|
2
|
-
module Extensions
|
3
|
-
module MongoidAudit
|
4
|
-
class VersionProxy
|
5
|
-
def initialize(version)
|
6
|
-
@version = version
|
7
|
-
end
|
8
|
-
|
9
|
-
def message
|
10
|
-
@message = @version.action
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
end
|
85
|
-
|
86
|
-
def listing_for_object(model, object, query, sort, sort_reverse, all, page, per_page = (RailsAdmin::Config.default_items_per_page || 20))
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
1
|
+
module RailsAdmin
|
2
|
+
module Extensions
|
3
|
+
module MongoidAudit
|
4
|
+
class VersionProxy
|
5
|
+
def initialize(version)
|
6
|
+
@version = version
|
7
|
+
end
|
8
|
+
|
9
|
+
def message
|
10
|
+
@message = @version.action
|
11
|
+
if @message == 'create'
|
12
|
+
return 'new'
|
13
|
+
end
|
14
|
+
if @message == 'destroy'
|
15
|
+
return 'delete'
|
16
|
+
end
|
17
|
+
mods = @version.modified.to_a.map do |c|
|
18
|
+
if c[1].class.name == "Moped::BSON::Binary" || c[1].class.name == "BSON::Binary"
|
19
|
+
c[0] + " = {binary data}"
|
20
|
+
elsif c[1].to_s.length > 220
|
21
|
+
c[0] + " = " + c[1].to_s[0..200]
|
22
|
+
else
|
23
|
+
c[0] + " = " + c[1].to_s
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
@version.respond_to?(:modified) ? @message + ' ' + table + " [" + mods.join(", ") + "]" : @message
|
28
|
+
end
|
29
|
+
|
30
|
+
def created_at
|
31
|
+
@version.created_at
|
32
|
+
end
|
33
|
+
|
34
|
+
def table
|
35
|
+
@version.association_chain.last['name']
|
36
|
+
end
|
37
|
+
|
38
|
+
def username
|
39
|
+
@version.updater.try(:email) || @version.updater
|
40
|
+
end
|
41
|
+
|
42
|
+
def item
|
43
|
+
@version.association_chain.last['id']
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
class AuditingAdapter
|
48
|
+
COLUMN_MAPPING = {
|
49
|
+
:table => 'association_chain.name',
|
50
|
+
:username => 'modifier_id',
|
51
|
+
:item => 'association_chain.id',
|
52
|
+
:created_at => :created_at,
|
53
|
+
:message => :action
|
54
|
+
}
|
55
|
+
|
56
|
+
def initialize(controller, version_class = HistoryTracker)
|
57
|
+
@controller = controller
|
58
|
+
@version_class = version_class.to_s.constantize
|
59
|
+
end
|
60
|
+
|
61
|
+
def latest(include_empty_modifier = false)
|
62
|
+
versions = @version_class
|
63
|
+
unless include_empty_modifier
|
64
|
+
versions.where(:updater_id.exists => true)
|
65
|
+
end
|
66
|
+
versions = versions.desc(:_id).limit(20)
|
67
|
+
versions.map { |version| VersionProxy.new(version) }
|
68
|
+
end
|
69
|
+
|
70
|
+
def delete_object(object, model, user)
|
71
|
+
# do nothing
|
72
|
+
end
|
73
|
+
|
74
|
+
def update_object(object, model, user, changes)
|
75
|
+
# do nothing
|
76
|
+
end
|
77
|
+
|
78
|
+
def create_object(object, abstract_model, user)
|
79
|
+
# do nothing
|
80
|
+
end
|
81
|
+
|
82
|
+
def listing_for_model(model, query, sort, sort_reverse, all, page, per_page = (RailsAdmin::Config.default_items_per_page || 20))
|
83
|
+
listing_for_model_or_object(model, nil, query, sort, sort_reverse, all, page, per_page)
|
84
|
+
end
|
85
|
+
|
86
|
+
def listing_for_object(model, object, query, sort, sort_reverse, all, page, per_page = (RailsAdmin::Config.default_items_per_page || 20))
|
87
|
+
listing_for_model_or_object(model, object, query, sort, sort_reverse, all, page, per_page)
|
88
|
+
end
|
89
|
+
|
90
|
+
protected
|
91
|
+
def listing_for_model_or_object(model, object, query, sort, sort_reverse, all, page, per_page)
|
92
|
+
if sort.present?
|
93
|
+
sort = COLUMN_MAPPING[sort.to_sym]
|
94
|
+
else
|
95
|
+
sort = :created_at
|
96
|
+
sort_reverse = 'true'
|
97
|
+
end
|
98
|
+
model_name = model.model.name
|
99
|
+
if object
|
100
|
+
versions = @version_class.where('association_chain.name' => model.model_name, 'association_chain.id' => object.id)
|
101
|
+
else
|
102
|
+
versions = @version_class.where('association_chain.name' => model_name)
|
103
|
+
end
|
104
|
+
versions = versions.order_by([sort, sort_reverse == 'true' ? :desc : :asc])
|
105
|
+
unless all
|
106
|
+
page = 1 if page.nil?
|
107
|
+
versions = versions.send(Kaminari.config.page_method_name, page).per(per_page)
|
108
|
+
end
|
109
|
+
versions.map { |version| VersionProxy.new(version) }
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
RailsAdmin.add_extension(:mongoid_audit, RailsAdmin::Extensions::MongoidAudit, {
|
117
|
+
:auditing => true
|
118
|
+
})
|
119
|
+
|