Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

events: Fix realm_upload_quota_mib value to be in MiB.

Mateusz Mandera540d419ef74c
diff --git a/api_docs/changelog.md b/api_docs/changelog.md
index d0a02c2092b..4f49975805f 100644
--- a/api_docs/changelog.md
+++ b/api_docs/changelog.md
@@ -20,6 +20,11 @@ format used by the Zulip server that they are interacting with.
## Changes in Zulip 9.0
+**Feature level 251**
+
+* [`POST /register`](/api/register-queue): Fixed `realm_upload_quota_mib`
+ value to actually be in MiB. Until now the value was in bytes.
+
**Feature level 250**
* [`GET /messages`](/api/get-messages),
diff --git a/version.py b/version.py
index 04675df8325..af78fb5c162 100644
--- a/version.py
+++ b/version.py
@@ -33,7 +33,7 @@ DESKTOP_WARNING_VERSION = "5.9.3"
# Changes should be accompanied by documentation explaining what the
# new level means in api_docs/changelog.md, as well as "**Changes**"
# entries in the endpoint's documentation in `zulip.yaml`.
-API_FEATURE_LEVEL = 250
+API_FEATURE_LEVEL = 251
# Bump the minor PROVISION_VERSION to indicate that folks should provision
# only when going from an old version of the code to a newer version. Bump
diff --git a/web/src/attachments_ui.ts b/web/src/attachments_ui.ts
index d29eef8c348..c318f0740f9 100644
--- a/web/src/attachments_ui.ts
+++ b/web/src/attachments_ui.ts
@@ -70,11 +70,15 @@ export function bytes_to_size(bytes: number, kb_with_1024_bytes = false): string
return size + " " + sizes[i];
}
+export function mib_to_bytes(mib: number): number {
+ return mib * 1024 * 1024;
+}
+
export function percentage_used_space(uploads_size: number): string | null {
if (realm.realm_upload_quota_mib === null) {
return null;
}
- return ((100 * uploads_size) / realm.realm_upload_quota_mib).toFixed(1);
+ return ((100 * uploads_size) / mib_to_bytes(realm.realm_upload_quota_mib)).toFixed(1);
}
function set_upload_space_stats(): void {
@@ -84,7 +88,7 @@ function set_upload_space_stats(): void {
const args = {
show_upgrade_message: realm.realm_plan_type === 2,
percent_used: percentage_used_space(upload_space_used),
- upload_quota: bytes_to_size(realm.realm_upload_quota_mib, true),
+ upload_quota: bytes_to_size(mib_to_bytes(realm.realm_upload_quota_mib), true),
};
const rendered_upload_stats_html = render_settings_upload_space_stats(args);
$("#attachment-stats-holder").html(rendered_upload_stats_html);
diff --git a/zerver/lib/events.py b/zerver/lib/events.py
index efc1dbe386b..d62aeb100b5 100644
--- a/zerver/lib/events.py
+++ b/zerver/lib/events.py
@@ -69,6 +69,7 @@ from zerver.lib.users import (
is_administrator_role,
max_message_id_for_user,
)
+from zerver.lib.utils import optional_bytes_to_mib
from zerver.models import (
Client,
CustomProfileField,
@@ -301,7 +302,8 @@ def fetch_initial_state_data(
state["max_avatar_file_size_mib"] = settings.MAX_AVATAR_FILE_SIZE_MIB
state["max_file_upload_size_mib"] = settings.MAX_FILE_UPLOAD_SIZE
state["max_icon_file_size_mib"] = settings.MAX_ICON_FILE_SIZE_MIB
- state["realm_upload_quota_mib"] = realm.upload_quota_bytes()
+ upload_quota_bytes = realm.upload_quota_bytes()
+ state["realm_upload_quota_mib"] = optional_bytes_to_mib(upload_quota_bytes)
state["realm_icon_url"] = realm_icon_url(realm)
state["realm_icon_source"] = realm.icon_source
@@ -1157,7 +1159,9 @@ def apply_event(
if event["property"] == "plan_type":
# Then there are some extra fields that also need to be set.
state["zulip_plan_is_not_limited"] = event["value"] != Realm.PLAN_TYPE_LIMITED
- state["realm_upload_quota_mib"] = event["extra_data"]["upload_quota"]
+ # upload_quota is in bytes, so we need to convert it to MiB.
+ upload_quota_bytes = event["extra_data"]["upload_quota"]
+ state["realm_upload_quota_mib"] = optional_bytes_to_mib(upload_quota_bytes)
if field == "realm_jitsi_server_url":
state["jitsi_server_url"] = (
diff --git a/zerver/lib/utils.py b/zerver/lib/utils.py
index a0fd067841c..768414a2a8a 100644
--- a/zerver/lib/utils.py
+++ b/zerver/lib/utils.py
@@ -33,3 +33,10 @@ def process_list_in_batches(
break
process_batch(items)
offset += chunk_size
+
+
+def optional_bytes_to_mib(value: Optional[int]) -> Optional[int]:
+ if value is None:
+ return None
+ else:
+ return value >> 20
diff --git a/zerver/openapi/zulip.yaml b/zerver/openapi/zulip.yaml
index e85d0619801..5c5dd02f45e 100644
--- a/zerver/openapi/zulip.yaml
+++ b/zerver/openapi/zulip.yaml
@@ -15277,7 +15277,10 @@ paths:
If `null`, there is no limit.
- **Changes**: New in Zulip 5.0 (feature level 72). Previously,
+ **Changes**: Before Zulip 9.0 (feature level 251), this field
+ was incorrectly measured in bytes, not MiB.
+
+ New in Zulip 5.0 (feature level 72). Previously,
this was called `realm_upload_quota`.
realm_org_type:
type: integer