mirror of
https://github.com/hanzoai/insights.git
synced 2026-10-30 16:15:31 +00:00
Mechanically re-derived: bin/debrand runs over a fresh import of posthog/posthog@fa1a9a60d4 (2026-08-06). The pipeline (.hanzo/workflows), the Dockerfiles and bin/docker* entrypoints, compose files, LLM.md and the squashed initial migration are restored from the shipped tree, same as the previous import. The prune's import-closure guard kept 21 products the new core now imports; dropping them is a refactor now, recorded rather than forced.
49 lines
1.7 KiB
Python
49 lines
1.7 KiB
Python
from typing import TYPE_CHECKING
|
|
|
|
import hanzo_insights
|
|
|
|
from insights.models.user import User
|
|
|
|
from .models import CodeInviteRedemption
|
|
|
|
if TYPE_CHECKING:
|
|
from insights.models.team.team import Team
|
|
|
|
|
|
def _is_flag_enabled(flag_key: str, user: User, team: "Team | None" = None) -> bool:
|
|
if not user.distinct_id:
|
|
return False
|
|
org = team.organization if team is not None else getattr(user, "organization", None)
|
|
kwargs: dict = {
|
|
"only_evaluate_locally": False,
|
|
"send_feature_flag_events": False,
|
|
}
|
|
if org is not None:
|
|
# The `tasks` flag's release conditions are mostly person-level (email allowlist + domain),
|
|
# but maybe we want org level conditions later on.
|
|
org_id = str(org.id)
|
|
kwargs["groups"] = {"organization": org_id}
|
|
kwargs["group_properties"] = {"organization": {"id": org_id}}
|
|
return bool(hanzo_insights.feature_enabled(flag_key, user.distinct_id, **kwargs))
|
|
|
|
|
|
def has_tasks_access(user: User) -> bool:
|
|
"""
|
|
User has access to Insights Desktop if the `tasks` feature flag is enabled for them
|
|
OR they have redeemed an invite code.
|
|
"""
|
|
if not user or not user.is_authenticated:
|
|
return False
|
|
if _is_flag_enabled("tasks", user):
|
|
return True
|
|
return CodeInviteRedemption.objects.filter(user=user).exists()
|
|
|
|
|
|
def has_loops_access(user: User, team: "Team | None" = None) -> bool:
|
|
"""Loops sits behind its own `loops` flag (see docs/LOOPS.md Rollout).
|
|
|
|
Not layered on `has_tasks_access` any more: `tasks` gates the Desktop waitlist, and the
|
|
backend no longer enforces that on task execution — only the Desktop client's own UI reads it.
|
|
"""
|
|
return _is_flag_enabled("loops", user, team)
|