mirror of
https://github.com/zulip/zulip.git
synced 2025-10-23 04:52:12 +00:00
channel-folders: Add order field and backfill it alphabetically.
This commit is contained in:
committed by
Tim Abbott
parent
d609bd44a9
commit
40132e200b
6
api_docs/unmerged.d/ZF-fcae8c.md
Normal file
6
api_docs/unmerged.d/ZF-fcae8c.md
Normal 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.
|
@@ -15,6 +15,7 @@ class ChannelFolderDict(TypedDict):
|
|||||||
name: str
|
name: str
|
||||||
description: str
|
description: str
|
||||||
rendered_description: str
|
rendered_description: str
|
||||||
|
order: int
|
||||||
creator_id: int | None
|
creator_id: int | None
|
||||||
date_created: int
|
date_created: int
|
||||||
is_archived: bool
|
is_archived: bool
|
||||||
@@ -49,6 +50,7 @@ def get_channel_folder_dict(channel_folder: ChannelFolder) -> ChannelFolderDict:
|
|||||||
name=channel_folder.name,
|
name=channel_folder.name,
|
||||||
description=channel_folder.description,
|
description=channel_folder.description,
|
||||||
rendered_description=channel_folder.rendered_description,
|
rendered_description=channel_folder.rendered_description,
|
||||||
|
order=channel_folder.order,
|
||||||
date_created=date_created,
|
date_created=date_created,
|
||||||
creator_id=channel_folder.creator_id,
|
creator_id=channel_folder.creator_id,
|
||||||
is_archived=channel_folder.is_archived,
|
is_archived=channel_folder.is_archived,
|
||||||
|
42
zerver/migrations/0748_channelfolder_add_order.py
Normal file
42
zerver/migrations/0748_channelfolder_add_order.py
Normal 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
|
||||||
|
),
|
||||||
|
]
|
@@ -15,6 +15,7 @@ class ChannelFolder(models.Model):
|
|||||||
name = models.CharField(max_length=MAX_NAME_LENGTH)
|
name = models.CharField(max_length=MAX_NAME_LENGTH)
|
||||||
description = models.CharField(max_length=MAX_DESCRIPTION_LENGTH, default="")
|
description = models.CharField(max_length=MAX_DESCRIPTION_LENGTH, default="")
|
||||||
rendered_description = models.TextField(default="")
|
rendered_description = models.TextField(default="")
|
||||||
|
order = models.IntegerField(default=0)
|
||||||
|
|
||||||
date_created = models.DateTimeField(default=timezone_now)
|
date_created = models.DateTimeField(default=timezone_now)
|
||||||
creator = models.ForeignKey(UserProfile, null=True, on_delete=models.SET_NULL)
|
creator = models.ForeignKey(UserProfile, null=True, on_delete=models.SET_NULL)
|
||||||
|
@@ -6081,6 +6081,7 @@ paths:
|
|||||||
"date_created": 1717484476,
|
"date_created": 1717484476,
|
||||||
"description": "Channels for frontend discussions",
|
"description": "Channels for frontend discussions",
|
||||||
"rendered_description": "<p>Channels for frontend discussions</p>",
|
"rendered_description": "<p>Channels for frontend discussions</p>",
|
||||||
|
"order": 1,
|
||||||
"id": 2,
|
"id": 2,
|
||||||
"is_archived": false,
|
"is_archived": false,
|
||||||
},
|
},
|
||||||
@@ -27561,6 +27562,14 @@ components:
|
|||||||
work correctly. And any client-side security logic for
|
work correctly. And any client-side security logic for
|
||||||
user-generated message content should be applied when displaying
|
user-generated message content should be applied when displaying
|
||||||
this HTML as though it were the body of a Zulip message.
|
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:
|
id:
|
||||||
type: integer
|
type: integer
|
||||||
description: |
|
description: |
|
||||||
|
Reference in New Issue
Block a user