You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/3.0/audit-logging/overview.md
+77-196
Original file line number
Diff line number
Diff line change
@@ -7,11 +7,11 @@ outline: [2,3]
7
7
8
8
# Audit Logging
9
9
10
-
Avo's Audit Logging feature provides a seamless way to track and visualize user activity and changes within your applications. It supports integrations with [`audited`](https://github.com/collectiveidea/audited) and [`paper_trail`](https://github.com/paper-trail-gem/paper_trail), and offers flexible installation and customization options.
10
+
Avo's Audit Logging feature provides a seamless way to track and visualize user activity and changes within your applications. It seamlessly integrates with [`paper_trail`](https://github.com/paper-trail-gem/paper_trail), offering flexible installation and customization options.
11
11
12
-
Captures user's activities on Avo resources and actions, recording details like the author and the performed event.
12
+
Captures user activities on Avo resources and actions, recording details such as the author and the performed event.
13
13
14
-
The installation process will automatically generate the necessary migrations, resources, and controllers that powers activity tracking. Additionally, the chosen versioning gem, either [`audited`](https://github.com/collectiveidea/audited) or[`paper_trail`](https://github.com/paper-trail-gem/paper_trail) will be installed if it is not already present in your project.
14
+
The installation process will automatically generate the necessary migrations, resources, and controllers that power activity tracking. Additionally [`paper_trail`](https://github.com/paper-trail-gem/paper_trail) will be installed if it is not already present in your project.
15
15
16
16
## Requirements
17
17
@@ -20,7 +20,7 @@ The installation process will automatically generate the necessary migrations, r
20
20
## Installation
21
21
22
22
:::info
23
-
When installing `avo-audit_logging` on a application, we strongly recommend following this documentation page step-by-step without skipping sections, as it was designed with that approach in mind.
23
+
When installing `avo-audit_logging` on an application, we strongly recommend following this documentation page step-by-step without skipping sections, as it was designed with that approach in mind.
24
24
:::
25
25
26
26
### 1. Install the gem
@@ -36,25 +36,11 @@ Then
36
36
bundle install
37
37
```
38
38
39
-
### 2. Select the audit gem
39
+
### 2. Run the installer
40
40
41
-
Prior to running the installer, choose the gem you want to use for record versioning:
Setting this configuration to `false` will disable the audit logging feature entirely, overriding any other specific settings. We'll cover those specific settings in the next step.
76
+
Setting this configuration to `false` will disable the audit logging feature entirely, overriding any other specific settings. We'll cover those specific settings in the next steps.
90
77
:::
91
78
92
79
### Configure author models
@@ -95,7 +82,7 @@ Setting this configuration to `false` will disable the audit logging feature ent
95
82
If `User` is your only author model, you can skip this step as it will be automatically set by default.
96
83
:::
97
84
98
-
Avo needs to identify the author possible models to properly set up associations behind the scenes. This will allow to fetch all activities for a specific author using the `avo_authored` association. To mark a model as an author use the `config.author_model` or for multiples models use`config.author_models`
85
+
Avo must determine the potential author models to correctly establish associations in the background. This setup enables the retrieval of all activities associated with a specific author via the `avo_authored` association. To designate a model as an author, use `config.author_model`, for multiple models, utilize`config.author_models`.
99
86
100
87
```ruby
101
88
# config/initializers/avo.rb # [!code focus]
@@ -110,7 +97,7 @@ Avo::AuditLogging.configure do |config| # [!code focus]
At this point, all resources and actions with audit logging activity enabled are being tracked.
152
+
All resources and actions with audit logging activity enabled are being tracked now.
166
153
167
154
But these activities aren't visible yet, right? Let's look at how to display them in the next step.
168
155
169
156
## Display logged activities
170
157
171
-
### Table with detailed activities
172
-
After installing and enabling audit logging, it's time to display the tracked activities. By default, they will appear like this, using the generated resource, which you can customize as needed.
The `Avo::ResourceTools::Timeline` tool, provided by the `avo-audit_logging` gem, is designed for use in the sidebar. It offers a compact view of activities that have occurred on a specific resource, presenting them in a streamlined format:
175
161
176
-
To display this table as an association view, add the `:avo_activities` field to resources that have audit logging enabled.
162
+
<Imagesrc="/assets/img/3_0/audit-logging/sidebar-activities.png"width="1915"height="719"alt="Avo compact activities on sidebar image" />
field :avo_activities, as::has_many# [!code ++] # [!code focus]
189
-
end# [!code focus]
190
-
191
-
defactions
192
-
action Avo::Actions::ChangePrice
193
-
end
194
-
end# [!code focus]
195
-
```
196
-
197
-
:::info
198
-
This table is displayed using the `Avo::Resources::AvoActivity` generated during installation. You have full control to customize it as desired.
199
-
:::
200
-
201
-
### Sidebar with compact activities
202
-
203
-
During installation, a resource tool called `Avo::ResourceTools::Timeline` was also generated. This tool is designed for use in the sidebar, providing a compact view of activities that looks like this:
204
-
205
-
<Imagesrc="/assets/img/3_0/audit-logging/sidebar-activities.png"width="1934"height="733"alt="Avo compact activities on sidebar image" />
206
-
207
-
This can be achieved by configuring the resource to ensure that the main menu sidebar includes the resource tool:
166
+
To enable this feature, configure the resource to include the resource tool in the main menu sidebar:
208
167
209
168
```ruby{7,12-15}
210
169
class Avo::Resources::Product < Avo::BaseResource # [!code focus]
Hovering over an entry reveals the precise timestamp in UTC. Clicking on an entry navigates to a detailed page displaying the full payload.
197
+
198
+
<Imagesrc="/assets/img/3_0/audit-logging/hover-activities.png"width="657"height="284"alt="Hover on activity" />
199
+
200
+
### Enabling Change Logs and Reverting Changes
201
+
202
+
By default, update activities do not display a change log, and there is no way to revert changes. This is because PaperTrail has not yet been enabled on the model. To enable it, simply add `has_paper_trail` to the model:
203
+
204
+
```ruby
205
+
# app/models/product.rb # [!code focus]
206
+
207
+
classProduct < ApplicationRecord# [!code focus]
208
+
has_paper_trail # [!code ++] # [!code focus]
209
+
210
+
belongs_to :user, optional:true
211
+
212
+
validates_presence_of :price
213
+
end# [!code focus]
214
+
```
215
+
216
+
Once enabled, the changelog will be visible, along with an action to revert changes.
If the `changeset` field in the versions table consistently appears as `nil`, ensure you add the following configuration in your `application.rb` file:
224
+
225
+
```ruby
226
+
config.active_record.yaml_column_permitted_classes = [Symbol, Date, Time, ActiveSupport::TimeWithZone, ActiveSupport::TimeZone]
227
+
```
228
+
:::
229
+
230
+
### Display author logged activities
231
+
232
+
We’ve already covered how to view all activity on a specific record. Now, let’s display a table within `Avo::Resources::User` to view all tracked activity for a particular user.
field :avo_authored, as::has_many# [!code ++] # [!code focus]
247
+
end# [!code focus]
248
+
end# [!code focus]
249
+
```
250
+
235
251
### Overview of all activities
236
252
237
-
We've covered how to view activity for specific records and how to review all actions by a particular author. However, having an overview of all activities in one place can also be useful. This can be achieved by configuring the menu to include a section with an entry for all activities.
253
+
We've covered how to view activities for specific records and how to view all actions made by a particular author. However, having an overview of all the activities in one place can also be useful. This can be achieved by configuring the menu to include a section with an entry for all activities.
238
254
239
255
```ruby
240
256
# config/initializers/avo.rb
@@ -303,143 +319,8 @@ The default value for `actions` is:
303
319
}
304
320
```
305
321
306
-
## Display author logged activities
307
-
308
-
We’ve already covered how to view all activity on a specific record. Now, let’s display a table within `Avo::Resources::User` to view all tracked activity for a particular user.
field :avo_authored, as::has_many# [!code ++] # [!code focus]
323
-
end# [!code focus]
324
-
end# [!code focus]
325
-
```
326
-
327
-
## Display Record Versions
328
-
329
-
During installation, you chose between [`audited`](https://github.com/collectiveidea/audited) and [`paper_trail`](https://github.com/paper-trail-gem/paper_trail). Now, let's enable tracking for record changes and display them.
330
-
331
-
### 1. Enable record versioning
332
-
333
-
Each gem has its own method for enabling versioning, which needs to be configured at the model level:
334
-
335
-
336
-
:::code-group
337
-
```ruby [audited]
338
-
# app/models/product.rb # [!code focus]
339
-
340
-
classProduct < ApplicationRecord# [!code focus]
341
-
audited # [!code ++] # [!code focus]
342
-
343
-
belongs_to :user, optional:true
344
-
345
-
validates_presence_of :price
346
-
end# [!code focus]
347
-
```
348
-
349
-
```ruby [paper_trail]
350
-
# app/models/product.rb # [!code focus]
351
-
352
-
classProduct < ApplicationRecord# [!code focus]
353
-
has_paper_trail # [!code ++] # [!code focus]
354
-
355
-
belongs_to :user, optional:true
356
-
357
-
validates_presence_of :price
358
-
end# [!code focus]
359
-
```
360
-
:::
361
-
362
-
### 2. Display Record Versions
363
-
364
-
:::warning
365
-
If you're using `paper_trail` and the `changeset` field in the versions table consistently appears as `nil`, ensure you add the following configuration in your `application.rb` file:
366
-
367
-
```ruby
368
-
config.active_record.yaml_column_permitted_classes = [Symbol, Date, Time, ActiveSupport::TimeWithZone, ActiveSupport::TimeZone]
369
-
370
-
```
371
-
:::
372
-
373
-
To show record changes, you'll need to use one of the resources generated during installation. The resource name and structure will vary based on the gem you selected:
field :versions, as::has_many, use_resource:Avo::Resources::PaperTrail# [!code ++] # [!code focus]
430
-
end# [!code focus]
431
-
432
-
defactions
433
-
action Avo::Actions::ChangePrice
434
-
end
435
-
end# [!code focus]
436
-
```
437
-
:::
438
-
439
322
## Conclusion
440
323
441
-
With Avo’s Audit Logging, you now have the ability to track and visualize user actions and records changes across your application. By following each setup step and configuring logging as needed, you can create a robust audit system.
442
-
443
-
For more advanced configurations, consider exploring the extended documentation (not available yet, work in progress) to gain further control over your audit logging setup.
324
+
With Avo's Audit Logging, you gain a powerful tool to track and visualize user actions and record changes seamlessly across your application. By carefully following the setup steps and configuring logging to fit your needs, you can establish a robust and transparent audit system, enhancing accountability and preserving data integrity.
0 commit comments