Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

models: Add can_remove_subscribers_group field to Stream.

Sahil Batra49d61d19f4cf
diff --git a/zerver/migrations/0408_stream_can_remove_subscribers_group.py b/zerver/migrations/0408_stream_can_remove_subscribers_group.py
new file mode 100644
index 00000000000..4eadc5ff5a5
--- /dev/null
+++ b/zerver/migrations/0408_stream_can_remove_subscribers_group.py
@@ -0,0 +1,21 @@
+# Generated by Django 3.2.13 on 2022-06-24 14:18
+
+import django.db.models.deletion
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ("zerver", "0407_userprofile_user_list_style"),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name="stream",
+ name="can_remove_subscribers_group",
+ field=models.ForeignKey(
+ null=True, on_delete=django.db.models.deletion.RESTRICT, to="zerver.usergroup"
+ ),
+ ),
+ ]
diff --git a/zerver/models.py b/zerver/models.py
index 0f9b3aeed4b..9a4d9e5d12a 100644
--- a/zerver/models.py
+++ b/zerver/models.py
@@ -2507,6 +2507,14 @@ class Stream(models.Model):
}
message_retention_days: Optional[int] = models.IntegerField(null=True, default=None)
+ # on_delete field here is set to RESTRICT because we don't want to allow
+ # deleting a user group in case it is referenced by this settig.
+ # We are not using PROTECT since we want to allow deletion of user groups
+ # when realm itself is deleted.
+ can_remove_subscribers_group: Optional[UserGroup] = models.ForeignKey(
+ UserGroup, null=True, on_delete=models.RESTRICT
+ )
+
# The very first message ID in the stream. Used to help clients
# determine whether they might need to display "more topics" for a
# stream based on what messages they have cached.