-
Notifications
You must be signed in to change notification settings - Fork 20
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
Local content item support #4366
Merged
Merged
Commits on Nov 19, 2024
-
Configuration menu - View commit details
-
Copy full SHA for 7d49f2d - Browse repository at this point
Copy the full SHA 7d49f2dView commit details -
Add ContentItemLoader class and tests
- ContentItemLoader replaces direct calls to GdsApi.content_store.content_item, (of which there are only 4 in the rest of the codebase), and provides two functions. - First, it centralises caching of calls, so that that can be removed from the FormatRoutingConstraint classes and using request.env to save those values can be simplified. - Second, if the ALLOW_LOCAL_CONTENT_ITEM_OVERRIDE env var is set true, it allows loading content items from a file in /lib/data/local-content-items, which gives developers an extra option for local development or preview apps when working with content types that have not crystalised yet or where publishing support is not yet present. It should not be used in production. - The load method is slightly odd in that it will either return an API response or an exception (note: return the exception, not raise it!). This allows us to cache errors in a similar way to the way the routing constraints used to. It might be there are better ways to handle this, but for the moment this is a minimal change to maintain the current behaviour.
Configuration menu - View commit details
-
Copy full SHA for b78bb9d - Browse repository at this point
Copy the full SHA b78bb9dView commit details -
Add a helper to all tests that resets the ContentItemLoader cache
- Because the cache is at class level, it's very aggressive and would otherwise interfere with what people would normally expect about tests (ie that in two unrelated tests you could use the same slug to point to different things). So we default here to just clearing the cache before each test. - Do it manually in shared tests, which have their own setup that might conflict with "before" blocks in the system specs that call them.
Configuration menu - View commit details
-
Copy full SHA for 28e39bd - Browse repository at this point
Copy the full SHA 28e39bdView commit details -
Update routing constraints to use ContentItemLoader
- Now that ContentItemLoader is handling the caching, we can remove that layer of code / responsibility from the constraints. - ContentItemLoader either returns the adapter response or the error that it caught, so querying for those classes gives us a "was it or wasn't it an error" check. - We also simplify the spec tests slightly to use more idiomatic RSpec.
Configuration menu - View commit details
-
Copy full SHA for 80c3e74 - Browse repository at this point
Copy the full SHA 80c3e74View commit details -
Update controllers to use ContentItemLoader
- Now that ContentItemLoader handles caching we can use that rather than the stuff that the format constraints were putting into the request env. - LandingPageController's scaffolding is still needed for the moment, but we can remove it soon (since part of this project is about replacing that scaffolding with a more generally useful one). - Content items in controllers are now always loaded from `content_item_path`, which defaults to the request path, and is overridden if necessary for items with multiple paths on one content item.
Configuration menu - View commit details
-
Copy full SHA for 50e0ee1 - Browse repository at this point
Copy the full SHA 50e0ee1View commit details -
Configuration menu - View commit details
-
Copy full SHA for 41e22f2 - Browse repository at this point
Copy the full SHA 41e22f2View commit details
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.