snapshot of https://github.com/zulip/zulip.git @ 48c69911c7dd4e03b20552eb3bd77ad8151c1357 (2026-09-15)
Some checks failed
Code scanning / CodeQL (push) Failing after 15s
Zulip production suite / Ubuntu 22.04 production build (push) Failing after 26s
Zulip production suite / Debian 12 production install with custom db name and user (push) Has been skipped
Zulip production suite / Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga (push) Has been skipped
Zulip production suite / Ubuntu 24.04 production install (push) Has been skipped
Zulip production suite / Ubuntu 26.04 production install (push) Has been skipped
Zulip production suite / Debian 13 production install (push) Has been skipped
Zulip production suite / 7.0 Version Upgrade (push) Has been skipped
Zulip production suite / 8.0 Version Upgrade (push) Has been skipped
Zulip production suite / 6.0 Version Upgrade (push) Has been skipped
Zulip production suite / 10.0 Version Upgrade (push) Has been skipped
Zulip production suite / 9.0 Version Upgrade (push) Has been skipped
Zulip production suite / 12.0 Version Upgrade (push) Has been skipped
Zulip production suite / 11.0 Version Upgrade (push) Has been skipped
GitHub Actions Security Analysis with zizmor / zizmor (push) Failing after 3s
Zulip CI / Debian 12 (Python 3.11, backend + documentation) (push) Failing after 26s
Zulip CI / Ubuntu 22.04 (Python 3.10, backend + frontend) (push) Failing after 3s
Zulip CI / Ubuntu 24.04 (Python 3.12, backend) (push) Failing after 25s
Zulip CI / Ubuntu 26.04 (Python 3.14, backend) (push) Failing after 25s
Zulip CI / Debian 13 (Python 3.13, backend) (push) Failing after 28s
Zulip production suite / Required jobs (push) Has been cancelled
Zulip CI / Required jobs (push) Has been cancelled
API Documentation Update Check / check-feature-level-updated (push) Has been cancelled
API Documentation Update Check / notify-if-api-docs-changed (push) Has been cancelled
Some checks failed
Code scanning / CodeQL (push) Failing after 15s
Zulip production suite / Ubuntu 22.04 production build (push) Failing after 26s
Zulip production suite / Debian 12 production install with custom db name and user (push) Has been skipped
Zulip production suite / Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga (push) Has been skipped
Zulip production suite / Ubuntu 24.04 production install (push) Has been skipped
Zulip production suite / Ubuntu 26.04 production install (push) Has been skipped
Zulip production suite / Debian 13 production install (push) Has been skipped
Zulip production suite / 7.0 Version Upgrade (push) Has been skipped
Zulip production suite / 8.0 Version Upgrade (push) Has been skipped
Zulip production suite / 6.0 Version Upgrade (push) Has been skipped
Zulip production suite / 10.0 Version Upgrade (push) Has been skipped
Zulip production suite / 9.0 Version Upgrade (push) Has been skipped
Zulip production suite / 12.0 Version Upgrade (push) Has been skipped
Zulip production suite / 11.0 Version Upgrade (push) Has been skipped
GitHub Actions Security Analysis with zizmor / zizmor (push) Failing after 3s
Zulip CI / Debian 12 (Python 3.11, backend + documentation) (push) Failing after 26s
Zulip CI / Ubuntu 22.04 (Python 3.10, backend + frontend) (push) Failing after 3s
Zulip CI / Ubuntu 24.04 (Python 3.12, backend) (push) Failing after 25s
Zulip CI / Ubuntu 26.04 (Python 3.14, backend) (push) Failing after 25s
Zulip CI / Debian 13 (Python 3.13, backend) (push) Failing after 28s
Zulip production suite / Required jobs (push) Has been cancelled
Zulip CI / Required jobs (push) Has been cancelled
API Documentation Update Check / check-feature-level-updated (push) Has been cancelled
API Documentation Update Check / notify-if-api-docs-changed (push) Has been cancelled
This commit is contained in:
70
zerver/views/realm_logo.py
Normal file
70
zerver/views/realm_logo.py
Normal file
@@ -0,0 +1,70 @@
|
||||
from django.conf import settings
|
||||
from django.core.files.uploadedfile import UploadedFile
|
||||
from django.http import HttpRequest, HttpResponse
|
||||
from django.shortcuts import redirect
|
||||
from django.utils.translation import gettext as _
|
||||
from pydantic import Json
|
||||
|
||||
from zerver.actions.realm_logo import do_change_logo_source
|
||||
from zerver.decorator import require_realm_admin
|
||||
from zerver.lib.exceptions import JsonableError
|
||||
from zerver.lib.realm_logo import get_realm_logo_url
|
||||
from zerver.lib.response import json_success
|
||||
from zerver.lib.typed_endpoint import typed_endpoint
|
||||
from zerver.lib.upload import get_file_info, upload_logo_image
|
||||
from zerver.lib.url_encoding import append_url_query_string
|
||||
from zerver.models import UserProfile
|
||||
|
||||
|
||||
@require_realm_admin
|
||||
@typed_endpoint
|
||||
def upload_logo(
|
||||
request: HttpRequest, user_profile: UserProfile, *, night: Json[bool]
|
||||
) -> HttpResponse:
|
||||
user_profile.realm.ensure_not_on_limited_plan()
|
||||
|
||||
if len(request.FILES) != 1:
|
||||
raise JsonableError(_("You must upload exactly one logo."))
|
||||
[logo_file] = request.FILES.values()
|
||||
assert isinstance(logo_file, UploadedFile)
|
||||
assert logo_file.size is not None
|
||||
if logo_file.size > settings.MAX_LOGO_FILE_SIZE_MIB * 1024 * 1024:
|
||||
raise JsonableError(
|
||||
_("Uploaded file is larger than the allowed limit of {max_size} MiB").format(
|
||||
max_size=settings.MAX_LOGO_FILE_SIZE_MIB,
|
||||
)
|
||||
)
|
||||
_filename, content_type = get_file_info(logo_file)
|
||||
upload_logo_image(logo_file, user_profile, night, content_type=content_type)
|
||||
do_change_logo_source(
|
||||
user_profile.realm, user_profile.realm.LOGO_UPLOADED, night, acting_user=user_profile
|
||||
)
|
||||
return json_success(request)
|
||||
|
||||
|
||||
@require_realm_admin
|
||||
@typed_endpoint
|
||||
def delete_logo_backend(
|
||||
request: HttpRequest, user_profile: UserProfile, *, night: Json[bool]
|
||||
) -> HttpResponse:
|
||||
# We don't actually delete the logo because it might still
|
||||
# be needed if the URL was cached and it is rewritten
|
||||
# in any case after next update.
|
||||
do_change_logo_source(
|
||||
user_profile.realm, user_profile.realm.LOGO_DEFAULT, night, acting_user=user_profile
|
||||
)
|
||||
return json_success(request)
|
||||
|
||||
|
||||
@typed_endpoint
|
||||
def get_logo_backend(
|
||||
request: HttpRequest, user_profile: UserProfile, *, night: Json[bool]
|
||||
) -> HttpResponse:
|
||||
url = get_realm_logo_url(user_profile.realm, night)
|
||||
|
||||
# We can rely on the URL already having query parameters. Because
|
||||
# our templates depend on being able to use the ampersand to
|
||||
# add query parameters to our url, get_logo_url does '?version=version_number'
|
||||
# hacks to prevent us from having to jump through decode/encode hoops.
|
||||
url = append_url_query_string(url, request.META["QUERY_STRING"])
|
||||
return redirect(url)
|
||||
Reference in New Issue
Block a user