Skip to content
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 6 commits into from
Nov 20, 2024
Merged

Local content item support #4366

merged 6 commits into from
Nov 20, 2024

Commits on Nov 19, 2024

  1. Configuration menu
    Copy the full SHA
    7d49f2d View commit details
    Browse the repository at this point in the history
  2. 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.
    KludgeKML committed Nov 19, 2024
    Configuration menu
    Copy the full SHA
    b78bb9d View commit details
    Browse the repository at this point in the history
  3. 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.
    KludgeKML committed Nov 19, 2024
    Configuration menu
    Copy the full SHA
    28e39bd View commit details
    Browse the repository at this point in the history
  4. 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.
    KludgeKML committed Nov 19, 2024
    Configuration menu
    Copy the full SHA
    80c3e74 View commit details
    Browse the repository at this point in the history
  5. 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.
    KludgeKML committed Nov 19, 2024
    Configuration menu
    Copy the full SHA
    50e0ee1 View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    41e22f2 View commit details
    Browse the repository at this point in the history