From 77d5041e3c64cc8adc86bba18c1e9feb0ce1fed9 Mon Sep 17 00:00:00 2001 From: Jailson Pinheiro Lima Date: Wed, 11 Feb 2026 10:20:20 -0300 Subject: [PATCH 01/15] refactor: request failed code --- app/models/concerns/sys_log.rb | 37 +++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/app/models/concerns/sys_log.rb b/app/models/concerns/sys_log.rb index eabfdcf6c..de6bb0eed 100644 --- a/app/models/concerns/sys_log.rb +++ b/app/models/concerns/sys_log.rb @@ -22,15 +22,13 @@ def log_create objs = [eval("@#{sobj}")].compact unless obj.nil? # only if obj doesn't exist, use objs list ignored_attrs = %w[id created_at updated_at attachment_updated_at] - # if some error happened, don't save log - - response_status = JSON.parse(response.body) rescue nil - - Rails.logger.info("\n\n\n #{model} \n #{sobj} \n #{objs} \n #{obj}") + Rails.logger.info("\n\n #{model} \n #{sobj} \n #{objs} \n #{obj} \n\n") - return if ((!(response_status.nil?) && response_status.has_key?("success") && response_status["success"] == false) || (params.include?(:success) && params[:success] == false)) + # if some error happened, don't save log + return if request_failed? if !(objs.nil?) && !(objs.empty?) + Rails.logger.info("\n\n Entrou na regra geral de criação de logs \n\n") objs.each do |obj| # general rule for creating a log description @@ -52,19 +50,23 @@ def log_create description = "#{sobj.singularize}: #{obj.id}#{changed_attributes(obj, ignored_attrs)}, #{log_payload.to_json}" - if ((obj.respond_to?(:academic_allocations) && !obj.try(:academic_allocations).empty?) || obj.respond_to?(:academic_allocation)) + if ((obj.respond_to?(:academic_allocations) && !obj.try(:academic_allocations).empty?) || obj.respond_to?(:academic_allocation)) # if there is academic_allocations allocation_tag_id = params[:allocation_tag_id] || active_tab[:url][:allocation_tag_id] || obj.allocation_tag.id rescue nil [(obj.respond_to?(:academic_allocations) ? obj.academic_allocations : obj.academic_allocation)].flatten.each do |al| LogAction.create(log_type: LogAction::TYPE[request_method(request.request_method)], user_id: current_user.id, academic_allocation_id: al.id, allocation_tag_id: (allocation_tag_id || al.allocation_tag_id), ip: get_remote_ip, description: description) end - elsif (obj.respond_to?(:allocation_tag) && !(obj.allocation_tag.nil?)) + + elsif (obj.respond_to?(:allocation_tag) && !(obj.allocation_tag.nil?)) # if there is allocation_tag LogAction.create(log_type: LogAction::TYPE[request_method(request.request_method)], user_id: current_user.id, allocation_tag_id: obj.allocation_tag.id, ip: get_remote_ip, description: description) - else # generic log + + else # generic log (if academic_allocations and allocation_tag do not exists) + Rails.logger.info("\n\n Caiu no log genérico com sobj e obj \n\n") generic_log(sobj, obj) end end else + Rails.logger.info("\n\n Caiu no log genérico com somente sobj \n\n") generic_log(sobj) end @@ -81,6 +83,14 @@ def self.log_info(msg = nil, &block) private + def request_failed? + response_status = JSON.parse(response.body) rescue nil + + return true if response_status&.key?("success") && response_status["success"] == false + return true if (params.include?(:success) && params[:success] == false) + false + end + def changed_attributes(obj, ignored) return '' unless obj.saved_changes? @@ -103,6 +113,8 @@ def request_method(rm) end def generic_log(sobj, obj = nil) + binding.pry + return if params.include?(:digital_classes) return if !obj.nil? && obj.new_record?# && !params.include?(:digital_classes) # not saved @@ -110,6 +122,8 @@ def generic_log(sobj, obj = nil) academic_allocation_id = nil tbname = obj.try(:class).try(:table_name).to_s.singularize.to_sym if obj.try(:class).respond_to?(:table_name) description = if !tbname.nil? && (params.has_key?(tbname) || params.size <= 3) && !obj.nil? + Rails.logger.info("\n\n Entrou no if \n\n") + binding.pry obj_attrs = (obj.respond_to?(:log_description) ? obj.log_description : obj.attributes.except('attachment_updated_at', 'created_at', 'updated_at')) obj_attrs.merge!({'files' => obj.files.map {|f| f.attributes.except('attachment_updated_at') } }) if obj.respond_to?(:files) && obj.files.any? @@ -117,10 +131,15 @@ def generic_log(sobj, obj = nil) "#{sobj}: #{obj.id}, changed: #{obj.changed}, #{obj_attrs}" elsif params[:id].present? + Rails.logger.info("\n\n Entrou no elsif \n\n") + binding.pry + # gets any extra information if exists info = ActiveSupport::JSON.encode(params.except(:controller, :action, :id)) "#{sobj}: #{[params[:id], info].compact.join(", ")}" else # controllers saving other objects. ex: assingments -> student files + Rails.logger.info("\n\n Entrou no else \n\n") + d = [] variables = self.instance_variable_names.to_ary.delete_if { |v| v.to_s.start_with?("@_") || ["@current_user", "@current_ability"].include?(v) } variables.each do |v| From 4f1663cbae136f7aaf5f0012352f93e9f4453847 Mon Sep 17 00:00:00 2001 From: Jailson Pinheiro Lima Date: Wed, 11 Feb 2026 14:57:43 -0300 Subject: [PATCH 02/15] refactor: general rule for a log description --- app/models/concerns/sys_log.rb | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/app/models/concerns/sys_log.rb b/app/models/concerns/sys_log.rb index de6bb0eed..ad4fb95c6 100644 --- a/app/models/concerns/sys_log.rb +++ b/app/models/concerns/sys_log.rb @@ -20,7 +20,6 @@ def log_create sobj = sobj.singularize obj = eval("@#{sobj}") objs = [eval("@#{sobj}")].compact unless obj.nil? # only if obj doesn't exist, use objs list - ignored_attrs = %w[id created_at updated_at attachment_updated_at] Rails.logger.info("\n\n #{model} \n #{sobj} \n #{objs} \n #{obj} \n\n") @@ -91,6 +90,27 @@ def request_failed? false end + def general_log_description(obj, sobj) + ignored_attrs = %w[id created_at updated_at attachment_updated_at] + + log_payload = obj.respond_to?(:log_description) ? obj.log_description : obj.attributes.except(*ignored_attrs) + + log_payload = log_payload.as_json unless log_payload.is_a?(Hash) + + all_associations = obj.class.reflect_on_all_associations(:has_many).map(&:name) + + all_associations.each do |association| + if(obj.respond_to?(association) && obj.send(association).any?) + association_data = obj.send(association).map {|a| a.attributes.except("attachment_updated_at") } + + # log_payload = log_payload.merge("#{association.to_s}" => association_data) if log_payload.is_a?(Hash) + log_payload[association.to_s] = association_data + end + end + + "#{sobj.singularize}: #{obj.id}#{changed_attributes(obj, ignored_attrs)}, #{log_payload.to_json}" + end + def changed_attributes(obj, ignored) return '' unless obj.saved_changes? From 4521bf1a04621240a6f2a91cc4cf9e8c2c2a49bc Mon Sep 17 00:00:00 2001 From: Jailson Pinheiro Lima Date: Wed, 11 Feb 2026 15:24:24 -0300 Subject: [PATCH 03/15] refactor: log targets with allocation_tag_id --- app/models/concerns/sys_log.rb | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/app/models/concerns/sys_log.rb b/app/models/concerns/sys_log.rb index ad4fb95c6..873267c79 100644 --- a/app/models/concerns/sys_log.rb +++ b/app/models/concerns/sys_log.rb @@ -111,6 +111,33 @@ def general_log_description(obj, sobj) "#{sobj.singularize}: #{obj.id}#{changed_attributes(obj, ignored_attrs)}, #{log_payload.to_json}" end + def log_targets(obj) # academic_allocations and allocation_tag to get allocation_tag_id + targets = [] + allocation_tag_id = params[:allocation_tag_id] || active_tab[url][:allocation_tag_id] || (obj.allocation_tag.id rescue nil) + + if obj.respond_to?(:academic_allocations) && obj.academic_allocations.present? + obj.academic_allocations.each do |al| + targets << { + allocation_id: al.id, + tag_id: (allocation_tag_id || al.try(:allocation_tag_id)) + } + end + elsif obj.respond_to?(:academic_allocation) && obj.academic_allocation.present? + al = obj.academic_allocation + targets << { + allocation_id: al.id, + tag_id: (allocation_tag_id || al.try(:allocation_tag_id)) + } + elsif obj.respond_to?(:allocation_tag) && obj.allocation_tag.present? + targets << { allocation_id: nil, tag_id: obj.allocation_tag.id } + else + targets << { allocation_id: nil, tag_id: allocation_tag_id } + end + + targets + end + + def changed_attributes(obj, ignored) return '' unless obj.saved_changes? From 64c26a822a0d371f9a5e5f43050939cd18d7cfc1 Mon Sep 17 00:00:00 2001 From: Jailson Pinheiro Lima Date: Thu, 12 Feb 2026 12:36:31 -0300 Subject: [PATCH 04/15] refactor: create log with LogAction --- app/models/concerns/sys_log.rb | 144 ++++++++++++++++++++++----------- 1 file changed, 99 insertions(+), 45 deletions(-) diff --git a/app/models/concerns/sys_log.rb b/app/models/concerns/sys_log.rb index 873267c79..99c292ab6 100644 --- a/app/models/concerns/sys_log.rb +++ b/app/models/concerns/sys_log.rb @@ -14,59 +14,99 @@ module Actions end def log_create - model = self.class.to_s.sub("Controller", "") - sobj = model.tableize - objs = eval("@#{sobj}") # created/updated/destroyied objects could be a list - sobj = sobj.singularize - obj = eval("@#{sobj}") - objs = [eval("@#{sobj}")].compact unless obj.nil? # only if obj doesn't exist, use objs list + # model = self.class.to_s.sub("Controller", "") + # sobj = model.tableize + # objs = eval("@#{sobj}") # created/updated/destroyied objects could be a list + # sobj = sobj.singularize + # obj = eval("@#{sobj}") + # objs = [eval("@#{sobj}")].compact unless obj.nil? # only if obj doesn't exist, use objs list - Rails.logger.info("\n\n #{model} \n #{sobj} \n #{objs} \n #{obj} \n\n") + # Rails.logger.info("\n\n #{model} \n #{sobj} \n #{objs} \n #{obj} \n\n") - # if some error happened, don't save log - return if request_failed? + # # if some error happened, don't save log + # return if request_failed? - if !(objs.nil?) && !(objs.empty?) - Rails.logger.info("\n\n Entrou na regra geral de criação de logs \n\n") - objs.each do |obj| + # if !(objs.nil?) && !(objs.empty?) + # Rails.logger.info("\n\n Entrou na regra geral de criação de logs \n\n") + # objs.each do |obj| - # general rule for creating a log description - all_associations = eval("#{model.singularize}").reflect_on_all_associations(:has_many).map(&:name) - - log_payload = if obj.respond_to?(:log_description) - obj.log_description + # # general rule for creating a log description + # all_associations = eval("#{model.singularize}").reflect_on_all_associations(:has_many).map(&:name) + + # log_payload = if obj.respond_to?(:log_description) + # obj.log_description + # else + # obj.attributes.except(*ignored_attrs) + # end + + # all_associations.each do |association| + # if(obj.respond_to?(association) && obj.send(association).any?) + # association_data = obj.send(association).map {|a| a.attributes.except("attachment_updated_at") } + + # log_payload = log_payload.merge("#{association.to_s}" => association_data) if log_payload.is_a?(Hash) + # end + # end + + # description = "#{sobj.singularize}: #{obj.id}#{changed_attributes(obj, ignored_attrs)}, #{log_payload.to_json}" + + # if ((obj.respond_to?(:academic_allocations) && !obj.try(:academic_allocations).empty?) || obj.respond_to?(:academic_allocation)) # if there is academic_allocations + # allocation_tag_id = params[:allocation_tag_id] || active_tab[:url][:allocation_tag_id] || obj.allocation_tag.id rescue nil + + # [(obj.respond_to?(:academic_allocations) ? obj.academic_allocations : obj.academic_allocation)].flatten.each do |al| + # LogAction.create(log_type: LogAction::TYPE[request_method(request.request_method)], user_id: current_user.id, academic_allocation_id: al.id, allocation_tag_id: (allocation_tag_id || al.allocation_tag_id), ip: get_remote_ip, description: description) + # end + + # elsif (obj.respond_to?(:allocation_tag) && !(obj.allocation_tag.nil?)) # if there is allocation_tag + # LogAction.create(log_type: LogAction::TYPE[request_method(request.request_method)], user_id: current_user.id, allocation_tag_id: obj.allocation_tag.id, ip: get_remote_ip, description: description) + + # else # generic log (if academic_allocations and allocation_tag do not exists) + # Rails.logger.info("\n\n Caiu no log genérico com sobj e obj \n\n") + # generic_log(sobj, obj) + # end + # end + # else + # Rails.logger.info("\n\n Caiu no log genérico com somente sobj \n\n") + # generic_log(sobj) + # end + + model_name = self.class.to_s.sub("Controller", "") + sobj = model_name.tableize.singularize + + obj = instance_variable_get("@#{sobj}") + objs = instance_variable_get("@#{model_name.tableize}") + + target_objects = if obj.present? + [obj] + elsif objs.present? && objs.is_a?(Enumerable) + objs else - obj.attributes.except(*ignored_attrs) + [] end + + return if request_failed? - all_associations.each do |association| - if(obj.respond_to?(association) && obj.send(association).any?) - association_data = obj.send(association).map {|a| a.attributes.except("attachment_updated_at") } - - log_payload = log_payload.merge("#{association.to_s}" => association_data) if log_payload.is_a?(Hash) - end - end - - description = "#{sobj.singularize}: #{obj.id}#{changed_attributes(obj, ignored_attrs)}, #{log_payload.to_json}" - - if ((obj.respond_to?(:academic_allocations) && !obj.try(:academic_allocations).empty?) || obj.respond_to?(:academic_allocation)) # if there is academic_allocations - allocation_tag_id = params[:allocation_tag_id] || active_tab[:url][:allocation_tag_id] || obj.allocation_tag.id rescue nil - - [(obj.respond_to?(:academic_allocations) ? obj.academic_allocations : obj.academic_allocation)].flatten.each do |al| - LogAction.create(log_type: LogAction::TYPE[request_method(request.request_method)], user_id: current_user.id, academic_allocation_id: al.id, allocation_tag_id: (allocation_tag_id || al.allocation_tag_id), ip: get_remote_ip, description: description) - end - - elsif (obj.respond_to?(:allocation_tag) && !(obj.allocation_tag.nil?)) # if there is allocation_tag - LogAction.create(log_type: LogAction::TYPE[request_method(request.request_method)], user_id: current_user.id, allocation_tag_id: obj.allocation_tag.id, ip: get_remote_ip, description: description) - - else # generic log (if academic_allocations and allocation_tag do not exists) - Rails.logger.info("\n\n Caiu no log genérico com sobj e obj \n\n") - generic_log(sobj, obj) + if target_objects.any? + target_objects.each do |obj| + next if obj.new_record? && params.include?(:digital_classes) + + description = general_log_description(obj, sobj) + + resolved_log_targets = log_targets(obj) + + resolved_log_targets.each do |target| + LogAction.create( + log_type: LogAction::TYPE[request_method(request.request_method)], + user_id: current_user.id, + ip: get_remote_ip, + description: description, + academic_allocation_id: target[:allocation_id], + allocation_tag_id: target[:tag_id], + ) end end else - Rails.logger.info("\n\n Caiu no log genérico com somente sobj \n\n") - generic_log(sobj) + # generic log(fallback) + Rails.logger.info("\n\n Log genérico \n\n") end rescue => error @@ -93,6 +133,9 @@ def request_failed? def general_log_description(obj, sobj) ignored_attrs = %w[id created_at updated_at attachment_updated_at] + Rails.logger.info("\n\n Entrou na regra geral de descrição \n\n") + binding.pry + log_payload = obj.respond_to?(:log_description) ? obj.log_description : obj.attributes.except(*ignored_attrs) log_payload = log_payload.as_json unless log_payload.is_a?(Hash) @@ -100,7 +143,7 @@ def general_log_description(obj, sobj) all_associations = obj.class.reflect_on_all_associations(:has_many).map(&:name) all_associations.each do |association| - if(obj.respond_to?(association) && obj.send(association).any?) + if((obj.respond_to?(association) && obj.send(association).any?) && !(obj.respond_to?(:log_description))) association_data = obj.send(association).map {|a| a.attributes.except("attachment_updated_at") } # log_payload = log_payload.merge("#{association.to_s}" => association_data) if log_payload.is_a?(Hash) @@ -113,7 +156,10 @@ def general_log_description(obj, sobj) def log_targets(obj) # academic_allocations and allocation_tag to get allocation_tag_id targets = [] - allocation_tag_id = params[:allocation_tag_id] || active_tab[url][:allocation_tag_id] || (obj.allocation_tag.id rescue nil) + allocation_tag_id = params[:allocation_tag_id] || active_tab[:url][:allocation_tag_id] || (obj.allocation_tag.id rescue nil) + + Rails.logger.info("\n\n Entrou no método que captura os alvos \n\n") + binding.pry if obj.respond_to?(:academic_allocations) && obj.academic_allocations.present? obj.academic_allocations.each do |al| @@ -122,16 +168,24 @@ def log_targets(obj) # academic_allocations and allocation_tag to get allocation tag_id: (allocation_tag_id || al.try(:allocation_tag_id)) } end + Rails.logger.info("\n\n Entrou no if \n\n") + binding.pry elsif obj.respond_to?(:academic_allocation) && obj.academic_allocation.present? al = obj.academic_allocation targets << { allocation_id: al.id, tag_id: (allocation_tag_id || al.try(:allocation_tag_id)) } + Rails.logger.info("\n\n Entrou no primeiro elsif \n\n") + binding.pry elsif obj.respond_to?(:allocation_tag) && obj.allocation_tag.present? targets << { allocation_id: nil, tag_id: obj.allocation_tag.id } + Rails.logger.info("\n\n Entrou no segundo elsif \n\n") + binding.pry else targets << { allocation_id: nil, tag_id: allocation_tag_id } + Rails.logger.info("\n\n Entrou no else \n\n") + binding.pry end targets From f3cf9918e8319a5178ec3f8dbc8303175a88496f Mon Sep 17 00:00:00 2001 From: Jailson Pinheiro Lima Date: Thu, 12 Feb 2026 13:11:52 -0300 Subject: [PATCH 05/15] feat: add fallback method in refactor --- app/models/concerns/sys_log.rb | 45 +++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/app/models/concerns/sys_log.rb b/app/models/concerns/sys_log.rb index 99c292ab6..d3aa523fe 100644 --- a/app/models/concerns/sys_log.rb +++ b/app/models/concerns/sys_log.rb @@ -106,7 +106,7 @@ def log_create end else # generic log(fallback) - Rails.logger.info("\n\n Log genérico \n\n") + fallback_log end rescue => error @@ -191,6 +191,49 @@ def log_targets(obj) # academic_allocations and allocation_tag to get allocation targets end + def fallback_log + return if params.include?(:digital_classes) + + Rails.logger.info("\n\n Entrou no Fallback do Log \n\n") + + description = nil + + if params[:id].present? && params.except(:controller, :action, :id).empty? + description = "#{params[:controller].singularize}: #{params[:id]}" + elsif params[:id].present? + info = params.except(:controller, :action, :id).to_json + description = "#{params[:controller].singularize}: #{params[:id]}, #{info}" + else + d = [] + variables = self.instance_variable_names.map(&:to_s).reject do |v| + v.start_with?("@_") || ["@current_user", "@current_ability"].include?(v) + end + + academic_allocation_id = nil + + variables.each do |v| + o = instance_variable_get(v) + next if ["Array", "String", "NilClass"].include?(o.class.to_s) + + if o.respond_to?(:academic_allocation) && o.academic_allocation.respond_to?(:id) + academic_allocation_id = o.academic_allocation.id + end + + d << %{#{v.sub("@", "")}: #{o.as_json}} + end + + description = d.any? ? d.join(', ') : "#{params[:controller]}: #{params.except('controller').to_json}" + end + + LogAction.create( + log_type: LogAction::TYPE[request_method(request.request_method)], + user_id: current_user.id, + ip: get_remote_ip, + description: description, + academic_allocation_id: academic_allocation_id, + allocation_tag_id: (active_tab[:url][:allocation_tag_id] rescue nil), + ) + end def changed_attributes(obj, ignored) return '' unless obj.saved_changes? From 765bc7f42430a30d74957a78c89699fabe660d5f Mon Sep 17 00:00:00 2001 From: Jailson Pinheiro Lima Date: Thu, 12 Feb 2026 14:06:31 -0300 Subject: [PATCH 06/15] refactor: updates associations that are listed --- app/models/concerns/sys_log.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/models/concerns/sys_log.rb b/app/models/concerns/sys_log.rb index d3aa523fe..f3d7a3fcf 100644 --- a/app/models/concerns/sys_log.rb +++ b/app/models/concerns/sys_log.rb @@ -106,6 +106,7 @@ def log_create end else # generic log(fallback) + Rails.logger.info("\n\n Entrou no fallback \n\n") fallback_log end @@ -140,7 +141,7 @@ def general_log_description(obj, sobj) log_payload = log_payload.as_json unless log_payload.is_a?(Hash) - all_associations = obj.class.reflect_on_all_associations(:has_many).map(&:name) + all_associations = obj.class.reflect_on_all_associations.select { |assoc| [:has_many, :belongs_to].include?(assoc.macro) }.map(&:name) all_associations.each do |association| if((obj.respond_to?(association) && obj.send(association).any?) && !(obj.respond_to?(:log_description))) From 3b14ab710acb733cf5f3a9a4e7d202b899c4f254 Mon Sep 17 00:00:00 2001 From: Jailson Pinheiro Lima Date: Thu, 12 Feb 2026 14:19:44 -0300 Subject: [PATCH 07/15] fix: update presence verification --- app/models/concerns/sys_log.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/concerns/sys_log.rb b/app/models/concerns/sys_log.rb index f3d7a3fcf..d48959d77 100644 --- a/app/models/concerns/sys_log.rb +++ b/app/models/concerns/sys_log.rb @@ -144,7 +144,7 @@ def general_log_description(obj, sobj) all_associations = obj.class.reflect_on_all_associations.select { |assoc| [:has_many, :belongs_to].include?(assoc.macro) }.map(&:name) all_associations.each do |association| - if((obj.respond_to?(association) && obj.send(association).any?) && !(obj.respond_to?(:log_description))) + if((obj.respond_to?(association) && obj.send(association).present?) && !(obj.respond_to?(:log_description))) association_data = obj.send(association).map {|a| a.attributes.except("attachment_updated_at") } # log_payload = log_payload.merge("#{association.to_s}" => association_data) if log_payload.is_a?(Hash) From eb8d4776c6f9ea2604868cb974bd2ddd548fbc16 Mon Sep 17 00:00:00 2001 From: Jailson Pinheiro Lima Date: Thu, 19 Feb 2026 09:38:33 -0300 Subject: [PATCH 08/15] fix: update all_associations iteration --- app/models/concerns/sys_log.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/models/concerns/sys_log.rb b/app/models/concerns/sys_log.rb index d48959d77..27c5ff317 100644 --- a/app/models/concerns/sys_log.rb +++ b/app/models/concerns/sys_log.rb @@ -145,9 +145,10 @@ def general_log_description(obj, sobj) all_associations.each do |association| if((obj.respond_to?(association) && obj.send(association).present?) && !(obj.respond_to?(:log_description))) - association_data = obj.send(association).map {|a| a.attributes.except("attachment_updated_at") } + associated_objects = [obj.send(association)].flatten + + association_data = associated_objects.map {|a| a.attributes.except("attachment_updated_at") } - # log_payload = log_payload.merge("#{association.to_s}" => association_data) if log_payload.is_a?(Hash) log_payload[association.to_s] = association_data end end From 21c0d61ea8ecd31fbba42ad8bde5c0ffd8d21610 Mon Sep 17 00:00:00 2001 From: Jailson Pinheiro Lima Date: Mon, 23 Feb 2026 10:44:47 -0300 Subject: [PATCH 09/15] fix: remove :belongs_to from associations list --- app/models/concerns/sys_log.rb | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/app/models/concerns/sys_log.rb b/app/models/concerns/sys_log.rb index 27c5ff317..c29520ec5 100644 --- a/app/models/concerns/sys_log.rb +++ b/app/models/concerns/sys_log.rb @@ -10,7 +10,7 @@ module Actions extend ActiveSupport::Concern included do - after_action :log_create, unless: Proc.new {|c| request.get? }, except: [:change_participant, :import, :export, :annul, :remove_record] + after_action :log_create, unless: Proc.new {|c| request.get? }, except: [:change_participant, :import, :export, :annul, :publish, :remove_record] end def log_create @@ -141,13 +141,14 @@ def general_log_description(obj, sobj) log_payload = log_payload.as_json unless log_payload.is_a?(Hash) - all_associations = obj.class.reflect_on_all_associations.select { |assoc| [:has_many, :belongs_to].include?(assoc.macro) }.map(&:name) + # all_associations = obj.class.reflect_on_all_associations.select { |assoc| [:has_many, :belongs_to].include?(assoc.macro) }.map(&:name) + all_associations = obj.class.reflect_on_all_associations(:has_many).map(&:name) all_associations.each do |association| - if((obj.respond_to?(association) && obj.send(association).present?) && !(obj.respond_to?(:log_description))) - associated_objects = [obj.send(association)].flatten + if((obj.respond_to?(association) && obj.send(association).any?) && !(obj.respond_to?(:log_description))) + # associated_objects = [obj.send(association)].flatten - association_data = associated_objects.map {|a| a.attributes.except("attachment_updated_at") } + association_data = obj.send(association).map {|a| a.attributes.except("attachment_updated_at") } log_payload[association.to_s] = association_data end @@ -161,7 +162,7 @@ def log_targets(obj) # academic_allocations and allocation_tag to get allocation allocation_tag_id = params[:allocation_tag_id] || active_tab[:url][:allocation_tag_id] || (obj.allocation_tag.id rescue nil) Rails.logger.info("\n\n Entrou no método que captura os alvos \n\n") - binding.pry + # binding.pry if obj.respond_to?(:academic_allocations) && obj.academic_allocations.present? obj.academic_allocations.each do |al| @@ -171,7 +172,7 @@ def log_targets(obj) # academic_allocations and allocation_tag to get allocation } end Rails.logger.info("\n\n Entrou no if \n\n") - binding.pry + # binding.pry elsif obj.respond_to?(:academic_allocation) && obj.academic_allocation.present? al = obj.academic_allocation targets << { @@ -179,15 +180,15 @@ def log_targets(obj) # academic_allocations and allocation_tag to get allocation tag_id: (allocation_tag_id || al.try(:allocation_tag_id)) } Rails.logger.info("\n\n Entrou no primeiro elsif \n\n") - binding.pry + # binding.pry elsif obj.respond_to?(:allocation_tag) && obj.allocation_tag.present? targets << { allocation_id: nil, tag_id: obj.allocation_tag.id } Rails.logger.info("\n\n Entrou no segundo elsif \n\n") - binding.pry + # binding.pry else targets << { allocation_id: nil, tag_id: allocation_tag_id } Rails.logger.info("\n\n Entrou no else \n\n") - binding.pry + # binding.pry end targets @@ -227,6 +228,8 @@ def fallback_log description = d.any? ? d.join(', ') : "#{params[:controller]}: #{params.except('controller').to_json}" end + # binding.pry + LogAction.create( log_type: LogAction::TYPE[request_method(request.request_method)], user_id: current_user.id, From 37a73c87e55a426b9e6e28b4dfd844ff160d4462 Mon Sep 17 00:00:00 2001 From: Jailson Pinheiro Lima Date: Mon, 23 Feb 2026 10:45:28 -0300 Subject: [PATCH 10/15] feat: add log on publish exam question --- app/controllers/exam_questions_controller.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/controllers/exam_questions_controller.rb b/app/controllers/exam_questions_controller.rb index bf274e408..575d701d9 100644 --- a/app/controllers/exam_questions_controller.rb +++ b/app/controllers/exam_questions_controller.rb @@ -136,6 +136,10 @@ def publish ExamQuestion.where(id: ids).each do |exam_question| exam_question.question.can_change_status? exam_question.question.update_attributes status: true + + binding.pry + + log(exam_question.exam, "question: #{exam_question.question_id} [publish], exam: #{exam_question.exam_id}, #{exam_question.log_description}", LogAction::TYPE[:update]) rescue nil end end From e7fecff174fc12628cab66f8c81edb95b306b17b Mon Sep 17 00:00:00 2001 From: Jailson Pinheiro Lima Date: Mon, 23 Feb 2026 15:36:52 -0300 Subject: [PATCH 11/15] fix: exam publication log --- app/controllers/exams_controller.rb | 19 ++++++++++++++++++- app/models/concerns/sys_log.rb | 2 +- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/app/controllers/exams_controller.rb b/app/controllers/exams_controller.rb index 0d884fa37..e849b1eb5 100644 --- a/app/controllers/exams_controller.rb +++ b/app/controllers/exams_controller.rb @@ -325,8 +325,15 @@ def calculate_grade def change_status authorize! :change_status, Exam, { on: params[:allocation_tags_ids] } exam = Exam.find(params[:id]) + exam.can_change_status? - exam.update_attributes status: !exam.status + + updated_status = !exam.status + + log(exam, "exam: #{exam.id} [#{updated_status ? 'publish' : 'unpublish' }], #{exam.attributes.except('id')}", LogAction::TYPE[:update]) rescue nil + + exam.update_attributes status: updated_status + render_exam_success_json('status') rescue CanCan::AccessDenied render json: { success: false, alert: t(:no_permission) }, status: :unauthorized @@ -452,4 +459,14 @@ def return_acu_result(acu, at_id, score_type) render json: { success: false, alert: error } end + def log(object, message, type=LogAction::TYPE[:update]) + user_params = { user_id: current_user.id, ip: get_remote_ip } + + binding.pry + + object.academic_allocations.each do |ac| + LogAction.create(user_params.merge!(description: "user_id: #{user_params[:user_id]}, #{message}", academic_allocation_id: ac.id, log_type: type)) + end + end + end diff --git a/app/models/concerns/sys_log.rb b/app/models/concerns/sys_log.rb index c29520ec5..1d253b8ce 100644 --- a/app/models/concerns/sys_log.rb +++ b/app/models/concerns/sys_log.rb @@ -10,7 +10,7 @@ module Actions extend ActiveSupport::Concern included do - after_action :log_create, unless: Proc.new {|c| request.get? }, except: [:change_participant, :import, :export, :annul, :publish, :remove_record] + after_action :log_create, unless: Proc.new {|c| request.get? }, except: [:change_participant, :import, :export, :annul, :publish, :remove_record, :change_status] end def log_create From f6ad2c4b448c58076be58adb9e5a3f82ada753a6 Mon Sep 17 00:00:00 2001 From: Jailson Pinheiro Lima Date: Thu, 26 Feb 2026 12:38:15 -0300 Subject: [PATCH 12/15] feat: add log when starting and finishing the exam --- app/controllers/exams_controller.rb | 8 +++++++- app/models/concerns/sys_log.rb | 4 +++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/controllers/exams_controller.rb b/app/controllers/exams_controller.rb index e849b1eb5..a4893ae3b 100644 --- a/app/controllers/exams_controller.rb +++ b/app/controllers/exams_controller.rb @@ -149,6 +149,10 @@ def open @total_time = (@last_attempt.try(:complete) ? 0 : @last_attempt.total_time) || 0 + if params[:page].nil? && @last_attempt.total_time == 0 + log(@exam, "exam_id: #{@exam&.id}#{@exam.attempts > 1 ? ", attempt: #{@exam&.exam_user_attempts&.length}" : ''}, description: \"Prova iniciada!\"", LogAction::TYPE[:update]) + end + SysLog::Actions.log_info do "[PROVA] Abriu prova pagina #{params[:page]} exam_id #{@exam.try(:id)} user_id=#{current_user.try(:id)} last_attempt: #{@last_attempt.as_json} - total_time #{@total_time} - exam_user_attempt #{params[:exam_user_attempt_id]}" end @@ -263,6 +267,8 @@ def complete format.js { render :js => "validation_error('#{I18n.t('exam_responses.error.' + params[:error] + '')}');" } end else + log(exam, "exam_id: #{exam&.id}#{exam.attempts > 1 ? ", attempt: #{exam&.exam_user_attempts&.length}" : ''}, description: \"Prova finalizada!\"", LogAction::TYPE[:update]) + SysLog::Actions.log_info do "[PROVA] Abriu método de finalizar prova #{params[:id]} user_id=#{current_user.try(:id)} acu #{acu.as_json} - SUCESSO" end @@ -462,7 +468,7 @@ def return_acu_result(acu, at_id, score_type) def log(object, message, type=LogAction::TYPE[:update]) user_params = { user_id: current_user.id, ip: get_remote_ip } - binding.pry + # binding.pry object.academic_allocations.each do |ac| LogAction.create(user_params.merge!(description: "user_id: #{user_params[:user_id]}, #{message}", academic_allocation_id: ac.id, log_type: type)) diff --git a/app/models/concerns/sys_log.rb b/app/models/concerns/sys_log.rb index 1d253b8ce..616ffa40b 100644 --- a/app/models/concerns/sys_log.rb +++ b/app/models/concerns/sys_log.rb @@ -75,6 +75,8 @@ def log_create obj = instance_variable_get("@#{sobj}") objs = instance_variable_get("@#{model_name.tableize}") + Rails.logger.info("\n\n Log Info Obj \n\n #{model_name} \n #{sobj} \n #{obj} \n #{objs} \n\n") + target_objects = if obj.present? [obj] elsif objs.present? && objs.is_a?(Enumerable) @@ -135,7 +137,7 @@ def general_log_description(obj, sobj) ignored_attrs = %w[id created_at updated_at attachment_updated_at] Rails.logger.info("\n\n Entrou na regra geral de descrição \n\n") - binding.pry + # binding.pry log_payload = obj.respond_to?(:log_description) ? obj.log_description : obj.attributes.except(*ignored_attrs) From 1e60d9591a9640279949a6afc917709665256ba2 Mon Sep 17 00:00:00 2001 From: Jailson Pinheiro Lima Date: Thu, 26 Feb 2026 13:09:57 -0300 Subject: [PATCH 13/15] style: removes comments and logs --- app/controllers/exam_questions_controller.rb | 2 - app/controllers/exams_controller.rb | 2 - app/models/concerns/sys_log.rb | 117 ------------------- 3 files changed, 121 deletions(-) diff --git a/app/controllers/exam_questions_controller.rb b/app/controllers/exam_questions_controller.rb index 575d701d9..693237d05 100644 --- a/app/controllers/exam_questions_controller.rb +++ b/app/controllers/exam_questions_controller.rb @@ -137,8 +137,6 @@ def publish exam_question.question.can_change_status? exam_question.question.update_attributes status: true - binding.pry - log(exam_question.exam, "question: #{exam_question.question_id} [publish], exam: #{exam_question.exam_id}, #{exam_question.log_description}", LogAction::TYPE[:update]) rescue nil end end diff --git a/app/controllers/exams_controller.rb b/app/controllers/exams_controller.rb index a4893ae3b..3995ebdb7 100644 --- a/app/controllers/exams_controller.rb +++ b/app/controllers/exams_controller.rb @@ -468,8 +468,6 @@ def return_acu_result(acu, at_id, score_type) def log(object, message, type=LogAction::TYPE[:update]) user_params = { user_id: current_user.id, ip: get_remote_ip } - # binding.pry - object.academic_allocations.each do |ac| LogAction.create(user_params.merge!(description: "user_id: #{user_params[:user_id]}, #{message}", academic_allocation_id: ac.id, log_type: type)) end diff --git a/app/models/concerns/sys_log.rb b/app/models/concerns/sys_log.rb index 616ffa40b..288f7713c 100644 --- a/app/models/concerns/sys_log.rb +++ b/app/models/concerns/sys_log.rb @@ -14,61 +14,6 @@ module Actions end def log_create - # model = self.class.to_s.sub("Controller", "") - # sobj = model.tableize - # objs = eval("@#{sobj}") # created/updated/destroyied objects could be a list - # sobj = sobj.singularize - # obj = eval("@#{sobj}") - # objs = [eval("@#{sobj}")].compact unless obj.nil? # only if obj doesn't exist, use objs list - - # Rails.logger.info("\n\n #{model} \n #{sobj} \n #{objs} \n #{obj} \n\n") - - # # if some error happened, don't save log - # return if request_failed? - - # if !(objs.nil?) && !(objs.empty?) - # Rails.logger.info("\n\n Entrou na regra geral de criação de logs \n\n") - # objs.each do |obj| - - # # general rule for creating a log description - # all_associations = eval("#{model.singularize}").reflect_on_all_associations(:has_many).map(&:name) - - # log_payload = if obj.respond_to?(:log_description) - # obj.log_description - # else - # obj.attributes.except(*ignored_attrs) - # end - - # all_associations.each do |association| - # if(obj.respond_to?(association) && obj.send(association).any?) - # association_data = obj.send(association).map {|a| a.attributes.except("attachment_updated_at") } - - # log_payload = log_payload.merge("#{association.to_s}" => association_data) if log_payload.is_a?(Hash) - # end - # end - - # description = "#{sobj.singularize}: #{obj.id}#{changed_attributes(obj, ignored_attrs)}, #{log_payload.to_json}" - - # if ((obj.respond_to?(:academic_allocations) && !obj.try(:academic_allocations).empty?) || obj.respond_to?(:academic_allocation)) # if there is academic_allocations - # allocation_tag_id = params[:allocation_tag_id] || active_tab[:url][:allocation_tag_id] || obj.allocation_tag.id rescue nil - - # [(obj.respond_to?(:academic_allocations) ? obj.academic_allocations : obj.academic_allocation)].flatten.each do |al| - # LogAction.create(log_type: LogAction::TYPE[request_method(request.request_method)], user_id: current_user.id, academic_allocation_id: al.id, allocation_tag_id: (allocation_tag_id || al.allocation_tag_id), ip: get_remote_ip, description: description) - # end - - # elsif (obj.respond_to?(:allocation_tag) && !(obj.allocation_tag.nil?)) # if there is allocation_tag - # LogAction.create(log_type: LogAction::TYPE[request_method(request.request_method)], user_id: current_user.id, allocation_tag_id: obj.allocation_tag.id, ip: get_remote_ip, description: description) - - # else # generic log (if academic_allocations and allocation_tag do not exists) - # Rails.logger.info("\n\n Caiu no log genérico com sobj e obj \n\n") - # generic_log(sobj, obj) - # end - # end - # else - # Rails.logger.info("\n\n Caiu no log genérico com somente sobj \n\n") - # generic_log(sobj) - # end - model_name = self.class.to_s.sub("Controller", "") sobj = model_name.tableize.singularize @@ -136,19 +81,14 @@ def request_failed? def general_log_description(obj, sobj) ignored_attrs = %w[id created_at updated_at attachment_updated_at] - Rails.logger.info("\n\n Entrou na regra geral de descrição \n\n") - # binding.pry - log_payload = obj.respond_to?(:log_description) ? obj.log_description : obj.attributes.except(*ignored_attrs) log_payload = log_payload.as_json unless log_payload.is_a?(Hash) - # all_associations = obj.class.reflect_on_all_associations.select { |assoc| [:has_many, :belongs_to].include?(assoc.macro) }.map(&:name) all_associations = obj.class.reflect_on_all_associations(:has_many).map(&:name) all_associations.each do |association| if((obj.respond_to?(association) && obj.send(association).any?) && !(obj.respond_to?(:log_description))) - # associated_objects = [obj.send(association)].flatten association_data = obj.send(association).map {|a| a.attributes.except("attachment_updated_at") } @@ -163,9 +103,6 @@ def log_targets(obj) # academic_allocations and allocation_tag to get allocation targets = [] allocation_tag_id = params[:allocation_tag_id] || active_tab[:url][:allocation_tag_id] || (obj.allocation_tag.id rescue nil) - Rails.logger.info("\n\n Entrou no método que captura os alvos \n\n") - # binding.pry - if obj.respond_to?(:academic_allocations) && obj.academic_allocations.present? obj.academic_allocations.each do |al| targets << { @@ -173,24 +110,16 @@ def log_targets(obj) # academic_allocations and allocation_tag to get allocation tag_id: (allocation_tag_id || al.try(:allocation_tag_id)) } end - Rails.logger.info("\n\n Entrou no if \n\n") - # binding.pry elsif obj.respond_to?(:academic_allocation) && obj.academic_allocation.present? al = obj.academic_allocation targets << { allocation_id: al.id, tag_id: (allocation_tag_id || al.try(:allocation_tag_id)) } - Rails.logger.info("\n\n Entrou no primeiro elsif \n\n") - # binding.pry elsif obj.respond_to?(:allocation_tag) && obj.allocation_tag.present? targets << { allocation_id: nil, tag_id: obj.allocation_tag.id } - Rails.logger.info("\n\n Entrou no segundo elsif \n\n") - # binding.pry else targets << { allocation_id: nil, tag_id: allocation_tag_id } - Rails.logger.info("\n\n Entrou no else \n\n") - # binding.pry end targets @@ -199,8 +128,6 @@ def log_targets(obj) # academic_allocations and allocation_tag to get allocation def fallback_log return if params.include?(:digital_classes) - Rails.logger.info("\n\n Entrou no Fallback do Log \n\n") - description = nil if params[:id].present? && params.except(:controller, :action, :id).empty? @@ -230,8 +157,6 @@ def fallback_log description = d.any? ? d.join(', ') : "#{params[:controller]}: #{params.except('controller').to_json}" end - # binding.pry - LogAction.create( log_type: LogAction::TYPE[request_method(request.request_method)], user_id: current_user.id, @@ -263,48 +188,6 @@ def request_method(rm) end end - def generic_log(sobj, obj = nil) - binding.pry - - return if params.include?(:digital_classes) - return if !obj.nil? && obj.new_record?# && !params.include?(:digital_classes) # not saved - - # academic_allocation_id = obj.try(:academic_allocation).try(:id) - academic_allocation_id = nil - tbname = obj.try(:class).try(:table_name).to_s.singularize.to_sym if obj.try(:class).respond_to?(:table_name) - description = if !tbname.nil? && (params.has_key?(tbname) || params.size <= 3) && !obj.nil? - Rails.logger.info("\n\n Entrou no if \n\n") - binding.pry - - obj_attrs = (obj.respond_to?(:log_description) ? obj.log_description : obj.attributes.except('attachment_updated_at', 'created_at', 'updated_at')) - obj_attrs.merge!({'files' => obj.files.map {|f| f.attributes.except('attachment_updated_at') } }) if obj.respond_to?(:files) && obj.files.any? - obj_attrs = ActiveSupport::JSON.encode(obj_attrs) - - "#{sobj}: #{obj.id}, changed: #{obj.changed}, #{obj_attrs}" - elsif params[:id].present? - Rails.logger.info("\n\n Entrou no elsif \n\n") - binding.pry - - # gets any extra information if exists - info = ActiveSupport::JSON.encode(params.except(:controller, :action, :id)) - "#{sobj}: #{[params[:id], info].compact.join(", ")}" - else # controllers saving other objects. ex: assingments -> student files - Rails.logger.info("\n\n Entrou no else \n\n") - - d = [] - variables = self.instance_variable_names.to_ary.delete_if { |v| v.to_s.start_with?("@_") || ["@current_user", "@current_ability"].include?(v) } - variables.each do |v| - o = eval(v) - academic_allocation_id = o.academic_allocation.id if o.respond_to?(:academic_allocation) # assignment_file - d << %{#{v.sub("@", "")}: #{o.as_json}} unless ["Array", "String"].include?(o.class) - end - d.join(', ') - d = "#{params[:controller]}: #{params.except('controller').to_s}" if d.blank? - end - - LogAction.create(log_type: LogAction::TYPE[request_method(request.request_method)], user_id: current_user.id, ip: get_remote_ip, academic_allocation_id: academic_allocation_id, description: description, allocation_tag_id: (active_tab[:url][:allocation_tag_id] rescue nil)) unless description.nil? - end - end # Actions module Devise From 2352abb6acf7b42430b85700fd91abe03c5e6cc1 Mon Sep 17 00:00:00 2001 From: Jailson Pinheiro Lima Date: Tue, 31 Mar 2026 12:49:53 -0300 Subject: [PATCH 14/15] chore: change final exam position --- app/controllers/exams_controller.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/controllers/exams_controller.rb b/app/controllers/exams_controller.rb index 3995ebdb7..d1540718e 100644 --- a/app/controllers/exams_controller.rb +++ b/app/controllers/exams_controller.rb @@ -267,12 +267,13 @@ def complete format.js { render :js => "validation_error('#{I18n.t('exam_responses.error.' + params[:error] + '')}');" } end else - log(exam, "exam_id: #{exam&.id}#{exam.attempts > 1 ? ", attempt: #{exam&.exam_user_attempts&.length}" : ''}, description: \"Prova finalizada!\"", LogAction::TYPE[:update]) - SysLog::Actions.log_info do "[PROVA] Abriu método de finalizar prova #{params[:id]} user_id=#{current_user.try(:id)} acu #{acu.as_json} - SUCESSO" end + user_session[:blocking_content] = Exam.verify_blocking_content(current_user.id) + + log(exam, "exam_id: #{exam&.id}#{exam.attempts > 1 ? ", attempt: #{exam&.exam_user_attempts&.length}" : ''}, description: \"Prova finalizada!\"", LogAction::TYPE[:update]) #render_exam_success_json('finish') redirect_to exams_path, notice: t('finish', scope: 'exams.success') end From 7d7b0b49236b4b908bbf9ab5cee7ec923f76a64b Mon Sep 17 00:00:00 2001 From: Bianca Date: Tue, 7 Apr 2026 15:44:57 -0300 Subject: [PATCH 15/15] fix: remove change_status from exception list to log; update log_description exam method; update render after creating or updating question --- app/controllers/exam_questions_controller.rb | 4 ++-- app/controllers/questions_controller.rb | 2 +- app/models/concerns/sys_log.rb | 6 ++---- app/models/exam.rb | 16 ++++++++++------ 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/app/controllers/exam_questions_controller.rb b/app/controllers/exam_questions_controller.rb index bc63011c8..158d5e9e6 100644 --- a/app/controllers/exam_questions_controller.rb +++ b/app/controllers/exam_questions_controller.rb @@ -38,7 +38,7 @@ def create if @exam_question.save if @exam_question.exam.questions.size > 1 - render partial: 'question', locals: { question: @exam_question.question, exam_question: @exam_question, exam: @exam_question.exam, hide_columns: false, can_see_preview: true } + render partial: 'question', locals: { question: @exam_question.question, exam_question: @exam_question, exam: @exam_question.exam, hide_columns: false, can_see_preview: true, can_show_order: true } else redirect_to exam_questions_path(exam_id: @exam_question.exam_id, allocation_tags_ids: at_ids) end @@ -94,7 +94,7 @@ def update QuestionText.find(params['question_texts_id']).destroy end end - render partial: 'question', locals: { question: @exam_question.question, exam_question: @exam_question, exam: @exam_question.exam, hide_columns: false, can_see_preview: true } + render partial: 'question', locals: { question: @exam_question.question, exam_question: @exam_question, exam: @exam_question.exam, hide_columns: false, can_see_preview: true, can_show_order: true } else @errors = [] @exam_question.errors.each do |attribute, erro| diff --git a/app/controllers/questions_controller.rb b/app/controllers/questions_controller.rb index 2c9d64acc..535733e8f 100644 --- a/app/controllers/questions_controller.rb +++ b/app/controllers/questions_controller.rb @@ -93,7 +93,7 @@ def update end if @question.update_attributes question_params - render partial: 'question', locals: { question: @question } + render partial: 'question', locals: { question: @question, can_show_order: true } else @errors = [] @question.errors.each do |attribute, erro| diff --git a/app/models/concerns/sys_log.rb b/app/models/concerns/sys_log.rb index 288f7713c..cc4ceb421 100644 --- a/app/models/concerns/sys_log.rb +++ b/app/models/concerns/sys_log.rb @@ -10,7 +10,7 @@ module Actions extend ActiveSupport::Concern included do - after_action :log_create, unless: Proc.new {|c| request.get? }, except: [:change_participant, :import, :export, :annul, :publish, :remove_record, :change_status] + after_action :log_create, unless: Proc.new {|c| request.get? }, except: [:change_participant, :import, :export, :annul, :publish, :remove_record] end def log_create @@ -29,15 +29,13 @@ def log_create else [] end - + return if request_failed? if target_objects.any? target_objects.each do |obj| next if obj.new_record? && params.include?(:digital_classes) - description = general_log_description(obj, sobj) - resolved_log_targets = log_targets(obj) resolved_log_targets.each do |target| diff --git a/app/models/exam.rb b/app/models/exam.rb index 19e18ca1a..988acdfb6 100644 --- a/app/models/exam.rb +++ b/app/models/exam.rb @@ -417,13 +417,17 @@ def responses_question_user(acu_id, id) def log_description desc = {} - - desc.merge!(question.attributes.except('attachment_updated_at', 'updated_at', 'created_at')) - desc.merge!(exam_id: exam.id) + desc.merge!(exam_id: id) desc.merge!(attributes.except('attachment_updated_at', 'updated_at', 'created_at')) - desc.merge!(images: question.question_images.collect{|img| img.attributes.except('image_updated_at' 'question_id')}) - desc.merge!(items: question.question_items.collect{|item| item.attributes.except('question_id', 'item_image_updated_at')}) - desc.merge!(labels: question.question_labels.collect{|label| label.attributes.except('created_at', 'updated_at')}) + desc.merge!(schedules: schedule.attributes.except('id', 'updated_at', 'created_at')) + + questions.each do |question| + desc.merge!(questions: question.attributes.except('attachment_updated_at', 'updated_at', 'created_at')) + desc.merge!(items: question.question_items.collect{|item| item.attributes.except('question_id', 'item_image_updated_at')}) + desc.merge!(images: question.question_images.collect{|img| img.attributes.except('image_updated_at' 'question_id')}) + desc.merge!(labels: question.question_labels.collect{|label| label.attributes.except('created_at', 'updated_at')}) + end + return desc end def set_random_questions