Files
zeekay 1b367e2b62 chore: rebase the tree onto upstream master
The tree was a debranded snapshot of upstream taken around 2026-02-20, and
upstream has moved about five months since. This replaces it with upstream
master, mechanically re-derived: bin/debrand does the rename, and the
pipeline and squashed migrations are restored from the shipped tree.

Not a merge. The previous import replaced the tree wholesale in a single
commit, so there is no shared content history to merge against. Reproducing
the rename on the new tree is what actually converges.

What survives: .hanzo/workflows, the Dockerfiles and bin/docker* entrypoints,
compose files, LLM.md, and insights/migrations. The squashed initial
migration is load-bearing — the live database records it by name, so
upstream's ~918 individual migrations cannot come back.

Nine products are dropped as unreferenced. Twenty-one more that we do not run
are kept anyway because the core app still imports them; unpicking those is a
refactor and does not belong in a rebase.

This base does not build yet, and the reasons are not in the rename:
upstream now wants Python 3.13.13 against our 3.12.12 and Django 5.2 against
our 4.2, and the dependency manifests still name upstream packages that we
republish under our own names. Those are decisions, not renames.
2026-08-01 15:44:40 -07:00

45 lines
2.0 KiB
Python

from __future__ import annotations
from typing import TYPE_CHECKING
from products.dashboards.backend.widget_specs.registry import get_widget_spec
if TYPE_CHECKING:
from insights.models.team import Team
def is_widget_availability_requirement_met(requirement: str, team: Team) -> bool | None:
"""Whether a single widget availability requirement is satisfied for the team.
Mirrors the frontend `isWidgetAvailabilityRequirementMet`. Returns None for an
unrecognized requirement so callers can treat it as "unknown" rather than "unmet".
"""
if requirement == "session_replay_enabled":
return bool(team.session_recording_opt_in)
if requirement == "exception_autocapture":
# Reflects the team opt-in only. The widget UI additionally treats "has received
# exceptions" as enabled, so a team ingesting exceptions without the opt-in flag
# reads as not-enabled here. We avoid the events-received check to keep this off
# the hot widget-add path (no Datastore query).
return bool(team.autocapture_exceptions_opt_in)
return None
def get_widget_feature_enabled(widget_type: str, team: Team) -> bool | None:
"""Whether the feature(s) a widget depends on are enabled for the team.
Recorded at widget-add time so we can tell whether the user saw real data or the
setup/custom view. Returns None when the widget declares no availability
requirements or any requirement is unrecognized.
"""
spec = get_widget_spec(widget_type)
if spec is None or not spec.availability_requirements:
return None
results = [is_widget_availability_requirement_met(req, team) for req in spec.availability_requirements]
# An unrecognized requirement is "unknown", not "met" — we can't confirm the feature is on, so
# don't silently drop it and risk emitting feature_enabled=True. Report the whole widget as unknown.
if any(result is None for result in results):
return None
return all(results)