Problem/Motivation

PromoBarBlock::build() filters bars by the current user's roles and by the request time against start_date/end_date, but its cacheability covers neither:
- Roles: user.roles is missing from the cache contexts, so a bar restricted to one role is cached and served to all visitors, or a missing bar stays missing.
- Dates: there's no max-age, so a scheduled bar doesn't appear at its start date, and an expired one keeps showing until another cache clear.
- Countdown: whether a countdown is attached depends on the request time too.

Steps to reproduce

1. Create a bar restricted to the "authenticated" role.
2. Load a page as an authenticated user, then load it again as anonymous.
3. Result: the anonymous visitor sees the bar.
4. Create a bar with start_date 5 minutes from now and load the page.
5. Wait 5 minutes and load the page again.
6. Result: the bar doesn't appear.

Proposed resolution

- Add the user.roles cache context.
- Set max-age to the seconds until the nearest future start_date, end_date or countdown_date among the store's enabled bars, including bars not yet started.
- Keep the current list cache tags.

Remaining tasks

- MR
- Kernel tests for the contexts and the max-age

User interface changes

API changes

Data model changes

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

valic created an issue. See original summary.

valic’s picture

Category: Bug report » Feature request
valic’s picture

Title: Resolve visible promo bars outside the block (explicit path, token replacement, event context) » Promo bar block cache ignores customer roles and start/end dates
Category: Feature request » Bug report

wrong title

valic’s picture

Status: Active » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.