def _disable_provider(self, request, organization, auth_provider):
        self.create_audit_entry(
            request,
            organization=organization,
            target_object=auth_provider.id,
            event=AuditLogEntryEvent.SSO_DISABLE,
            data=auth_provider.get_audit_log_data(),
        )

        if db.is_sqlite():
            for om in OrganizationMember.objects.filter(organization=organization):
                om.flags['sso:linked'] = False
                om.flags['sso:invalid'] = False
                om.save()
        else:
            OrganizationMember.objects.filter(
                organization=organization,
            ).update(
                flags=F('flags').bitand(
                    ~OrganizationMember.flags['sso:linked'],
                ).bitand(
                    ~OrganizationMember.flags['sso:invalid'],
                ),
            )

        user_ids = OrganizationMember.objects.filter(organization=organization).values('user')
        User.objects.filter(id__in=user_ids).update(is_managed=False)

        email_unlink_notifications.delay(organization.id, request.user.id, auth_provider.provider)
        auth_provider.delete()
    def _disable_provider(self, request, organization, auth_provider):
        self.create_audit_entry(
            request,
            organization=organization,
            target_object=auth_provider.id,
            event=AuditLogEntryEvent.SSO_DISABLE,
            data=auth_provider.get_audit_log_data(),
        )

        OrganizationMember.objects.filter(organization=organization).update(
            flags=F("flags").bitand(~OrganizationMember.flags["sso:linked"]).
            bitand(~OrganizationMember.flags["sso:invalid"]))

        user_ids = OrganizationMember.objects.filter(
            organization=organization).values("user")
        User.objects.filter(id__in=user_ids).update(is_managed=False)

        email_unlink_notifications.delay(organization.id, request.user.id,
                                         auth_provider.provider)
        auth_provider.delete()