mirror of
https://github.com/zulip/zulip.git
synced 2025-11-18 04:43:58 +00:00
Redirect legacy URLs to their new secure location.
URLs with a realm of "unk" will be queried against the new bucket to determine the relevant realm of the uploading user. (imported from commit 5d39801951face3cc33c46a61246ba434862a808)
This commit is contained in:
@@ -9,6 +9,8 @@ from boto.s3.key import Key
|
||||
from boto.s3.connection import S3Connection
|
||||
from mimetypes import guess_type, guess_extension
|
||||
|
||||
from zerver.models import get_user_profile_by_id
|
||||
|
||||
import base64
|
||||
import os
|
||||
from PIL import Image, ImageOps
|
||||
@@ -115,6 +117,14 @@ def get_signed_upload_url(path):
|
||||
conn = S3Connection(settings.S3_KEY, settings.S3_SECRET_KEY)
|
||||
return conn.generate_url(15, 'GET', bucket=settings.S3_AUTH_UPLOADS_BUCKET, key=path)
|
||||
|
||||
def get_realm_for_filename(path):
|
||||
conn = S3Connection(settings.S3_KEY, settings.S3_SECRET_KEY)
|
||||
key = get_bucket(conn, settings.S3_AUTH_UPLOADS_BUCKET).get_key(path)
|
||||
if key is None:
|
||||
# This happens if the key does not exist.
|
||||
return None
|
||||
return get_user_profile_by_id(key.metadata["user_profile_id"]).realm.id
|
||||
|
||||
def upload_avatar_image_s3(user_file, user_profile, email):
|
||||
content_type = guess_type(user_file.name)[0]
|
||||
bucket_name = settings.S3_AVATAR_BUCKET
|
||||
|
||||
Reference in New Issue
Block a user