Skip to content

Commit

Permalink
Merge pull request #675 from ChicagoWorldcon/PLAN-737-diff-report-fixes
Browse files Browse the repository at this point in the history
plan-737 fixes for diffs (2.0.2)
  • Loading branch information
Gailbear authored Aug 21, 2022
2 parents a525038 + 2d85d19 commit 0b7de1a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 23 deletions.
25 changes: 8 additions & 17 deletions app/controllers/reports/schedule_reports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@ def schedule_diff
ChangeService.published_changes(from: from, to: to)
else
live = true
ChangeService.session_changes(from: from)
to ||= Time.now
ChangeService.session_changes(from: from, to: to)
end
fully_dropped = ChangeService.dropped_people(from: from, to: to)

to ||= Time.now

workbook = FastExcel.open(constant_memory: true)
init_sheets(workbook: workbook)

Expand Down Expand Up @@ -65,9 +64,8 @@ def check_sessions_changed(changes:, to:, live:)

if (change[:changes]['room_id'] || change[:changes]['start_time']) #&& !change[:changes]['status']
next if ignore_session_status_change?(change: change)
next if live && !change[:changes]['status'] && ['draft', 'dropped'].include?(change[:object].status)
next if live && !change[:changes]['status'] && ['draft', 'dropped'].include?(change[:recent].status)

# Rails.logger.debug "******** SESSION ADD/REMOVE #{change[:changes]} "
# If either room or time was added to the session
if room_added?(change) || start_time_added?(change)
session_added_row(@session_added, change, to)
Expand All @@ -94,6 +92,7 @@ def check_sessions_changed(changes:, to:, live:)
end

# If the object is scheduked and title or description was changed
# We need the object as it is now???
if change[:object].start_time && change[:object].room_id
check_status_change(change: change, to: to, live: live)

Expand Down Expand Up @@ -140,7 +139,7 @@ def check_assignments_changed(changes:, state_change_sessions:, to:)
roles = [moderator.id, participant.id]

changes.each do |id, change|
changed_assignment = change[:object]
changed_assignment = change[:recent]
changed_assignment ||= SessionAssignment.find(id) if SessionAssignment.exists?(id)

next unless changed_assignment
Expand Down Expand Up @@ -191,12 +190,7 @@ def check_status_change(change:, to:, live: false)
return if ignore_session_status_change?(change: change)

if session_status_change_to_drop?(change: change)
if live
return unless change[:object].published_session

live_drop(session: change[:object], sheet: @participants_add_drop)
end

live_drop(session: change[:object], sheet: @participants_add_drop) if live
session_removed_row(@session_removed, change)

return
Expand Down Expand Up @@ -307,10 +301,9 @@ def session_room_change_row(sheet, change)
end

def session_removed_row(sheet, change)
# TODO: if it is a destroy ....
sheet.append_row(
[
change[:object].title
change[:recent].title
]
)
end
Expand All @@ -321,7 +314,7 @@ def session_time_change_row(sheet, change)
# Rails.logger.debug "********* #{change[:changes]['start_time'][1]} => #{new_time.class} #{new_time.strftime("%H")}"
sheet.append_row(
[
change[:object].title,
change[:recent].title,
orig_time ? FastExcel.date_num(orig_time, orig_time.in_time_zone.utc_offset) : nil,
new_time ? FastExcel.date_num(new_time, new_time.in_time_zone.utc_offset) : nil
],
Expand Down Expand Up @@ -353,8 +346,6 @@ def session_added_row(sheet, change, to)
object.room&.name,
assignments[:moderators].collect{|a| a.person.published_name}.join("; "),
assignments[:participants].collect{|a| a.person.published_name}.join("; ")
# object.participant_assignments.where("session_assignment_role_type_id = ?", moderator).collect{|a| a.person.published_name}.join("; "),
# 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
Expand Down
25 changes: 19 additions & 6 deletions app/services/change_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,12 @@ def self.object_as_of(audit:, item_id:, item_type:, to:)
object_version = audit.where("item_id = ? and item_type = ? and created_at <= ?", item_id, item_type, to)
.order('created_at desc')
.first
return nil unless object_version
object = if object_version
object_version.reify
else
item_type.constantize.find(session_id) if item_type.constantize.exists?(id)
end

object = object_version.reify
return object
end

Expand All @@ -66,7 +69,7 @@ def self.assignments_for(session_id:, role_id:, to:)

res = []
grouped_audits.each do |key, item_audits|
change = self.comnbined_changes(item_audits: item_audits, type: SessionAssignment)
change = self.combined_changes(item_audits: item_audits, type: SessionAssignment, to: to)
res.concat [change[:object]] if self.assigned?(change: change, role_id: role_id)
end

Expand Down Expand Up @@ -119,7 +122,7 @@ def self.get_changes(clazz:, type:, from:, to:, publishable_session_ids: nil)
grouped_audits.each do |key, item_audits|
# Rails.logger.debug "**** AUDIT #{key} #{publishable_session_ids}"
# just in case we sort by date
change = self.comnbined_changes(item_audits: item_audits, type: type)
change = self.combined_changes(item_audits: item_audits, type: type, to: to)
if publishable_session_ids && change[:object].respond_to?(:session_id)
next unless publishable_session_ids.include?(change[:object].session_id)
end
Expand All @@ -130,21 +133,31 @@ def self.get_changes(clazz:, type:, from:, to:, publishable_session_ids: nil)
changes
end

def self.comnbined_changes(item_audits:, type:)
def self.combined_changes(item_audits:, type:, to:)
changes = nil

item_audits.sort{|a,b| a.created_at <=> b.created_at}.each do |audit|
# merge the change history
if changes
changes[:changes] = self.merge_change_set(to: changes[:changes], from: audit.object_changes)
else
# Get the most recent version (as of the to datetime)
recent = self.object_as_of(audit: audit.class, item_id: audit.item_id, item_type: audit.item_type, to: to)

# Get the old version of the object
obj = if audit.event == 'create'
type.find(audit.item_id) if type.exists?(audit.item_id)
else
audit.reify
end
changes = {item_id: audit.item_id, item_type: audit.item_type, event: audit.event, object: obj, changes: audit.object_changes}
changes = {
item_id: audit.item_id,
item_type: audit.item_type,
event: audit.event,
object: obj,
recent: recent,
changes: audit.object_changes
}
end
end

Expand Down

0 comments on commit 0b7de1a

Please sign in to comment.