mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2026-01-04 01:46:54 +10:00
This commit completes the simplification of the ID system by: - Removing the ABID (ArchiveBox ID) system entirely - Removing the base_models/abid.py file - Removing KVTag model in favor of the existing Tag model in core/models.py - Simplifying all models to use standard UUIDv7 primary keys - Removing ABID-related admin functionality - Cleaning up commented-out ABID code from views and statemachines - Deleting migration files for ABID field removal (no longer needed) All models now use simple UUIDv7 ids via `id = models.UUIDField(primary_key=True, default=uuid7)` Note: Old migrations containing ABID references are preserved for database migration history compatibility. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
52 lines
1.8 KiB
Python
52 lines
1.8 KiB
Python
__package__ = 'archivebox.api'
|
|
|
|
import secrets
|
|
from uuid import uuid7
|
|
from datetime import timedelta
|
|
|
|
from django.conf import settings
|
|
from django.db import models
|
|
from django.utils import timezone
|
|
from django_stubs_ext.db.models import TypedModelMeta
|
|
from signal_webhooks.models import WebhookBase
|
|
|
|
|
|
def generate_secret_token() -> str:
|
|
return secrets.token_hex(16)
|
|
|
|
|
|
class APIToken(models.Model):
|
|
id = models.UUIDField(primary_key=True, default=uuid7, editable=False, unique=True)
|
|
created_by = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, default=None, null=False)
|
|
created_at = models.DateTimeField(default=timezone.now, db_index=True)
|
|
modified_at = models.DateTimeField(auto_now=True)
|
|
token = models.CharField(max_length=32, default=generate_secret_token, unique=True)
|
|
expires = models.DateTimeField(null=True, blank=True)
|
|
|
|
class Meta(TypedModelMeta):
|
|
verbose_name = "API Key"
|
|
verbose_name_plural = "API Keys"
|
|
|
|
def __str__(self) -> str:
|
|
return self.token
|
|
|
|
@property
|
|
def token_redacted(self):
|
|
return f'************{self.token[-4:]}'
|
|
|
|
def is_valid(self, for_date=None):
|
|
return not self.expires or self.expires >= (for_date or timezone.now())
|
|
|
|
|
|
class OutboundWebhook(models.Model, WebhookBase):
|
|
id = models.UUIDField(primary_key=True, default=uuid7, editable=False, unique=True)
|
|
created_by = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, default=None, null=False)
|
|
created_at = models.DateTimeField(default=timezone.now, db_index=True)
|
|
modified_at = models.DateTimeField(auto_now=True)
|
|
|
|
class Meta(WebhookBase.Meta):
|
|
verbose_name = 'API Outbound Webhook'
|
|
|
|
def __str__(self) -> str:
|
|
return f'[{self.id}] {self.ref} -> {self.endpoint}'
|