Skip to content

Commit

Permalink
Merge pull request #641 from ChicagoWorldcon/plan-724-diff-fixes
Browse files Browse the repository at this point in the history
PLAN-724 various fixes to diff logic (2.0.1)
  • Loading branch information
Gailbear authored Aug 17, 2022
2 parents d885b58 + 3e3cdcf commit d3e83ef
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 34 deletions.
20 changes: 11 additions & 9 deletions app/controllers/publication_dates_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@ class PublicationDatesController < ResourceController

def reset
# Make sure that people can not publish etc while we clean up
PublicationStatus.last.update(status: 'inprogress')
if PublicationStatus.last
PublicationStatus.last.update(status: 'inprogress')

# Get rid of published data first
PublishedSession.destroy_all
# Get rid of published data first
PublishedSession.destroy_all

# Then get rid of the audit
Audit::PublishedSessionVersion.delete_all
# Then get rid of the audit
Audit::PublishedSessionVersion.delete_all

# Then remove caches, dates, and status
PublishSnapshot.delete_all
PublicationDate.delete_all
PublicationStatus.delete_all
# Then remove caches, dates, and status
PublishSnapshot.delete_all
PublicationDate.delete_all
PublicationStatus.delete_all
end

render status: :ok,
json: { message: 'publication reset' }.to_json,
Expand Down
43 changes: 20 additions & 23 deletions app/controllers/reports/schedule_reports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,13 @@ def check_sessions_changed(changes:, live:)
changes.values.sort{|a,b| (a[:object] ? a[:object].title : '') <=> (b[:object] ? b[:object].title : '')}.each do |change|
next unless change[:object]

if change[:object] && session_status_change_to_publishable?(change: change) || session_status_change_to_drop?(change: change)
state_change_sessions << change[:object].id
end

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

# Rails.logger.debug "******** SESSION ADD/REMOVE #{change[:changes]} "
if room_added?(change) || start_time_added?(change)
Expand All @@ -81,12 +86,7 @@ def check_sessions_changed(changes:, live:)
end

if change[:object].start_time && change[:object].room_id
session_id = check_status_change(change: change, live: live)

if session_id
state_change_sessions << session_id
next
end
check_status_change(change: change, live: live)

if change[:changes]['title']
session_title_change_row(@session_title_changed, change)
Expand All @@ -98,7 +98,6 @@ def check_sessions_changed(changes:, live:)
end

# Rails.logger.debug "*********** ST #{state_change_sessions}"

return state_change_sessions
end

Expand Down Expand Up @@ -194,43 +193,41 @@ 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 ignore_session_status_change?(change: change)

# Rails.logger.debug "********* STATUS CHANGE ..... #{change[:changes]['status']}"
if ['draft', 'dropped'].include?(change[:changes]['status'][1])
if session_status_change_to_drop?(change: change)
if live
return unless change[:object].published_session

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

return change[:object].id
else
session_removed_row(@session_removed, change)
end

session_removed_row(@session_removed, change)

return
end

if ['draft', 'dropped'].include?(change[:changes]['status'][0])
if session_status_change_to_publishable?(change: change)
# Rails.logger.debug "********* STATUS CHANGE ..... ADDD #{live}"
session_added_row(@session_added, change)
if live
live_add(session: change[:object], sheet: @participants_add_drop)

return change[:object].id
end
live_add(session: change[:object], sheet: @participants_add_drop) if live

return
end
end

def ignore_session_status_change?(change:)
['draft', 'dropped'].include?(change[:changes]['status'][0]) && ['draft', 'dropped'].include?(change[:changes]['status'][1])
change[:changes]['status'] && ['draft', 'dropped'].include?(change[:changes]['status'][0]) && ['draft', 'dropped'].include?(change[:changes]['status'][1])
end

def session_status_change_to_publishable?(change:)
change[:changes]['status'] && ['draft', 'dropped'].include?(change[:changes]['status'][0]) && ['reviewed', 'revised'].include?(change[:changes]['status'][1])
end

def session_status_change_to_drop?(change:)
change[:changes]['status'] && ['draft', 'dropped'].include?(change[:changes]['status'][1]) && ['reviewed', 'revised'].include?(change[:changes]['status'][0])
end

def init_sheets(workbook:)
@session_time_changed = workbook.add_worksheet("Session Time Changed")
Expand Down
9 changes: 7 additions & 2 deletions app/services/change_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,13 @@ def self.get_changes(clazz:, type:, from:, to:, publishable_session_ids: nil)
if changes[key]
changes[key][:changes] = self.merge_change_set(to: changes[key][:changes], from: audit.object_changes)
else
obj = type.find(audit.item_id) if audit.event != 'destroy' && type.exists?(audit.item_id)
obj ||= audit.reify
# 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
# obj = audit.reify
if publishable_session_ids
next unless publishable_session_ids.include?(obj.session_id)
end
Expand Down

0 comments on commit d3e83ef

Please sign in to comment.