mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-03 21:43:21 +00:00 
			
		
		
		
	user_groups: Add support to set can_mention_group during creation.
This commit adds API support to set can_mention_group while creating a user group. Fixes a part of #25927.
This commit is contained in:
		@@ -1,5 +1,5 @@
 | 
			
		||||
import datetime
 | 
			
		||||
from typing import Dict, List, Optional, Sequence, TypedDict
 | 
			
		||||
from typing import Dict, List, Mapping, Optional, Sequence, TypedDict
 | 
			
		||||
 | 
			
		||||
import django.db.utils
 | 
			
		||||
from django.db import transaction
 | 
			
		||||
@@ -37,14 +37,20 @@ def create_user_group_in_database(
 | 
			
		||||
    *,
 | 
			
		||||
    acting_user: Optional[UserProfile],
 | 
			
		||||
    description: str = "",
 | 
			
		||||
    group_settings_map: Mapping[str, UserGroup] = {},
 | 
			
		||||
    is_system_group: bool = False,
 | 
			
		||||
) -> UserGroup:
 | 
			
		||||
    user_group = UserGroup(
 | 
			
		||||
        name=name, realm=realm, description=description, is_system_group=is_system_group
 | 
			
		||||
    )
 | 
			
		||||
    system_groups_name_dict = get_role_based_system_groups_dict(realm)
 | 
			
		||||
    user_group = set_defaults_for_group_settings(user_group, system_groups_name_dict)
 | 
			
		||||
 | 
			
		||||
    for setting_name, setting_value in group_settings_map.items():
 | 
			
		||||
        setattr(user_group, setting_name, setting_value)
 | 
			
		||||
 | 
			
		||||
    system_groups_name_dict = get_role_based_system_groups_dict(realm)
 | 
			
		||||
    user_group = set_defaults_for_group_settings(
 | 
			
		||||
        user_group, group_settings_map, system_groups_name_dict
 | 
			
		||||
    )
 | 
			
		||||
    user_group.save()
 | 
			
		||||
 | 
			
		||||
    UserGroupMembership.objects.bulk_create(
 | 
			
		||||
@@ -150,12 +156,18 @@ def check_add_user_group(
 | 
			
		||||
    name: str,
 | 
			
		||||
    initial_members: List[UserProfile],
 | 
			
		||||
    description: str = "",
 | 
			
		||||
    group_settings_map: Mapping[str, UserGroup] = {},
 | 
			
		||||
    *,
 | 
			
		||||
    acting_user: Optional[UserProfile],
 | 
			
		||||
) -> UserGroup:
 | 
			
		||||
    try:
 | 
			
		||||
        user_group = create_user_group_in_database(
 | 
			
		||||
            name, initial_members, realm, description=description, acting_user=acting_user
 | 
			
		||||
            name,
 | 
			
		||||
            initial_members,
 | 
			
		||||
            realm,
 | 
			
		||||
            description=description,
 | 
			
		||||
            group_settings_map=group_settings_map,
 | 
			
		||||
            acting_user=acting_user,
 | 
			
		||||
        )
 | 
			
		||||
        do_send_create_user_group_event(user_group, initial_members)
 | 
			
		||||
        return user_group
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user