sequel-auditer 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -16
- data/lib/sequel/auditer.rb +1 -1
- data/lib/sequel/auditer/version.rb +1 -1
- data/lib/sequel/plugins/auditer.rb +6 -14
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9d249b743759c5b297d1e2dbd0c5a98ab0fa37e34c4fb08d7d8ee8f7bc5aa06a
|
4
|
+
data.tar.gz: 4b9985ed63226fa69db058142c45bec509d874e044841c284d7d4acb23d82392
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 14b094ff17583f16093f0f0024950a26b1031c07d8e90179932604097081a29a3487dc02ad826704e30a9999de44425f098967c90d3f171adc756a5046c9cf79
|
7
|
+
data.tar.gz: b70313f6589bc455bed54e89f6cfd2b5aa749fd6661147b9df30b5c84cb26f9f8f6851016405307d8b759d429e2591e9fc778a4c52fce4744c4acae20f9d008b
|
data/README.md
CHANGED
@@ -7,12 +7,6 @@ and when the change was made.
|
|
7
7
|
This plugin provides model auditing (a.k.a: record versioning) for DB scenarios when DB triggers
|
8
8
|
are not possible. (ie: on a web app on Heroku).
|
9
9
|
|
10
|
-
<br>
|
11
|
-
|
12
|
-
----
|
13
|
-
|
14
|
-
<br>
|
15
|
-
|
16
10
|
## Installation
|
17
11
|
|
18
12
|
### 1) Install the gem
|
@@ -88,10 +82,9 @@ Modifier is who changed the data. This can be user itself, staff member or admin
|
|
88
82
|
Resource owner respresents modified data's owner. This is usually an user. So, you can browse audit logs based on resource owner id and see who is the modifier. This data came from target model. You need to specify user method in model like this:
|
89
83
|
|
90
84
|
```ruby
|
91
|
-
plugin :auditer, additional_info: :additional_info, user_method: :global_user,
|
85
|
+
plugin :auditer, additional_info: :additional_info, user_method: :global_user, owner_method: :owner_user
|
92
86
|
```
|
93
87
|
|
94
|
-
Now, `:owner_field` is a field in `Folder` model. `:global_user` is a global function/method that came from somewhere else in our app. Something like `current_user`.
|
95
88
|
|
96
89
|
### IMPORTANT SIDENOTE!
|
97
90
|
|
@@ -103,9 +96,6 @@ to use it.
|
|
103
96
|
|
104
97
|
<br>
|
105
98
|
|
106
|
-
----
|
107
|
-
|
108
|
-
|
109
99
|
<a name="usage"></a>
|
110
100
|
## Usage
|
111
101
|
|
@@ -316,7 +306,7 @@ So if you want to customize the modifier per model you can do that here.
|
|
316
306
|
|
317
307
|
<br>
|
318
308
|
|
319
|
-
#### `Sequel::auditer.
|
309
|
+
#### `Sequel::auditer.auditer_resource_owner_method`
|
320
310
|
|
321
311
|
Sets the name of the model name (association) that provides the resource owner object.
|
322
312
|
Default is: `nil`.
|
@@ -324,11 +314,12 @@ Default is: `nil`.
|
|
324
314
|
You can easily change the name of this model by calling:
|
325
315
|
|
326
316
|
```ruby
|
327
|
-
Sequel::auditer.
|
317
|
+
Sequel::auditer.auditer_resource_owner_method = :user
|
328
318
|
```
|
329
319
|
|
330
320
|
**Note!** the name of the function must be given as a symbol.
|
331
|
-
**Note!!** it will first try to hit the method on the model (i.e. Post) itself first.
|
321
|
+
**Note!!** it will first try to hit the method on the model (i.e. Post) itself first. Then it will hit the global method.<br>
|
322
|
+
So if you want to customize the modifier per model you can do that here.
|
332
323
|
|
333
324
|
<br>
|
334
325
|
|
@@ -597,8 +588,6 @@ Not everything is perfect or fully formed, so this gem may be in need of the fol
|
|
597
588
|
to pay attention to this functionality as there's a 10,000 rows limit on Heroku.
|
598
589
|
|
599
590
|
|
600
|
-
|
601
|
-
|
602
591
|
## Development
|
603
592
|
|
604
593
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run
|
data/lib/sequel/auditer.rb
CHANGED
@@ -11,7 +11,7 @@ module Sequel
|
|
11
11
|
@auditer_current_user_method = :current_user
|
12
12
|
# set any additional info such as :ip, :user_agent, ...
|
13
13
|
@auditer_additional_info_method = :additional_info
|
14
|
-
@
|
14
|
+
@auditer_resource_owner_method = :owner_method
|
15
15
|
# enable swapping of the Audit model
|
16
16
|
@auditer_model_name = :AuditLog
|
17
17
|
# toggle for enabling / disabling auditing
|
@@ -23,9 +23,9 @@ class AuditLog < Sequel::Model
|
|
23
23
|
end
|
24
24
|
|
25
25
|
# grab resource owner
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
if o = audit_owner
|
27
|
+
self.resource_owner = o
|
28
|
+
end
|
29
29
|
|
30
30
|
super
|
31
31
|
end
|
@@ -58,8 +58,7 @@ class AuditLog < Sequel::Model
|
|
58
58
|
|
59
59
|
def audit_owner
|
60
60
|
m = Kernel.const_get(associated_type)
|
61
|
-
|
62
|
-
# abort o.inspect
|
61
|
+
m.send(m.auditer_resource_owner_field) || send(m.auditer_resource_owner_field)
|
63
62
|
end
|
64
63
|
end
|
65
64
|
|
@@ -232,7 +231,7 @@ module Sequel
|
|
232
231
|
end
|
233
232
|
|
234
233
|
def set_owner_method(opts)
|
235
|
-
@auditer_resource_owner_field = opts[:
|
234
|
+
@auditer_resource_owner_field = opts[:owner_method] || ::Sequel::Auditer.auditer_resource_owner_field
|
236
235
|
end
|
237
236
|
|
238
237
|
def set_additional_info_method(opts)
|
@@ -297,17 +296,10 @@ module Sequel
|
|
297
296
|
def add_audited(event)
|
298
297
|
changed = auditer_values(event)
|
299
298
|
|
300
|
-
begin
|
301
|
-
res_owner = self.send(*model.auditer_resource_owner_field)
|
302
|
-
rescue
|
303
|
-
res_owner = nil
|
304
|
-
end
|
305
|
-
|
306
299
|
unless changed.blank?
|
307
300
|
add_version(
|
308
301
|
event: event,
|
309
|
-
changed: changed
|
310
|
-
resource_owner: res_owner
|
302
|
+
changed: changed
|
311
303
|
)
|
312
304
|
end
|
313
305
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sequel-auditer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kematzy
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: exe
|
13
13
|
cert_chain: []
|
14
|
-
date: 2018-12-
|
14
|
+
date: 2018-12-28 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: sequel
|