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:
122
zerver/migrations/0298_fix_realmauditlog_format.py
Normal file
122
zerver/migrations/0298_fix_realmauditlog_format.py
Normal file
@@ -0,0 +1,122 @@
|
||||
# Generated by Django 2.2.14 on 2020-08-07 19:13
|
||||
|
||||
import json
|
||||
|
||||
from django.db import migrations
|
||||
from django.db.backends.base.schema import BaseDatabaseSchemaEditor
|
||||
from django.db.migrations.state import StateApps
|
||||
|
||||
|
||||
def update_realmauditlog_values(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
|
||||
"""
|
||||
This migration fixes two issues with the RealmAuditLog format for certain event types:
|
||||
* The notifications_stream and signup_notifications_stream fields had the
|
||||
Stream objects passed into `ujson.dumps()` and thus marshalled as a giant
|
||||
JSON object, when the intent was to store the stream ID.
|
||||
* The default_sending_stream would also been marshalled wrong, but are part
|
||||
of a feature that nobody should be using, so we simply assert that's the case.
|
||||
* Changes the structure of the extra_data JSON dictionaries for those
|
||||
RealmAuditLog entries with a sub-property field from:
|
||||
{
|
||||
OLD_VALUE: {"property": property, "value": old_value},
|
||||
NEW_VALUE: {"property": property, "value": new_value},
|
||||
}
|
||||
|
||||
to the more natural:
|
||||
|
||||
{
|
||||
OLD_VALUE: old_value,
|
||||
NEW_VALUE: new_value,
|
||||
"property": property,
|
||||
}
|
||||
"""
|
||||
RealmAuditLog = apps.get_model("zerver", "RealmAuditLog")
|
||||
# Constants from models/realm_audit_logs.py
|
||||
USER_DEFAULT_SENDING_STREAM_CHANGED = 129
|
||||
USER_DEFAULT_REGISTER_STREAM_CHANGED = 130
|
||||
USER_DEFAULT_ALL_PUBLIC_STREAMS_CHANGED = 131
|
||||
# Note that this was renamed to USER_SETTING_CHANGED sometime
|
||||
# after this migration; we preserve the original name here to
|
||||
# highlight that as of this migration, only notification settings
|
||||
# had RealmAuditLog entries for changes.
|
||||
USER_NOTIFICATION_SETTINGS_CHANGED = 132
|
||||
REALM_PROPERTY_CHANGED = 207
|
||||
SUBSCRIPTION_PROPERTY_CHANGED = 304
|
||||
OLD_VALUE = "1"
|
||||
NEW_VALUE = "2"
|
||||
|
||||
unlikely_event_types = [
|
||||
USER_DEFAULT_SENDING_STREAM_CHANGED,
|
||||
USER_DEFAULT_REGISTER_STREAM_CHANGED,
|
||||
USER_DEFAULT_ALL_PUBLIC_STREAMS_CHANGED,
|
||||
]
|
||||
# These 3 event types are the ones that used a format with
|
||||
# OLD_VALUE containing a dictionary with a `property` key.
|
||||
affected_event_types = [
|
||||
REALM_PROPERTY_CHANGED,
|
||||
USER_NOTIFICATION_SETTINGS_CHANGED,
|
||||
SUBSCRIPTION_PROPERTY_CHANGED,
|
||||
]
|
||||
improperly_marshalled_properties = [
|
||||
"notifications_stream",
|
||||
"signup_notifications_stream",
|
||||
]
|
||||
|
||||
# These are also corrupted but are part of a feature nobody uses,
|
||||
# so it's not worth writing code to fix them.
|
||||
assert not RealmAuditLog.objects.filter(event_type__in=unlikely_event_types).exists()
|
||||
|
||||
for ra in RealmAuditLog.objects.filter(event_type__in=affected_event_types):
|
||||
extra_data = json.loads(ra.extra_data)
|
||||
old_key = extra_data[OLD_VALUE]
|
||||
new_key = extra_data[NEW_VALUE]
|
||||
|
||||
# Skip any already-migrated values in case we're running this
|
||||
# migration a second time.
|
||||
if not isinstance(old_key, dict) and not isinstance(new_key, dict):
|
||||
continue
|
||||
if "value" not in old_key or "value" not in new_key:
|
||||
continue
|
||||
|
||||
old_value = old_key["value"]
|
||||
new_value = new_key["value"]
|
||||
prop = old_key["property"]
|
||||
|
||||
# The `authentication_methods` key is the only event whose
|
||||
# action value type is expected to be a dictionary. That
|
||||
# property is marshalled properly but still wants the second
|
||||
# migration below.
|
||||
if prop != "authentication_methods":
|
||||
# For the other properties, we have `stream` rather than `stream['id']`
|
||||
# in the original extra_data object; the fix is simply to extract
|
||||
# the intended ID field via `value = value['id']`.
|
||||
if isinstance(old_value, dict):
|
||||
assert prop in improperly_marshalled_properties
|
||||
old_value = old_value["id"]
|
||||
if isinstance(new_value, dict):
|
||||
assert prop in improperly_marshalled_properties
|
||||
new_value = new_value["id"]
|
||||
|
||||
# Sanity check that the original event has exactly the keys we expect.
|
||||
assert set(extra_data.keys()) <= {OLD_VALUE, NEW_VALUE}
|
||||
|
||||
ra.extra_data = json.dumps(
|
||||
{
|
||||
OLD_VALUE: old_value,
|
||||
NEW_VALUE: new_value,
|
||||
"property": prop,
|
||||
}
|
||||
)
|
||||
ra.save(update_fields=["extra_data"])
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("zerver", "0297_draft"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(
|
||||
update_realmauditlog_values, reverse_code=migrations.RunPython.noop, elidable=True
|
||||
),
|
||||
]
|
||||
Reference in New Issue
Block a user