Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ ONCALL_VERSION=
ONCALL_APP_NAME=On-call
ONCALL_APP_SUBTITLE=

# Optional decoration of the interface, off while this is empty. List the
# packs once and leave the line alone: each knows its own days. `winter` (a
# hat on the logo, lights and snow on the "Teraz" strip, a winter night on the
# sign-in screen, a sleigh on the generator's progress bar) shows from
# 6 December to 6 January; `doodles` puts a small drawing on the logo on seven
# days of the year. Both: ONCALL_ACCENT=winter,doodles
ONCALL_ACCENT=
# Another winter season, as MM-DD, both or neither; it may run across New Year.
# ONCALL_ACCENT_FROM=12-01
# ONCALL_ACCENT_UNTIL=01-06

# Local development default, publicly known. Every non-local host sets a unique
# POSTGRES_PASSWORD (below) before the first start and the same password here;
# user and database match POSTGRES_USER and POSTGRES_DB. Changing it on an
Expand Down
37 changes: 36 additions & 1 deletion DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,40 @@ in the light theme), today a 12 % blue wash and the day-number pill in
action blue, a gap in staffing a pink wash. In the sticky header every wash
lies on an opaque `s2`. The start of a week is a 2 px left line.

## Seasonal accent
An opt-in exception to the calm of everything above, off unless the
deployment sets `ONCALL_ACCENT` (`docs/wdrozenie/uruchomienie.md`, "Ozdoby
sezonowe"). The API names what today carries, the shell and the sign-in
screen write it to `data-accent` on `<html>` (`src/accent.ts`), and every
drawing lives in one lazily loaded chunk with its own stylesheet
(`src/decor/`).

`winter` puts a hat on the logo mark, snow inside the "Teraz" strip and a
garland of lights under it, a night sky with a tree of role marks on the
sign-in screen, and a sleigh ahead of the generator's progress bar.
`doodles` puts one small drawing on the logo mark on seven days of the year.
The garland and the snow of the strip are on the desktop "Teraz" strip only:
the top bar of a phone shows only the hat or the day's doodle on the mark,
because a garland under that sticky bar would cover content.

### Named Rules
**The Frame, Not the Instrument Rule.** The accent decorates the frame: the
rail, the strip, the sign-in screen, a progress bar. It never draws on the
duty matrix, never covers text or a control, and never borrows a role or
state colour as a state.
**The Decoration Only Rule.** Every drawing carries the class `fx`, is
`aria-hidden`, takes no pointer events and takes its colours from
`tokens.css`: the accent's own `--fx-*` ones, and the palette where they
already match. `decor.css` styles it on a screen only, so a printout, the
e-mails and the exports are the plain interface.
**The Stillness Rule.** Nothing of it moves under `prefers-reduced-motion`
(the snow is a still scatter of flakes), and what moves without end (the
snow and the lights of the strip) can be turned off by each person in the
account menu. The sign-in screen, which has no such switch yet, stops moving
by itself.
**The Insiders Rule.** A share-link session, opened by people outside the
team, is never decorated.

## Do's and Don'ts

### Do:
Expand Down Expand Up @@ -583,7 +617,8 @@ lies on an opaque `s2`. The start of a week is a 2 px left line.
- **Don't** use the action blue as a text colour or a section background;
the text blue is `--sig`.
- **Don't** introduce a second accent, gradients (apart from the radial
sign-in background) or coloured icons; icons are monochrome, 24 px.
sign-in background) or coloured icons; icons are monochrome, 24 px. The
one exception is the opt-in seasonal accent, under its own rules above.
- **Don't** add a component library or custom date pickers; fields are
native (`AGENTS.md`).
- **Don't** format numbers or name days inside a component; everything
Expand Down
16 changes: 16 additions & 0 deletions backend/contracts/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -3408,6 +3408,21 @@
"PublicConfigResponse": {
"description": "Instance settings the UI needs before anyone is logged in.",
"properties": {
"accent": {
"items": {
"enum": [
"winter",
"sparkle",
"doughnut",
"heart",
"egg",
"flip"
],
"type": "string"
},
"title": "Accent",
"type": "array"
},
"app_name": {
"title": "App Name",
"type": "string"
Expand Down Expand Up @@ -3446,6 +3461,7 @@
"sso_enabled",
"app_name",
"app_subtitle",
"accent",
"version",
"audit_retention_days",
"login_audit_retention_days",
Expand Down
70 changes: 70 additions & 0 deletions backend/src/oncall/accent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
"""The opt-in seasonal accent: which decorations the interface draws today.

A deployment lists packs in ``ONCALL_ACCENT``; none is the default. Each pack
carries its own calendar, so the setting is written once and left, and the
answer changes with the Warsaw business date: ``winter`` holds through its
season, ``doodles`` names the one drawing its day puts on the logo mark.
The interface draws what ``/api/v1/config`` lists and keeps no calendar of
its own.
"""

from collections.abc import Collection
from datetime import date, timedelta
from typing import Literal

from oncall.workdays import polish_holidays

#: What a deployment may list in ONCALL_ACCENT.
AccentPack = Literal["winter", "doodles"]
#: What the interface may be told to draw: `winter`, or the day's doodle.
Accent = Literal["winter", "sparkle", "doughnut", "heart", "egg", "flip"]

#: The winter season of a deployment that names no bounds of its own, as
#: inclusive MM-DD: St Nicholas' Day to Epiphany.
WINTER_SEASON = ("12-06", "01-06")

#: Fat Thursday, the last Thursday before Lent.
_FAT_THURSDAY_BEFORE_EASTER = timedelta(days=52)


def easter_sunday(year: int) -> date:
"""Easter by the statutory calendar, where its Sunday and Monday are the
only holidays between the earliest and the latest date Easter can have."""
return min(polish_holidays(date(year, 3, 22), date(year, 4, 25)))


def in_season(day: date, starts: str, ends: str) -> bool:
"""Whether the day lies within inclusive MM-DD bounds. A season that
starts later in the year than it ends runs across New Year."""
today = day.strftime("%m-%d")
if starts <= ends:
return starts <= today <= ends
return today >= starts or today <= ends


def doodle_of(day: date) -> Accent | None:
"""The drawing this day puts on the logo mark, on the seven days that
have one. A movable feast wins the day it shares with a fixed one."""
easter = easter_sunday(day.year)
month_day = (day.month, day.day)
if month_day in ((12, 31), (1, 1)):
return "sparkle"
if day == easter - _FAT_THURSDAY_BEFORE_EASTER:
return "doughnut"
if month_day == (2, 14):
return "heart"
if easter <= day <= easter + timedelta(days=1):
return "egg"
if month_day == (4, 1):
return "flip"
return None


def accents_on(day: date, packs: Collection[str], season: tuple[str, str]) -> list[Accent]:
"""What the listed packs draw on this day; `season` bounds `winter` only."""
active: list[Accent] = []
if "winter" in packs and in_season(day, *season):
active.append("winter")
if "doodles" in packs and (doodle := doodle_of(day)):
active.append(doodle)
return active
61 changes: 59 additions & 2 deletions backend/src/oncall/config.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import os
import re
from datetime import date
from functools import lru_cache
from math import ceil
from pathlib import Path
from typing import Self
from typing import Annotated, Self

from cryptography.fernet import Fernet
from pydantic import Field, SecretStr, field_validator, model_validator
from pydantic_settings import BaseSettings, SettingsConfigDict
from pydantic_settings import BaseSettings, NoDecode, SettingsConfigDict

from oncall.accent import WINTER_SEASON, AccentPack

CGROUP_ROOT = Path("/sys/fs/cgroup")

Expand Down Expand Up @@ -73,6 +77,16 @@ class Settings(BaseSettings):
#: public repository carries no organisation name.
app_name: str = "On-call"
app_subtitle: str = ""
#: Opt-in decoration of the interface (`oncall.accent`): the packs this
#: deployment allows, comma-separated. Empty, the default, draws nothing.
#: It is written once and left, because each pack knows its own days:
#: `winter` holds through its season, 6 December to 6 January unless both
#: bounds below name another (MM-DD, inclusive, across New Year when the
#: first is the later date); `doodles` puts a small drawing on the logo
#: mark on seven days of the year and ignores the bounds.
accent: Annotated[tuple[AccentPack, ...], NoDecode] = ()
accent_from: str = ""
accent_until: str = ""
#: The release this process runs, shown in the interface. The image bakes
#: in the git tag it was built from (backend/Dockerfile, ARG ONCALL_VERSION
#: from release.yml), so this names what really runs even when the host's
Expand Down Expand Up @@ -256,6 +270,32 @@ def _blank_version_means_dev(cls, value: str) -> str:
"""An empty ONCALL_VERSION (a copied .env with the line unset) is a dev build."""
return value.strip() or DEV_VERSION

@field_validator("accent", mode="before")
@classmethod
def _accent_is_a_comma_separated_list(cls, value: object) -> object:
"""`winter,doodles` as the environment writes it; blank is none."""
if isinstance(value, str):
return tuple(name.strip() for name in value.split(",")) if value.strip() else ()
return value

@field_validator("accent_from", "accent_until")
@classmethod
def _accent_bound_is_a_day_of_the_year(cls, value: str) -> str:
"""Blank is unset; anything else is a day of the year, 29 February
included, in two digits each so two bounds compare as text."""
if not value.strip():
return ""
try:
if not re.fullmatch(r"\d{2}-\d{2}", value, re.ASCII):
raise ValueError
date.fromisoformat(f"2000-{value}")
except ValueError:
raise ValueError(
"ONCALL_ACCENT_FROM and ONCALL_ACCENT_UNTIL are days of the year written "
"MM-DD, such as 12-06."
) from None
return value

@field_validator("solver_workers", mode="before")
@classmethod
def _blank_solver_workers_is_unset(cls, value: object) -> object:
Expand Down Expand Up @@ -316,6 +356,17 @@ def _secrets_key_is_fernet_keys(cls, value: SecretStr | None) -> SecretStr | Non
) from None
return SecretStr(",".join(keys))

@model_validator(mode="after")
def _accent_bounds_come_in_pairs(self) -> Self:
"""Half a season has no meaning, and guessing the other half would
decorate on days nobody chose."""
if bool(self.accent_from) != bool(self.accent_until):
raise ValueError(
"Set both ONCALL_ACCENT_FROM and ONCALL_ACCENT_UNTIL to move the winter "
"season, or leave both empty for 6 December to 6 January."
)
return self

@model_validator(mode="after")
def _smtp_credentials_come_in_pairs(self) -> Self:
"""A username alone would log in with an empty password, and a
Expand Down Expand Up @@ -367,6 +418,12 @@ def _https_requires_secure_cookie(self) -> Self:
)
return self

@property
def accent_season(self) -> tuple[str, str]:
"""The inclusive MM-DD bounds of `winter`: this deployment's own, or
the pack's."""
return (self.accent_from, self.accent_until) if self.accent_from else WINTER_SEASON


@lru_cache
def get_settings() -> Settings:
Expand Down
6 changes: 6 additions & 0 deletions backend/src/oncall/presentation/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from pydantic import BaseModel

from oncall.accent import Accent


class HealthResponse(BaseModel):
status: str = "ok"
Expand All @@ -16,6 +18,10 @@ class PublicConfigResponse(BaseModel):
#: Brand shown before login: the product name and its optional subtitle.
app_name: str
app_subtitle: str
#: The decorations to draw today (`oncall.accent`): `winter` through its
#: season, and the day's doodle for the logo mark. Empty on every day of
#: a deployment that lists no pack.
accent: list[Accent]
#: The release running, as its image was built: `1.2.0`, `1.3.0-rc.1`,
#: or `dev` for a build from a checkout.
version: str
Expand Down
3 changes: 3 additions & 0 deletions backend/src/oncall/routes/system.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from fastapi import APIRouter

from oncall.accent import accents_on
from oncall.config import get_settings
from oncall.domain.clock import business_today
from oncall.notifications.service import UNDO_WINDOW
from oncall.presentation.system import HealthResponse, PublicConfigResponse

Expand All @@ -20,6 +22,7 @@ async def public_config() -> PublicConfigResponse:
sso_enabled=settings.sso_enabled,
app_name=settings.app_name,
app_subtitle=settings.app_subtitle,
accent=accents_on(business_today(), settings.accent, settings.accent_season),
version=settings.version,
audit_retention_days=settings.retention_audit_days,
login_audit_retention_days=settings.retention_login_audit_days,
Expand Down
1 change: 1 addition & 0 deletions backend/tests/contract/test_http_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ async def test_public_response_and_validation_envelopes(client) -> None:
"sso_enabled": False,
"app_name": "On-call",
"app_subtitle": "",
"accent": [],
"version": "dev",
"audit_retention_days": 365,
"login_audit_retention_days": 90,
Expand Down
Loading
Loading