snapshot of https://github.com/zulip/zulip.git @ 48c69911c7dd4e03b20552eb3bd77ad8151c1357 (2026-09-15)
Some checks failed
Code scanning / CodeQL (push) Failing after 15s
Zulip production suite / Ubuntu 22.04 production build (push) Failing after 26s
Zulip production suite / Debian 12 production install with custom db name and user (push) Has been skipped
Zulip production suite / Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga (push) Has been skipped
Zulip production suite / Ubuntu 24.04 production install (push) Has been skipped
Zulip production suite / Ubuntu 26.04 production install (push) Has been skipped
Zulip production suite / Debian 13 production install (push) Has been skipped
Zulip production suite / 7.0 Version Upgrade (push) Has been skipped
Zulip production suite / 8.0 Version Upgrade (push) Has been skipped
Zulip production suite / 6.0 Version Upgrade (push) Has been skipped
Zulip production suite / 10.0 Version Upgrade (push) Has been skipped
Zulip production suite / 9.0 Version Upgrade (push) Has been skipped
Zulip production suite / 12.0 Version Upgrade (push) Has been skipped
Zulip production suite / 11.0 Version Upgrade (push) Has been skipped
GitHub Actions Security Analysis with zizmor / zizmor (push) Failing after 3s
Zulip CI / Debian 12 (Python 3.11, backend + documentation) (push) Failing after 26s
Zulip CI / Ubuntu 22.04 (Python 3.10, backend + frontend) (push) Failing after 3s
Zulip CI / Ubuntu 24.04 (Python 3.12, backend) (push) Failing after 25s
Zulip CI / Ubuntu 26.04 (Python 3.14, backend) (push) Failing after 25s
Zulip CI / Debian 13 (Python 3.13, backend) (push) Failing after 28s
Zulip production suite / Required jobs (push) Has been cancelled
Zulip CI / Required jobs (push) Has been cancelled
API Documentation Update Check / check-feature-level-updated (push) Has been cancelled
API Documentation Update Check / notify-if-api-docs-changed (push) Has been cancelled
Some checks failed
Code scanning / CodeQL (push) Failing after 15s
Zulip production suite / Ubuntu 22.04 production build (push) Failing after 26s
Zulip production suite / Debian 12 production install with custom db name and user (push) Has been skipped
Zulip production suite / Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga (push) Has been skipped
Zulip production suite / Ubuntu 24.04 production install (push) Has been skipped
Zulip production suite / Ubuntu 26.04 production install (push) Has been skipped
Zulip production suite / Debian 13 production install (push) Has been skipped
Zulip production suite / 7.0 Version Upgrade (push) Has been skipped
Zulip production suite / 8.0 Version Upgrade (push) Has been skipped
Zulip production suite / 6.0 Version Upgrade (push) Has been skipped
Zulip production suite / 10.0 Version Upgrade (push) Has been skipped
Zulip production suite / 9.0 Version Upgrade (push) Has been skipped
Zulip production suite / 12.0 Version Upgrade (push) Has been skipped
Zulip production suite / 11.0 Version Upgrade (push) Has been skipped
GitHub Actions Security Analysis with zizmor / zizmor (push) Failing after 3s
Zulip CI / Debian 12 (Python 3.11, backend + documentation) (push) Failing after 26s
Zulip CI / Ubuntu 22.04 (Python 3.10, backend + frontend) (push) Failing after 3s
Zulip CI / Ubuntu 24.04 (Python 3.12, backend) (push) Failing after 25s
Zulip CI / Ubuntu 26.04 (Python 3.14, backend) (push) Failing after 25s
Zulip CI / Debian 13 (Python 3.13, backend) (push) Failing after 28s
Zulip production suite / Required jobs (push) Has been cancelled
Zulip CI / Required jobs (push) Has been cancelled
API Documentation Update Check / check-feature-level-updated (push) Has been cancelled
API Documentation Update Check / notify-if-api-docs-changed (push) Has been cancelled
This commit is contained in:
103
zerver/management/commands/unarchive_channel.py
Normal file
103
zerver/management/commands/unarchive_channel.py
Normal file
@@ -0,0 +1,103 @@
|
||||
from argparse import ArgumentParser
|
||||
from typing import Any
|
||||
|
||||
from django.core.management.base import CommandError
|
||||
from typing_extensions import override
|
||||
|
||||
from zerver.actions.streams import deactivated_streams_by_old_name, do_unarchive_stream
|
||||
from zerver.lib.management import ZulipBaseCommand
|
||||
from zerver.models import RealmAuditLog, Stream
|
||||
from zerver.models.realm_audit_logs import AuditLogEventType
|
||||
|
||||
|
||||
class Command(ZulipBaseCommand):
|
||||
help = """Reactivate a channel that was deactivated."""
|
||||
|
||||
@override
|
||||
def add_arguments(self, parser: ArgumentParser) -> None:
|
||||
specify_channel = parser.add_mutually_exclusive_group(required=True)
|
||||
specify_channel.add_argument(
|
||||
"-c",
|
||||
"--channel",
|
||||
help="Name of a deactivated channel in the realm.",
|
||||
)
|
||||
specify_channel.add_argument(
|
||||
"--channel-id",
|
||||
help="ID of a deactivated channel in the realm.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-n",
|
||||
"--new-name",
|
||||
required=False,
|
||||
help="Name to reactivate as; defaults to the old name.",
|
||||
)
|
||||
self.add_realm_args(parser, required=True)
|
||||
|
||||
@override
|
||||
def handle(self, *args: Any, **options: str | None) -> None:
|
||||
realm = self.get_realm(options)
|
||||
assert realm is not None # Should be ensured by parser
|
||||
|
||||
# Looking up the channel is complicated, since they get renamed
|
||||
# when they are deactivated, in a transformation which may be
|
||||
# lossy.
|
||||
|
||||
if options["channel_id"] is not None:
|
||||
channel = Stream.objects.get(id=options["channel_id"])
|
||||
if channel.realm_id != realm.id:
|
||||
raise CommandError(
|
||||
f"Channel id {channel.id}, named '{channel.name}', is in realm '{channel.realm.string_id}', not '{realm.string_id}'"
|
||||
)
|
||||
if not channel.deactivated:
|
||||
raise CommandError(
|
||||
f"Channel id {channel.id}, named '{channel.name}', is not deactivated"
|
||||
)
|
||||
if options["new_name"] is None:
|
||||
raise CommandError("--new-name flag is required with --channel-id")
|
||||
new_name = options["new_name"]
|
||||
else:
|
||||
channel_name = options["channel"]
|
||||
assert channel_name is not None
|
||||
|
||||
possible_channels = deactivated_streams_by_old_name(realm, channel_name)
|
||||
if len(possible_channels) == 0:
|
||||
raise CommandError("No matching deactivated channels found!")
|
||||
|
||||
if len(possible_channels) > 1:
|
||||
# Print ids of all possible channels, support passing by id
|
||||
print("Matching channels:")
|
||||
for channel in possible_channels:
|
||||
last_deactivation = (
|
||||
RealmAuditLog.objects.filter(
|
||||
realm=realm,
|
||||
modified_stream=channel,
|
||||
event_type=AuditLogEventType.CHANNEL_DEACTIVATED,
|
||||
)
|
||||
.order_by("-id")
|
||||
.first()
|
||||
)
|
||||
assert last_deactivation is not None
|
||||
print(
|
||||
f" ({channel.id}) {channel.name}, deactivated on {last_deactivation.event_time}"
|
||||
)
|
||||
raise CommandError(
|
||||
"More than one matching channel found! Specify which with --channel-id"
|
||||
)
|
||||
|
||||
channel = possible_channels[0]
|
||||
if options["new_name"] is not None:
|
||||
new_name = options["new_name"]
|
||||
else:
|
||||
new_name = channel_name
|
||||
|
||||
if (
|
||||
Stream.objects.filter(realm=realm, name__iexact=new_name)
|
||||
.exclude(id=channel.id)
|
||||
.exists()
|
||||
):
|
||||
raise CommandError(
|
||||
f"Channel with name '{new_name}' already exists; pass a different --new-name"
|
||||
)
|
||||
|
||||
assert channel is not None
|
||||
do_unarchive_stream(channel, new_name, acting_user=None)
|
||||
Reference in New Issue
Block a user