streams: Refactor code to set group-based stream settings.

We add stream_permission_group_settings object which is
similar to property_types framework used for realm settings.

This commit also adds GroupPermissionSetting dataclass for
defining settings inside stream_permission_group_settings.

We add "do_change_stream_group_based_setting" function which
is called in loop to update all the group-based stream settings
and it is now used to update 'can_remove_subscribers_group'
setting instead of "do_change_can_remove_subscribers_group".

We also change the variable name for event_type field of
RealmAuditLog objects to STREAM_GROUP_BASED_SETTING_CHANGED
since this will be used for all group-based stream settings.

'property' field is also added to extra_data field to identify
the setting for which RealmAuditLog object was created.

We will add a migration in further commits which will add the
property field to existing RealmAuditLog objects created for
changing can_remove_subscribers_group setting.
This commit is contained in:
Sahil Batra
2023-02-17 17:16:14 +05:30
committed by Tim Abbott
parent 416c7c2199
commit 0cf99cf5c3
6 changed files with 66 additions and 25 deletions

View File

@@ -91,6 +91,7 @@ from zerver.lib.types import (
ExtendedFieldElement,
ExtendedValidator,
FieldElement,
GroupPermissionSetting,
LinkifierDict,
ProfileData,
ProfileDataElementBase,
@@ -2541,6 +2542,14 @@ class Stream(models.Model):
# stream based on what messages they have cached.
first_message_id = models.IntegerField(null=True, db_index=True)
stream_permission_group_settings = {
"can_remove_subscribers_group": GroupPermissionSetting(
require_system_group=True,
allow_internet_group=False,
allow_owners_group=False,
),
}
def __str__(self) -> str:
return f"<Stream: {self.name}>"
@@ -4382,7 +4391,7 @@ class AbstractRealmAuditLog(models.Model):
STREAM_REACTIVATED = 604
STREAM_MESSAGE_RETENTION_DAYS_CHANGED = 605
STREAM_PROPERTY_CHANGED = 607
STREAM_CAN_REMOVE_SUBSCRIBERS_GROUP_CHANGED = 608
STREAM_GROUP_BASED_SETTING_CHANGED = 608
# The following values are only for RemoteZulipServerAuditLog
# Values should be exactly 10000 greater than the corresponding