Skip to content

Commit 0434d68

Browse files
committed
Merge branch 'main' of github.com:avo-hq/docs.avohq.io
2 parents a03e9b8 + 8fed847 commit 0434d68

File tree

10 files changed

+307
-211
lines changed

10 files changed

+307
-211
lines changed

docs/.vitepress/config.js

+1
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ const config = {
287287
{text: "<code>Avo::Services::EncryptionService</code>", link: "/3.0/encryption-service.html"},
288288
{text: "Select All", link: "/3.0/select-all.html"},
289289
{text: "Icons", link: "/3.0/icons.html"},
290+
{text: "Reserved model names and routes", link: "/3.0/internal-model-names.html"},
290291
],
291292
},
292293
{

docs/3.0/audit-logging/overview.md

+77-196
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ outline: [2,3]
77

88
# Audit Logging
99

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.
1111

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.
1313

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.
1515

1616
## Requirements
1717

@@ -20,7 +20,7 @@ The installation process will automatically generate the necessary migrations, r
2020
## Installation
2121

2222
:::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.
2424
:::
2525

2626
### 1. Install the gem
@@ -36,25 +36,11 @@ Then
3636
bundle install
3737
```
3838

39-
### 2. Select the audit gem
39+
### 2. Run the installer
4040

41-
Prior to running the installer, choose the gem you want to use for record versioning:
42-
43-
- [`audited`](https://github.com/collectiveidea/audited)
44-
- [`paper_trail`](https://github.com/paper-trail-gem/paper_trail)
45-
46-
Once you've chosen a gem, proceed by running the installation command:
47-
48-
:::code-group
49-
```bash [audited]
50-
bin/rails generate avo:audit_logging install --gem audited
51-
52-
```
53-
54-
```bash [paper_trail]
55-
bin/rails generate avo:audit_logging install --gem paper_trail
41+
```bash
42+
bin/rails generate avo:audit_logging install
5643
```
57-
:::
5844

5945
### 3. Migrate
6046

@@ -72,7 +58,7 @@ After installation, audit logging is disabled by default. To enable it, navigate
7258

7359
Set `config.enabled` to `true` within this configuration.
7460

75-
```ruby{7-9}
61+
```ruby
7662
# config/initializers/avo.rb # [!code focus]
7763

7864
Avo.configure do |config|
@@ -82,11 +68,12 @@ end
8268
Avo::AuditLogging.configure do |config| # [!code focus]
8369
# config.enabled = false # [!code --] # [!code focus]
8470
config.enabled = true # [!code ++] # [!code focus]
71+
# config.author_model = "User"
8572
end # [!code focus]
8673
```
8774

8875
:::info
89-
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.
9077
:::
9178

9279
### Configure author models
@@ -95,7 +82,7 @@ Setting this configuration to `false` will disable the audit logging feature ent
9582
If `User` is your only author model, you can skip this step as it will be automatically set by default.
9683
:::
9784

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`.
9986

10087
```ruby
10188
# config/initializers/avo.rb # [!code focus]
@@ -110,7 +97,7 @@ Avo::AuditLogging.configure do |config| # [!code focus]
11097
# config.author_model = "User" # [!code --] # [!code focus]
11198
config.author_model = "Account" # [!code ++] # [!code focus]
11299

113-
# Or if multiples # [!code focus]
100+
# Or for multiples models # [!code focus]
114101
config.author_models = ["User", "Account"] # [!code ++] # [!code focus]
115102
end # [!code focus]
116103
```
@@ -162,49 +149,21 @@ end # [!code focus]
162149
```
163150
:::
164151

165-
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.
166153

167154
But these activities aren't visible yet, right? Let's look at how to display them in the next step.
168155

169156
## Display logged activities
170157

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.
158+
### Resource-Specific Activities
173159

174-
<Image src="/assets/img/3_0/audit-logging/avo-activities.png" width="1912" height="682" alt="Avo activities table image" />
160+
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:
175161

176-
To display this table as an association view, add the `:avo_activities` field to resources that have audit logging enabled.
162+
<Image src="/assets/img/3_0/audit-logging/sidebar-activities.png" width="1915" height="719" alt="Avo compact activities on sidebar image" />
177163

178-
```ruby
179-
class Avo::Resources::Product < Avo::BaseResource # [!code focus]
180-
self.audit_logging = {
181-
activity: true
182-
}
164+
### Configuring the Sidebar for Activity Tracking
183165

184-
def fields # [!code focus]
185-
field :id, as: :id, link_to_record: true
186-
field :name, as: :text, link_to_record: true
187-
field :price, as: :number, step: 1
188-
field :avo_activities, as: :has_many # [!code ++] # [!code focus]
189-
end # [!code focus]
190-
191-
def actions
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-
<Image src="/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:
208167

209168
```ruby{7,12-15}
210169
class Avo::Resources::Product < Avo::BaseResource # [!code focus]
@@ -232,9 +191,66 @@ class Avo::Resources::Product < Avo::BaseResource # [!code focus]
232191
end # [!code focus]
233192
```
234193

194+
### Viewing and Navigating Activity Logs
195+
196+
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+
<Image src="/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+
class Product < 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.
217+
218+
<Image src="/assets/img/3_0/audit-logging/activity-details.png" width="2010" height="1152" alt="Activity details page" />
219+
220+
### Troubleshooting: Missing `changeset` Field
221+
222+
:::warning
223+
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.
233+
234+
<Image src="/assets/img/3_0/audit-logging/authored.png" width="1921" height="754" alt="Authored table image" />
235+
236+
:::warning
237+
If you're using a model other than `User`, make sure you have already [configured the author models](#configure-author-models).
238+
:::
239+
240+
```ruby
241+
class Avo::Resources::User < Avo::BaseResource # [!code focus]
242+
def fields # [!code focus]
243+
field :id, as: :id, link_to_record: true
244+
field :email, as: :text, link_to_record: true
245+
field :products, as: :has_many
246+
field :avo_authored, as: :has_many # [!code ++] # [!code focus]
247+
end # [!code focus]
248+
end # [!code focus]
249+
```
250+
235251
### Overview of all activities
236252

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.
238254

239255
```ruby
240256
# config/initializers/avo.rb
@@ -303,143 +319,8 @@ The default value for `actions` is:
303319
}
304320
```
305321

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.
309-
310-
<Image src="/assets/img/3_0/audit-logging/authored.png" width="1926" height="739" alt="Authored table image" />
311-
312-
:::warning
313-
If you're using a model other than `User`, make sure you have already [configured the author models](#_2-configure-author-models).
314-
:::
315-
316-
```ruby
317-
class Avo::Resources::User < Avo::BaseResource # [!code focus]
318-
def fields # [!code focus]
319-
field :id, as: :id, link_to_record: true
320-
field :email, as: :text, link_to_record: true
321-
field :products, as: :has_many
322-
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-
class Product < 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-
class Product < 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:
374-
375-
:::code-group
376-
```ruby [audited]{22}
377-
class Avo::Resources::Product < Avo::BaseResource # [!code focus]
378-
self.audit_logging = {
379-
activity: true,
380-
actions: {
381-
edit: false,
382-
show: false
383-
}
384-
}
385-
386-
def fields # [!code focus]
387-
main_menu do
388-
field :id, as: :id, link_to_record: true
389-
field :name, as: :text, link_to_record: true
390-
field :price, as: :number, step: 1
391-
392-
sidebar do
393-
tool Avo::ResourceTools::Timeline
394-
end
395-
end
396-
397-
field :avo_activities, as: :has_many
398-
field :audits, as: :has_many, use_resource: Avo::Resources::Audited # [!code ++] # [!code focus]
399-
end # [!code focus]
400-
401-
def actions
402-
action Avo::Actions::ChangePrice
403-
end
404-
end # [!code focus]
405-
```
406-
407-
```ruby [paper_trail]{22}
408-
class Avo::Resources::Product < Avo::BaseResource # [!code focus]
409-
self.audit_logging = {
410-
activity: true,
411-
actions: {
412-
edit: false,
413-
show: false
414-
}
415-
}
416-
417-
def fields # [!code focus]
418-
main_menu do
419-
field :id, as: :id, link_to_record: true
420-
field :name, as: :text, link_to_record: true
421-
field :price, as: :number, step: 1
422-
423-
sidebar do
424-
tool Avo::ResourceTools::Timeline
425-
end
426-
end
427-
428-
field :avo_activities, as: :has_many
429-
field :versions, as: :has_many, use_resource: Avo::Resources::PaperTrail # [!code ++] # [!code focus]
430-
end # [!code focus]
431-
432-
def actions
433-
action Avo::Actions::ChangePrice
434-
end
435-
end # [!code focus]
436-
```
437-
:::
438-
439322
## Conclusion
440323

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.
444325

445326
Happy auditing!

0 commit comments

Comments
 (0)