Skip to content
Snippets Groups Projects
Unverified Commit 4ae6acc8 authored by Felix Eckhofer's avatar Felix Eckhofer :man_dancing:
Browse files

Deal with canceled talks

When talks are removed from Fahrplan, move them to a dummy stage.
parent b3fc6123
No related branches found
No related tags found
No related merge requests found
...@@ -13,6 +13,10 @@ module Pretalx ...@@ -13,6 +13,10 @@ module Pretalx
response.success? or return Rails.logger.error "Failed to fetch schedule from #{url}" response.success? or return Rails.logger.error "Failed to fetch schedule from #{url}"
schedule = JSON.parse(response.body) schedule = JSON.parse(response.body)
return Rails.logger.error "Incomplete JSON received from #{url}" unless
schedule.dig('schedule', 'conference', 'rooms') &&
schedule.dig('schedule', 'conference', 'days')
# We keep a local hash of the stages, because the sessions reference stages by name instead of id # We keep a local hash of the stages, because the sessions reference stages by name instead of id
stages = {} stages = {}
schedule['schedule']['conference']['rooms'].each do |stage_data| schedule['schedule']['conference']['rooms'].each do |stage_data|
...@@ -21,10 +25,21 @@ module Pretalx ...@@ -21,10 +25,21 @@ module Pretalx
stage_.save! stage_.save!
end end
end end
# This is where canceled sessions are moved to, so we can still easily access them
canceled_stage = Stage.find_or_initialize_by(conference:, ref_id: 'c3lingo_canceled').tap do |stage_|
stage_.name = 'Canceled talk'
stage_.description = 'A dummy stage where talks move to when the disappear from the Fahrplan'
stage_.save!
end
# We build a list of sessions that exist in the current version of the fahrplan. That way we can move removed sessions to the "Canceled session" fake stage.
sessions = []
schedule['schedule']['conference']['days'].each do |day_data| schedule['schedule']['conference']['days'].each do |day_data|
day_data['rooms'].each do |stage_name, stage_data| day_data['rooms'].each do |stage_name, stage_data|
stage = stages[stage_name] stage = stages[stage_name]
stage_data.each do |session_data| stage_data.each do |session_data|
sessions << session_data['guid']
Session.find_or_initialize_by(conference:, ref_id: session_data['guid']).tap do |session| Session.find_or_initialize_by(conference:, ref_id: session_data['guid']).tap do |session|
session.stage = stage session.stage = stage
session.title = session_data['title'] session.title = session_data['title']
...@@ -48,6 +63,11 @@ module Pretalx ...@@ -48,6 +63,11 @@ module Pretalx
end end
end end
end end
Session.where(conference:).where.not(ref_id: sessions).each do |canceled|
canceled.stage = canceled_stage
canceled.save!
end
end end
def perform(conference_slug, *args) def perform(conference_slug, *args)
......
...@@ -50,7 +50,8 @@ class User < ApplicationRecord ...@@ -50,7 +50,8 @@ class User < ApplicationRecord
private private
def valid_invitation_token valid_tokens = ["gargamel"] def valid_invitation_token
valid_tokens = ["gargamel"]
errors.add(:invitation_token, "is invalid") unless valid_tokens.include?(invitation_token) errors.add(:invitation_token, "is invalid") unless valid_tokens.include?(invitation_token)
end end
end end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment