From 116782849656b9e5ccd95b585e839c38f761c224 Mon Sep 17 00:00:00 2001 From: Paul Bob Date: Wed, 10 Jan 2024 18:23:35 +0200 Subject: [PATCH 01/34] WIP --- app/components/avo/sidebar_component.html.erb | 10 ++++++++++ app/controllers/avo/actions_controller.rb | 15 +++++++++++++-- lib/avo/configuration.rb | 10 +++++++++- lib/generators/avo/templates/initializer/avo.tt | 3 +++ 4 files changed, 35 insertions(+), 3 deletions(-) diff --git a/app/components/avo/sidebar_component.html.erb b/app/components/avo/sidebar_component.html.erb index f536d28ccf..77749a7014 100644 --- a/app/components/avo/sidebar_component.html.erb +++ b/app/components/avo/sidebar_component.html.erb @@ -54,6 +54,16 @@ <% end %> <% end %> + <% if Avo.configuration.audit? %> +
+ <%= render Avo::Sidebar::HeadingComponent.new label: t('avo.audits'), icon: helpers.svg('presentation-chart-bar', class: 'h-4') %> +
+ <%= render Avo::Sidebar::LinkComponent.new label: t('avo.audits'), path: helpers.avo_enterprise.audits_path %> + <%= render Avo::Sidebar::LinkComponent.new label: t('avo.actions'), path: helpers.avo_enterprise.audits_actions_path %> +
+
+ <% end %> + <%= render partial: "/avo/partials/sidebar_extra" %> diff --git a/app/controllers/avo/actions_controller.rb b/app/controllers/avo/actions_controller.rb index 7ae03803fb..aa6e25cb84 100644 --- a/app/controllers/avo/actions_controller.rb +++ b/app/controllers/avo/actions_controller.rb @@ -30,8 +30,19 @@ def handle (resource_ids.any? ? @resource.find_record(resource_ids, params: params) : []) ) - @response = performed_action.response - respond + AvoAudit.create!( + auditable_class: @action.class, + action: "avo_action", + author_id: _current_user.id, + author_type: _current_user.class, + payload: { + fields: action_params[:fields].except(:avo_resource_ids, :avo_selected_query), + resource: resource, + query: (decrypted_query || (resource_ids.any? ? @resource.find_record(resource_ids, params: params) : [])).map(&:id) + }.to_json + ) + + respond performed_action.response end private diff --git a/lib/avo/configuration.rb b/lib/avo/configuration.rb index 4a9d882eee..0d18281ebe 100644 --- a/lib/avo/configuration.rb +++ b/lib/avo/configuration.rb @@ -7,6 +7,7 @@ class Configuration attr_writer :root_path attr_writer :cache_store attr_writer :logger + attr_writer :audit attr_accessor :timezone attr_accessor :per_page attr_accessor :per_page_steps @@ -99,6 +100,7 @@ def initialize @mount_avo_engines = true @cache_store = computed_cache_store @logger = default_logger + @audit = false end def current_user_method(&block) @@ -156,7 +158,9 @@ def license=(value) def license gems = Gem::Specification.map {|gem| gem.name} - @license ||= if gems.include?("avo-advanced") + @license ||= if gems.include?("avo-enterprise") + "enterprise" + elsif gems.include?("avo-advanced") "advanced" elsif gems.include?("avo-pro") "pro" @@ -214,6 +218,10 @@ def default_logger file_logger } end + + def audit? + Avo.plugin_manager.installed?("avo-enterprise") && @audit && ActiveRecord::Base.connection.table_exists?(:avo_audits) + end end def self.configuration diff --git a/lib/generators/avo/templates/initializer/avo.tt b/lib/generators/avo/templates/initializer/avo.tt index 228d390811..d773355901 100644 --- a/lib/generators/avo/templates/initializer/avo.tt +++ b/lib/generators/avo/templates/initializer/avo.tt @@ -78,6 +78,9 @@ Avo.configure do |config| # file_logger # } + ## == Audit == + # config.audit = false + ## == Customization == # config.app_name = 'Avocadelicious' # config.timezone = 'UTC' From 8c4c54aecc78b493584ceae54a99893360b2253c Mon Sep 17 00:00:00 2001 From: Paul Bob Date: Wed, 10 Jan 2024 18:29:14 +0200 Subject: [PATCH 02/34] wip --- app/controllers/avo/actions_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/avo/actions_controller.rb b/app/controllers/avo/actions_controller.rb index aa6e25cb84..177af54f4a 100644 --- a/app/controllers/avo/actions_controller.rb +++ b/app/controllers/avo/actions_controller.rb @@ -42,7 +42,8 @@ def handle }.to_json ) - respond performed_action.response + @response = performed_action.response + respond end private From fc9720b1e39c679a0e869ec850bdbc3fad36e728 Mon Sep 17 00:00:00 2001 From: Paul Bob Date: Sat, 13 Jan 2024 14:26:03 +0200 Subject: [PATCH 03/34] WIP --- app/components/avo/sidebar_component.html.erb | 9 ------ app/controllers/avo/actions_controller.rb | 32 +++++++++++-------- .../avo/templates/resource/controller.tt | 2 +- 3 files changed, 20 insertions(+), 23 deletions(-) diff --git a/app/components/avo/sidebar_component.html.erb b/app/components/avo/sidebar_component.html.erb index 77749a7014..25ad7756b6 100644 --- a/app/components/avo/sidebar_component.html.erb +++ b/app/components/avo/sidebar_component.html.erb @@ -54,15 +54,6 @@ <% end %> <% end %> - <% if Avo.configuration.audit? %> -
- <%= render Avo::Sidebar::HeadingComponent.new label: t('avo.audits'), icon: helpers.svg('presentation-chart-bar', class: 'h-4') %> -
- <%= render Avo::Sidebar::LinkComponent.new label: t('avo.audits'), path: helpers.avo_enterprise.audits_path %> - <%= render Avo::Sidebar::LinkComponent.new label: t('avo.actions'), path: helpers.avo_enterprise.audits_actions_path %> -
-
- <% end %> <%= render partial: "/avo/partials/sidebar_extra" %> diff --git a/app/controllers/avo/actions_controller.rb b/app/controllers/avo/actions_controller.rb index 177af54f4a..f1dc3cdd8c 100644 --- a/app/controllers/avo/actions_controller.rb +++ b/app/controllers/avo/actions_controller.rb @@ -22,25 +22,31 @@ def show def handle resource_ids = action_params[:fields][:avo_resource_ids].split(",") + query = decrypted_query || (resource_ids.any? ? @resource.find_record(resource_ids, params: params) : []) + performed_action = @action.handle_action( fields: action_params[:fields].except(:avo_resource_ids, :avo_selected_query), current_user: _current_user, resource: resource, - query: decrypted_query || - (resource_ids.any? ? @resource.find_record(resource_ids, params: params) : []) + query: query ) - AvoAudit.create!( - auditable_class: @action.class, - action: "avo_action", - author_id: _current_user.id, - author_type: _current_user.class, - payload: { - fields: action_params[:fields].except(:avo_resource_ids, :avo_selected_query), - resource: resource, - query: (decrypted_query || (resource_ids.any? ? @resource.find_record(resource_ids, params: params) : [])).map(&:id) - }.to_json - ) + if Avo.configuration.audit? + (query.presence || [nil]).each do |record| + AvoAudit.create!( + auditable_class: @action.class, + auditable_id: record&.to_param, + auditable_type: record&.class, + action: "avo_action", + author_id: _current_user.id, + author_type: _current_user.class, + payload: { + fields: action_params[:fields].except(:avo_resource_ids, :avo_selected_query), + resource: resource, + }.to_json + ) + end + end @response = performed_action.response respond diff --git a/lib/generators/avo/templates/resource/controller.tt b/lib/generators/avo/templates/resource/controller.tt index 1eba1194b2..bc6e183eae 100644 --- a/lib/generators/avo/templates/resource/controller.tt +++ b/lib/generators/avo/templates/resource/controller.tt @@ -1,4 +1,4 @@ # This controller has been generated to enable Rails' resource routes. -# More information on https://docs.avohq.io/2.0/controllers.html +# More information on https://docs.avohq.io/3.0/controllers.html class <%= controller_class %> < <%= parent_controller %> end From 04e7d7f4a7df0e4434f1655f35053ee5923ea3f5 Mon Sep 17 00:00:00 2001 From: Paul Bob Date: Mon, 15 Jan 2024 10:37:48 +0200 Subject: [PATCH 04/34] wip --- app/controllers/avo/actions_controller.rb | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/app/controllers/avo/actions_controller.rb b/app/controllers/avo/actions_controller.rb index f1dc3cdd8c..4a6124b9ed 100644 --- a/app/controllers/avo/actions_controller.rb +++ b/app/controllers/avo/actions_controller.rb @@ -23,28 +23,29 @@ def handle resource_ids = action_params[:fields][:avo_resource_ids].split(",") query = decrypted_query || (resource_ids.any? ? @resource.find_record(resource_ids, params: params) : []) + field = action_params[:fields].except(:avo_resource_ids, :avo_selected_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: query ) if Avo.configuration.audit? - (query.presence || [nil]).each do |record| - AvoAudit.create!( + audit = Avo::Audit.create!( auditable_class: @action.class, - auditable_id: record&.to_param, - auditable_type: record&.class, action: "avo_action", author_id: _current_user.id, author_type: _current_user.class, payload: { - fields: action_params[:fields].except(:avo_resource_ids, :avo_selected_query), + fields: fields, resource: resource, }.to_json ) + + query.each do |record| + audit.avo_audit_records.create!(record: record) end end From 2f6dbc320529481e7062a470bcd79fb8e6764b65 Mon Sep 17 00:00:00 2001 From: Paul Bob Date: Mon, 15 Jan 2024 12:04:01 +0200 Subject: [PATCH 05/34] typo --- app/controllers/avo/actions_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/avo/actions_controller.rb b/app/controllers/avo/actions_controller.rb index 4a6124b9ed..19e6d221b8 100644 --- a/app/controllers/avo/actions_controller.rb +++ b/app/controllers/avo/actions_controller.rb @@ -23,7 +23,7 @@ def handle resource_ids = action_params[:fields][:avo_resource_ids].split(",") query = decrypted_query || (resource_ids.any? ? @resource.find_record(resource_ids, params: params) : []) - field = action_params[:fields].except(:avo_resource_ids, :avo_selected_query) + fields = action_params[:fields].except(:avo_resource_ids, :avo_selected_query) performed_action = @action.handle_action( fields: fields, From 0070b19a2bc15cd759bdea72f7d19514c5568036 Mon Sep 17 00:00:00 2001 From: Paul Bob Date: Wed, 17 Jan 2024 19:37:10 +0200 Subject: [PATCH 06/34] WIP --- app/controllers/avo/actions_controller.rb | 27 +++++++++-------------- app/controllers/avo/base_controller.rb | 4 ++++ app/helpers/avo/application_helper.rb | 17 ++++++++++++++ lib/avo/current.rb | 1 + 4 files changed, 32 insertions(+), 17 deletions(-) diff --git a/app/controllers/avo/actions_controller.rb b/app/controllers/avo/actions_controller.rb index 19e6d221b8..042fe35fc0 100644 --- a/app/controllers/avo/actions_controller.rb +++ b/app/controllers/avo/actions_controller.rb @@ -25,6 +25,16 @@ def handle query = decrypted_query || (resource_ids.any? ? @resource.find_record(resource_ids, params: params) : []) fields = action_params[:fields].except(:avo_resource_ids, :avo_selected_query) + audit( + auditable_class: @action.class, + payload: { + fields: fields, + resource: resource, + }, + action: __method__, + records: query + ) + performed_action = @action.handle_action( fields: fields, current_user: _current_user, @@ -32,23 +42,6 @@ def handle query: query ) - if Avo.configuration.audit? - audit = Avo::Audit.create!( - auditable_class: @action.class, - action: "avo_action", - author_id: _current_user.id, - author_type: _current_user.class, - payload: { - fields: fields, - resource: resource, - }.to_json - ) - - query.each do |record| - audit.avo_audit_records.create!(record: record) - end - end - @response = performed_action.response respond end diff --git a/app/controllers/avo/base_controller.rb b/app/controllers/avo/base_controller.rb index 1b2fa936ce..428671a5f2 100644 --- a/app/controllers/avo/base_controller.rb +++ b/app/controllers/avo/base_controller.rb @@ -124,6 +124,7 @@ def new def create # record gets instantiated and filled in the fill_record method + audit(auditable_class: @resource.class, payload: params, action: __method__) saved = save_record @resource.hydrate(record: @record, view: :new, user: _current_user) @@ -178,6 +179,8 @@ def edit end def update + audit(auditable_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: :edit, user: _current_user) @@ -193,6 +196,7 @@ def update end def destroy + audit(auditable_class: @resource.class, payload: params, action: __method__, records: @record) if destroy_model destroy_success_action else diff --git a/app/helpers/avo/application_helper.rb b/app/helpers/avo/application_helper.rb index e0f826b533..a2bfd7c5f8 100644 --- a/app/helpers/avo/application_helper.rb +++ b/app/helpers/avo/application_helper.rb @@ -133,6 +133,23 @@ def frame_id(resource) ["frame", resource.model_name.singular, resource.record.id].compact.join("-") end + def audit(auditable_class:, payload:, action:, records: []) + return unless Avo.configuration.audit? + + Avo::Current.audit = Avo::Audit.create!( + auditable_class: auditable_class, + action: action, + author_id: _current_user.id, + author_type: _current_user.class, + payload: payload.to_json + ) + + + Array(records).each do |record| + Avo::Current.audit.avo_audit_records.create!(record: record) + end + end + private # Taken from the original library diff --git a/lib/avo/current.rb b/lib/avo/current.rb index 54b208845e..0ba2052301 100644 --- a/lib/avo/current.rb +++ b/lib/avo/current.rb @@ -25,6 +25,7 @@ class Avo::Current < ActiveSupport::CurrentAttributes attribute :tool_manager attribute :plugin_manager attribute :locale + attribute :audit # Protect from error # when request is ActionDispatch::Request.empty def params From f64dfb8ac5948fe08bc47f93d7be6804b4cb2c18 Mon Sep 17 00:00:00 2001 From: Paul Bob Date: Fri, 19 Jan 2024 19:42:00 +0200 Subject: [PATCH 07/34] WIP --- app/controllers/avo/application_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/avo/application_controller.rb b/app/controllers/avo/application_controller.rb index 08e508ae66..abb55ca52e 100644 --- a/app/controllers/avo/application_controller.rb +++ b/app/controllers/avo/application_controller.rb @@ -25,6 +25,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 From 8d9248cbf88b035dff539a6373995d4c04530661 Mon Sep 17 00:00:00 2001 From: Paul Bob Date: Mon, 22 Jan 2024 20:08:03 +0200 Subject: [PATCH 08/34] wip --- app/helpers/avo/application_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/avo/application_helper.rb b/app/helpers/avo/application_helper.rb index a2bfd7c5f8..fb8a35925d 100644 --- a/app/helpers/avo/application_helper.rb +++ b/app/helpers/avo/application_helper.rb @@ -134,7 +134,7 @@ def frame_id(resource) end def audit(auditable_class:, payload:, action:, records: []) - return unless Avo.configuration.audit? + return unless Avo.configuration.audit? && auditable_class.has_avo_audit Avo::Current.audit = Avo::Audit.create!( auditable_class: auditable_class, From 2c9b896a2e271aa764068f8287ebbcb756f89940 Mon Sep 17 00:00:00 2001 From: Paul Bob Date: Fri, 16 Feb 2024 17:20:33 +0200 Subject: [PATCH 09/34] wip --- app/controllers/avo/actions_controller.rb | 2 +- app/controllers/avo/base_controller.rb | 6 +++--- app/helpers/avo/application_helper.rb | 10 +++++----- lib/avo/current.rb | 2 +- lib/tasks/avo_tasks.rake | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/controllers/avo/actions_controller.rb b/app/controllers/avo/actions_controller.rb index 0d598173a7..29965c588b 100644 --- a/app/controllers/avo/actions_controller.rb +++ b/app/controllers/avo/actions_controller.rb @@ -26,7 +26,7 @@ def handle fields = action_params[:fields].except(:avo_resource_ids, :avo_selected_query) audit( - auditable_class: @action.class, + activity_class: @action.class, payload: { fields: fields, resource: resource, diff --git a/app/controllers/avo/base_controller.rb b/app/controllers/avo/base_controller.rb index 428671a5f2..4a9a74dd04 100644 --- a/app/controllers/avo/base_controller.rb +++ b/app/controllers/avo/base_controller.rb @@ -124,7 +124,7 @@ def new def create # record gets instantiated and filled in the fill_record method - audit(auditable_class: @resource.class, payload: params, action: __method__) + audit(activity_class: @resource.class, payload: params, action: __method__) saved = save_record @resource.hydrate(record: @record, view: :new, user: _current_user) @@ -179,7 +179,7 @@ def edit end def update - audit(auditable_class: @resource.class, payload: params, action: __method__, records: @record) + audit(activity_class: @resource.class, payload: params, action: __method__, records: @record) # record gets instantiated and filled in the fill_record method saved = save_record @@ -196,7 +196,7 @@ def update end def destroy - audit(auditable_class: @resource.class, payload: params, action: __method__, records: @record) + audit(activity_class: @resource.class, payload: params, action: __method__, records: @record) if destroy_model destroy_success_action else diff --git a/app/helpers/avo/application_helper.rb b/app/helpers/avo/application_helper.rb index fb8a35925d..ee01bac28c 100644 --- a/app/helpers/avo/application_helper.rb +++ b/app/helpers/avo/application_helper.rb @@ -133,11 +133,11 @@ def frame_id(resource) ["frame", resource.model_name.singular, resource.record.id].compact.join("-") end - def audit(auditable_class:, payload:, action:, records: []) - return unless Avo.configuration.audit? && auditable_class.has_avo_audit + def audit(activity_class:, payload:, action:, records: []) + return unless Avo.configuration.audit? && activity_class.has_avo_activity - Avo::Current.audit = Avo::Audit.create!( - auditable_class: auditable_class, + Avo::Current.activity = Avo::Activity.create!( + activity_class: activity_class, action: action, author_id: _current_user.id, author_type: _current_user.class, @@ -146,7 +146,7 @@ def audit(auditable_class:, payload:, action:, records: []) Array(records).each do |record| - Avo::Current.audit.avo_audit_records.create!(record: record) + Avo::Current.activity.avo_activity_pivots.create!(record: record) end end diff --git a/lib/avo/current.rb b/lib/avo/current.rb index 0ba2052301..82440efac9 100644 --- a/lib/avo/current.rb +++ b/lib/avo/current.rb @@ -25,7 +25,7 @@ class Avo::Current < ActiveSupport::CurrentAttributes attribute :tool_manager attribute :plugin_manager attribute :locale - attribute :audit + attribute :activity # Protect from error # when request is ActionDispatch::Request.empty def params diff --git a/lib/tasks/avo_tasks.rake b/lib/tasks/avo_tasks.rake index a094a1069d..cb77591576 100644 --- a/lib/tasks/avo_tasks.rake +++ b/lib/tasks/avo_tasks.rake @@ -71,7 +71,7 @@ task "avo:sym_link" do `touch #{packages_path}/.keep` end - ["avo-advanced", "avo-pro", "avo-dynamic_filters", "avo-dashboards", "avo-menu"].each do |gem| + ["avo-advanced", "avo-pro", "avo-dynamic_filters", "avo-dashboards", "avo-menu", "avo-enterprise"].each do |gem| path = `bundle show #{gem} 2> /dev/null`.chomp # If path is emty we check if package is defined outside of root (on release process it is) From 361120a89ef1fec589b034e85007041c083e9646 Mon Sep 17 00:00:00 2001 From: Paul Bob Date: Fri, 16 Feb 2024 18:38:07 +0200 Subject: [PATCH 10/34] wip --- lib/avo/configuration.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/avo/configuration.rb b/lib/avo/configuration.rb index 0d18281ebe..ff32b1aae6 100644 --- a/lib/avo/configuration.rb +++ b/lib/avo/configuration.rb @@ -220,7 +220,7 @@ def default_logger end def audit? - Avo.plugin_manager.installed?("avo-enterprise") && @audit && ActiveRecord::Base.connection.table_exists?(:avo_audits) + Avo.plugin_manager.installed?("avo-enterprise") && @audit && ActiveRecord::Base.connection.table_exists?(:avo_activities) end end From 4986af896d0d686a2750a77ac79ecda6ffad9ab5 Mon Sep 17 00:00:00 2001 From: Paul Bob Date: Tue, 2 Apr 2024 16:57:58 +0300 Subject: [PATCH 11/34] dont break if db do not exist --- lib/avo/configuration.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/avo/configuration.rb b/lib/avo/configuration.rb index 3edde08457..c18e81d7b2 100644 --- a/lib/avo/configuration.rb +++ b/lib/avo/configuration.rb @@ -224,7 +224,10 @@ def default_logger end def audit? - Avo.plugin_manager.installed?("avo-enterprise") && @audit && ActiveRecord::Base.connection.table_exists?(:avo_activities) + Avo.plugin_manager.installed?("avo-enterprise") && + @audit && + ActiveRecord::Base.connected? && + ActiveRecord::Base.connection.table_exists?(:avo_activities) end def turbo From 16c3019137a0ae0c34d3363ad03a2ce04b9059b2 Mon Sep 17 00:00:00 2001 From: Paul Bob Date: Wed, 3 Apr 2024 16:42:23 +0300 Subject: [PATCH 12/34] wip --- lib/avo/configuration.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/avo/configuration.rb b/lib/avo/configuration.rb index c18e81d7b2..bb851138e2 100644 --- a/lib/avo/configuration.rb +++ b/lib/avo/configuration.rb @@ -223,10 +223,19 @@ def default_logger } end + def database_exists? + ActiveRecord::Base.connection + rescue ActiveRecord::NoDatabaseError + false + else + true + end + + def audit? Avo.plugin_manager.installed?("avo-enterprise") && @audit && - ActiveRecord::Base.connected? && + database_exists? && ActiveRecord::Base.connection.table_exists?(:avo_activities) end From 496f42dab6e585c06b8ff0eec139dfc2fef1f97d Mon Sep 17 00:00:00 2001 From: Paul Bob Date: Tue, 9 Apr 2024 11:24:14 +0300 Subject: [PATCH 13/34] rename package --- lib/avo/configuration.rb | 4 ++-- lib/tasks/avo_tasks.rake | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/avo/configuration.rb b/lib/avo/configuration.rb index bb851138e2..e05f961ed2 100644 --- a/lib/avo/configuration.rb +++ b/lib/avo/configuration.rb @@ -162,7 +162,7 @@ def license=(value) def license gems = Gem::Specification.map {|gem| gem.name} - @license ||= if gems.include?("avo-enterprise") + @license ||= if gems.include?("avo-audits") "enterprise" elsif gems.include?("avo-advanced") "advanced" @@ -233,7 +233,7 @@ def database_exists? def audit? - Avo.plugin_manager.installed?("avo-enterprise") && + Avo.plugin_manager.installed?("avo-audits") && @audit && database_exists? && ActiveRecord::Base.connection.table_exists?(:avo_activities) diff --git a/lib/tasks/avo_tasks.rake b/lib/tasks/avo_tasks.rake index 0ab0561a94..c95ffa3902 100644 --- a/lib/tasks/avo_tasks.rake +++ b/lib/tasks/avo_tasks.rake @@ -79,7 +79,7 @@ task "avo:sym_link" do `touch #{packages_path}/.keep` end - ["avo-advanced", "avo-pro", "avo-dynamic_filters", "avo-dashboards", "avo-menu", "avo-enterprise"].each do |gem| + ["avo-advanced", "avo-pro", "avo-dynamic_filters", "avo-dashboards", "avo-menu", "avo-audits"].each do |gem| path = `bundle show #{gem} 2> /dev/null`.chomp # If path is emty we check if package is defined outside of root (on release process it is) From 58210f763866be51354cb3ad0d8f3ed06d083da0 Mon Sep 17 00:00:00 2001 From: Paul Bob Date: Mon, 13 May 2024 18:11:22 +0300 Subject: [PATCH 14/34] extract audit method and safe_call it --- app/controllers/avo/actions_controller.rb | 3 +-- app/controllers/avo/base_controller.rb | 10 +++------- app/helpers/avo/application_helper.rb | 17 ++--------------- 3 files changed, 6 insertions(+), 24 deletions(-) diff --git a/app/controllers/avo/actions_controller.rb b/app/controllers/avo/actions_controller.rb index 785a4a6fd8..0a0f20187c 100644 --- a/app/controllers/avo/actions_controller.rb +++ b/app/controllers/avo/actions_controller.rb @@ -52,7 +52,7 @@ def handle query = decrypted_query || (resource_ids.any? ? @resource.find_record(resource_ids, params: params) : []) fields = action_params[:fields].except(:avo_resource_ids, :avo_selected_query) - audit( + safe_call :audit, activity_class: @action.class, payload: { fields: fields, @@ -60,7 +60,6 @@ def handle }, action: __method__, records: query - ) performed_action = @action.handle_action( fields: fields, diff --git a/app/controllers/avo/base_controller.rb b/app/controllers/avo/base_controller.rb index b6844ba08e..09ec2a968c 100644 --- a/app/controllers/avo/base_controller.rb +++ b/app/controllers/avo/base_controller.rb @@ -143,7 +143,7 @@ def create end # record gets instantiated and filled in the fill_record method - audit(activity_class: @resource.class, payload: params, action: __method__) + safe_call :audit, activity_class: @resource.class, payload: params, action: __method__ saved = save_record @resource.hydrate(record: @record, view: :new, user: _current_user) @@ -167,7 +167,7 @@ def edit end def update - audit(activity_class: @resource.class, payload: params, action: __method__, records: @record) + 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 @@ -184,7 +184,7 @@ def update end def destroy - audit(activity_class: @resource.class, payload: params, action: __method__, records: @record) + safe_call :audit, activity_class: @resource.class, payload: params, action: __method__, records: @record if destroy_model destroy_success_action else @@ -553,10 +553,6 @@ def set_pagy_locale @pagy_locale = locale.to_s || Avo.configuration.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 ae65abe0e6..8f5fb969b4 100644 --- a/app/helpers/avo/application_helper.rb +++ b/app/helpers/avo/application_helper.rb @@ -133,21 +133,8 @@ def frame_id(resource) ["frame", resource.model_name.singular, resource.record.id].compact.join("-") end - def audit(activity_class:, payload:, action:, records: []) - return unless Avo.configuration.audit? && activity_class.has_avo_activity - - Avo::Current.activity = Avo::Activity.create!( - activity_class: activity_class, - action: action, - author_id: _current_user.id, - author_type: _current_user.class, - payload: payload.to_json - ) - - - Array(records).each do |record| - Avo::Current.activity.avo_activity_pivots.create!(record: record) - end + def safe_call(method, **args) + send(method, **args) if respond_to?(method, true) end def chart_color(index) From 53221df4d3e99e3b9625ea9de5f94253daa9ec1b Mon Sep 17 00:00:00 2001 From: Paul Bob Date: Tue, 14 May 2024 13:32:37 +0300 Subject: [PATCH 15/34] register all activity --- app/controllers/avo/base_controller.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/controllers/avo/base_controller.rb b/app/controllers/avo/base_controller.rb index 09ec2a968c..054dde5c4f 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 add_breadcrumb @resource.plural_name.humanize @@ -58,6 +60,8 @@ def index end def show + safe_call :audit, activity_class: @resource.class, payload: params, action: __method__, records: @record + @resource.hydrate(record: @record, view: :show, user: _current_user, params: params).detect_fields set_actions @@ -108,6 +112,8 @@ def new add_breadcrumb @resource.plural_name.humanize, resources_path(resource: @resource) 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 @@ -143,7 +149,6 @@ def create end # record gets instantiated and filled in the fill_record method - safe_call :audit, activity_class: @resource.class, payload: params, action: __method__ saved = save_record @resource.hydrate(record: @record, view: :new, user: _current_user) @@ -153,6 +158,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 @@ -161,6 +167,8 @@ def create end def edit + safe_call :audit, activity_class: @resource.class, payload: params, action: __method__, records: @record + set_actions set_component_for __method__ From 70cd62c696600cc62f1d1f941ecb8bfdededfd73 Mon Sep 17 00:00:00 2001 From: Paul Bob <69730720+Paul-Bob@users.noreply.github.com> Date: Tue, 14 May 2024 20:09:55 +0300 Subject: [PATCH 16/34] Update app/components/avo/sidebar_component.html.erb --- app/components/avo/sidebar_component.html.erb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/components/avo/sidebar_component.html.erb b/app/components/avo/sidebar_component.html.erb index dfebc816ce..c68b7f8809 100644 --- a/app/components/avo/sidebar_component.html.erb +++ b/app/components/avo/sidebar_component.html.erb @@ -54,7 +54,6 @@ <% end %> <% end %> - <%= render partial: "/avo/partials/sidebar_extra" %> From f0ab0a2c580a6b184467ce00be8d5304fe4ff71a Mon Sep 17 00:00:00 2001 From: Paul Bob <69730720+Paul-Bob@users.noreply.github.com> Date: Tue, 14 May 2024 20:10:35 +0300 Subject: [PATCH 17/34] Update lib/avo/configuration.rb --- lib/avo/configuration.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/avo/configuration.rb b/lib/avo/configuration.rb index 73abb852c4..40bdc2d4bd 100644 --- a/lib/avo/configuration.rb +++ b/lib/avo/configuration.rb @@ -232,8 +232,6 @@ def database_exists? else true end - - def audit? Avo.plugin_manager.installed?("avo-audits") && @audit && From f3c5e1cc91c9b65355e84c659760ab9da34b3d31 Mon Sep 17 00:00:00 2001 From: Paul Bob <69730720+Paul-Bob@users.noreply.github.com> Date: Tue, 14 May 2024 20:11:14 +0300 Subject: [PATCH 18/34] Update lib/avo/configuration.rb --- lib/avo/configuration.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/avo/configuration.rb b/lib/avo/configuration.rb index 40bdc2d4bd..a8ee11dfab 100644 --- a/lib/avo/configuration.rb +++ b/lib/avo/configuration.rb @@ -232,6 +232,7 @@ def database_exists? else true end + def audit? Avo.plugin_manager.installed?("avo-audits") && @audit && From bd07682f0fc4df299ec79478ee5b54d8c0386835 Mon Sep 17 00:00:00 2001 From: Paul Bob Date: Thu, 20 Jun 2024 14:25:54 +0300 Subject: [PATCH 19/34] rename to avo-audit_logging --- lib/avo/configuration.rb | 4 ++-- lib/tasks/avo_tasks.rake | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/avo/configuration.rb b/lib/avo/configuration.rb index aec477b85e..6c58b6f69e 100644 --- a/lib/avo/configuration.rb +++ b/lib/avo/configuration.rb @@ -166,7 +166,7 @@ def license=(value) def license gems = Gem::Specification.map {|gem| gem.name} - @license ||= if gems.include?("avo-audits") + @license ||= if gems.include?("avo-audit_logging") "enterprise" elsif gems.include?("avo-advanced") "advanced" @@ -236,7 +236,7 @@ def database_exists? end def audit? - Avo.plugin_manager.installed?("avo-audits") && + Avo.plugin_manager.installed?("avo-audit_logging") && @audit && database_exists? && ActiveRecord::Base.connection.table_exists?(:avo_activities) diff --git a/lib/tasks/avo_tasks.rake b/lib/tasks/avo_tasks.rake index c95ffa3902..ec265ee6f5 100644 --- a/lib/tasks/avo_tasks.rake +++ b/lib/tasks/avo_tasks.rake @@ -79,7 +79,7 @@ task "avo:sym_link" do `touch #{packages_path}/.keep` end - ["avo-advanced", "avo-pro", "avo-dynamic_filters", "avo-dashboards", "avo-menu", "avo-audits"].each do |gem| + ["avo-advanced", "avo-pro", "avo-dynamic_filters", "avo-dashboards", "avo-menu", "avo-audit_logging"].each do |gem| path = `bundle show #{gem} 2> /dev/null`.chomp # If path is emty we check if package is defined outside of root (on release process it is) From dc2f2887328ef1ca2017caab7c99af5a2217f83d Mon Sep 17 00:00:00 2001 From: Paul Bob Date: Fri, 21 Jun 2024 10:29:23 +0300 Subject: [PATCH 20/34] feature: log attach and detach --- app/controllers/avo/associations_controller.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/controllers/avo/associations_controller.rb b/app/controllers/avo/associations_controller.rb index 2ccea61e31..5b00d0e168 100644 --- a/app/controllers/avo/associations_controller.rb +++ b/app/controllers/avo/associations_controller.rb @@ -70,6 +70,8 @@ def create respond_to do |format| if @record.save + 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) } else format.html { render :new } @@ -86,6 +88,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 From 6fc5c464e603d93228ee4ef826b615d0b0639834 Mon Sep 17 00:00:00 2001 From: Paul Bob Date: Fri, 13 Sep 2024 12:11:02 +0300 Subject: [PATCH 21/34] unbundle audits from enterprise license --- lib/avo/configuration.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/avo/configuration.rb b/lib/avo/configuration.rb index cafa7218db..b96000d7f9 100644 --- a/lib/avo/configuration.rb +++ b/lib/avo/configuration.rb @@ -174,9 +174,7 @@ def license=(value) def license gems = Gem::Specification.map {|gem| gem.name} - @license ||= if gems.include?("avo-audit_logging") - "enterprise" - elsif gems.include?("avo-advanced") + @license ||= if gems.include?("avo-advanced") "advanced" elsif gems.include?("avo-pro") "pro" From 80b049a29d194ac88b3f7bd4ce1980cef2ec4602 Mon Sep 17 00:00:00 2001 From: Paul Bob Date: Fri, 13 Sep 2024 13:38:48 +0300 Subject: [PATCH 22/34] implement gem configuration --- lib/avo/configuration.rb | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/lib/avo/configuration.rb b/lib/avo/configuration.rb index b96000d7f9..33ca592339 100644 --- a/lib/avo/configuration.rb +++ b/lib/avo/configuration.rb @@ -233,21 +233,6 @@ def default_logger } end - def database_exists? - ActiveRecord::Base.connection - rescue ActiveRecord::NoDatabaseError - false - else - true - end - - def audit? - Avo.plugin_manager.installed?("avo-audit_logging") && - @audit && - database_exists? && - ActiveRecord::Base.connection.table_exists?(:avo_activities) - end - def turbo Avo::ExecutionContext.new(target: @turbo).handle end From 959504652991092f2b4f6b2ca91d5c461df33f1f Mon Sep 17 00:00:00 2001 From: Paul Bob Date: Fri, 13 Sep 2024 13:39:29 +0300 Subject: [PATCH 23/34] rm unused config attribute --- lib/avo/configuration.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/avo/configuration.rb b/lib/avo/configuration.rb index 33ca592339..c578c896c3 100644 --- a/lib/avo/configuration.rb +++ b/lib/avo/configuration.rb @@ -7,7 +7,6 @@ class Configuration attr_writer :root_path attr_writer :cache_store attr_writer :logger - attr_writer :audit attr_writer :turbo attr_writer :pagination attr_accessor :timezone @@ -108,7 +107,6 @@ def initialize @mount_avo_engines = true @cache_store = computed_cache_store @logger = default_logger - @audit = false @turbo = default_turbo @default_url_options = [] @pagination = {} From 02d35957e47b3ddb52bc59ec485faf10ded3090a Mon Sep 17 00:00:00 2001 From: Paul Bob Date: Fri, 13 Sep 2024 14:15:47 +0300 Subject: [PATCH 24/34] clear template --- lib/generators/avo/templates/initializer/avo.tt | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/generators/avo/templates/initializer/avo.tt b/lib/generators/avo/templates/initializer/avo.tt index 6a87c9c026..e399adc283 100644 --- a/lib/generators/avo/templates/initializer/avo.tt +++ b/lib/generators/avo/templates/initializer/avo.tt @@ -100,9 +100,6 @@ Avo.configure do |config| # file_logger # } - ## == Audit == - # config.audit = false - ## == Customization == # config.app_name = 'Avocadelicious' # config.timezone = 'UTC' From cefc4ddcf2bfa7af1fc397e29dc7e72904fb2083 Mon Sep 17 00:00:00 2001 From: Paul Bob Date: Mon, 23 Sep 2024 11:34:50 +0300 Subject: [PATCH 25/34] extract direct call --- app/controllers/avo/associations_controller.rb | 4 ++-- app/controllers/avo/base_controller.rb | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/controllers/avo/associations_controller.rb b/app/controllers/avo/associations_controller.rb index 536382be0a..0ec2d1a27c 100644 --- a/app/controllers/avo/associations_controller.rb +++ b/app/controllers/avo/associations_controller.rb @@ -63,7 +63,7 @@ def new def create respond_to do |format| if create_association - safe_call :audit, activity_class: @resource.class, payload: params, action: :attach, records: @record + instance_exec(:attach, &audit) format.html { redirect_back fallback_location: resource_view_response_path, @@ -104,7 +104,7 @@ def destroy @record.send(:"#{association_name}=", nil) end - safe_call :audit, activity_class: @resource.class, payload: params, action: :detach, records: @record + 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 diff --git a/app/controllers/avo/base_controller.rb b/app/controllers/avo/base_controller.rb index 4606006abf..f900709c64 100644 --- a/app/controllers/avo/base_controller.rb +++ b/app/controllers/avo/base_controller.rb @@ -17,7 +17,7 @@ class BaseController < ApplicationController before_action :set_pagy_locale, only: :index def index - safe_call :audit, activity_class: @resource.class, payload: params, action: __method__ + instance_exec(__method__, &audit) if @reflection.blank? @page_title = @resource.plural_name.humanize @@ -72,7 +72,7 @@ def index end def show - safe_call :audit, activity_class: @resource.class, payload: params, action: __method__, records: @record + instance_exec(__method__, &audit) @resource.hydrate( record: @record, @@ -135,7 +135,7 @@ def new add_breadcrumb t("avo.new").humanize - safe_call :audit, activity_class: @resource.class, payload: params, action: __method__ + instance_exec(__method__, &audit) set_component_for __method__, fallback_view: :edit end @@ -181,7 +181,7 @@ def create set_component_for :edit - safe_call :audit, activity_class: @resource.class, payload: params, action: __method__, records: @record + instance_exec(__method__, &audit) if saved create_success_action else @@ -190,7 +190,7 @@ def create end def edit - safe_call :audit, activity_class: @resource.class, payload: params, action: __method__, records: @record + instance_exec(__method__, &audit) set_actions @@ -198,7 +198,7 @@ def edit end def update - safe_call :audit, activity_class: @resource.class, payload: params, action: __method__, records: @record + instance_exec(__method__, &audit) # record gets instantiated and filled in the fill_record method saved = save_record @@ -215,7 +215,7 @@ def update end def destroy - safe_call :audit, activity_class: @resource.class, payload: params, action: __method__, records: @record + instance_exec(__method__, &audit) if destroy_model destroy_success_action else From 4dca5857f247d39d15cb1bd64d76013b5028930c Mon Sep 17 00:00:00 2001 From: Paul Bob Date: Mon, 23 Sep 2024 11:51:28 +0300 Subject: [PATCH 26/34] remove direct audit call --- app/controllers/avo/actions_controller.rb | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/app/controllers/avo/actions_controller.rb b/app/controllers/avo/actions_controller.rb index 0526ce8108..76dd099015 100644 --- a/app/controllers/avo/actions_controller.rb +++ b/app/controllers/avo/actions_controller.rb @@ -49,23 +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) - - safe_call :audit, - activity_class: @action.class, - payload: { - fields: fields, - resource: resource, - }, - action: __method__, - records: query + @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: fields, + fields: @fields, current_user: _current_user, resource: @resource, - query: query + query: @query ) @response = performed_action.response From f03c4ccb6422a240fbe9645cabf644635042e30b Mon Sep 17 00:00:00 2001 From: Paul Bob Date: Mon, 23 Sep 2024 11:56:45 +0300 Subject: [PATCH 27/34] rm set_paper_trail_whodunnit --- app/controllers/avo/application_controller.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/controllers/avo/application_controller.rb b/app/controllers/avo/application_controller.rb index fe3ad3f08f..76f8e1f3f5 100644 --- a/app/controllers/avo/application_controller.rb +++ b/app/controllers/avo/application_controller.rb @@ -26,7 +26,6 @@ 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 From 0d28364fbfb294a90157cdf3187eba12641070c2 Mon Sep 17 00:00:00 2001 From: Paul Bob Date: Mon, 23 Sep 2024 11:58:51 +0300 Subject: [PATCH 28/34] revert safe_call enhancement --- app/controllers/avo/base_controller.rb | 4 ++++ app/helpers/avo/application_helper.rb | 4 ---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/avo/base_controller.rb b/app/controllers/avo/base_controller.rb index f900709c64..8e02796c0e 100644 --- a/app/controllers/avo/base_controller.rb +++ b/app/controllers/avo/base_controller.rb @@ -589,6 +589,10 @@ 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 9ac02cf515..c9babc1418 100644 --- a/app/helpers/avo/application_helper.rb +++ b/app/helpers/avo/application_helper.rb @@ -137,10 +137,6 @@ 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 From d582db0a08e5136b42fc5db6a63e13ecf73b9207 Mon Sep 17 00:00:00 2001 From: Paul Bob Date: Mon, 23 Sep 2024 12:09:31 +0300 Subject: [PATCH 29/34] temporary solution for not defined audit --- app/helpers/avo/application_helper.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/helpers/avo/application_helper.rb b/app/helpers/avo/application_helper.rb index c9babc1418..085b910add 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 audit + Proc.new + end + def chart_color(index) Avo.configuration.branding.chart_colors[index % Avo.configuration.branding.chart_colors.length] end From 4d8728f6be33aeeeef90c203506d1bfc75d90190 Mon Sep 17 00:00:00 2001 From: Paul Bob Date: Mon, 23 Sep 2024 12:13:25 +0300 Subject: [PATCH 30/34] wip --- app/helpers/avo/application_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/avo/application_helper.rb b/app/helpers/avo/application_helper.rb index 085b910add..804a346a68 100644 --- a/app/helpers/avo/application_helper.rb +++ b/app/helpers/avo/application_helper.rb @@ -138,7 +138,7 @@ def frame_id(resource) end def audit - Proc.new + -> {} end def chart_color(index) From bc71d7aae3bc41d2bfa36e10e4786de15efe29b0 Mon Sep 17 00:00:00 2001 From: Paul Bob Date: Mon, 23 Sep 2024 12:18:19 +0300 Subject: [PATCH 31/34] . --- app/helpers/avo/application_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/avo/application_helper.rb b/app/helpers/avo/application_helper.rb index 804a346a68..25708c5ef3 100644 --- a/app/helpers/avo/application_helper.rb +++ b/app/helpers/avo/application_helper.rb @@ -138,7 +138,7 @@ def frame_id(resource) end def audit - -> {} + -> (_) {} end def chart_color(index) From 9db0654a3cef55361b695c223b91ef9af792f385 Mon Sep 17 00:00:00 2001 From: Paul Bob Date: Mon, 23 Sep 2024 13:55:56 +0300 Subject: [PATCH 32/34] lint --- app/helpers/avo/application_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/avo/application_helper.rb b/app/helpers/avo/application_helper.rb index 25708c5ef3..38a4e02f92 100644 --- a/app/helpers/avo/application_helper.rb +++ b/app/helpers/avo/application_helper.rb @@ -138,7 +138,7 @@ def frame_id(resource) end def audit - -> (_) {} + ->(_) {} end def chart_color(index) From e7f14ae457a4fc1dd32fb5bbc74711e00c8bf547 Mon Sep 17 00:00:00 2001 From: Paul Bob Date: Tue, 24 Sep 2024 15:12:28 +0300 Subject: [PATCH 33/34] extract audit call --- app/controllers/avo/actions_controller.rb | 18 +++++++++++------- app/controllers/avo/associations_controller.rb | 3 --- app/controllers/avo/base_controller.rb | 12 ------------ app/helpers/avo/application_helper.rb | 4 ---- 4 files changed, 11 insertions(+), 26 deletions(-) diff --git a/app/controllers/avo/actions_controller.rb b/app/controllers/avo/actions_controller.rb index 76dd099015..63c30b645b 100644 --- a/app/controllers/avo/actions_controller.rb +++ b/app/controllers/avo/actions_controller.rb @@ -11,6 +11,7 @@ class ActionsController < ApplicationController end before_action :set_action, only: [:show, :handle] before_action :verify_authorization, only: [:show, :handle] + before_action :set_query, :set_fields, only: :handle layout :choose_layout @@ -47,13 +48,6 @@ def build_background_url end 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: @fields, current_user: _current_user, @@ -67,6 +61,16 @@ def handle private + def set_query + resource_ids = action_params[:fields][:avo_resource_ids].split(",") + + @query = decrypted_query || (resource_ids.any? ? @resource.find_record(resource_ids, params: params) : []) + end + + def set_fields + @fields = action_params[:fields].except(:avo_resource_ids, :avo_selected_query) + end + def action_params @action_params ||= params.permit(:id, :authenticity_token, :resource_name, :action_id, :button, fields: {}) end diff --git a/app/controllers/avo/associations_controller.rb b/app/controllers/avo/associations_controller.rb index 0ec2d1a27c..d16c9d0cb7 100644 --- a/app/controllers/avo/associations_controller.rb +++ b/app/controllers/avo/associations_controller.rb @@ -63,8 +63,6 @@ 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) @@ -104,7 +102,6 @@ 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 diff --git a/app/controllers/avo/base_controller.rb b/app/controllers/avo/base_controller.rb index 8e02796c0e..7c44587ab3 100644 --- a/app/controllers/avo/base_controller.rb +++ b/app/controllers/avo/base_controller.rb @@ -17,8 +17,6 @@ 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? @@ -72,8 +70,6 @@ def index end def show - instance_exec(__method__, &audit) - @resource.hydrate( record: @record, view: Avo::ViewInquirer.new(:show), @@ -135,8 +131,6 @@ def new add_breadcrumb t("avo.new").humanize - instance_exec(__method__, &audit) - set_component_for __method__, fallback_view: :edit end @@ -181,7 +175,6 @@ def create set_component_for :edit - instance_exec(__method__, &audit) if saved create_success_action else @@ -190,16 +183,12 @@ 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) @@ -215,7 +204,6 @@ def update end def destroy - instance_exec(__method__, &audit) if destroy_model destroy_success_action else diff --git a/app/helpers/avo/application_helper.rb b/app/helpers/avo/application_helper.rb index 38a4e02f92..c9babc1418 100644 --- a/app/helpers/avo/application_helper.rb +++ b/app/helpers/avo/application_helper.rb @@ -137,10 +137,6 @@ def frame_id(resource) ["frame", resource.model_name.singular, resource.record_param].compact.join("-") end - def audit - ->(_) {} - end - def chart_color(index) Avo.configuration.branding.chart_colors[index % Avo.configuration.branding.chart_colors.length] end From 6ecaf15a38181487317a4649150ec4823c84f792 Mon Sep 17 00:00:00 2001 From: Paul Bob Date: Tue, 24 Sep 2024 15:21:35 +0300 Subject: [PATCH 34/34] rm activity --- lib/avo/current.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/avo/current.rb b/lib/avo/current.rb index 55439405ef..9baf2da9ac 100644 --- a/lib/avo/current.rb +++ b/lib/avo/current.rb @@ -9,7 +9,6 @@ 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