mirror of https://github.com/zulip/zulip.git
help: Rename unarchive_stream management command to unarchive_channel.
This commit is contained in:
parent
64c251089d
commit
422f5c4e1a
|
@ -125,9 +125,9 @@ There are dozens of useful management commands under
|
||||||
- `./manage.py export_single_user`: does a limited version of the [main
|
- `./manage.py export_single_user`: does a limited version of the [main
|
||||||
export tools](export-and-import.md) containing just
|
export tools](export-and-import.md) containing just
|
||||||
the messages accessible by a single user.
|
the messages accessible by a single user.
|
||||||
- `./manage.py unarchive_stream`:
|
- `./manage.py unarchive_channel`:
|
||||||
[Reactivates](https://zulip.com/help/archive-a-stream#unarchiving-archived-streams)
|
[Reactivates](https://zulip.com/help/archive-a-stream#unarchiving-archived-streams)
|
||||||
an archived stream.
|
an archived channel.
|
||||||
- `./manage.py reactivate_realm`: Reactivates a realm.
|
- `./manage.py reactivate_realm`: Reactivates a realm.
|
||||||
- `./manage.py deactivate_user`: Deactivates a user. This can be done
|
- `./manage.py deactivate_user`: Deactivates a user. This can be done
|
||||||
more easily in Zulip's organization administrator UI.
|
more easily in Zulip's organization administrator UI.
|
||||||
|
|
|
@ -44,7 +44,7 @@ than archiving them.
|
||||||
## Unarchiving archived channels
|
## Unarchiving archived channels
|
||||||
|
|
||||||
If you are self-hosting, you can unarchive an archived channel using the
|
If you are self-hosting, you can unarchive an archived channel using the
|
||||||
`unarchive_stream` [management command][management-command]. This will restore
|
`unarchive_channel` [management command][management-command]. This will restore
|
||||||
it as a private channel with shared history, and subscribe all organization
|
it as a private channel with shared history, and subscribe all organization
|
||||||
owners to it. If you are using Zulip Cloud, you can [contact us](/help/contact-support)
|
owners to it. If you are using Zulip Cloud, you can [contact us](/help/contact-support)
|
||||||
for help.
|
for help.
|
||||||
|
|
|
@ -10,19 +10,19 @@ from zerver.models import RealmAuditLog, Stream
|
||||||
|
|
||||||
|
|
||||||
class Command(ZulipBaseCommand):
|
class Command(ZulipBaseCommand):
|
||||||
help = """Reactivate a stream that was deactivated."""
|
help = """Reactivate a channel that was deactivated."""
|
||||||
|
|
||||||
@override
|
@override
|
||||||
def add_arguments(self, parser: ArgumentParser) -> None:
|
def add_arguments(self, parser: ArgumentParser) -> None:
|
||||||
specify_stream = parser.add_mutually_exclusive_group(required=True)
|
specify_channel = parser.add_mutually_exclusive_group(required=True)
|
||||||
specify_stream.add_argument(
|
specify_channel.add_argument(
|
||||||
"-s",
|
"-c",
|
||||||
"--stream",
|
"--channel",
|
||||||
help="Name of a deactivated stream in the realm.",
|
help="Name of a deactivated channel in the realm.",
|
||||||
)
|
)
|
||||||
specify_stream.add_argument(
|
specify_channel.add_argument(
|
||||||
"--stream-id",
|
"--channel-id",
|
||||||
help="ID of a deactivated stream in the realm.",
|
help="ID of a deactivated channel in the realm.",
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-n",
|
"-n",
|
||||||
|
@ -37,39 +37,39 @@ class Command(ZulipBaseCommand):
|
||||||
realm = self.get_realm(options)
|
realm = self.get_realm(options)
|
||||||
assert realm is not None # Should be ensured by parser
|
assert realm is not None # Should be ensured by parser
|
||||||
|
|
||||||
# Looking up the stream is complicated, since they get renamed
|
# Looking up the channel is complicated, since they get renamed
|
||||||
# when they are deactivated, in a transformation which may be
|
# when they are deactivated, in a transformation which may be
|
||||||
# lossy.
|
# lossy.
|
||||||
|
|
||||||
if options["stream_id"] is not None:
|
if options["channel_id"] is not None:
|
||||||
stream = Stream.objects.get(id=options["stream_id"])
|
channel = Stream.objects.get(id=options["channel_id"])
|
||||||
if stream.realm_id != realm.id:
|
if channel.realm_id != realm.id:
|
||||||
raise CommandError(
|
raise CommandError(
|
||||||
f"Stream id {stream.id}, named '{stream.name}', is in realm '{stream.realm.string_id}', not '{realm.string_id}'"
|
f"Channel id {channel.id}, named '{channel.name}', is in realm '{channel.realm.string_id}', not '{realm.string_id}'"
|
||||||
)
|
)
|
||||||
if not stream.deactivated:
|
if not channel.deactivated:
|
||||||
raise CommandError(
|
raise CommandError(
|
||||||
f"Stream id {stream.id}, named '{stream.name}', is not deactivated"
|
f"Channel id {channel.id}, named '{channel.name}', is not deactivated"
|
||||||
)
|
)
|
||||||
if options["new_name"] is None:
|
if options["new_name"] is None:
|
||||||
raise CommandError("--new-name flag is required with --stream-id")
|
raise CommandError("--new-name flag is required with --channel-id")
|
||||||
new_name = options["new_name"]
|
new_name = options["new_name"]
|
||||||
else:
|
else:
|
||||||
stream_name = options["stream"]
|
channel_name = options["channel"]
|
||||||
assert stream_name is not None
|
assert channel_name is not None
|
||||||
|
|
||||||
possible_streams = deactivated_streams_by_old_name(realm, stream_name)
|
possible_channels = deactivated_streams_by_old_name(realm, channel_name)
|
||||||
if len(possible_streams) == 0:
|
if len(possible_channels) == 0:
|
||||||
raise CommandError("No matching deactivated streams found!")
|
raise CommandError("No matching deactivated channels found!")
|
||||||
|
|
||||||
if len(possible_streams) > 1:
|
if len(possible_channels) > 1:
|
||||||
# Print ids of all possible streams, support passing by id
|
# Print ids of all possible channels, support passing by id
|
||||||
print("Matching streams:")
|
print("Matching channels:")
|
||||||
for stream in possible_streams:
|
for channel in possible_channels:
|
||||||
last_deactivation = (
|
last_deactivation = (
|
||||||
RealmAuditLog.objects.filter(
|
RealmAuditLog.objects.filter(
|
||||||
realm=realm,
|
realm=realm,
|
||||||
modified_stream=stream,
|
modified_stream=channel,
|
||||||
event_type=RealmAuditLog.STREAM_DEACTIVATED,
|
event_type=RealmAuditLog.STREAM_DEACTIVATED,
|
||||||
)
|
)
|
||||||
.order_by("-id")
|
.order_by("-id")
|
||||||
|
@ -77,22 +77,22 @@ class Command(ZulipBaseCommand):
|
||||||
)
|
)
|
||||||
assert last_deactivation is not None
|
assert last_deactivation is not None
|
||||||
print(
|
print(
|
||||||
f" ({stream.id}) {stream.name}, deactivated on {last_deactivation.event_time}"
|
f" ({channel.id}) {channel.name}, deactivated on {last_deactivation.event_time}"
|
||||||
)
|
)
|
||||||
raise CommandError(
|
raise CommandError(
|
||||||
"More than one matching stream found! Specify which with --stream-id"
|
"More than one matching channel found! Specify which with --channel-id"
|
||||||
)
|
)
|
||||||
|
|
||||||
stream = possible_streams[0]
|
channel = possible_channels[0]
|
||||||
if options["new_name"] is not None:
|
if options["new_name"] is not None:
|
||||||
new_name = options["new_name"]
|
new_name = options["new_name"]
|
||||||
else:
|
else:
|
||||||
new_name = stream_name
|
new_name = channel_name
|
||||||
|
|
||||||
if Stream.objects.filter(realm=realm, name=new_name).exists():
|
if Stream.objects.filter(realm=realm, name=new_name).exists():
|
||||||
raise CommandError(
|
raise CommandError(
|
||||||
f"Stream with name '{new_name}' already exists; pass a different --new-name"
|
f"Channel with name '{new_name}' already exists; pass a different --new-name"
|
||||||
)
|
)
|
||||||
|
|
||||||
assert stream is not None
|
assert channel is not None
|
||||||
do_unarchive_stream(stream, new_name, acting_user=None)
|
do_unarchive_stream(channel, new_name, acting_user=None)
|
Loading…
Reference in New Issue