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:
121
zerver/actions/navigation_views.py
Normal file
121
zerver/actions/navigation_views.py
Normal file
@@ -0,0 +1,121 @@
|
||||
from django.db import transaction
|
||||
from django.utils.timezone import now as timezone_now
|
||||
|
||||
from zerver.lib.navigation_views import get_navigation_view_dict
|
||||
from zerver.models import NavigationView, RealmAuditLog, UserProfile
|
||||
from zerver.models.realm_audit_logs import AuditLogEventType
|
||||
from zerver.tornado.django_api import send_event_on_commit
|
||||
|
||||
|
||||
@transaction.atomic(durable=True)
|
||||
def do_add_navigation_view(
|
||||
user: UserProfile,
|
||||
fragment: str,
|
||||
is_pinned: bool,
|
||||
name: str | None = None,
|
||||
) -> NavigationView:
|
||||
navigation_view = NavigationView.objects.create(
|
||||
user=user,
|
||||
fragment=fragment,
|
||||
is_pinned=is_pinned,
|
||||
name=name,
|
||||
)
|
||||
|
||||
RealmAuditLog.objects.create(
|
||||
realm=user.realm,
|
||||
acting_user=user,
|
||||
modified_user=user,
|
||||
event_type=AuditLogEventType.NAVIGATION_VIEW_CREATED,
|
||||
event_time=timezone_now(),
|
||||
extra_data={"fragment": fragment},
|
||||
)
|
||||
|
||||
event = {
|
||||
"type": "navigation_view",
|
||||
"op": "add",
|
||||
"navigation_view": get_navigation_view_dict(navigation_view),
|
||||
}
|
||||
send_event_on_commit(user.realm, event, [user.id])
|
||||
return navigation_view
|
||||
|
||||
|
||||
@transaction.atomic(durable=True)
|
||||
def do_update_navigation_view(
|
||||
user: UserProfile,
|
||||
navigation_view: NavigationView,
|
||||
is_pinned: bool | None,
|
||||
name: str | None = None,
|
||||
) -> None:
|
||||
update_dict: dict[str, str | bool] = {}
|
||||
audit_logs_extra_data: list[dict[str, str | bool | None]] = []
|
||||
if name is not None:
|
||||
old_name = navigation_view.name
|
||||
navigation_view.name = name
|
||||
update_dict["name"] = name
|
||||
audit_logs_extra_data.append(
|
||||
{
|
||||
"fragment": navigation_view.fragment,
|
||||
RealmAuditLog.OLD_VALUE: old_name,
|
||||
RealmAuditLog.NEW_VALUE: name,
|
||||
"property": "name",
|
||||
}
|
||||
)
|
||||
|
||||
if is_pinned is not None:
|
||||
old_is_pinned_value = navigation_view.is_pinned
|
||||
navigation_view.is_pinned = is_pinned
|
||||
update_dict["is_pinned"] = is_pinned
|
||||
audit_logs_extra_data.append(
|
||||
{
|
||||
"fragment": navigation_view.fragment,
|
||||
RealmAuditLog.OLD_VALUE: old_is_pinned_value,
|
||||
RealmAuditLog.NEW_VALUE: is_pinned,
|
||||
"property": "is_pinned",
|
||||
}
|
||||
)
|
||||
|
||||
navigation_view.save(update_fields=["name", "is_pinned"])
|
||||
|
||||
now = timezone_now()
|
||||
for audit_log_extra_data in audit_logs_extra_data:
|
||||
RealmAuditLog.objects.create(
|
||||
realm=user.realm,
|
||||
acting_user=user,
|
||||
modified_user=user,
|
||||
event_type=AuditLogEventType.NAVIGATION_VIEW_UPDATED,
|
||||
event_time=now,
|
||||
extra_data=audit_log_extra_data,
|
||||
)
|
||||
|
||||
event = {
|
||||
"type": "navigation_view",
|
||||
"op": "update",
|
||||
"fragment": navigation_view.fragment,
|
||||
"data": update_dict,
|
||||
}
|
||||
send_event_on_commit(user.realm, event, [user.id])
|
||||
|
||||
|
||||
@transaction.atomic(durable=True)
|
||||
def do_remove_navigation_view(
|
||||
user: UserProfile,
|
||||
navigation_view: NavigationView,
|
||||
) -> None:
|
||||
fragment = navigation_view.fragment
|
||||
navigation_view.delete()
|
||||
|
||||
RealmAuditLog.objects.create(
|
||||
realm=user.realm,
|
||||
acting_user=user,
|
||||
modified_user=user,
|
||||
event_type=AuditLogEventType.NAVIGATION_VIEW_DELETED,
|
||||
event_time=timezone_now(),
|
||||
extra_data={"fragment": fragment},
|
||||
)
|
||||
|
||||
event = {
|
||||
"type": "navigation_view",
|
||||
"op": "remove",
|
||||
"fragment": navigation_view.fragment,
|
||||
}
|
||||
send_event_on_commit(user.realm, event, [user.id])
|
||||
Reference in New Issue
Block a user