events: Fix realm_upload_quota_mib value to be in MiB.

This was bytes until now.
This commit is contained in:
Mateusz Mandera 2024-03-20 02:30:08 +01:00 committed by Tim Abbott
parent 3df46d542b
commit 540d419ef7
6 changed files with 29 additions and 6 deletions

View File

@ -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),

View File

@ -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

View File

@ -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);

View File

@ -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"] = (

View File

@ -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

View File

@ -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