s3 exports: Validate user metadata for all assets.

This preps us to download assets for just a single
user.
This commit is contained in:
Steve Howell
2021-12-06 18:08:13 +00:00
committed by Tim Abbott
parent 946ab22bba
commit 0166f13d83

View File

@@ -1441,13 +1441,12 @@ def export_files_from_s3(
avatar_hash_values.add(avatar_path)
avatar_hash_values.add(avatar_path + ".original")
email_gateway_bot: Optional[UserProfile] = None
if settings.EMAIL_GATEWAY_BOT is not None:
internal_realm = get_realm(settings.SYSTEM_BOT_REALM)
email_gateway_bot: Optional[UserProfile] = get_system_bot(
settings.EMAIL_GATEWAY_BOT, internal_realm.id
)
else:
email_gateway_bot = None
email_gateway_bot = get_system_bot(settings.EMAIL_GATEWAY_BOT, internal_realm.id)
user_ids.add(email_gateway_bot.id)
count = 0
for bkey in bucket.objects.filter(Prefix=object_prefix):
@@ -1462,6 +1461,9 @@ def export_files_from_s3(
if "user_profile_id" not in key.metadata:
raise AssertionError(f"Missing user_profile_id in key metadata: {key.metadata}")
if int(key.metadata["user_profile_id"]) not in user_ids:
continue
# This can happen if an email address has moved realms
if key.metadata["realm_id"] != str(realm.id):
if email_gateway_bot is None or key.metadata["user_profile_id"] != str(