Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: audit logs #2703

Open
wants to merge 47 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 44 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
1167828
WIP
Paul-Bob Jan 10, 2024
8c4c54a
wip
Paul-Bob Jan 10, 2024
fc9720b
WIP
Paul-Bob Jan 13, 2024
04e7d7f
wip
Paul-Bob Jan 15, 2024
2f6dbc3
typo
Paul-Bob Jan 15, 2024
9826cdc
Merge branch 'main' into feature/audit_logs
Paul-Bob Jan 17, 2024
0070b19
WIP
Paul-Bob Jan 17, 2024
f64dfb8
WIP
Paul-Bob Jan 19, 2024
8d9248c
wip
Paul-Bob Jan 22, 2024
0771d63
Merge branch 'main' into feature/audit_logs
Paul-Bob Feb 15, 2024
2c9b896
wip
Paul-Bob Feb 16, 2024
361120a
wip
Paul-Bob Feb 16, 2024
0db29ba
Merge branch 'main' into feature/audit_logs
Paul-Bob Apr 2, 2024
4986af8
dont break if db do not exist
Paul-Bob Apr 2, 2024
16c3019
wip
Paul-Bob Apr 3, 2024
f88a17f
Merge branch 'main' into feature/audit_logs
Paul-Bob Apr 4, 2024
496f42d
rename package
Paul-Bob Apr 9, 2024
cdde642
Merge branch 'main' into feature/audit_logs
Paul-Bob Apr 11, 2024
da5f08f
Merge branch 'main' into feature/audit_logs
Paul-Bob May 13, 2024
58210f7
extract audit method and safe_call it
Paul-Bob May 13, 2024
53221df
register all activity
Paul-Bob May 14, 2024
70cd62c
Update app/components/avo/sidebar_component.html.erb
Paul-Bob May 14, 2024
f0ab0a2
Update lib/avo/configuration.rb
Paul-Bob May 14, 2024
f3c5e1c
Update lib/avo/configuration.rb
Paul-Bob May 14, 2024
8840724
Merge branch 'main' into feature/audit_logs
Paul-Bob May 14, 2024
5e614a4
Merge branch 'main' into feature/audit_logs
Paul-Bob Jun 20, 2024
bd07682
rename to avo-audit_logging
Paul-Bob Jun 20, 2024
dc2f288
feature: log attach and detach
Paul-Bob Jun 21, 2024
019ca76
Merge branch 'main' into feature/audit_logs
Paul-Bob Sep 11, 2024
6745d11
Merge branch 'main' into feature/audit_logs
Paul-Bob Sep 11, 2024
cf57fe1
Merge branch 'main' into feature/audit_logs
Paul-Bob Sep 13, 2024
6fc5c46
unbundle audits from enterprise license
Paul-Bob Sep 13, 2024
80b049a
implement gem configuration
Paul-Bob Sep 13, 2024
9595046
rm unused config attribute
Paul-Bob Sep 13, 2024
02d3595
clear template
Paul-Bob Sep 13, 2024
cefc4dd
extract direct call
Paul-Bob Sep 23, 2024
4dca585
remove direct audit call
Paul-Bob Sep 23, 2024
f03c4cc
rm set_paper_trail_whodunnit
Paul-Bob Sep 23, 2024
0d28364
revert safe_call enhancement
Paul-Bob Sep 23, 2024
415c940
Merge branch 'main' into feature/audit_logs
Paul-Bob Sep 23, 2024
d582db0
temporary solution for not defined audit
Paul-Bob Sep 23, 2024
8ed38be
Merge branch 'feature/audit_logs' of github.com:avo-hq/avo into featu…
Paul-Bob Sep 23, 2024
4d8728f
wip
Paul-Bob Sep 23, 2024
bc71d7a
.
Paul-Bob Sep 23, 2024
9db0654
lint
Paul-Bob Sep 23, 2024
e7f14ae
extract audit call
Paul-Bob Sep 24, 2024
6ecaf15
rm activity
Paul-Bob Sep 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions app/controllers/avo/actions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,16 @@ def build_background_url
def handle
resource_ids = action_params[:fields][:avo_resource_ids].split(",")

@query = decrypted_query || (resource_ids.any? ? @resource.find_record(resource_ids, params: params) : [])
@fields = action_params[:fields].except(:avo_resource_ids, :avo_selected_query)

instance_exec(__method__, &audit)

performed_action = @action.handle_action(
fields: action_params[:fields].except(:avo_resource_ids, :avo_selected_query),
fields: @fields,
current_user: _current_user,
resource: @resource,
query: decrypted_query ||
(resource_ids.any? ? @resource.find_record(resource_ids, params: params) : [])
query: @query
)

@response = performed_action.response
Expand Down
3 changes: 3 additions & 0 deletions app/controllers/avo/associations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ def new
def create
respond_to do |format|
if create_association
instance_exec(:attach, &audit)

format.html {
redirect_back fallback_location: resource_view_response_path,
notice: t("avo.attachment_class_attached", attachment_class: @related_resource.name)
Expand Down Expand Up @@ -102,6 +104,7 @@ def destroy
@record.send(:"#{association_name}=", nil)
end

instance_exec(:detach, &audit)
respond_to do |format|
format.html { redirect_to params[:referrer] || resource_view_response_path, notice: t("avo.attachment_class_detached", attachment_class: @attachment_class) }
end
Expand Down
12 changes: 12 additions & 0 deletions app/controllers/avo/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class BaseController < ApplicationController
before_action :set_pagy_locale, only: :index

def index
instance_exec(__method__, &audit) if @reflection.blank?

@page_title = @resource.plural_name.humanize

if @reflection.present? && !turbo_frame_request?
Expand Down Expand Up @@ -70,6 +72,8 @@ def index
end

def show
instance_exec(__method__, &audit)

@resource.hydrate(
record: @record,
view: Avo::ViewInquirer.new(:show),
Expand Down Expand Up @@ -131,6 +135,8 @@ def new

add_breadcrumb t("avo.new").humanize

instance_exec(__method__, &audit)

set_component_for __method__, fallback_view: :edit
end

Expand Down Expand Up @@ -175,6 +181,7 @@ def create

set_component_for :edit

instance_exec(__method__, &audit)
if saved
create_success_action
else
Expand All @@ -183,12 +190,16 @@ def create
end

def edit
instance_exec(__method__, &audit)

set_actions

set_component_for __method__
end

def update
instance_exec(__method__, &audit)

# record gets instantiated and filled in the fill_record method
saved = save_record
@resource = @resource.hydrate(record: @record, view: Avo::ViewInquirer.new(:edit), user: _current_user)
Expand All @@ -204,6 +215,7 @@ def update
end

def destroy
instance_exec(__method__, &audit)
if destroy_model
destroy_success_action
else
Expand Down
4 changes: 4 additions & 0 deletions app/helpers/avo/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ def frame_id(resource)
["frame", resource.model_name.singular, resource.record_param].compact.join("-")
end

def audit
-> (_) {}
Paul-Bob marked this conversation as resolved.
Show resolved Hide resolved
end

def chart_color(index)
Avo.configuration.branding.chart_colors[index % Avo.configuration.branding.chart_colors.length]
end
Expand Down
1 change: 1 addition & 0 deletions lib/avo/current.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Avo::Current < ActiveSupport::CurrentAttributes
attribute :tool_manager
attribute :plugin_manager
attribute :locale
attribute :activity

# The tenant attributes are here so the user can add them on their own will
attribute :tenant_id
Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/avo_tasks.rake
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ task "avo:sym_link" do

gem_paths = `bundle list --paths 2>/dev/null`.split("\n")

["avo-advanced", "avo-pro", "avo-dynamic_filters", "avo-dashboards", "avo-menu", "avo-kanban"].each do |gem|
["avo-advanced", "avo-pro", "avo-dynamic_filters", "avo-dashboards", "avo-menu", "avo-kanban", "avo-audit_logging"].each do |gem|
path = gem_paths.find { |gem_path| gem_path.include?("/#{gem}-") }

# If path is nil we check if package is defined outside of root (on release process it is)
Expand Down
Loading