diff --git a/app/controllers/avo/actions_controller.rb b/app/controllers/avo/actions_controller.rb index a0b9a1aba9..0526ce8108 100644 --- a/app/controllers/avo/actions_controller.rb +++ b/app/controllers/avo/actions_controller.rb @@ -49,12 +49,23 @@ 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) + + safe_call :audit, + activity_class: @action.class, + payload: { + fields: fields, + resource: resource, + }, + action: __method__, + records: query + 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 diff --git a/app/controllers/avo/application_controller.rb b/app/controllers/avo/application_controller.rb index 76f8e1f3f5..fe3ad3f08f 100644 --- a/app/controllers/avo/application_controller.rb +++ b/app/controllers/avo/application_controller.rb @@ -26,6 +26,7 @@ class ApplicationController < ::ActionController::Base before_action :set_view before_action :set_sidebar_open before_action :set_stylesheet_assets_path + before_action :set_paper_trail_whodunnit, if: -> { defined? PaperTrail } rescue_from Avo::NotAuthorizedError, with: :render_unauthorized rescue_from ActiveRecord::RecordInvalid, with: :exception_logger diff --git a/app/controllers/avo/associations_controller.rb b/app/controllers/avo/associations_controller.rb index d16c9d0cb7..536382be0a 100644 --- a/app/controllers/avo/associations_controller.rb +++ b/app/controllers/avo/associations_controller.rb @@ -63,6 +63,8 @@ def new def create respond_to do |format| if create_association + safe_call :audit, activity_class: @resource.class, payload: params, action: :attach, records: @record + format.html { redirect_back fallback_location: resource_view_response_path, notice: t("avo.attachment_class_attached", attachment_class: @related_resource.name) @@ -102,6 +104,7 @@ def destroy @record.send(:"#{association_name}=", nil) end + safe_call :audit, activity_class: @resource.class, payload: params, action: :detach, records: @record 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 diff --git a/app/controllers/avo/base_controller.rb b/app/controllers/avo/base_controller.rb index 7c44587ab3..4606006abf 100644 --- a/app/controllers/avo/base_controller.rb +++ b/app/controllers/avo/base_controller.rb @@ -17,6 +17,8 @@ class BaseController < ApplicationController before_action :set_pagy_locale, only: :index def index + safe_call :audit, activity_class: @resource.class, payload: params, action: __method__ + @page_title = @resource.plural_name.humanize if @reflection.present? && !turbo_frame_request? @@ -70,6 +72,8 @@ def index end def show + safe_call :audit, activity_class: @resource.class, payload: params, action: __method__, records: @record + @resource.hydrate( record: @record, view: Avo::ViewInquirer.new(:show), @@ -131,6 +135,8 @@ def new add_breadcrumb t("avo.new").humanize + safe_call :audit, activity_class: @resource.class, payload: params, action: __method__ + set_component_for __method__, fallback_view: :edit end @@ -175,6 +181,7 @@ def create set_component_for :edit + safe_call :audit, activity_class: @resource.class, payload: params, action: __method__, records: @record if saved create_success_action else @@ -183,12 +190,16 @@ def create end def edit + safe_call :audit, activity_class: @resource.class, payload: params, action: __method__, records: @record + set_actions set_component_for __method__ end def update + safe_call :audit, activity_class: @resource.class, payload: params, action: __method__, records: @record + # 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) @@ -204,6 +215,7 @@ def update end def destroy + safe_call :audit, activity_class: @resource.class, payload: params, action: __method__, records: @record if destroy_model destroy_success_action else @@ -577,10 +589,6 @@ def set_pagy_locale @pagy_locale = locale.to_s || Avo.configuration.default_locale || "en" end - def safe_call(method) - send(method) if respond_to?(method, true) - end - def pagy_query @query end diff --git a/app/helpers/avo/application_helper.rb b/app/helpers/avo/application_helper.rb index c9babc1418..9ac02cf515 100644 --- a/app/helpers/avo/application_helper.rb +++ b/app/helpers/avo/application_helper.rb @@ -137,6 +137,10 @@ def frame_id(resource) ["frame", resource.model_name.singular, resource.record_param].compact.join("-") end + def safe_call(method, **args) + send(method, **args) if respond_to?(method, true) + end + def chart_color(index) Avo.configuration.branding.chart_colors[index % Avo.configuration.branding.chart_colors.length] end diff --git a/lib/avo/current.rb b/lib/avo/current.rb index 9baf2da9ac..55439405ef 100644 --- a/lib/avo/current.rb +++ b/lib/avo/current.rb @@ -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 diff --git a/lib/tasks/avo_tasks.rake b/lib/tasks/avo_tasks.rake index ec95c247be..5a58aca02d 100644 --- a/lib/tasks/avo_tasks.rake +++ b/lib/tasks/avo_tasks.rake @@ -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)