From ea0640d51907a501130dbab5f4920bb20d8cd309 Mon Sep 17 00:00:00 2001 From: Henry Date: Sun, 14 Aug 2022 17:32:11 -0400 Subject: [PATCH 1/4] WIP --- .../reports/schedule_reports_controller.rb | 197 +++++++++++------- 1 file changed, 124 insertions(+), 73 deletions(-) diff --git a/app/controllers/reports/schedule_reports_controller.rb b/app/controllers/reports/schedule_reports_controller.rb index a3811d346..f5aa71d46 100644 --- a/app/controllers/reports/schedule_reports_controller.rb +++ b/app/controllers/reports/schedule_reports_controller.rb @@ -1,48 +1,55 @@ class Reports::ScheduleReportsController < ApplicationController around_action :set_timezone + # + # Get the sched diffs based on "publication dates" + # def schedule_diff authorize Person, policy_class: Reports::ScheduleReportPolicy - # TODO: base the from and to on the publish ids and this will be ok as a get pd_from = PublicationDate.find params[:from] if params[:from] from = pd_from.timestamp if pd_from from ||= PublicationDate.order('created_at desc').first&.timestamp - from ||= Time.now - 2.year # TODO: for testing + from ||= Time.now - 2.year pd_to = PublicationDate.find params[:to] if params[:to] to = pd_to.timestamp if pd_to live = false - # changes = ChangeService.published_changes(from: from, to: to) changes = if to ChangeService.published_changes(from: from, to: to) else live = true ChangeService.session_changes(from: from) end - to ||= Time.now - workbook = FastExcel.open(constant_memory: true) - date_time_style = workbook.number_format(EXCEL_NBR_FORMAT) - session_time_changed = workbook.add_worksheet("Session Time Changed") - session_room_changed = workbook.add_worksheet("Session Room Changed") - session_title_changed = workbook.add_worksheet("Session Title Changed") - session_description_changed = workbook.add_worksheet("Session Description Changed") - session_added = workbook.add_worksheet("Sessions Add") - session_removed = workbook.add_worksheet("Sessions Removed") + workbook = FastExcel.open(constant_memory: true) + init_sheets(workbook: workbook) - participants_fully_dropped = workbook.add_worksheet("Participants Dropped") - participants_add_drop = workbook.add_worksheet("Participants Add Drop") + # Rails.logger.debug "******** CHANGES: #{changes[:sessions]}" + state_change_sessions = check_sessions_changed(changes: changes[:sessions], live: live) + fully_dropped = check_assignments_changed( + changes: changes[:assignments], + state_change_sessions: state_change_sessions + ) - tab_headers(session_time_changed, session_room_changed, session_title_changed, session_description_changed, session_added, session_removed, participants_add_drop, participants_fully_dropped) + fully_dropped.uniq.each do |name| + @participants_fully_dropped.append_row(name) + end - # Rails.logger.debug "******** CHANGES: #{changes[:sessions]}" + send_data workbook.read_string, + filename: "ScheduleDiff-#{from.strftime('%m-%d-%Y_%H_%M')}_to_#{to.strftime('%m-%d-%Y_%H_%M')}.xlsx", + disposition: 'attachment' + end + # + # + # + def check_sessions_changed(changes:, live:) state_change_sessions = [] - changes[:sessions].values.sort{|a,b| (a[:object] ? a[:object].title : '') <=> (b[:object] ? b[:object].title : '')}.each do |change| + changes.values.sort{|a,b| (a[:object] ? a[:object].title : '') <=> (b[:object] ? b[:object].title : '')}.each do |change| # Rails.logger.debug "******** CHANGE: #{change}" next unless change[:object] @@ -50,69 +57,76 @@ def schedule_diff if change[:changes]['room_id'] && change[:changes]['start_time'] && ((!change[:changes]['room_id'][0] && change[:changes]['room_id'][1]) || (!change[:changes]['start_time'][0] && change[:changes]['start_time'][1])) - session_added_row(session_added, change, date_time_style) - live_add(session: change[:object], sheet: participants_add_drop) if live + session_added_row(@session_added, change) + live_add(session: change[:object], sheet: @participants_add_drop) if live next else if (change[:changes]['room_id'] && !change[:changes]['room_id'][1]) || (change[:changes]['start_time'] && !change[:changes]['start_time'][1])|| change[:event] == 'destroy' # Rails.logger.debug "******** removed because room or time" - session_removed_row(session_removed, change) - live_drop(session: change[:object], sheet: participants_add_drop) if live + session_removed_row(@session_removed, change) + live_drop(session: change[:object], sheet: @participants_add_drop) if live next else if change[:changes]['room_id'] - session_room_change_row(session_room_changed, change) + session_room_change_row(@session_room_changed, change) end if change[:changes]['start_time'] - session_time_change_row(session_time_changed, change, date_time_style) + session_time_change_row(@session_time_changed, change) end end end end if change[:object].start_time && change[:object].room_id - if change[:changes]['status'] - if (change[:changes]['status'][1] == 'draft' || change[:changes]['status'][1] == 'dropped') - # Rails.logger.debug "******** removed because draft" - session_removed_row(session_removed, change) - if live - live_drop(session: change[:object], sheet: participants_add_drop) - state_change_sessions << change[:object].id - end - next - elsif (change[:changes]['status'][0] == 'draft' || change[:changes]['status'][0] == 'dropped') - # Rails.logger.debug "******** added because state change" - session_added_row(session_added, change, date_time_style) - if live - live_add(session: change[:object], sheet: participants_add_drop) - state_change_sessions << change[:object].id - end - next + session_id = check_status_change(change: change, live: live) + + if session_id + state_change_sessions << session_id #change[:object].id + else + if change[:changes]['title'] + session_title_change_row(@session_title_changed, change) + end + if change[:changes]['description'] + session_description_change_row(@session_description_changed, change) end end - if change[:changes]['title'] - session_title_change_row(session_title_changed, change) - end - if change[:changes]['description'] - session_description_change_row(session_description_changed, change) - end + # if change[:changes]['status'] + # if (change[:changes]['status'][1] == 'draft' || change[:changes]['status'][1] == 'dropped') + # # Rails.logger.debug "******** removed because draft" + # session_removed_row(@session_removed, change) + # if live + # live_drop(session: change[:object], sheet: @participants_add_drop) + # state_change_sessions << change[:object].id + # end + # next + # elsif (change[:changes]['status'][0] == 'draft' || change[:changes]['status'][0] == 'dropped') + # # Rails.logger.debug "******** added because state change" + # session_added_row(@session_added, change) + # if live + # live_add(session: change[:object], sheet: @participants_add_drop) + # state_change_sessions << change[:object].id + # end + # next + # end + # end + end end - # Deal with the assignment changes + return state_change_sessions + end + + def check_assignments_changed(changes:, state_change_sessions:) moderator = SessionAssignmentRoleType.find_by(name: 'Moderator') participant = SessionAssignmentRoleType.find_by(name: 'Participant') roles = [moderator.id, participant.id] - # Rails.logger.debug "******** ROLES #{roles}" - # TODO: sort .... ??? how fully_dropped = [] - changes[:assignments].each do |id, change| - # next unless change[:object] + changes.each do |id, change| changed_assignment = change[:object] changed_assignment ||= SessionAssignment.find change[:session_assignment_id] - next if state_change_sessions.include? change[:object].session_id + next if state_change_sessions.include? changed_assignment.session_id session = changed_assignment.session if changed_assignment.session session ||= Session.find changed_assignment.session_id @@ -123,7 +137,7 @@ def schedule_diff if change[:changes]['session_assignment_role_type_id'] && change[:event] != 'destroy' if session.start_time && session.room_id if (roles.include?(change[:changes]['session_assignment_role_type_id'][1])) - participants_add_drop.append_row( + @participants_add_drop.append_row( [ session.title, '', @@ -131,7 +145,7 @@ def schedule_diff ] ) elsif (roles.include?(change[:changes]['session_assignment_role_type_id'][0])) - participants_add_drop.append_row( + @participants_add_drop.append_row( [ session.title, changed_assignment.person.published_name, @@ -145,7 +159,7 @@ def schedule_diff else # Rails.logger.debug "******** Assignment EVENT DROP ????" if change[:event] == 'destroy' - participants_add_drop.append_row( + @participants_add_drop.append_row( [ session.title, changed_assignment.person.published_name, @@ -158,25 +172,62 @@ def schedule_diff end end - fully_dropped.uniq.each do |name| - participants_fully_dropped.append_row(name) + return fully_dropped + end + + def check_status_change(change:, live: false) + return unless change[:changes]['status'] + return if ['draft', 'dropped'].include?(change[:changes]['status'][0]) && ['draft', 'dropped'].include?(change[:changes]['status'][1]) + + if ['draft', 'dropped'].include?(change[:changes]['status'][1]) + session_removed_row(@session_removed, change) + + if live + live_drop(session: change[:object], sheet: @participants_add_drop) + # state_change_sessions << + return change[:object].id + end + + return end - send_data workbook.read_string, - filename: "ScheduleDiff-#{from.strftime('%m-%d-%Y_%H_%M')}_to_#{to.strftime('%m-%d-%Y_%H_%M')}.xlsx", - disposition: 'attachment' + if ['draft', 'dropped'].include?(change[:changes]['status'][0]) + session_added_row(@session_added, change) + if live + live_add(session: change[:object], sheet: @participants_add_drop) + # state_change_sessions << + return change[:object].id + end + + return + end + end + + + def init_sheets(workbook:) + @session_time_changed = workbook.add_worksheet("Session Time Changed") + @session_room_changed = workbook.add_worksheet("Session Room Changed") + @session_title_changed = workbook.add_worksheet("Session Title Changed") + @session_description_changed = workbook.add_worksheet("Session Description Changed") + @session_added = workbook.add_worksheet("Sessions Add") + @session_removed = workbook.add_worksheet("Sessions Removed") + @participants_fully_dropped = workbook.add_worksheet("Participants Dropped") + @participants_add_drop = workbook.add_worksheet("Participants Add Drop") + + @date_time_style = workbook.number_format(EXCEL_NBR_FORMAT) + tab_headers end - def tab_headers(session_time_changed, session_room_changed, session_title_changed, session_description_changed, session_added, session_removed, participants_add_drop, participants_fully_dropped) - session_time_changed.append_row(['Session Title','Original Start Time', 'New Start Time']) - session_room_changed.append_row(['Session Title','Original Room', 'New Room']) - session_title_changed.append_row(['Original Session Title', 'New Session Title']) - session_description_changed.append_row(['Session Title','Original Description', 'New Description']) - session_added.append_row(['Session Title', 'Session Description', 'Format', 'Areas', 'Start Time', 'Room', 'Moderators', 'Participants']) - session_removed.append_row(['Session Title']) + def tab_headers + @session_time_changed.append_row(['Session Title','Original Start Time', 'New Start Time']) + @session_room_changed.append_row(['Session Title','Original Room', 'New Room']) + @session_title_changed.append_row(['Original Session Title', 'New Session Title']) + @session_description_changed.append_row(['Session Title','Original Description', 'New Description']) + @session_added.append_row(['Session Title', 'Session Description', 'Format', 'Areas', 'Start Time', 'Room', 'Moderators', 'Participants']) + @session_removed.append_row(['Session Title']) - participants_add_drop.append_row(['Session Title', 'Participant Dropped', 'Participant Added']) - participants_fully_dropped.append_row(['Participant Dropped']) + @participants_add_drop.append_row(['Session Title', 'Participant Dropped', 'Participant Added']) + @participants_fully_dropped.append_row(['Participant Dropped']) end def live_add(session:, sheet:) @@ -242,7 +293,7 @@ def session_removed_row(sheet, change) ) end - def session_time_change_row(sheet, change, date_time_style) + def session_time_change_row(sheet, change) orig_time = Time.parse(change[:changes]['start_time'][0]) if change[:changes]['start_time'][0] new_time = Time.parse(change[:changes]['start_time'][1]) if change[:changes]['start_time'][1] # Rails.logger.debug "********* #{change[:changes]['start_time'][1]} => #{new_time.class} #{new_time.strftime("%H")}" @@ -253,13 +304,13 @@ def session_time_change_row(sheet, change, date_time_style) new_time ? FastExcel.date_num(new_time, new_time.in_time_zone.utc_offset) : nil ], [ - nil, date_time_style, date_time_style + nil, @date_time_style, @date_time_style ] ) end # Generate a row for sessions added - def session_added_row(sheet, change, date_time_style) + def session_added_row(sheet, change) moderator = SessionAssignmentRoleType.find_by(name: 'Moderator') participant = SessionAssignmentRoleType.find_by(name: 'Participant') @@ -277,7 +328,7 @@ def session_added_row(sheet, change, date_time_style) change[:object].participant_assignments.where("session_assignment_role_type_id = ?", participant).collect{|a| a.person.published_name}.join("; ") ], [ - nil, nil, nil, nil, date_time_style, nil, nil, nil + nil, nil, nil, nil, @date_time_style, nil, nil, nil ] ) end From 7c3a65da91b2cc1ab366b4967464a814c49a833e Mon Sep 17 00:00:00 2001 From: Henry Date: Sun, 14 Aug 2022 17:53:53 -0400 Subject: [PATCH 2/4] WIP --- .../reports/schedule_reports_controller.rb | 34 +++++-------------- 1 file changed, 9 insertions(+), 25 deletions(-) diff --git a/app/controllers/reports/schedule_reports_controller.rb b/app/controllers/reports/schedule_reports_controller.rb index f5aa71d46..9bdd4aac5 100644 --- a/app/controllers/reports/schedule_reports_controller.rb +++ b/app/controllers/reports/schedule_reports_controller.rb @@ -90,27 +90,6 @@ def check_sessions_changed(changes:, live:) session_description_change_row(@session_description_changed, change) end end - - # if change[:changes]['status'] - # if (change[:changes]['status'][1] == 'draft' || change[:changes]['status'][1] == 'dropped') - # # Rails.logger.debug "******** removed because draft" - # session_removed_row(@session_removed, change) - # if live - # live_drop(session: change[:object], sheet: @participants_add_drop) - # state_change_sessions << change[:object].id - # end - # next - # elsif (change[:changes]['status'][0] == 'draft' || change[:changes]['status'][0] == 'dropped') - # # Rails.logger.debug "******** added because state change" - # session_added_row(@session_added, change) - # if live - # live_add(session: change[:object], sheet: @participants_add_drop) - # state_change_sessions << change[:object].id - # end - # next - # end - # end - end end @@ -176,16 +155,21 @@ def check_assignments_changed(changes:, state_change_sessions:) end def check_status_change(change:, live: false) + # Rails.logger.debug "********* STATUS CHANGE" return unless change[:changes]['status'] return if ['draft', 'dropped'].include?(change[:changes]['status'][0]) && ['draft', 'dropped'].include?(change[:changes]['status'][1]) + # Rails.logger.debug "********* STATUS CHANGE ....." if ['draft', 'dropped'].include?(change[:changes]['status'][1]) - session_removed_row(@session_removed, change) - if live + return unless change[:object].published_session + + session_removed_row(@session_removed, change) live_drop(session: change[:object], sheet: @participants_add_drop) - # state_change_sessions << + return change[:object].id + else + session_removed_row(@session_removed, change) end return @@ -195,7 +179,7 @@ def check_status_change(change:, live: false) session_added_row(@session_added, change) if live live_add(session: change[:object], sheet: @participants_add_drop) - # state_change_sessions << + return change[:object].id end From 2a62ba904662d17c86c9eab2b9a548e3be5e8023 Mon Sep 17 00:00:00 2001 From: Henry Date: Sun, 14 Aug 2022 18:51:19 -0400 Subject: [PATCH 3/4] WIP --- .../reports/schedule_reports_controller.rb | 93 +++++++++++-------- 1 file changed, 55 insertions(+), 38 deletions(-) diff --git a/app/controllers/reports/schedule_reports_controller.rb b/app/controllers/reports/schedule_reports_controller.rb index 9bdd4aac5..64e9fcd86 100644 --- a/app/controllers/reports/schedule_reports_controller.rb +++ b/app/controllers/reports/schedule_reports_controller.rb @@ -29,7 +29,10 @@ def schedule_diff init_sheets(workbook: workbook) # Rails.logger.debug "******** CHANGES: #{changes[:sessions]}" - state_change_sessions = check_sessions_changed(changes: changes[:sessions], live: live) + state_change_sessions = check_sessions_changed( + changes: changes[:sessions], + live: live + ) fully_dropped = check_assignments_changed( changes: changes[:assignments], state_change_sessions: state_change_sessions @@ -50,30 +53,28 @@ def schedule_diff def check_sessions_changed(changes:, live:) state_change_sessions = [] changes.values.sort{|a,b| (a[:object] ? a[:object].title : '') <=> (b[:object] ? b[:object].title : '')}.each do |change| - # Rails.logger.debug "******** CHANGE: #{change}" next unless change[:object] - if change[:changes]['room_id'] || change[:changes]['start_time'] - if change[:changes]['room_id'] && change[:changes]['start_time'] && - ((!change[:changes]['room_id'][0] && change[:changes]['room_id'][1]) || - (!change[:changes]['start_time'][0] && change[:changes]['start_time'][1])) + if (change[:changes]['room_id'] || change[:changes]['start_time']) && !change[:changes]['status'] + # Rails.logger.debug "******** SESSION ADD/REMOVE #{change[:changes]['status']} " + if room_added?(change) || start_time_added?(change) session_added_row(@session_added, change) live_add(session: change[:object], sheet: @participants_add_drop) if live next - else - if (change[:changes]['room_id'] && !change[:changes]['room_id'][1]) || (change[:changes]['start_time'] && !change[:changes]['start_time'][1])|| change[:event] == 'destroy' - # Rails.logger.debug "******** removed because room or time" - session_removed_row(@session_removed, change) - live_drop(session: change[:object], sheet: @participants_add_drop) if live - next - else - if change[:changes]['room_id'] - session_room_change_row(@session_room_changed, change) - end - if change[:changes]['start_time'] - session_time_change_row(@session_time_changed, change) - end - end + end + + if room_removed?(change) || start_time_removed?(change) + session_removed_row(@session_removed, change) + live_drop(session: change[:object], sheet: @participants_add_drop) if live + next + end + + if change[:changes]['room_id'] + session_room_change_row(@session_room_changed, change) + end + + if change[:changes]['start_time'] + session_time_change_row(@session_time_changed, change) end end @@ -81,14 +82,15 @@ def check_sessions_changed(changes:, live:) session_id = check_status_change(change: change, live: live) if session_id - state_change_sessions << session_id #change[:object].id - else - if change[:changes]['title'] - session_title_change_row(@session_title_changed, change) - end - if change[:changes]['description'] - session_description_change_row(@session_description_changed, change) - end + state_change_sessions << session_id + next + end + + if change[:changes]['title'] + session_title_change_row(@session_title_changed, change) + end + if change[:changes]['description'] + session_description_change_row(@session_description_changed, change) end end end @@ -96,6 +98,22 @@ def check_sessions_changed(changes:, live:) return state_change_sessions end + def room_added?(change) + !change[:changes]['room_id'][0] && change[:changes]['room_id'][1] + end + + def start_time_added?(change) + !change[:changes]['start_time'][0] && change[:changes]['start_time'][1] + end + + def room_removed?(change) + change[:changes]['room_id'][0] && !change[:changes]['room_id'][1] + end + + def start_time_removed?(change) + change[:changes]['start_time'][0] && !change[:changes]['start_time'][1] + end + def check_assignments_changed(changes:, state_change_sessions:) moderator = SessionAssignmentRoleType.find_by(name: 'Moderator') participant = SessionAssignmentRoleType.find_by(name: 'Participant') @@ -103,14 +121,11 @@ def check_assignments_changed(changes:, state_change_sessions:) fully_dropped = [] changes.each do |id, change| - changed_assignment = change[:object] - changed_assignment ||= SessionAssignment.find change[:session_assignment_id] - next if state_change_sessions.include? changed_assignment.session_id + next if state_change_sessions.include? change[:item_id] - session = changed_assignment.session if changed_assignment.session - session ||= Session.find changed_assignment.session_id - - # Rails.logger.debug "******** Assignment changes #{change}" + changed_assignment = change[:object] + changed_assignment ||= SessionAssignment.find(change[:item_id]) if SessionAssignment.exists?(change[:item_id]) + session = changed_assignment.session # Participants add/drop if change[:changes]['session_assignment_role_type_id'] && change[:event] != 'destroy' @@ -130,7 +145,8 @@ def check_assignments_changed(changes:, state_change_sessions:) changed_assignment.person.published_name, ] ) - if changed_assignment.person.sessions.scheduled.count == 0 + + if ['declined', 'rejected'].include? changed_assignment.person.con_state fully_dropped.append [change[:object].person.published_name] end end @@ -144,7 +160,7 @@ def check_assignments_changed(changes:, state_change_sessions:) changed_assignment.person.published_name, ] ) - if changed_assignment.person.sessions.scheduled.count == 0 + if ['declined', 'rejected'].include? changed_assignment.person.con_state fully_dropped.append [changed_assignment.person.published_name] end end @@ -159,7 +175,7 @@ def check_status_change(change:, live: false) return unless change[:changes]['status'] return if ['draft', 'dropped'].include?(change[:changes]['status'][0]) && ['draft', 'dropped'].include?(change[:changes]['status'][1]) - # Rails.logger.debug "********* STATUS CHANGE ....." + # Rails.logger.debug "********* STATUS CHANGE ..... #{change[:changes]['status']}" if ['draft', 'dropped'].include?(change[:changes]['status'][1]) if live return unless change[:object].published_session @@ -176,6 +192,7 @@ def check_status_change(change:, live: false) end if ['draft', 'dropped'].include?(change[:changes]['status'][0]) + # Rails.logger.debug "********* STATUS CHANGE ..... ADDD #{live}" session_added_row(@session_added, change) if live live_add(session: change[:object], sheet: @participants_add_drop) From bc6d42c136fac08e64a2e016ecf814653f5a9087 Mon Sep 17 00:00:00 2001 From: Henry Date: Mon, 15 Aug 2022 08:05:25 -0400 Subject: [PATCH 4/4] plan-712, plan-713, plan-714, plan-715 fixes for pub diffs --- .../reports/schedule_reports_controller.rb | 33 +++++++++++++------ app/services/change_service.rb | 5 +-- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/app/controllers/reports/schedule_reports_controller.rb b/app/controllers/reports/schedule_reports_controller.rb index 64e9fcd86..bf21849ad 100644 --- a/app/controllers/reports/schedule_reports_controller.rb +++ b/app/controllers/reports/schedule_reports_controller.rb @@ -95,6 +95,8 @@ def check_sessions_changed(changes:, live:) end end + Rails.logger.debug "*********** ST #{state_change_sessions}" + return state_change_sessions end @@ -121,11 +123,22 @@ def check_assignments_changed(changes:, state_change_sessions:) fully_dropped = [] changes.each do |id, change| - next if state_change_sessions.include? change[:item_id] - changed_assignment = change[:object] changed_assignment ||= SessionAssignment.find(change[:item_id]) if SessionAssignment.exists?(change[:item_id]) - session = changed_assignment.session + + next if state_change_sessions.include?(changed_assignment.session_id || changed_assignment.published_session_id) + + session = if changed_assignment + changed_assignment.session + else + session_id = change[:published_session_id] || change[:session_id] + Session.find session_id if Session.exists? session_id + end + next unless session + + person = change[:object].person + person ||= Session.find change[:person_id] if Session.exists? change[:person_id] + next unless person # Participants add/drop if change[:changes]['session_assignment_role_type_id'] && change[:event] != 'destroy' @@ -135,19 +148,19 @@ def check_assignments_changed(changes:, state_change_sessions:) [ session.title, '', - changed_assignment.person.published_name + person.published_name ] ) elsif (roles.include?(change[:changes]['session_assignment_role_type_id'][0])) @participants_add_drop.append_row( [ session.title, - changed_assignment.person.published_name, + person.published_name, ] ) - if ['declined', 'rejected'].include? changed_assignment.person.con_state - fully_dropped.append [change[:object].person.published_name] + if ['declined', 'rejected'].include? person.con_state + fully_dropped.append [person.published_name] end end end @@ -157,11 +170,11 @@ def check_assignments_changed(changes:, state_change_sessions:) @participants_add_drop.append_row( [ session.title, - changed_assignment.person.published_name, + person.published_name, ] ) - if ['declined', 'rejected'].include? changed_assignment.person.con_state - fully_dropped.append [changed_assignment.person.published_name] + if ['declined', 'rejected'].include? person.con_state + fully_dropped.append [person.published_name] end end end diff --git a/app/services/change_service.rb b/app/services/change_service.rb index 1d5921d99..bb7f47724 100644 --- a/app/services/change_service.rb +++ b/app/services/change_service.rb @@ -47,8 +47,6 @@ def self.get_changes(clazz:, type:, from:, to:, publishable_session_ids: nil) audits = audits.where("created_at >= ?", from) if from audits = audits.where("created_at <= ?", to) if to - # Rails.logger.debug "**** AUDITS #{audits.count}" - grouped_audits = audits.group_by {|a| a.item_id} grouped_audits.each do |key, item_audits| @@ -64,12 +62,11 @@ def self.get_changes(clazz:, type:, from:, to:, publishable_session_ids: nil) if publishable_session_ids next unless publishable_session_ids.include?(obj.session_id) end - changes[key] = {event: audit.event, object: obj, changes: audit.object_changes} + changes[key] = {item_id: audit.item_id, event: audit.event, object: obj, changes: audit.object_changes} end end end - # TODO: any way we can order by the session title ??? changes end