From bef7cfe00f48892b36d42ca941ba9ce7ce9d1f35 Mon Sep 17 00:00:00 2001 From: Sahil Batra Date: Wed, 15 May 2024 18:46:05 +0530 Subject: [PATCH] user_groups: Add deactivated field to NamedUserGroup model. --- zerver/lib/import_realm.py | 3 ++- zerver/lib/user_groups.py | 5 +++-- .../0578_namedusergroup_deactivated.py | 17 +++++++++++++++++ zerver/models/groups.py | 1 + 4 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 zerver/migrations/0578_namedusergroup_deactivated.py diff --git a/zerver/lib/import_realm.py b/zerver/lib/import_realm.py index 45186b545a..5c20a62685 100644 --- a/zerver/lib/import_realm.py +++ b/zerver/lib/import_realm.py @@ -753,13 +753,14 @@ def bulk_import_named_user_groups(data: TableData) -> None: group["is_system_group"], group["can_manage_group_id"], group["can_mention_group_id"], + group["deactivated"], ) for group in data["zerver_namedusergroup"] ] query = SQL( """ - INSERT INTO zerver_namedusergroup (usergroup_ptr_id, realm_id, name, description, is_system_group, can_manage_group_id, can_mention_group_id) + INSERT INTO zerver_namedusergroup (usergroup_ptr_id, realm_id, name, description, is_system_group, can_manage_group_id, can_mention_group_id, deactivated) VALUES %s """ ) diff --git a/zerver/lib/user_groups.py b/zerver/lib/user_groups.py index 23b1ef3a37..f046761f69 100644 --- a/zerver/lib/user_groups.py +++ b/zerver/lib/user_groups.py @@ -614,7 +614,7 @@ def bulk_create_system_user_groups(groups: list[dict[str, str]], realm: Realm) - user_group_ids = [id for (id,) in cursor.fetchall()] rows = [ - SQL("({},{},{},{},{},{},{})").format( + SQL("({},{},{},{},{},{},{},{})").format( Literal(user_group_ids[idx]), Literal(realm.id), Literal(group["name"]), @@ -622,12 +622,13 @@ def bulk_create_system_user_groups(groups: list[dict[str, str]], realm: Realm) - Literal(True), Literal(initial_group_setting_value), Literal(initial_group_setting_value), + Literal(False), ) for idx, group in enumerate(groups) ] query = SQL( """ - INSERT INTO zerver_namedusergroup (usergroup_ptr_id, realm_id, name, description, is_system_group, can_manage_group_id, can_mention_group_id) + INSERT INTO zerver_namedusergroup (usergroup_ptr_id, realm_id, name, description, is_system_group, can_manage_group_id, can_mention_group_id, deactivated) VALUES {rows} """ ).format(rows=SQL(", ").join(rows)) diff --git a/zerver/migrations/0578_namedusergroup_deactivated.py b/zerver/migrations/0578_namedusergroup_deactivated.py new file mode 100644 index 0000000000..94dd99eb87 --- /dev/null +++ b/zerver/migrations/0578_namedusergroup_deactivated.py @@ -0,0 +1,17 @@ +# Generated by Django 5.0.6 on 2024-05-15 13:12 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("zerver", "0577_merge_20240829_0153"), + ] + + operations = [ + migrations.AddField( + model_name="namedusergroup", + name="deactivated", + field=models.BooleanField(default=False, db_default=False), + ), + ] diff --git a/zerver/models/groups.py b/zerver/models/groups.py index 3e95be594a..9decab12b2 100644 --- a/zerver/models/groups.py +++ b/zerver/models/groups.py @@ -60,6 +60,7 @@ class NamedUserGroup(UserGroup): # type: ignore[django-manager-missing] # djang ) realm_for_sharding = models.ForeignKey("zerver.Realm", on_delete=CASCADE, db_column="realm_id") + deactivated = models.BooleanField(default=False, db_default=False) # We do not have "Full members" and "Everyone on the internet" # group here since there isn't a separate role value for full