New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update script_level URLs from /stage to /lessons and /puzzle to /levels #38802
Conversation
This reverts commit 2f189d4.
e1acc7c
to
1d842a2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really understand what's going on with the translation stuff but the core route changes look good to me and I'm assuming drone will catch any issues with the tests.
Thank you so much for doing this! This is difficult, tedious work and this is a huge step forward towards unifying our urls and getting rid of the 'stage' terminology in our codebase.
dashboard/config/routes.rb
Outdated
## TODO: Once we move levels over to /lessons as well combine the routing rules | ||
resources :lessons, only: [:show], param: 'position' do | ||
# /s/xxx/lessons/yyy | ||
resources :lessons, only: [:show], path: "/lessons", param: 'position', format: false do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious, is it necessary to specify path
here (since it matches the resource name)?
Also, I noticed that we also have edit and update actions defined for lessons above on 297. Is it intentional that these are separate? (I could imagine us wanting to keep those closer to the other edit/update entries.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll try removing path since we are no longer using stage you are probably right its no longer needed. I'll also take a look at the other lesson entries to see if I can bring them closer together
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I know why I left the other lessons stuff separate. Its because when you are editing or updating you are not using the nested route inside the script like we do for showing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice job pulling this all together, Dani! I have some comments around testing and caching.
I think it will also be important to think about "deployment strategy", i.e. is it safe to deploy this entire PR at once, or is there some place where we need to point people to a new route before taking away an old one. since you are replacing the old routes with redirects, I think we are generally good there. Just thought I'd mention this in case it gives other reviewers any ideas.
@@ -41,7 +41,7 @@ class HttpCache | |||
oceans | |||
).map do |script_name| | |||
# Most scripts use the default route pattern. | |||
[script_name, "/s/#{script_name}/stage/*"] | |||
[script_name, "/s/#{script_name}/lessons/*"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should consider whether we want to cache requests for the original /s/.../stage/...
paths. @sureshc , any ideas how we can figure out if more complex patterns are allowed here other than a trailing wildcard? we'd ideally want something like /s/[a-z0-9-]+/stage/*
.
I think this might be https://docs.aws.amazon.com/cloudfront/latest/APIReference/API_CacheBehavior.html --> PathPattern, in which case perhaps we could do /s/*/stage/*/puzzle/*
. However, I'm not sure if (1) those are the right docs or (2) if we use this same config somewhere else outside of cloudfront.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suresh provided some additional context in slack:
Suresh (he/him):lightning: 6 hours ago
I believe so. Here’s where we generate the cache behavior CloudFormation template logiccode-dot-org/lib/cdo/aws/cloudfront.rb
Line 229 in 98b78da
def self.cache_behavior(behavior_config, path=nil)
Suresh (he/him):lightning: 6 hours ago
I always start with the CloudFormation template reference for a particular AWS service https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cloudfront-distribution-cachebehavior.html
I think this means we could update http_cache.rb to filter on /s/*/stage/*/puzzle/*
to maximize the caching efficiency of those pages.
I am going to suggest that we try to do this in a follow-up task. this PR is already quite large and complex, and I don't think we will suffer any irreversible consequences by failing to cache these responses for a short period of time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tracked to follow up: https://codedotorg.atlassian.net/browse/PLAT-982
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get '/s/csp6-2020/lockable/1(*all)', to: redirect(path: '/s/csp6-2020/lessons/6%{all}') | ||
get '/s/csp7-2020/lockable/1(*all)', to: redirect(path: '/s/csp7-2020/lessons/11%{all}') | ||
get '/s/csp9-2020/lockable/1(*all)', to: redirect(path: '/s/csp9-2020/lessons/9%{all}') | ||
get '/s/csp10-2020/lockable/1(*all)', to: redirect(path: '/s/csp10-2020/lessons/14%{all}') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should consider whether these redirect requests should be cached. they should be easy enough to add to http_cache.rb, so that's what I would recommend. this could be done in a separate PR after this one. better to do after than before, since this PR changes the redirect destination, so might as well avoid ever telling browsers to cache the old value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tracked to follow up: https://codedotorg.atlassian.net/browse/PLAT-960
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these redirects use status code 301, which some browsers cache indefinitely. I think we are good here, but here is me thinking aloud through a couple scenarios:
-
the redirect from /s/csp1-2020/lockable/2/puzzle/1 to /s/csp1-2020/stage/14/puzzle/1 may be cached by some browsers. the other routes you are adding in this PR will then redirect from /s/csp1-2020/stage/14/puzzle/1 to /s/csp1-2020/lessons/14/levels/1. this seems correct.
-
if someone hits /s/csp1-2020/lockable/2/levels/1, it would be bad if the old redirect were cached, because that would send them to /s/csp1-2020/stage/14/levels/1, which would 404, because stage + levels is never handled. It seems very unlikely for someone to have this redirect cached though, because they would only be able to cache the response to an individual request, not the entire pattern of
/s/csp1-2020/lockable/2(*all)
, and there is no point in time at which our servers should ever have sent anyone to/s/csp1-2020/lockable/2/levels/1
. This is because we stopped sending people anywhere within/s/csp1-2020/lockable/2/
in Send users to new CSP 20-21 URLs for lockable lessons with lesson plans and redirect old URL #39128, and we won't be sending anyone to /levels/ urls until after this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for thinking this through!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work Dani! I am nervous about this change, but I've checked all the things i can think of to check and I can't think of any other precautions to take. LGTM!
@@ -41,7 +41,7 @@ class HttpCache | |||
oceans | |||
).map do |script_name| | |||
# Most scripts use the default route pattern. | |||
[script_name, "/s/#{script_name}/stage/*"] | |||
[script_name, "/s/#{script_name}/lessons/*"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suresh provided some additional context in slack:
Suresh (he/him):lightning: 6 hours ago
I believe so. Here’s where we generate the cache behavior CloudFormation template logiccode-dot-org/lib/cdo/aws/cloudfront.rb
Line 229 in 98b78da
def self.cache_behavior(behavior_config, path=nil)
Suresh (he/him):lightning: 6 hours ago
I always start with the CloudFormation template reference for a particular AWS service https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cloudfront-distribution-cachebehavior.html
I think this means we could update http_cache.rb to filter on /s/*/stage/*/puzzle/*
to maximize the caching efficiency of those pages.
I am going to suggest that we try to do this in a follow-up task. this PR is already quite large and complex, and I don't think we will suffer any irreversible consequences by failing to cache these responses for a short period of time.
get '/s/csp6-2020/lockable/1(*all)', to: redirect(path: '/s/csp6-2020/lessons/6%{all}') | ||
get '/s/csp7-2020/lockable/1(*all)', to: redirect(path: '/s/csp7-2020/lessons/11%{all}') | ||
get '/s/csp9-2020/lockable/1(*all)', to: redirect(path: '/s/csp9-2020/lessons/9%{all}') | ||
get '/s/csp10-2020/lockable/1(*all)', to: redirect(path: '/s/csp10-2020/lessons/14%{all}') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these redirects use status code 301, which some browsers cache indefinitely. I think we are good here, but here is me thinking aloud through a couple scenarios:
-
the redirect from /s/csp1-2020/lockable/2/puzzle/1 to /s/csp1-2020/stage/14/puzzle/1 may be cached by some browsers. the other routes you are adding in this PR will then redirect from /s/csp1-2020/stage/14/puzzle/1 to /s/csp1-2020/lessons/14/levels/1. this seems correct.
-
if someone hits /s/csp1-2020/lockable/2/levels/1, it would be bad if the old redirect were cached, because that would send them to /s/csp1-2020/stage/14/levels/1, which would 404, because stage + levels is never handled. It seems very unlikely for someone to have this redirect cached though, because they would only be able to cache the response to an individual request, not the entire pattern of
/s/csp1-2020/lockable/2(*all)
, and there is no point in time at which our servers should ever have sent anyone to/s/csp1-2020/lockable/2/levels/1
. This is because we stopped sending people anywhere within/s/csp1-2020/lockable/2/
in Send users to new CSP 20-21 URLs for lockable lessons with lesson plans and redirect old URL #39128, and we won't be sending anyone to /levels/ urls until after this PR.
|
||
# This is a a temporary method to help with moving translations onto the new level urls. To start this will | ||
# keep translations on the old URL until foundations can do the work to bring them over to the new url | ||
def build_script_level_path_for_translations(script_level) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed this doesn't have the exact same code as the old build_script_level_path
. Is that intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it is. I noticed that the translations call to build_script_level_path was not using the second paramater param
and that means it would never hit certain cases. So I just kept the cases that it would hit
@daynew @davidsbailey @wjordan @sureshc @jamescodeorg I'm planning to ship this change this week once PM gives the thumbs up on one last thing. Is there anything from you all that you would like me to check before merging? Any other considerations here? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! I've tagged Suresh and Will in places related to caching. If they don't have time to look this week, then it should be ok to proceed, and we can address any concerns in follow-up work.
@@ -41,7 +41,7 @@ class HttpCache | |||
oceans | |||
).map do |script_name| | |||
# Most scripts use the default route pattern. | |||
[script_name, "/s/#{script_name}/stage/*"] | |||
[script_name, "/s/#{script_name}/lessons/*"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get '/s/csp6-2020/lockable/1(*all)', to: redirect(path: '/s/csp6-2020/lessons/6%{all}') | ||
get '/s/csp7-2020/lockable/1(*all)', to: redirect(path: '/s/csp7-2020/lessons/11%{all}') | ||
get '/s/csp9-2020/lockable/1(*all)', to: redirect(path: '/s/csp9-2020/lessons/9%{all}') | ||
get '/s/csp10-2020/lockable/1(*all)', to: redirect(path: '/s/csp10-2020/lessons/14%{all}') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Proposal Of URL Changes
As we bring content over from CB to LB we have been considering how to improve our URL scheme to better support our curriculum model. The new lesson plans which have been brought over are going to live at
/s/<script name and year>/lesson/<relative_position>
. However current the levels that will be in these lessons are at/s/<script name and year>/stage/<relative_position>/puzzle/<position>
. In order to make our URLs more consistent we would like to move the levels to be at/s/<script name and year>/lessons/<relative_position>/levels/<position>
.Summary
.../stage/...
to.../lessons/...
and.../puzzle/...
to.../levels/...
Overview of Code Changes
The core of the change in this PR is in routes.rb. That is where the updates to the script_level routes can be found as well as the new redirects that will redirect old URLs to the new URL.
0cdd2aa creates a helper method so that level keys for translations stay on the old URLs for now until foundations has a chance to move them over to the new system.
All of the other changes were to get tests passing. There are A LOT of UI tests where we are updating the URL that we are navigating to.
Links
Testing story
We have a lot of existing tests covering script levels especially in script_levels_controller_test.rb so I am relying on those for unit testing. We will also be doing 2 bug bashes of this before launching.
Reviewer Checklist: