mirror of
https://github.com/zulip/zulip.git
synced 2025-11-05 22:43:42 +00:00
channel-folders: Order by order field in GET method.
This commit is contained in:
committed by
Tim Abbott
parent
22b231ab6f
commit
c4cb75979a
@@ -7,3 +7,5 @@
|
|||||||
* [`PATCH /channel_folders`](/api/patch-channel-folders): Added a new
|
* [`PATCH /channel_folders`](/api/patch-channel-folders): Added a new
|
||||||
endpoint for reordering channel folders. It accepts an array of channel
|
endpoint for reordering channel folders. It accepts an array of channel
|
||||||
folder IDs arranged in the order the user desires it to be in.
|
folder IDs arranged in the order the user desires it to be in.
|
||||||
|
* [`GET /channel_folders`](/api/get-channel-folders): Channel folders will
|
||||||
|
be ordered by the `order` field instead of `id` field when being returned.
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ def get_channel_folders_in_realm(
|
|||||||
folders = folders.exclude(is_archived=True)
|
folders = folders.exclude(is_archived=True)
|
||||||
|
|
||||||
channel_folders = [get_channel_folder_dict(channel_folder) for channel_folder in folders]
|
channel_folders = [get_channel_folder_dict(channel_folder) for channel_folder in folders]
|
||||||
return sorted(channel_folders, key=lambda folder: folder["id"])
|
return sorted(channel_folders, key=lambda folder: folder["order"])
|
||||||
|
|
||||||
|
|
||||||
def get_channel_folder_by_id(channel_folder_id: int, realm: Realm) -> ChannelFolder:
|
def get_channel_folder_by_id(channel_folder_id: int, realm: Realm) -> ChannelFolder:
|
||||||
|
|||||||
@@ -24453,8 +24453,12 @@ paths:
|
|||||||
tags: ["channels"]
|
tags: ["channels"]
|
||||||
description: |
|
description: |
|
||||||
Fetches all of the channel folders in the organization.
|
Fetches all of the channel folders in the organization.
|
||||||
|
The folders are sorted by the `order` field.
|
||||||
|
|
||||||
**Changes**: New in Zulip 11.0 (feature level 389).
|
**Changes**: Before Zulip 11.0 (feature level ZF-fcae8c),
|
||||||
|
these were sorted by ID. (The `order` field didn't exist).
|
||||||
|
|
||||||
|
New in Zulip 11.0 (feature level 389).
|
||||||
requestBody:
|
requestBody:
|
||||||
required: false
|
required: false
|
||||||
content:
|
content:
|
||||||
|
|||||||
@@ -3,7 +3,11 @@ from typing import Any
|
|||||||
import orjson
|
import orjson
|
||||||
from typing_extensions import override
|
from typing_extensions import override
|
||||||
|
|
||||||
from zerver.actions.channel_folders import check_add_channel_folder, do_archive_channel_folder
|
from zerver.actions.channel_folders import (
|
||||||
|
check_add_channel_folder,
|
||||||
|
do_archive_channel_folder,
|
||||||
|
try_reorder_realm_channel_folders,
|
||||||
|
)
|
||||||
from zerver.actions.streams import do_change_stream_folder, do_deactivate_stream
|
from zerver.actions.streams import do_change_stream_folder, do_deactivate_stream
|
||||||
from zerver.lib.test_classes import ZulipTestCase
|
from zerver.lib.test_classes import ZulipTestCase
|
||||||
from zerver.models import ChannelFolder
|
from zerver.models import ChannelFolder
|
||||||
@@ -215,6 +219,24 @@ class GetChannelFoldersTest(ChannelFoldersTestCase):
|
|||||||
channel_folders_data = orjson.loads(result.content)["channel_folders"]
|
channel_folders_data = orjson.loads(result.content)["channel_folders"]
|
||||||
check_channel_folders_in_zulip_realm(channel_folders_data)
|
check_channel_folders_in_zulip_realm(channel_folders_data)
|
||||||
|
|
||||||
|
def test_get_channel_folders_according_to_order(self) -> None:
|
||||||
|
iago = self.example_user("iago")
|
||||||
|
realm = iago.realm
|
||||||
|
self.login_user(iago)
|
||||||
|
|
||||||
|
result = self.client_get("/json/channel_folders")
|
||||||
|
channel_folders_data = orjson.loads(result.content)["channel_folders"]
|
||||||
|
channel_folders_names = [item["name"] for item in channel_folders_data]
|
||||||
|
self.assertEqual(channel_folders_names, ["Frontend", "Backend", "Marketing"])
|
||||||
|
|
||||||
|
try_reorder_realm_channel_folders(
|
||||||
|
realm, reversed([item["id"] for item in channel_folders_data])
|
||||||
|
)
|
||||||
|
result = self.client_get("/json/channel_folders")
|
||||||
|
channel_folders_data = orjson.loads(result.content)["channel_folders"]
|
||||||
|
channel_folders_names = [item["name"] for item in channel_folders_data]
|
||||||
|
self.assertEqual(channel_folders_names, ["Marketing", "Backend", "Frontend"])
|
||||||
|
|
||||||
|
|
||||||
class UpdateChannelFoldersTest(ChannelFoldersTestCase):
|
class UpdateChannelFoldersTest(ChannelFoldersTestCase):
|
||||||
def test_updating_channel_folder_name(self) -> None:
|
def test_updating_channel_folder_name(self) -> None:
|
||||||
|
|||||||
Reference in New Issue
Block a user