def METHOD_NAME(group_ids: list[int] | None) -> Response:
    """
    Lock users active group list.
    Users with locked active group list can preview documents as member of only the specified groups.
    :param group_ids: List of group IDs that the user should be locked to.
                      The user must be either a member of the group or can have edit access to it.
    :return: OK response.
    """
    verify_logged_in()
    if group_ids is None:
        set_locked_active_groups(None)
        return ok_response()
    user = get_current_user_object()
    user.bypass_access_lock = True
    group_ids_set = set(group_ids)
    group_ids_set -= set(ug.id for ug in user.groups)
    group_ids_set -= {
        get_logged_in_group_id(),
        get_anonymous_group_id(),
    }
    if not user.is_admin:
        groups: list[UserGroup] = UserGroup.query.filter(
            UserGroup.id.in_(group_ids_set)
        ).all()
        for ug in groups:
            if not verify_group_edit_access(ug, user, require=False):
                raise AccessDenied(
                    f"You must be a member of or have edit access to group {ug.name} in order to lock your role."
                )
    # Ensure anonymous user group is always present
    # This is not necessary but it generally doesn't make sense not to include it by default
    # as all users inherit the anonymous group's rights.
    locked_groups = set(group_ids) | {get_anonymous_group_id()}
    set_locked_active_groups(locked_groups)
    return ok_response()