user_groups: Add transaction.atomic decorator to add_user_group view.

The database operations in 'access_user_group_for_setting' and
'check_add_user_group' used in 'add_user_group' view should be
collectively atomic.

This commit adds transaction.atomic decorator for that purpose.
This commit is contained in:
Prakhar Pratyush 2024-08-09 16:00:44 +05:30 committed by Tim Abbott
parent 427c59ec68
commit bae6188d92
2 changed files with 4 additions and 3 deletions

View File

@ -26,7 +26,7 @@ from zerver.models import (
)
from zerver.models.groups import SystemGroups
from zerver.models.users import active_user_ids
from zerver.tornado.django_api import send_event, send_event_on_commit
from zerver.tornado.django_api import send_event_on_commit
class MemberGroupUserDict(TypedDict):
@ -35,7 +35,7 @@ class MemberGroupUserDict(TypedDict):
date_joined: datetime
@transaction.atomic
@transaction.atomic(savepoint=False)
def create_user_group_in_database(
name: str,
members: list[UserProfile],
@ -182,7 +182,7 @@ def do_send_create_user_group_event(
can_mention_group=get_group_setting_value_for_api(user_group.can_mention_group),
),
)
send_event(user_group.realm, event, active_user_ids(user_group.realm_id))
send_event_on_commit(user_group.realm, event, active_user_ids(user_group.realm_id))
def check_add_user_group(

View File

@ -45,6 +45,7 @@ from zerver.models.users import get_system_bot
from zerver.views.streams import compose_views
@transaction.atomic(durable=True)
@require_user_group_edit_permission
@typed_endpoint
def add_user_group(