2023-07-02 17:00:21 -04:00
|
|
|
from datetime import timedelta
|
2023-08-10 11:27:31 -04:00
|
|
|
|
|
|
|
from django.core.management.base import BaseCommand
|
2023-07-02 17:00:21 -04:00
|
|
|
from django.utils import timezone
|
|
|
|
from tqdm import tqdm
|
|
|
|
|
2023-08-10 11:27:31 -04:00
|
|
|
from users.models import Preference, User
|
|
|
|
|
2023-07-02 17:00:21 -04:00
|
|
|
|
|
|
|
class Command(BaseCommand):
|
|
|
|
help = "Check integrity all users"
|
|
|
|
|
|
|
|
def add_arguments(self, parser):
|
|
|
|
parser.add_argument(
|
|
|
|
"--verbose",
|
|
|
|
action="store_true",
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"--fix",
|
|
|
|
action="store_true",
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"--integrity",
|
|
|
|
action="store_true",
|
2024-11-20 21:46:36 -05:00
|
|
|
help="check and fix integrity for missing data for user models",
|
2023-07-02 17:00:21 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
def handle(self, *args, **options):
|
|
|
|
self.verbose = options["verbose"]
|
|
|
|
self.fix = options["fix"]
|
|
|
|
if options["integrity"]:
|
|
|
|
self.integrity()
|
|
|
|
|
|
|
|
def integrity(self):
|
|
|
|
count = 0
|
2024-11-20 21:46:36 -05:00
|
|
|
for user in tqdm(User.objects.filter(is_active=True)):
|
|
|
|
i = user.identity.takahe_identity
|
|
|
|
if i.public_key is None:
|
|
|
|
count += 1
|
|
|
|
if self.fix:
|
|
|
|
i.generate_keypair()
|
|
|
|
if i.inbox_uri is None:
|
|
|
|
count += 1
|
|
|
|
if self.fix:
|
|
|
|
i.ensure_uris()
|
2023-07-02 17:00:21 -04:00
|
|
|
if not Preference.objects.filter(user=user).first():
|
|
|
|
if self.fix:
|
|
|
|
Preference.objects.create(user=user)
|
|
|
|
count += 1
|
2024-11-20 21:46:36 -05:00
|
|
|
print(f"{count} issues")
|