from typing import TYPE_CHECKING
import tqdm
+from allauth.socialaccount.models import SocialAccount
+from allauth.socialaccount.models import SocialApp
+from allauth.socialaccount.models import SocialToken
from django.conf import settings
from django.contrib.auth.models import Group
from django.contrib.auth.models import Permission
from filelock import FileLock
from guardian.models import GroupObjectPermission
from guardian.models import UserObjectPermission
+from rest_framework.authtoken.models import Token
if TYPE_CHECKING:
from django.db.models import QuerySet
"app_configs": ApplicationConfiguration.objects.all(),
"notes": Note.objects.all(),
"documents": Document.objects.order_by("id").all(),
+ "social_accounts": SocialAccount.objects.all(),
+ "social_apps": SocialApp.objects.all(),
+ "social_tokens": SocialToken.objects.all(),
+ "auth_tokens": Token.objects.all(),
}
if settings.AUDIT_LOG_ENABLED:
crypt_fields = crypt_config["fields"]
for manifest_record in manifest[exporter_key]:
for field in crypt_fields:
- manifest_record["fields"][field] = self.encrypt_string(
- value=manifest_record["fields"][field],
- )
-
- elif MailAccount.objects.count() > 0:
+ if manifest_record["fields"][field]:
+ manifest_record["fields"][field] = self.encrypt_string(
+ value=manifest_record["fields"][field],
+ )
+
+ elif (
+ MailAccount.objects.count() > 0
+ or SocialToken.objects.count() > 0
+ or Token.objects.count() > 0
+ ):
self.stdout.write(
self.style.NOTICE(
- "You have configured mail accounts, "
- "but no passphrase was given. "
- "Passwords will be in plaintext",
+ "No passphrase was given, sensitive fields will be in plaintext",
),
)
):
had_at_least_one_record = True
for field in crypt_fields:
- record["fields"][field] = self.decrypt_string(
- value=record["fields"][field],
- )
+ if record["fields"][field]:
+ record["fields"][field] = self.decrypt_string(
+ value=record["fields"][field],
+ )
if had_at_least_one_record:
# It's annoying, but the DB is loaded from the JSON directly