|
2 | 2 |
|
3 | 3 | import secrets |
4 | 4 | from datetime import timedelta |
5 | | -from typing import ClassVar, Collection, Optional, Tuple |
| 5 | +from typing import Any, ClassVar, Collection, Optional, Tuple |
6 | 6 |
|
7 | 7 | from django.db import models, router, transaction |
8 | 8 | from django.utils import timezone |
9 | 9 | from django.utils.encoding import force_str |
10 | 10 |
|
| 11 | +from sentry import options |
11 | 12 | from sentry.backup.dependencies import ImportKind |
12 | 13 | from sentry.backup.helpers import ImportFlags |
13 | 14 | from sentry.backup.scopes import ImportScope, RelocationScope |
@@ -57,15 +58,12 @@ class Meta: |
57 | 58 | def __str__(self): |
58 | 59 | return force_str(self.token) |
59 | 60 |
|
60 | | - # TODO(mdtro): uncomment this function after 0583_apitoken_add_name_and_last_chars migration has been applied |
61 | | - # def save(self, *args: Any, **kwargs: Any) -> None: |
62 | | - # # when a new ApiToken is created we take the last four characters of the token |
63 | | - # # and save them in the `token_last_characters` field so users can identify |
64 | | - # # tokens in the UI where they're mostly obfuscated |
65 | | - # token_last_characters = self.token[-4:] |
66 | | - # self.token_last_characters = token_last_characters |
| 61 | + def save(self, *args: Any, **kwargs: Any) -> None: |
| 62 | + if options.get("apitoken.auto-add-last-chars"): |
| 63 | + token_last_characters = self.token[-4:] |
| 64 | + self.token_last_characters = token_last_characters |
67 | 65 |
|
68 | | - # return super().save(**kwargs) |
| 66 | + return super().save(**kwargs) |
69 | 67 |
|
70 | 68 | def outbox_region_names(self) -> Collection[str]: |
71 | 69 | return list(find_all_region_names()) |
|
0 commit comments