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

Code before:
        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(
                "Invalid privacy setting '" + default_privacy_setting.get("type"),
                "Unknown"
                + "'. 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,
            _("Page '%(page_title)s' created.")
            % {"page_title": self.page.get_admin_display_title()},
        )


Review comment (refactor):
Suggestion: Simplify the exception message, since this should come from an enum.

```suggestion
            raise ValueError(
                f"Invalid privacy setting {default_privacy_setting.get("type")!r}"
            )
```

Code after:
        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,
            _("Page '%(page_title)s' created.")
            % {"page_title": self.page.get_admin_display_title()},
        )