folders: Don't allow archiving a folder if it contains channels.

This commit is contained in:
Sahil Batra
2025-05-21 15:09:51 +05:30
committed by Tim Abbott
parent 677390d3f6
commit d8ae21a4f4
3 changed files with 41 additions and 2 deletions

View File

@@ -1,6 +1,7 @@
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.channel_folders import (
@@ -12,10 +13,12 @@ from zerver.actions.channel_folders import (
)
from zerver.decorator import require_realm_admin
from zerver.lib.channel_folders import (
check_channel_folder_in_use,
check_channel_folder_name,
get_channel_folder_by_id,
get_channel_folders_in_realm,
)
from zerver.lib.exceptions import JsonableError
from zerver.lib.response import json_success
from zerver.lib.typed_endpoint import PathOnly, typed_endpoint
from zerver.models.channel_folders import ChannelFolder
@@ -71,6 +74,11 @@ def update_channel_folder(
if is_archived is not None and channel_folder.is_archived != is_archived:
if is_archived:
if check_channel_folder_in_use(channel_folder):
raise JsonableError(
_("You need to remove all the channels from this folder to archive it.")
)
do_archive_channel_folder(channel_folder, acting_user=user_profile)
else:
do_unarchive_channel_folder(channel_folder, acting_user=user_profile)