Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
navigation_views: Add backend for navigation views in left sidebar.
Aditya Kumar Kasaudhanc5f126c6ff47
diff --git a/api_docs/changelog.md b/api_docs/changelog.mdindex 93644d56c93..8e375d29a62 100644--- a/api_docs/changelog.md+++ b/api_docs/changelog.md@@ -20,6 +20,26 @@ format used by the Zulip server that they are interacting with.## Changes in Zulip 11.0+**Feature level 390**++* [`GET /events`](/api/get-events): Events with `type: "navigation_view"` are+ sent to the user when a navigation view is created, updated, or removed.++* [`POST /register`](/api/register-queue): Added `navigation_views` field in+ response.++* [`GET /navigation_views`](/api/get-navigation-views): Added a new endpoint for+ fetching all navigation views of the user.++* [`POST /navigation_views`](/api/add-navigation-view): Added a new endpoint for+ creating a new navigation view.++* [`PATCH /navigation_views/{fragment}`](/api/edit-navigation-view): Added a new+ endpoint for editing the details of a navigation view.++* [`DELETE /navigation_views/{fragment}`](/api/remove-navigation-view): Added a new+ endpoint for removing a navigation view.+**Feature level 389*** [`POST /channel_folders/create`](/api/create-channel-folder): Addeddiff --git a/api_docs/include/rest-endpoints.md b/api_docs/include/rest-endpoints.mdindex 6a9282f8b8f..c4d2d9d8ac1 100644--- a/api_docs/include/rest-endpoints.md+++ b/api_docs/include/rest-endpoints.md@@ -42,6 +42,13 @@* [Edit a saved snippet](/api/edit-saved-snippet)* [Delete a saved snippet](/api/delete-saved-snippet)+#### Navigation views++* [Get all navigation views](/api/get-navigation-views)+* [Add a navigation view](/api/add-navigation-view)+* [Update the navigation view](/api/edit-navigation-view)+* [Remove a navigation view](/api/remove-navigation-view)+#### Channels* [Get subscribed channels](/api/get-subscriptions)diff --git a/version.py b/version.pyindex 1924fb58f6b..1230d435c72 100644--- a/version.py+++ b/version.py@@ -34,7 +34,7 @@ DESKTOP_WARNING_VERSION = "5.9.3"# new level means in api_docs/changelog.md, as well as "**Changes**"# entries in the endpoint's documentation in `zulip.yaml`.-API_FEATURE_LEVEL = 389+API_FEATURE_LEVEL = 390# 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. Bumpdiff --git a/zerver/actions/navigation_views.py b/zerver/actions/navigation_views.pynew file mode 100644index 00000000000..6e4fd97f809--- /dev/null+++ b/zerver/actions/navigation_views.py@@ -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++[email protected](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++[email protected](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])++[email protected](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])diff --git a/zerver/lib/event_schema.py b/zerver/lib/event_schema.pyindex 0beee72ad63..f04a0c03f1f 100644--- a/zerver/lib/event_schema.py+++ b/zerver/lib/event_schema.py@@ -39,6 +39,9 @@ from zerver.lib.event_types import (EventMessage,EventMutedTopics,EventMutedUsers,+ EventNavigationViewsAdd,+ EventNavigationViewsRemove,+ EventNavigationViewsUpdate,EventOnboardingSteps,EventPresence,EventReactionAdd,@@ -175,6 +178,9 @@ check_heartbeat = make_checker(EventHeartbeat)check_invites_changed = make_checker(EventInvitesChanged)check_message = make_checker(EventMessage)check_muted_users = make_checker(EventMutedUsers)+check_navigation_view_add = make_checker(EventNavigationViewsAdd)+check_navigation_view_remove = make_checker(EventNavigationViewsRemove)+check_navigation_view_update = make_checker(EventNavigationViewsUpdate)check_onboarding_steps = make_checker(EventOnboardingSteps)check_reaction_add = make_checker(EventReactionAdd)check_reaction_remove = make_checker(EventReactionRemove)diff --git a/zerver/lib/event_types.py b/zerver/lib/event_types.pyindex 31cf2ceb6b8..0686e9df68f 100644--- a/zerver/lib/event_types.py+++ b/zerver/lib/event_types.py@@ -283,6 +283,36 @@ class EventOnboardingSteps(BaseEvent):onboarding_steps: list[OnboardingSteps]+class NavigationViewFields(BaseModel):+ fragment: str+ is_pinned: bool+ name: str | None+++class EventNavigationViewsAdd(BaseEvent):+ type: Literal["navigation_view"]+ op: Literal["add"]+ navigation_view: NavigationViewFields+++class EventNavigationViewsRemove(BaseEvent):+ type: Literal["navigation_view"]+ op: Literal["remove"]+ fragment: str+++class NavigationViewFieldsForUpdate(BaseModel):+ is_pinned: bool | None = None+ name: str | None = None+++class EventNavigationViewsUpdate(BaseEvent):+ type: Literal["navigation_view"]+ op: Literal["update"]+ fragment: str+ data: NavigationViewFieldsForUpdate++class Presence(BaseModel):status: Literal["active", "idle"]timestamp: intdiff --git a/zerver/lib/events.py b/zerver/lib/events.pyindex 2dc6007c495..591633afb08 100644--- a/zerver/lib/events.py+++ b/zerver/lib/events.py@@ -46,6 +46,7 @@ from zerver.lib.message import (from zerver.lib.muted_users import get_user_mutesfrom zerver.lib.narrow_helpers import NeverNegatedNarrowTerm, read_stop_wordsfrom zerver.lib.narrow_predicate import check_narrow_for_events+from zerver.lib.navigation_views import get_navigation_views_for_userfrom zerver.lib.onboarding_steps import get_next_onboarding_stepsfrom zerver.lib.presence import get_presence_for_user, get_presences_for_realmfrom zerver.lib.realm_icon import realm_icon_url@@ -301,6 +302,12 @@ def fetch_initial_state_data(else:state["saved_snippets"] = do_get_saved_snippets(user_profile)+ if want("navigation_views"):+ if user_profile is None:+ state["navigation_views"] = []+ else:+ state["navigation_views"] = get_navigation_views_for_user(user_profile)+if want("drafts"):if user_profile is None:state["drafts"] = []@@ -1010,6 +1017,20 @@ def apply_event(state["saved_snippets"][idx] = event["saved_snippet"]break+ elif event["type"] == "navigation_view":+ if event["op"] == "add":+ state["navigation_views"].append(event["navigation_view"])+ elif event["op"] == "update":+ for navigation_view in state["navigation_views"]:+ if navigation_view["fragment"] == event["fragment"]:+ navigation_view.update(event["data"])+ break+ elif event["op"] == "remove":+ for idx, navigation_view in enumerate(state["navigation_views"]):+ if navigation_view["fragment"] == event["fragment"]:+ del state["navigation_views"][idx]+ break+elif event["type"] == "drafts":if event["op"] == "add":state["drafts"].extend(event["drafts"])diff --git a/zerver/lib/export.py b/zerver/lib/export.pyindex 155d05ba707..6fcc5f34140 100644--- a/zerver/lib/export.py+++ b/zerver/lib/export.py@@ -59,6 +59,7 @@ from zerver.models import (Message,MutedUser,NamedUserGroup,+ NavigationView,OnboardingStep,OnboardingUserMessage,Reaction,@@ -166,6 +167,7 @@ ALL_ZULIP_TABLES = {"zerver_multiuseinvite_streams","zerver_multiuseinvite_groups","zerver_namedusergroup",+ "zerver_navigationview","zerver_onboardingstep","zerver_onboardingusermessage","zerver_preregistrationrealm",@@ -1176,6 +1178,14 @@ def add_user_profile_child_configs(user_profile_config: Config) -> None:limit_to_consenting_users=True,)+ Config(+ table="zerver_navigationview",+ model=NavigationView,+ normal_parent=user_profile_config,+ include_rows="user_id__in",+ limit_to_consenting_users=True,+ )+Config(table="zerver_onboardingstep",model=OnboardingStep,diff --git a/zerver/lib/import_realm.py b/zerver/lib/import_realm.pyindex e49d1d65f5f..227321264ec 100644--- a/zerver/lib/import_realm.py+++ b/zerver/lib/import_realm.py@@ -72,6 +72,7 @@ from zerver.models import (Message,MutedUser,NamedUserGroup,+ NavigationView,OnboardingStep,OnboardingUserMessage,Reaction,@@ -171,6 +172,7 @@ ID_MAP: dict[str, dict[int, int]] = {"onboardingusermessage": {},"savedsnippet": {},"channelfolder": {},+ "navigationview": {},}id_map_to_list: dict[str, dict[int, list[int]]] = {@@ -1550,6 +1552,11 @@ def do_import_realm(import_dir: Path, subdomain: str, processes: int = 1) -> Reaupdate_model_ids(AlertWord, data, "alertword")bulk_import_model(data, AlertWord)+ if "zerver_navigationview" in data:+ re_map_foreign_keys(data, "zerver_navigationview", "user", related_table="user_profile")+ update_model_ids(NavigationView, data, "navigationview")+ bulk_import_model(data, NavigationView)+if "zerver_savedsnippet" in data:fix_datetime_fields(data, "zerver_savedsnippet")re_map_foreign_keys(diff --git a/zerver/lib/navigation_views.py b/zerver/lib/navigation_views.pynew file mode 100644index 00000000000..67ad8321015--- /dev/null+++ b/zerver/lib/navigation_views.py@@ -0,0 +1,33 @@+from typing import TypedDict++from django.utils.translation import gettext as _++from zerver.lib.exceptions import ResourceNotFoundError+from zerver.models import NavigationView, UserProfile+++class NavigationViewDict(TypedDict):+ fragment: str+ is_pinned: bool+ name: str | None+++def get_navigation_view(user: UserProfile, fragment: str) -> NavigationView:+ try:+ navigation_view = NavigationView.objects.get(user=user, fragment=fragment)+ return navigation_view+ except NavigationView.DoesNotExist:+ raise ResourceNotFoundError(_("Navigation view does not exist."))+++def get_navigation_view_dict(navigation_view: NavigationView) -> NavigationViewDict:+ return NavigationViewDict(+ fragment=navigation_view.fragment,+ is_pinned=navigation_view.is_pinned,+ name=navigation_view.name,+ )+++def get_navigation_views_for_user(user: UserProfile) -> list[NavigationViewDict]:+ navigation_views = NavigationView.objects.filter(user=user)+ return [get_navigation_view_dict(navigation_view) for navigation_view in navigation_views]diff --git a/zerver/migrations/0709_navigationview.py b/zerver/migrations/0709_navigationview.pynew file mode 100644index 00000000000..cef417bf2fc--- /dev/null+++ b/zerver/migrations/0709_navigationview.py@@ -0,0 +1,37 @@+# Generated by Django 5.1.8 on 2025-05-23 20:31++import django.db.models.deletion+from django.conf import settings+from django.db import migrations, models+++class Migration(migrations.Migration):+ dependencies = [+ ("zerver", "0708_stream_folder"),+ ]++ operations = [+ migrations.CreateModel(+ name="NavigationView",+ fields=[+ (+ "id",+ models.BigAutoField(+ auto_created=True, primary_key=True, serialize=False, verbose_name="ID"+ ),+ ),+ ("fragment", models.TextField()),+ ("is_pinned", models.BooleanField(default=False)),+ ("name", models.TextField(blank=True, null=True)),+ (+ "user",+ models.ForeignKey(+ on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL+ ),+ ),+ ],+ options={+ "unique_together": {("user", "fragment")},+ },+ ),+ ]diff --git a/zerver/models/__init__.py b/zerver/models/__init__.pyindex 629fb79e352..f078e11d0ca 100644--- a/zerver/models/__init__.py+++ b/zerver/models/__init__.py@@ -33,6 +33,7 @@ from zerver.models.messages import Reaction as Reactionfrom zerver.models.messages import SubMessage as SubMessagefrom zerver.models.messages import UserMessage as UserMessagefrom zerver.models.muted_users import MutedUser as MutedUser+from zerver.models.navigation_views import NavigationView as NavigationViewfrom zerver.models.onboarding_steps import OnboardingStep as OnboardingStepfrom zerver.models.prereg_users import EmailChangeStatus as EmailChangeStatusfrom zerver.models.prereg_users import MultiuseInvite as MultiuseInvitediff --git a/zerver/models/navigation_views.py b/zerver/models/navigation_views.pynew file mode 100644index 00000000000..7cfae2d05c3--- /dev/null+++ b/zerver/models/navigation_views.py@@ -0,0 +1,27 @@+from django.db import models+from django.db.models import CASCADE++from zerver.models.users import UserProfile+++class NavigationView(models.Model):+ """+ Represents a user's configuration for pinned views in the left sidebar,+ allowing views to be pinned or hidden.+ """++ # Reference to the user who owns this pinned view configuration.+ user = models.ForeignKey(UserProfile, on_delete=CASCADE)++ # A unique URL hash identifier for the view (e.g., 'inbox', 'narrow/has/reactions'),+ # used for navigation and identification of the view.+ fragment = models.TextField()++ # Whether the view is pinned (True) or hidden in the menu (False).+ is_pinned = models.BooleanField(default=False)++ # Optional display name of the view, provided by the user for custom views.+ name = models.TextField(blank=True, null=True)++ class Meta:+ unique_together = ("user", "fragment")diff --git a/zerver/models/realm_audit_logs.py b/zerver/models/realm_audit_logs.pyindex d00589b3113..304001d0be4 100644--- a/zerver/models/realm_audit_logs.py+++ b/zerver/models/realm_audit_logs.py@@ -115,6 +115,10 @@ class AuditLogEventType(IntEnum):SAVED_SNIPPET_CREATED = 800+ NAVIGATION_VIEW_CREATED = 850+ NAVIGATION_VIEW_UPDATED = 851+ NAVIGATION_VIEW_DELETED = 852+CHANNEL_FOLDER_CREATED = 901CHANNEL_FOLDER_NAME_CHANGED = 902CHANNEL_FOLDER_DESCRIPTION_CHANGED = 903diff --git a/zerver/openapi/python_examples.py b/zerver/openapi/python_examples.pyindex 19c0232db12..be78f3c8382 100644--- a/zerver/openapi/python_examples.py+++ b/zerver/openapi/python_examples.py@@ -1160,6 +1160,74 @@ def remove_attachment(client: Client, attachment_id: int) -> None:validate_against_openapi_schema(result, "/attachments/{attachment_id}", "delete", "200")+@openapi_test_function("/navigation_views:get")+def get_navigation_views(client: Client) -> None:+ # {code_example|start}+ # Get all navigation views for the user+ result = client.call_endpoint(+ url="navigation_views",+ method="GET",+ )+ # {code_example|end}+ assert_success_response(result)+ validate_against_openapi_schema(result, "/navigation_views", "get", "200")+++@openapi_test_function("/navigation_views:post")+def add_navigation_views(client: Client) -> None:+ # {code_example|start}+ # Add a navigation view+ request = {+ "fragment": "narrow/is/alerted",+ "is_pinned": True,+ "name": "Alert Word",+ }+ result = client.call_endpoint(+ url="navigation_views",+ method="POST",+ request=request,+ )+ # {code_example|end}+ assert_success_response(result)+ validate_against_openapi_schema(result, "/navigation_views", "post", "200")+++@openapi_test_function("/navigation_views/{fragment}:patch")+def update_navigation_views(client: Client) -> None:+ # Fetch navigation views for updating+ result = client.call_endpoint(url="navigation_views", method="GET")+ fragment = result["navigation_views"][0]["fragment"]+ # {code_example|start}+ # Update a navigation view's location+ request = {+ "is_pinned": True,+ }+ result = client.call_endpoint(+ url=f"navigation_views/{fragment}",+ method="PATCH",+ request=request,+ )+ # {code_example|end}+ assert_success_response(result)+ validate_against_openapi_schema(result, "/navigation_views/{fragment}", "patch", "200")+++@openapi_test_function("/navigation_views/{fragment}:delete")+def remove_navigation_views(client: Client) -> None:+ # Fetch navigation views for deletion+ result = client.call_endpoint(url="navigation_views", method="GET")+ fragment = result["navigation_views"][0]["fragment"]+ # {code_example|start}+ # Remove a navigation views+ result = client.call_endpoint(+ url=f"navigation_views/{fragment}",+ method="DELETE",+ )+ # {code_example|end}+ assert_success_response(result)+ validate_against_openapi_schema(result, "/navigation_views/{fragment}", "delete", "200")++@openapi_test_function("/saved_snippets:post")def create_saved_snippet(client: Client) -> None:# {code_example|start}@@ -1901,6 +1969,10 @@ def test_users(client: Client, owner_client: Client) -> None:remove_user_mute(client)get_alert_words(client)add_alert_words(client)+ add_navigation_views(client)+ get_navigation_views(client)+ update_navigation_views(client)+ remove_navigation_views(client)create_saved_snippet(client)# Calling this again to pass the curl examples tests as the# `delete-saved-snippet` endpoint is called before `edit-saved-snippet`diff --git a/zerver/openapi/zulip.yaml b/zerver/openapi/zulip.yamlindex 146c8aa8ca6..fcd06bc2654 100644--- a/zerver/openapi/zulip.yaml+++ b/zerver/openapi/zulip.yaml@@ -5517,6 +5517,110 @@ paths:"op": "remove","draft_id": 17,}+ - type: object+ additionalProperties: false+ description: |+ Event containing details of a newly configured navigation view.++ **Changes**: New in Zulip 11.0 (feature level 390).+ properties:+ id:+ $ref: "#/components/schemas/EventIdSchema"+ type:+ allOf:+ - $ref: "#/components/schemas/EventTypeSchema"+ - enum:+ - navigation_view+ op:+ type: string+ enum:+ - add+ navigation_view:+ $ref: "#/components/schemas/NavigationView"+ example:+ {+ "type": "navigation_view",+ "op": "add",+ "navigation_view":+ {+ "fragment": "narrow/is/alerted",+ "is_pinned": true,+ "name": "Alert Words",+ },+ }+ - type: object+ additionalProperties: false+ description: |+ Event containing details of an update to an existing navigation view.++ **Changes**: New in Zulip 11.0 (feature level 390).+ properties:+ id:+ $ref: "#/components/schemas/EventIdSchema"+ type:+ allOf:+ - $ref: "#/components/schemas/EventTypeSchema"+ - enum:+ - navigation_view+ op:+ type: string+ enum:+ - update+ fragment:+ type: string+ description: |+ The unique URL hash of the navigation view being updated.+ data:+ type: object+ additionalProperties: false+ description: |+ A dictionary containing the updated properties of the navigation view.+ properties:+ name:+ type: string+ nullable: true+ description: |+ The user-facing name for custom navigation views. Omit this field for built-in views.+ is_pinned:+ type: boolean+ nullable: true+ description: |+ Determines whether the view is pinned (true) or hidden in the menu (false).+ example:+ {+ "type": "navigation_view",+ "op": "update",+ "fragment": "narrow/is/alerted",+ "data": {"is_pinned": false},+ }+ - type: object+ additionalProperties: false+ description: |+ Event containing the fragment of a deleted navigation view.++ **Changes**: New in Zulip 11.0 (feature level 390).+ properties:+ id:+ $ref: "#/components/schemas/EventIdSchema"+ type:+ allOf:+ - $ref: "#/components/schemas/EventTypeSchema"+ - enum:+ - navigation_view+ op:+ type: string+ enum:+ - remove+ fragment:+ type: string+ description: |+ The unique URL hash of the navigation view that was just deleted.+ example:+ {+ "type": "navigation_view",+ "op": "remove",+ "fragment": "narrow/is/mentioned",+ }- type: objectadditionalProperties: falsedescription: |@@ -6456,6 +6560,217 @@ paths:"result": "error","msg": "Draft does not exist",}+ /navigation_views:+ get:+ operationId: get-navigation-views+ tags: ["navigation_views"]+ summary: Get all navigation views+ description: |+ Fetch all configured custom navigation views for the current user.++ **Changes**: New in Zulip 11.0 (feature level 390).+ responses:+ "200":+ description: Success.+ content:+ application/json:+ schema:+ allOf:+ - $ref: "#/components/schemas/JsonSuccessBase"+ - additionalProperties: false+ properties:+ result: {}+ msg: {}+ navigation_views:+ type: array+ description: |+ An array of dictionaries containing the user's navigation views.+ items:+ $ref: "#/components/schemas/NavigationView"+ example:+ {+ "result": "success",+ "msg": "",+ "navigation_views":+ [+ {+ "fragment": "narrow/is/alerted",+ "is_pinned": false,+ "name": "Alert Words",+ },+ ],+ }+ post:+ operationId: add-navigation-view+ tags: ["navigation_views"]+ summary: Add a navigation view+ description: |+ Adds a new custom left sidebar navigation view configuration+ for the current user.++ This can be used both to configure built-in navigation views,+ or to add new navigation views.++ **Changes**: New in Zulip 11.0 (feature level 390).+ requestBody:+ required: true+ content:+ application/x-www-form-urlencoded:+ schema:+ $ref: "#/components/schemas/NavigationView"+ responses:+ "200":+ description: Request succeeded.+ content:+ application/json:+ schema:+ allOf:+ - $ref: "#/components/schemas/JsonSuccessBase"+ - type: object+ additionalProperties: false+ properties:+ result: {}+ msg: {}+ example: {"result": "success", "msg": ""}+ "400":+ description: Bad request.+ content:+ application/json:+ schema:+ $ref: "#/components/schemas/CodedError"+ examples:+ invalid_parameters:+ value:+ code: "BAD_REQUEST"+ msg: "fragment cannot be blank"+ result: "error"+ /navigation_views/{fragment}:+ patch:+ operationId: edit-navigation-view+ tags: ["navigation_views"]+ summary: Update the navigation view+ description: |+ Update the details of an existing configured navigation view,+ such as its name or whether it's pinned.++ **Changes**: New in Zulip 11.0 (feature level 390).+ parameters:+ - name: fragment+ in: path+ required: true+ schema:+ type: string+ description: |+ The unique URL hash of the navigation view to be updated.++ This also serves as the identifier for the navigation view.+ example: "narrow/is/alerted"+ requestBody:+ required: true+ content:+ application/x-www-form-urlencoded:+ schema:+ type: object+ properties:+ is_pinned:+ type: boolean+ description: |+ Determines whether the view is pinned (true) or hidden in+ the menu (false).+ example: true+ name:+ type: string+ description: |+ The user-facing name for custom navigation views. Omit this+ field for built-in views.+ example: "Watched Phrases"+ anyOf:+ - required:+ - is_pinned+ - required:+ - name+ responses:+ "200":+ description: Success.+ content:+ application/json:+ schema:+ allOf:+ - $ref: "#/components/schemas/JsonSuccessBase"+ - additionalProperties: false+ properties:+ result: {}+ msg: {}+ example: {"result": "success", "msg": ""}+ "400":+ description: Bad request.+ content:+ application/json:+ schema:+ allOf:+ - $ref: "#/components/schemas/CodedError"+ - example:+ {+ "code": "BAD_REQUEST",+ "msg": "Built-in views cannot have a custom name",+ "result": "error",+ }+ description: |+ A typical failed JSON response for invalid parameters.+ "404":+ description: Not Found.+ content:+ application/json:+ schema:+ allOf:+ - $ref: "#/components/schemas/CodedError"+ - description: |+ A typical failed JSON response when no navigation view+ exists with the provided fragment:+ example:+ {+ "code": "NOT_FOUND",+ "result": "error",+ "msg": "Navigation view does not exist.",+ }+ delete:+ operationId: remove-navigation-view+ tags: ["navigation_views"]+ summary: Remove a navigation view+ description: |+ Remove a navigation view.++ **Changes**: New in Zulip 11.0 (feature level 390).+ parameters:+ - name: fragment+ in: path+ schema:+ type: string+ description: |+ The unique URL hash of the navigation view to be removed.++ This also serves as the identifier for the navigation view.+ example: "narrow/is/alerted"+ required: true+ responses:+ "200":+ $ref: "#/components/responses/SimpleSuccess"+ "404":+ description: Not Found.+ content:+ application/json:+ schema:+ allOf:+ - $ref: "#/components/schemas/CodedError"+ - description: |+ A typical failed JSON response for when no navigation+ view exists with the provided fragment:+ example:+ {+ "code": "BAD_REQUEST",+ "result": "error",+ "msg": "Navigation view does not exist.",+ }/saved_snippets:get:operationId: get-saved-snippets@@ -15782,6 +16097,16 @@ paths:The list of users other than the current user in the direct messageconversation. This will be an empty list for direct messages sent tooneself.+ navigation_views:+ type: array+ items:+ $ref: "#/components/schemas/NavigationView"+ description: |+ Present if `navigation_views` is present in `fetch_event_types`.+ An array of dictionaries containing data on all of the current user's+ navigation views.++ **Changes**: New in Zulip 11.0 (feature level 390).saved_snippets:type: arrayitems:@@ -25489,6 +25814,46 @@ components:- to- topic- content+ NavigationView:+ type: object+ description: |+ Represents a user's personal configuration for a specific+ navigation view (displayed most visibly at the top of the web+ application's left sidebar).++ Navigation views can be either an override to the default+ behavior of a built-in view, or a custom view.++ **Changes**: New in Zulip 11.0 (feature level 390).+ additionalProperties: false+ required:+ - fragment+ - is_pinned+ properties:+ fragment:+ type: string+ description: |+ A unique identifier for the view, used to determine navigation+ behavior when clicked.++ Clients should use this value to navigate to the corresponding URL hash.+ example: "narrow/is/alerted"+ is_pinned:+ type: boolean+ description: |+ Determines whether the view appears directly in the sidebar or+ is hidden in the "More Views" menu.++ - `true` - Pinned and visible in the sidebar.+ - `false` - Hidden and accessible via the "More Views" menu.+ example: true+ name:+ type: string+ nullable: true+ description: |+ The user-facing name for custom navigation views. Omit this+ field for built-in views.+ example: "Alert Words"SavedSnippet:type: objectdescription: |diff --git a/zerver/tests/test_audit_log.py b/zerver/tests/test_audit_log.pyindex 6bb771f4d6f..c559a5370c0 100644--- a/zerver/tests/test_audit_log.py+++ b/zerver/tests/test_audit_log.py@@ -25,6 +25,11 @@ from zerver.actions.create_user import (do_create_user,do_reactivate_user,)+from zerver.actions.navigation_views import (+ do_add_navigation_view,+ do_remove_navigation_view,+ do_update_navigation_view,+)from zerver.actions.realm_domains import (do_add_realm_domain,do_change_realm_domain,@@ -1689,3 +1694,92 @@ class TestRealmAuditLog(ZulipTestCase):self.assertIsNone(audit_log_entries[0].modified_user)self.assertIsNone(audit_log_entries[0].modified_user_group)self.assertEqual(audit_log_entries[0].modified_channel_folder, channel_folder)++ def test_navigation_view_entries(self) -> None:+ hamlet = self.example_user("hamlet")++ now = timezone_now()+ navigation_view = do_add_navigation_view(+ hamlet,+ "inbox",+ True,+ "Inbox",+ )+ audit_log_entries = RealmAuditLog.objects.filter(+ acting_user=hamlet,+ realm=hamlet.realm,+ event_time__gte=now,+ event_type=AuditLogEventType.NAVIGATION_VIEW_CREATED,+ )+ self.assert_length(audit_log_entries, 1)+ self.assertEqual(audit_log_entries[0].modified_user, hamlet)+ self.assertEqual(audit_log_entries[0].extra_data, {"fragment": "inbox"})++ now = timezone_now()+ do_update_navigation_view(+ hamlet,+ navigation_view,+ False,+ )+ audit_log_entries = RealmAuditLog.objects.filter(+ acting_user=hamlet,+ realm=hamlet.realm,+ event_time__gte=now,+ event_type=AuditLogEventType.NAVIGATION_VIEW_UPDATED,+ )+ self.assert_length(audit_log_entries, 1)+ self.assertEqual(audit_log_entries[0].modified_user, hamlet)+ self.assertEqual(+ audit_log_entries[0].extra_data,+ {+ "fragment": "inbox",+ RealmAuditLog.OLD_VALUE: True,+ RealmAuditLog.NEW_VALUE: False,+ "property": "is_pinned",+ },+ )++ now = timezone_now()+ do_update_navigation_view(hamlet, navigation_view, True, "Inbox view")+ audit_log_entries = RealmAuditLog.objects.filter(+ acting_user=hamlet,+ realm=hamlet.realm,+ event_time__gte=now,+ event_type=AuditLogEventType.NAVIGATION_VIEW_UPDATED,+ )+ self.assert_length(audit_log_entries, 2)+ self.assertEqual(audit_log_entries[0].modified_user, hamlet)+ self.assertEqual(audit_log_entries[1].modified_user, hamlet)+ self.assertEqual(+ audit_log_entries[0].extra_data,+ {+ "fragment": "inbox",+ RealmAuditLog.OLD_VALUE: "Inbox",+ RealmAuditLog.NEW_VALUE: "Inbox view",+ "property": "name",+ },+ )+ self.assertEqual(+ audit_log_entries[1].extra_data,+ {+ "fragment": "inbox",+ RealmAuditLog.OLD_VALUE: False,+ RealmAuditLog.NEW_VALUE: True,+ "property": "is_pinned",+ },+ )++ now = timezone_now()+ do_remove_navigation_view(+ hamlet,+ navigation_view,+ )+ audit_log_entries = RealmAuditLog.objects.filter(+ acting_user=hamlet,+ realm=hamlet.realm,+ event_time__gte=now,+ event_type=AuditLogEventType.NAVIGATION_VIEW_DELETED,+ )+ self.assert_length(audit_log_entries, 1)+ self.assertEqual(audit_log_entries[0].modified_user, hamlet)+ self.assertEqual(audit_log_entries[0].extra_data, {"fragment": "inbox"})diff --git a/zerver/tests/test_event_system.py b/zerver/tests/test_event_system.pyindex c07b9f7a60d..833e9635bb9 100644--- a/zerver/tests/test_event_system.py+++ b/zerver/tests/test_event_system.py@@ -1241,7 +1241,7 @@ class FetchQueriesTest(ZulipTestCase):self.login_user(user)with (- self.assert_database_query_count(45),+ self.assert_database_query_count(46),mock.patch("zerver.lib.events.always_want") as want_mock,):fetch_initial_state_data(user, realm=user.realm)@@ -1256,6 +1256,7 @@ class FetchQueriesTest(ZulipTestCase):message=1,muted_topics=1,muted_users=1,+ navigation_views=1,onboarding_steps=1,presence=1,# 2 of the 3 queries here are a single query that is useddiff --git a/zerver/tests/test_events.py b/zerver/tests/test_events.pyindex 6f7cc4d7f7c..9810c11c767 100644--- a/zerver/tests/test_events.py+++ b/zerver/tests/test_events.py@@ -67,6 +67,11 @@ from zerver.actions.message_edit import ()from zerver.actions.message_flags import do_update_message_flagsfrom zerver.actions.muted_users import do_mute_user, do_unmute_user+from zerver.actions.navigation_views import (+ do_add_navigation_view,+ do_remove_navigation_view,+ do_update_navigation_view,+)from zerver.actions.onboarding_steps import do_mark_onboarding_step_as_readfrom zerver.actions.presence import do_update_user_presencefrom zerver.actions.reactions import do_add_reaction, do_remove_reaction@@ -178,6 +183,9 @@ from zerver.lib.event_schema import (check_message,check_muted_topics,check_muted_users,+ check_navigation_view_add,+ check_navigation_view_remove,+ check_navigation_view_update,check_onboarding_steps,check_presence,check_reaction_add,@@ -1758,6 +1766,29 @@ class NormalActionsTest(BaseAction):check_realm_user_update("events[0]", events[0], "custom_profile_field")self.assertEqual(events[0]["person"]["custom_profile_field"].keys(), {"id", "value"})+ def test_navigation_views_events(self) -> None:+ with self.verify_action() as events:+ navigation_view = do_add_navigation_view(+ self.user_profile, fragment="inbox", is_pinned=True, name=None+ )+ check_navigation_view_add("events[0]", events[0])+ self.assertEqual(events[0]["navigation_view"]["fragment"], "inbox")+ self.assertEqual(events[0]["navigation_view"]["is_pinned"], True)+ self.assertIsNone(events[0]["navigation_view"]["name"])++ with self.verify_action() as events:+ do_update_navigation_view(+ self.user_profile, navigation_view, is_pinned=False, name=None+ )+ check_navigation_view_update("events[0]", events[0])+ self.assertEqual(events[0]["fragment"], "inbox")+ self.assertEqual(events[0]["data"]["is_pinned"], False)++ with self.verify_action() as events:+ do_remove_navigation_view(self.user_profile, navigation_view)+ check_navigation_view_remove("events[0]", events[0])+ self.assertEqual(events[0]["fragment"], "inbox")+def test_presence_events(self) -> None:with self.verify_action(slim_presence=False) as events:do_update_user_presence(diff --git a/zerver/tests/test_home.py b/zerver/tests/test_home.pyindex 5215dbad533..310fd67c079 100644--- a/zerver/tests/test_home.py+++ b/zerver/tests/test_home.py@@ -108,6 +108,7 @@ class HomeTest(ZulipTestCase):"muted_topics","muted_users","navigation_tour_video_url",+ "navigation_views","never_subscribed","onboarding_steps","password_min_guesses",@@ -280,7 +281,7 @@ class HomeTest(ZulipTestCase):# Verify succeeds once logged-inwith (- self.assert_database_query_count(55),+ self.assert_database_query_count(56),patch("zerver.lib.cache.cache_set") as cache_mock,):result = self._get_home_page(stream="Denmark")@@ -588,7 +589,7 @@ class HomeTest(ZulipTestCase):# Verify number of queries for Realm admin isn't much higher than for normal users.self.login("iago")with (- self.assert_database_query_count(54),+ self.assert_database_query_count(55),patch("zerver.lib.cache.cache_set") as cache_mock,):result = self._get_home_page()@@ -620,7 +621,7 @@ class HomeTest(ZulipTestCase):self._get_home_page()# Then for the second page load, measure the number of queries.- with self.assert_database_query_count(50):+ with self.assert_database_query_count(51):result = self._get_home_page()# Do a sanity check that our new streams were in the payload.diff --git a/zerver/tests/test_import_export.py b/zerver/tests/test_import_export.pyindex 812d0d0e8b1..19bf80abf04 100644--- a/zerver/tests/test_import_export.py+++ b/zerver/tests/test_import_export.py@@ -26,6 +26,7 @@ from zerver.actions.custom_profile_fields import (try_add_realm_custom_profile_field,)from zerver.actions.muted_users import do_mute_user+from zerver.actions.navigation_views import do_add_navigation_viewfrom zerver.actions.presence import do_update_user_presencefrom zerver.actions.reactions import check_add_reactionfrom zerver.actions.realm_emoji import check_add_realm_emoji@@ -84,6 +85,7 @@ from zerver.models import (Message,MutedUser,NamedUserGroup,+ NavigationView,OnboardingStep,OnboardingUserMessage,Reaction,@@ -1580,6 +1582,17 @@ class RealmImportExportTest(ExportFile):reaction_type=Reaction.REALM_EMOJI,)+ do_add_navigation_view(+ hamlet,+ "inbox",+ True,+ )+ do_add_navigation_view(+ hamlet,+ "recent",+ False,+ )+user_status = UserStatus.objects.order_by("id").last()assert user_status@@ -2099,6 +2112,14 @@ class RealmImportExportTest(ExportFile):)return onboarding_steps+ @getter+ def get_navigation_views(r: Realm) -> set[str]:+ user_id = get_user_id(r, "King Hamlet")+ navigation_views = set(+ NavigationView.objects.filter(user_id=user_id).values_list("fragment", flat=True)+ )+ return navigation_views+# test muted topics@getterdef get_muted_topics(r: Realm) -> set[str]:@@ -3029,6 +3050,14 @@ class SingleUserExportTest(ExportFile):def zerver_muteduser(records: list[Record]) -> None:self.assertEqual(records[-1]["muted_user"], othello.id)+ do_add_navigation_view(hamlet, "inbox", True)+ do_add_navigation_view(cordelia, "recent", False)++ @checker+ def zerver_navigationview(records: list[Record]) -> None:+ self.assertEqual(records[-1]["fragment"], "recent")+ self.assertEqual(records[-1]["is_pinned"], False)+smile_message_id = self.send_stream_message(hamlet, "Denmark")check_add_reaction(diff --git a/zerver/tests/test_navigation_views.py b/zerver/tests/test_navigation_views.pynew file mode 100644index 00000000000..514a1f73294--- /dev/null+++ b/zerver/tests/test_navigation_views.py@@ -0,0 +1,170 @@+from zerver.actions.navigation_views import do_add_navigation_view+from zerver.lib.navigation_views import get_navigation_views_for_user+from zerver.lib.test_classes import ZulipTestCase+from zerver.models import UserProfile+++class NavigationViewTests(ZulipTestCase):+ def create_example_navigation_view(+ self, user: UserProfile, fragment: str, is_pinned: bool, name: str | None = None+ ) -> str:+ do_add_navigation_view(+ user,+ fragment,+ is_pinned,+ name,+ )+ return fragment++ def test_get_navigation_views(self) -> None:+ """Tests fetching navigation views."""+ user = self.example_user("hamlet")+ self.login_user(user)++ result = self.client_get("/json/navigation_views")+ response_dict = self.assert_json_success(result)+ self.assert_length(response_dict["navigation_views"], 0)++ # Test adding a built-in view and fetching it+ self.create_example_navigation_view(user, fragment="inbox", is_pinned=True)+ result = self.client_get("/json/navigation_views")+ response_dict = self.assert_json_success(result)+ self.assert_length(response_dict["navigation_views"], 1)+ self.assertEqual(response_dict["navigation_views"][0]["fragment"], "inbox")+ self.assertEqual(response_dict["navigation_views"][0]["is_pinned"], True)++ def test_add_navigation_view(self) -> None:+ """Tests creation of navigation views."""+ user = self.example_user("hamlet")+ self.login_user(user)++ # Test successful creation+ params = {+ "fragment": "recent",+ "is_pinned": "true",+ }+ result = self.client_post("/json/navigation_views", params)+ self.assert_json_success(result)++ # Test name value for builtin views+ params["name"] = "foo"+ result = self.client_post("/json/navigation_views", params)+ self.assert_json_error(result, "Built-in views cannot have a custom name.")++ # Test empty fragment+ params["fragment"] = ""+ result = self.client_post("/json/navigation_views", params)+ self.assert_json_error(result, "fragment cannot be blank")++ # Test no name value for custom views+ params = {+ "fragment": "narrow/view",+ "is_pinned": "true",+ }+ result = self.client_post("/json/navigation_views", params)+ self.assert_json_error(result, "Custom views must have a valid name.")++ # Test custom view with name value+ params["name"] = "foo"+ result = self.client_post("/json/navigation_views", params)+ self.assert_json_success(result)++ # Test duplicate view+ new_params = {+ "fragment": "recent",+ "is_pinned": "true",+ }+ result = self.client_post("/json/navigation_views", new_params)+ self.assert_json_error(result, "Navigation view already exists.")++ # Test duplicate view by name+ new_params = {+ "fragment": "narorw/is/attachment",+ "is_pinned": "true",+ "name": "foo",+ }+ result = self.client_post("/json/navigation_views", new_params)+ self.assert_json_error(result, "Navigation view already exists.")++ def test_update_navigation_view(self) -> None:+ """Tests updating navigation views."""+ user = self.example_user("hamlet")+ self.login_user(user)+ self.create_example_navigation_view(user, fragment="inbox", is_pinned=True)++ # Test successful update+ params = {+ "is_pinned": "false",+ }+ result = self.client_patch("/json/navigation_views/inbox", params)+ self.assert_json_success(result)++ navigation_views = get_navigation_views_for_user(user)+ self.assertEqual(navigation_views[0]["is_pinned"], False)++ params = {+ "is_pinned": "true",+ "name": "Inbox View",+ }+ result = self.client_patch("/json/navigation_views/inbox", params)+ self.assert_json_error(result, "Built-in views cannot have a custom name.")++ # Test with the name for custom views+ self.create_example_navigation_view(+ user, fragment="narrow/is/alerted", is_pinned=True, name="Alert Words"+ )+ params = {+ "is_pinned": "false",+ "name": "Watched Phrases",+ }+ result = self.client_patch("/json/navigation_views/narrow/is/alerted", params)+ self.assert_json_success(result)++ self.create_example_navigation_view(+ user, fragment="narrow/is/attachment", is_pinned=True, name="Attachments"+ )+ params = {+ "is_pinned": "false",+ "name": "Watched Phrases",+ }+ result = self.client_patch("/json/navigation_views/narrow/is/attachment", params)+ self.assert_json_error(result, "Navigation view already exists.")++ params = {+ "is_pinned": "false",+ "name": "New view",+ }+ # Test nonexistent view+ result = self.client_patch("/json/navigation_views/nonexistent", params)+ self.assert_json_error(result, "Navigation view does not exist.", status_code=404)++ def test_remove_navigation_view(self) -> None:+ """Tests removing navigation views."""+ user = self.example_user("hamlet")+ self.login_user(user)+ self.create_example_navigation_view(user, fragment="recent", is_pinned=True)++ # Test successful removal+ result = self.client_delete("/json/navigation_views/recent")+ self.assert_json_success(result)++ navigation_views = get_navigation_views_for_user(user)+ self.assert_length(navigation_views, 0)++ # Test nonexistent view+ result = self.client_delete("/json/navigation_views/nonexistent")+ self.assert_json_error(result, "Navigation view does not exist.", status_code=404)++ def test_navigation_view_permissions(self) -> None:+ """Tests permissions for navigation view operations."""+ hamlet = self.example_user("hamlet")+ othello = self.example_user("othello")+ self.login_user(othello)++ self.create_example_navigation_view(hamlet, fragment="recent", is_pinned=True)++ params = {+ "is_pinned": "false",+ }+ result = self.client_patch("/json/navigation_views/recent", params)+ self.assert_json_error(result, "Navigation view does not exist.", status_code=404)diff --git a/zerver/tests/test_openapi.py b/zerver/tests/test_openapi.pyindex 2b9069939a1..bc3ffafc518 100644--- a/zerver/tests/test_openapi.py+++ b/zerver/tests/test_openapi.py@@ -913,6 +913,7 @@ class OpenAPIAttributesTest(ZulipTestCase):"mobile","invites","reminders",+ "navigation_views",]paths = OpenAPISpec(OPENAPI_SPEC_PATH).openapi()["paths"]for path, path_item in paths.items():diff --git a/zerver/views/navigation_views.py b/zerver/views/navigation_views.pynew file mode 100644index 00000000000..2b545a5046b--- /dev/null+++ b/zerver/views/navigation_views.py@@ -0,0 +1,115 @@+from typing import Annotated++from django.http import HttpRequest, HttpResponse+from django.utils.translation import gettext as _+from pydantic import Json, StringConstraints++from zerver.actions.navigation_views import (+ do_add_navigation_view,+ do_remove_navigation_view,+ do_update_navigation_view,+)+from zerver.lib.exceptions import JsonableError+from zerver.lib.navigation_views import get_navigation_view, get_navigation_views_for_user+from zerver.lib.response import json_success+from zerver.lib.typed_endpoint import typed_endpoint+from zerver.models import NavigationView, UserProfile++BUILT_IN_VIEW_FRAGMENTS = [+ "inbox",+ "recent",+ "feed",+ "drafts",+ # Reactions view+ "narrow/has/reaction/sender/me",+ # Mentions view+ "narrow/is/mentioned",+ # Starred messages view+ "narrow/is/starred",+]+++def get_navigation_views(+ request: HttpRequest,+ user_profile: UserProfile,+) -> HttpResponse:+ """+ Fetch navigation views for the specified user.+ """+ navigation_views = get_navigation_views_for_user(user_profile)+ return json_success(request, data={"navigation_views": navigation_views})+++@typed_endpoint+def add_navigation_view(+ request: HttpRequest,+ user_profile: UserProfile,+ *,+ fragment: Annotated[str, StringConstraints(strip_whitespace=True, min_length=1)],+ is_pinned: Json[bool],+ name: Annotated[str, StringConstraints(strip_whitespace=True, min_length=1)] | None = None,+) -> HttpResponse:+ """+ Add a new navigation view (or settings for a default view) for the user.+ """+ if fragment in BUILT_IN_VIEW_FRAGMENTS:+ if name is not None:+ raise JsonableError(_("Built-in views cannot have a custom name."))+ else:+ if not name:+ raise JsonableError(_("Custom views must have a valid name."))++ if NavigationView.objects.filter(user=user_profile, fragment=fragment).exists():+ raise JsonableError(_("Navigation view already exists."))+ if name is not None and NavigationView.objects.filter(user=user_profile, name=name).exists():+ raise JsonableError(_("Navigation view already exists."))++ do_add_navigation_view(+ user_profile,+ fragment,+ is_pinned,+ name,+ )+ return json_success(request)+++@typed_endpoint+def update_navigation_view(+ request: HttpRequest,+ user_profile: UserProfile,+ fragment: Annotated[str, StringConstraints(strip_whitespace=True, min_length=1)],+ *,+ name: Annotated[str, StringConstraints(strip_whitespace=True, min_length=1)] | None = None,+ is_pinned: Json[bool] | None = None,+) -> HttpResponse:+ """+ Update an existing navigation view for the user.+ """+ if fragment in BUILT_IN_VIEW_FRAGMENTS and name is not None:+ raise JsonableError(_("Built-in views cannot have a custom name."))+ if name is not None and NavigationView.objects.filter(user=user_profile, name=name).exists():+ raise JsonableError(_("Navigation view already exists."))++ navigation_view = get_navigation_view(user_profile, fragment)++ do_update_navigation_view(+ user_profile,+ navigation_view,+ is_pinned,+ name,+ )+ return json_success(request)+++def remove_navigation_view(+ request: HttpRequest,+ user_profile: UserProfile,+ *,+ fragment: Annotated[str, StringConstraints(strip_whitespace=True, min_length=1)],+) -> HttpResponse:+ """+ Remove a navigation view for the user.+ """+ navigation_view = get_navigation_view(user_profile, fragment)+ do_remove_navigation_view(user_profile, navigation_view)+ return json_success(request)diff --git a/zproject/urls.py b/zproject/urls.pyindex d8372711a40..dc70da6aef6 100644--- a/zproject/urls.py+++ b/zproject/urls.py@@ -92,6 +92,12 @@ from zerver.views.message_report import report_message_backendfrom zerver.views.message_send import render_message_backend, send_message_backend, zcommand_backendfrom zerver.views.message_summary import get_messages_summaryfrom zerver.views.muted_users import mute_user, unmute_user+from zerver.views.navigation_views import (+ add_navigation_view,+ get_navigation_views,+ remove_navigation_view,+ update_navigation_view,+)from zerver.views.onboarding_steps import mark_onboarding_step_as_readfrom zerver.views.presence import (get_presence_backend,@@ -358,6 +364,13 @@ v1_api_and_json_patterns = [# Endpoints for syncing drafts.rest_path("drafts", GET=fetch_drafts, POST=create_drafts),rest_path("drafts/<int:draft_id>", PATCH=edit_draft, DELETE=delete_draft),+ # navigation_views -> zerver.views.navigation_views+ rest_path("navigation_views", GET=get_navigation_views, POST=add_navigation_view),+ rest_path(+ "navigation_views/<path:fragment>",+ PATCH=update_navigation_view,+ DELETE=remove_navigation_view,+ ),# saved_snippets -> zerver.views.saved_snippetsrest_path("saved_snippets", GET=get_saved_snippets, POST=create_saved_snippet),rest_path(