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

80 lines
3.0 KiB
Python

from django.db import models
from django.db.models import QuerySet
import structlog
from insights.models.file_system.constants import DEFAULT_SURFACE
from insights.models.file_system.file_system_mixin import FileSystemSyncMixin
from insights.models.file_system.file_system_representation import FileSystemRepresentation
from insights.models.team import Team
from insights.models.utils import CreatedMetaFields, UpdatedMetaFields, UUIDTModel
logger = structlog.get_logger(__name__)
class Link(FileSystemSyncMixin, CreatedMetaFields, UpdatedMetaFields, UUIDTModel):
"""
Links that redirect to a specified destination URL.
These are used for sharing URLs across the application.
"""
redirect_url = models.URLField(max_length=2048)
short_link_domain = models.CharField(max_length=255, help_text="Domain where the short link is hosted, e.g. script.gg")
short_code = models.CharField(
max_length=255, help_text="The unique code/path that identifies the short link, e.g. 'abc123'"
)
team = models.ForeignKey(
Team,
on_delete=models.CASCADE,
help_text="Team that owns this link",
)
description = models.TextField(null=True, blank=True)
class Meta:
indexes = [
models.Index(fields=["short_link_domain", "short_code"], name="domain_short_code_idx"),
models.Index(fields=["team_id"], name="team_id_idx"),
]
constraints = [
models.UniqueConstraint(
fields=["short_link_domain", "short_code"],
name="unique_short_link_domain_short_code",
)
]
db_table = "insights_link"
def __str__(self) -> str:
return f"{self.id} -> {self.redirect_url}"
@classmethod
def get_links_for_team(cls, team_id: int, limit: int = 100, offset: int = 0) -> QuerySet["Link"]:
"""
Get all links for a team with pagination.
Args:
team_id: The team ID to get links for
limit: Maximum number of links to return
offset: Offset for pagination
Returns:
A queryset of links for the team
"""
return cls.objects.filter(team_id=team_id).order_by("-created_at")[offset : offset + limit]
@classmethod
def get_file_system_unfiled(cls, team: "Team", surface: str = DEFAULT_SURFACE) -> QuerySet["Link"]:
base_qs = cls.objects.filter(team=team)
return cls._filter_unfiled_queryset(base_qs, team, type="link", ref_field="id", surface=surface)
def get_file_system_representation(self) -> FileSystemRepresentation:
return FileSystemRepresentation(
base_folder=self._get_assigned_folder("Unfiled/Links"),
type="link", # sync with APIScopeObject in scopes.py
ref=str(self.id),
name=self.short_code or "Untitled",
href=f"/link/{self.id}",
meta={
"created_at": str(self.created_at),
"created_by": self.created_by_id,
},
should_delete=False,
)