Repository: wagtail/wagtail
File: wagtail/admin/views/pages/create.py (Python)

Code before:
    def set_default_privacy_setting(self):
        # privacy setting options BaseViewRestriction.RESTRICTION_CHOICES
        default_privacy_setting = self.page.get_default_privacy_setting(self.request)

        if (
            default_privacy_setting["type"] == BaseViewRestriction.NONE
        ):  # default privacy setting is public no need to do anything
            pass
        elif default_privacy_setting["type"] == BaseViewRestriction.LOGIN:
            PageViewRestriction.objects.create(
                page=self.page, restriction_type=BaseViewRestriction.LOGIN
            )
        elif default_privacy_setting["type"] == BaseViewRestriction.PASSWORD:
            PageViewRestriction.objects.create(
                page=self.page,
                restriction_type=BaseViewRestriction.PASSWORD,
                password=default_privacy_setting["password"],
            )
        elif default_privacy_setting["type"] == BaseViewRestriction.GROUPS:
            # Create a page view restriction for groups
            groups_page_restriction = PageViewRestriction.objects.create(
                page=self.page, restriction_type=BaseViewRestriction.GROUPS
            )
            # add groups to the page view restriction
            for group in default_privacy_setting["groups"]:
                groups_page_restriction.groups.add(group)
        else:
            raise ValueError(
                "Invalid privacy setting. Choose one of the following: 'none', 'password', 'groups', 'login'."
            )

    def save_action(self):
        self.page = self.form.save(commit=False)
        self.page.live = False

        # Save page
        self.parent_page.add_child(instance=self.page)

        # Set pages privacy settings
        self.set_default_privacy_setting()

        # Save revision
        self.page.save_revision(user=self.request.user, log_action=True)

        # Save subscription settings
        self.subscription.page = self.page
        self.subscription.save()

        # Notification
        messages.success(
            self.request,

Review comment (suggestion):
Suggestion:

```suggestion
            groups_page_restriction.groups.set(default_privacy_setting["groups"])
```

Code after:
    def set_default_privacy_setting(self):
        # privacy setting options BaseViewRestriction.RESTRICTION_CHOICES
        default_privacy_setting = self.page.get_default_privacy_setting(self.request)

        if default_privacy_setting["type"] == BaseViewRestriction.NONE:
            # default privacy setting is public no need to do anything
            pass
        elif default_privacy_setting["type"] == BaseViewRestriction.LOGIN:
            PageViewRestriction.objects.create(
                page=self.page,
                restriction_type=BaseViewRestriction.LOGIN,
            )
        elif default_privacy_setting["type"] == BaseViewRestriction.PASSWORD:
            PageViewRestriction.objects.create(
                page=self.page,
                restriction_type=BaseViewRestriction.PASSWORD,
                password=default_privacy_setting["password"],
            )
        elif default_privacy_setting["type"] == BaseViewRestriction.GROUPS:
            # Create a page view restriction for groups
            groups_page_restriction = PageViewRestriction.objects.create(
                page=self.page,
                restriction_type=BaseViewRestriction.GROUPS,
            )
            # add groups to the page view restriction
            groups_page_restriction.groups.set(default_privacy_setting["groups"])
        else:
            raise ValueError(
                f"Invalid privacy setting {default_privacy_setting.get('type')!r}"
            )

    def save_action(self):
        self.page = self.form.save(commit=False)
        self.page.live = False

        # Save page
        self.parent_page.add_child(instance=self.page)

        # Set page privacy setting
        self.set_default_privacy_setting()

        # Save revision
        self.page.save_revision(user=self.request.user, log_action=True)

        # Save subscription settings
        self.subscription.page = self.page
        self.subscription.save()

        # Notification
        messages.success(
            self.request,