# What this PR does ```bash ❯ mypy . Success: no issues found in 595 source files ``` - re-enable the mypy CI check - fixes all `django-manager-missing` mypy errors - disable all other rules currently giving mypy errors - changing the approach here. rather than enforcing that backend contributors fix >= 1 `mypy` error on their PR, lets simply disable all the rules that're currently returning errors and slowly re-enable these one at a time #2392 ## Checklist - [ ] Unit, integration, and e2e (if applicable) tests updated (N/A) - [ ] Documentation added (or `pr:no public docs` PR label added if not required) (N/A) - [ ] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not required) (N/A)
49 lines
1.5 KiB
Python
49 lines
1.5 KiB
Python
from typing import Tuple
|
|
|
|
from django.db import models
|
|
|
|
from apps.auth_token import constants, crypto
|
|
from apps.auth_token.models.base_auth_token import BaseAuthToken
|
|
from apps.user_management.models import Organization, User
|
|
|
|
|
|
class ApiAuthToken(BaseAuthToken):
|
|
objects: models.QuerySet["ApiAuthToken"]
|
|
|
|
user = models.ForeignKey(to=User, null=False, blank=False, related_name="auth_tokens", on_delete=models.CASCADE)
|
|
organization = models.ForeignKey(
|
|
to=Organization, null=False, blank=False, related_name="auth_tokens", on_delete=models.CASCADE
|
|
)
|
|
name = models.CharField(max_length=50)
|
|
|
|
@classmethod
|
|
def create_auth_token(cls, user: User, organization: Organization, name: str) -> Tuple["ApiAuthToken", str]:
|
|
token_string = crypto.generate_token_string()
|
|
digest = crypto.hash_token_string(token_string)
|
|
|
|
instance = cls.objects.create(
|
|
token_key=token_string[: constants.TOKEN_KEY_LENGTH],
|
|
digest=digest,
|
|
user=user,
|
|
organization=organization,
|
|
name=name,
|
|
)
|
|
return instance, token_string
|
|
|
|
# Insight logs
|
|
@property
|
|
def insight_logs_type_verbal(self):
|
|
return "public_api_token"
|
|
|
|
@property
|
|
def insight_logs_verbal(self):
|
|
return self.name
|
|
|
|
@property
|
|
def insight_logs_serialized(self):
|
|
# API tokens are not modifiable, so return empty dict to implement InsightLoggable interface
|
|
return {}
|
|
|
|
@property
|
|
def insight_logs_metadata(self):
|
|
return {}
|