upload: Remove unused get_realm_for_filename.

This commit is contained in:
Tim Abbott
2020-06-18 16:45:28 -07:00
committed by Tim Abbott
parent 5962d1ea14
commit 0b6ebb4fbb
2 changed files with 1 additions and 33 deletions

View File

@@ -32,14 +32,7 @@ from PIL.Image import DecompressionBombError
from zerver.lib.avatar_hash import user_avatar_path
from zerver.lib.exceptions import ErrorCode, JsonableError
from zerver.lib.utils import generate_random_token
from zerver.models import (
Attachment,
Message,
Realm,
RealmEmoji,
UserProfile,
get_user_profile_by_id,
)
from zerver.models import Attachment, Message, Realm, RealmEmoji, UserProfile
DEFAULT_AVATAR_SIZE = 100
MEDIUM_AVATAR_SIZE = 500
@@ -339,17 +332,6 @@ def get_signed_upload_url(path: str) -> str:
ExpiresIn=SIGNED_UPLOAD_URL_DURATION,
HttpMethod='GET')
def get_realm_for_filename(path: str) -> Optional[int]:
session = boto3.Session(settings.S3_KEY, settings.S3_SECRET_KEY)
bucket = get_bucket(session, settings.S3_AUTH_UPLOADS_BUCKET)
key = bucket.Object(path)
try:
user_profile_id = key.metadata['user_profile_id']
except botocore.exceptions.ClientError:
return None
return get_user_profile_by_id(user_profile_id).realm_id
class S3UploadBackend(ZulipUploadBackend):
def __init__(self) -> None:
self.session = boto3.Session(settings.S3_KEY, settings.S3_SECRET_KEY)

View File

@@ -53,7 +53,6 @@ from zerver.lib.upload import (
delete_export_tarball,
delete_message_image,
exif_rotate,
get_realm_for_filename,
resize_avatar,
resize_emoji,
sanitize_name,
@@ -1788,19 +1787,6 @@ class S3Test(ZulipTestCase):
with self.assertRaises(botocore.exceptions.ClientError):
bucket.Object(avatar_medium_path_id).load()
@use_s3_backend
def test_get_realm_for_filename(self) -> None:
create_s3_buckets(settings.S3_AUTH_UPLOADS_BUCKET)
user_profile = self.example_user('hamlet')
uri = upload_message_file('dummy.txt', len(b'zulip!'), 'text/plain', b'zulip!', user_profile)
path_id = re.sub('/user_uploads/', '', uri)
self.assertEqual(user_profile.realm_id, get_realm_for_filename(path_id))
@use_s3_backend
def test_get_realm_for_filename_when_key_doesnt_exist(self) -> None:
self.assertIsNone(get_realm_for_filename('non-existent-file-path'))
@use_s3_backend
def test_upload_realm_icon_image(self) -> None:
bucket = create_s3_buckets(settings.S3_AVATAR_BUCKET)[0]