channel-folders: Add order field and backfill it alphabetically.

This commit is contained in:
Shubham Padia
2025-08-05 15:12:39 +00:00
committed by Tim Abbott
parent d609bd44a9
commit 40132e200b
5 changed files with 60 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
* [`POST /channel_folders/create`](/api/create-channel-folder),
[`GET /channel_folders`](/api/get-channel-folders),
[`PATCH /channel_folders/{channel_folder_id}`](/api/update-channel-folder):
Added a new field `order` to show in which order should channel folders be
displayed. The list is 0-indexed and works similar to the `order` field of
custom profile fields.

View File

@@ -15,6 +15,7 @@ class ChannelFolderDict(TypedDict):
name: str
description: str
rendered_description: str
order: int
creator_id: int | None
date_created: int
is_archived: bool
@@ -49,6 +50,7 @@ def get_channel_folder_dict(channel_folder: ChannelFolder) -> ChannelFolderDict:
name=channel_folder.name,
description=channel_folder.description,
rendered_description=channel_folder.rendered_description,
order=channel_folder.order,
date_created=date_created,
creator_id=channel_folder.creator_id,
is_archived=channel_folder.is_archived,

View File

@@ -0,0 +1,42 @@
# Generated by Django 5.2.4 on 2025-08-05 08:53
from django.db import migrations, models
from django.db.backends.base.schema import BaseDatabaseSchemaEditor
from django.db.migrations.state import StateApps
from django.db.models.functions import Lower
def migrate_set_order_value(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
Realm = apps.get_model("zerver", "Realm")
ChannelFolder = apps.get_model("zerver", "ChannelFolder")
realms = Realm.objects.all()
for realm in realms:
channel_folders = list(
ChannelFolder.objects.filter(realm_id=realm.id)
.annotate(lower_name=Lower("name"))
.order_by("lower_name")
)
for index, folder in enumerate(channel_folders):
folder.order = index
ChannelFolder.objects.bulk_update(channel_folders, ["order"])
class Migration(migrations.Migration):
dependencies = [
("zerver", "0747_realmcreationstatus"),
]
operations = [
migrations.AddField(
model_name="channelfolder",
name="order",
field=models.IntegerField(default=0),
),
migrations.RunPython(
migrate_set_order_value, reverse_code=migrations.RunPython.noop, elidable=True
),
]

View File

@@ -15,6 +15,7 @@ class ChannelFolder(models.Model):
name = models.CharField(max_length=MAX_NAME_LENGTH)
description = models.CharField(max_length=MAX_DESCRIPTION_LENGTH, default="")
rendered_description = models.TextField(default="")
order = models.IntegerField(default=0)
date_created = models.DateTimeField(default=timezone_now)
creator = models.ForeignKey(UserProfile, null=True, on_delete=models.SET_NULL)

View File

@@ -6081,6 +6081,7 @@ paths:
"date_created": 1717484476,
"description": "Channels for frontend discussions",
"rendered_description": "<p>Channels for frontend discussions</p>",
"order": 1,
"id": 2,
"is_archived": false,
},
@@ -27561,6 +27562,14 @@ components:
work correctly. And any client-side security logic for
user-generated message content should be applied when displaying
this HTML as though it were the body of a Zulip message.
order:
type: integer
description: |
This value determines in which order the channel folders will be
displayed in the UI. The value is 0 indexed, and the value with
the lower order will be displayed first.
**Changes**: New in Zulip 11.0 (feature level ZF-fcae8c).
id:
type: integer
description: |