mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 05:23:35 +00:00
upload: Remove unused get_realm_for_filename.
This commit is contained in:
@@ -32,14 +32,7 @@ from PIL.Image import DecompressionBombError
|
|||||||
from zerver.lib.avatar_hash import user_avatar_path
|
from zerver.lib.avatar_hash import user_avatar_path
|
||||||
from zerver.lib.exceptions import ErrorCode, JsonableError
|
from zerver.lib.exceptions import ErrorCode, JsonableError
|
||||||
from zerver.lib.utils import generate_random_token
|
from zerver.lib.utils import generate_random_token
|
||||||
from zerver.models import (
|
from zerver.models import Attachment, Message, Realm, RealmEmoji, UserProfile
|
||||||
Attachment,
|
|
||||||
Message,
|
|
||||||
Realm,
|
|
||||||
RealmEmoji,
|
|
||||||
UserProfile,
|
|
||||||
get_user_profile_by_id,
|
|
||||||
)
|
|
||||||
|
|
||||||
DEFAULT_AVATAR_SIZE = 100
|
DEFAULT_AVATAR_SIZE = 100
|
||||||
MEDIUM_AVATAR_SIZE = 500
|
MEDIUM_AVATAR_SIZE = 500
|
||||||
@@ -339,17 +332,6 @@ def get_signed_upload_url(path: str) -> str:
|
|||||||
ExpiresIn=SIGNED_UPLOAD_URL_DURATION,
|
ExpiresIn=SIGNED_UPLOAD_URL_DURATION,
|
||||||
HttpMethod='GET')
|
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):
|
class S3UploadBackend(ZulipUploadBackend):
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
self.session = boto3.Session(settings.S3_KEY, settings.S3_SECRET_KEY)
|
self.session = boto3.Session(settings.S3_KEY, settings.S3_SECRET_KEY)
|
||||||
|
|||||||
@@ -53,7 +53,6 @@ from zerver.lib.upload import (
|
|||||||
delete_export_tarball,
|
delete_export_tarball,
|
||||||
delete_message_image,
|
delete_message_image,
|
||||||
exif_rotate,
|
exif_rotate,
|
||||||
get_realm_for_filename,
|
|
||||||
resize_avatar,
|
resize_avatar,
|
||||||
resize_emoji,
|
resize_emoji,
|
||||||
sanitize_name,
|
sanitize_name,
|
||||||
@@ -1788,19 +1787,6 @@ class S3Test(ZulipTestCase):
|
|||||||
with self.assertRaises(botocore.exceptions.ClientError):
|
with self.assertRaises(botocore.exceptions.ClientError):
|
||||||
bucket.Object(avatar_medium_path_id).load()
|
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
|
@use_s3_backend
|
||||||
def test_upload_realm_icon_image(self) -> None:
|
def test_upload_realm_icon_image(self) -> None:
|
||||||
bucket = create_s3_buckets(settings.S3_AVATAR_BUCKET)[0]
|
bucket = create_s3_buckets(settings.S3_AVATAR_BUCKET)[0]
|
||||||
|
|||||||
Reference in New Issue
Block a user