From 13e9abf517119c920d5e2ef88e71bb0fb9fa331c Mon Sep 17 00:00:00 2001 From: David Bailey Date: Tue, 5 Jun 2018 21:49:56 -0700 Subject: [PATCH] make script levels redirect to 2017 versions again --- .../controllers/script_levels_controller.rb | 4 +- dashboard/app/models/script.rb | 43 +++++++++++++------ 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/dashboard/app/controllers/script_levels_controller.rb b/dashboard/app/controllers/script_levels_controller.rb index f98b1cdaa4f82..2fe756d1f6885 100644 --- a/dashboard/app/controllers/script_levels_controller.rb +++ b/dashboard/app/controllers/script_levels_controller.rb @@ -1,10 +1,12 @@ require 'cdo/script_config' require 'dynamic_config/dcdo' require 'dynamic_config/gatekeeper' +require 'cdo/script_constants' class ScriptLevelsController < ApplicationController check_authorization include LevelsHelper + include ScriptConstants # Default s-maxage to use for script level pages which are configured as # publicly cacheable. Used if the DCDO.public_proxy_max_age is not defined. @@ -67,7 +69,7 @@ def next def show @current_user = current_user && User.includes(:teachers).where(id: current_user.id).first authorize! :read, ScriptLevel - @script = Script.get_from_cache(params[:script_id]) + @script = Script.get_from_cache(params[:script_id], version_year: DEFAULT_VERSION_YEAR) # Redirect to the same script level within @script.redirect_to. # There are too many variations of the script level path to use diff --git a/dashboard/app/models/script.rb b/dashboard/app/models/script.rb index 59d60d4d807fc..2a90d2ee4e546 100644 --- a/dashboard/app/models/script.rb +++ b/dashboard/app/models/script.rb @@ -354,7 +354,7 @@ def cached self.class.get_from_cache(id) end - def self.get_without_cache(id_or_name) + def self.get_without_cache(id_or_name, version_year: nil) # Also serve any script by its new_name, if it has one. script = id_or_name && Script.find_by(new_name: id_or_name) return script if script @@ -369,36 +369,51 @@ def self.get_without_cache(id_or_name) unless is_id # We didn't find a script matching id_or_name. Next, look for a script # in the id_or_name script family to redirect to, e.g. csp1 --> csp1-2017. - script_with_redirect = Script.get_script_family_redirect(id_or_name) + script_with_redirect = Script.get_script_family_redirect(id_or_name, version_year: version_year) return script_with_redirect if script_with_redirect end - raise ActiveRecord::RecordNotFound.new("Couldn't find Script with id|name=#{id_or_name}") + raise ActiveRecord::RecordNotFound.new("Couldn't find Script with id|name|family_name=#{id_or_name}") end - def self.get_from_cache(id_or_name) - return get_without_cache(id_or_name) unless should_cache? - - script_cache.fetch(id_or_name.to_s) do + # Returns the script with the specified id, or a script with the specified + # name, or a redirect to the latest version of the script within the specified + # family. Also populates the script cache so that future responses will be cached. + # For example: + # get_from_cache('11') --> script_cache['11'] =