From 8167b5b645ce0406ebc64b4785a4755f327addb5 Mon Sep 17 00:00:00 2001 From: Rishi Gupta Date: Sat, 3 Aug 2019 18:08:29 -0700 Subject: [PATCH] email: Remove special integration doc behavior when gateway not set. The current code looks like it's trying to redirect /integrations/doc/email to /integrations when EMAIL_GATEWAY_PATTERN is not set. I think it doesn't currently do this. The test for that pathway has a bug: self.get_doc('integrations/doc-html/email', subdomain='zulip') needs a leading slash, and putting the slash back in results in the test failing. This redirection is not really desired behavior -- better is to unconditionally show that the email integration exists, and just point the user to https://zulip.readthedocs.io/en/latest/production/email-gateway.html (this is done in a child commit). --- templates/zerver/integrations/email.md | 2 +- zerver/lib/integrations.py | 9 ++------- zerver/tests/test_docs.py | 11 ----------- zerver/views/documentation.py | 5 +---- zproject/settings.py | 8 -------- 5 files changed, 4 insertions(+), 31 deletions(-) diff --git a/templates/zerver/integrations/email.md b/templates/zerver/integrations/email.md index d02193be63..3aed7f7e05 100644 --- a/templates/zerver/integrations/email.md +++ b/templates/zerver/integrations/email.md @@ -28,7 +28,7 @@ The default behavior of this integration is designed to be convenient in the common case. We offer a few options for overriding the default behavior, configured by editing the Zulip email address: -Example: `{{ email_gateway_example_with_options }}` +Example: `general.abcd1234.show-sender.include-footer@example.zulipchat.com` * `show-sender`: Will cause `From: ` to be displayed at the top of Zulip messages sent via this integration. diff --git a/zerver/lib/integrations.py b/zerver/lib/integrations.py index 79b1f08f5c..2def4c3864 100644 --- a/zerver/lib/integrations.py +++ b/zerver/lib/integrations.py @@ -1,7 +1,6 @@ import os from typing import Dict, List, Optional, Any -from django.conf import settings from django.conf.urls import url from django.contrib.staticfiles.storage import staticfiles_storage from django.urls.resolvers import LocaleRegexProvider @@ -128,10 +127,6 @@ class BotIntegration(Integration): doc = self.DEFAULT_DOC_PATH.format(name=name) self.doc = doc -class EmailIntegration(Integration): - def is_enabled(self) -> bool: - return settings.EMAIL_GATEWAY_PATTERN != "" - class WebhookIntegration(Integration): DEFAULT_FUNCTION_PATH = 'zerver.webhooks.{name}.view.api_{name}_webhook' DEFAULT_URL = 'api/v1/external/{name}' @@ -354,8 +349,8 @@ INTEGRATIONS = { doc='zerver/integrations/codebase.md'), 'discourse': Integration('discourse', 'discourse', ['communication'], doc='zerver/integrations/discourse.md'), - 'email': EmailIntegration('email', 'email', ['communication'], - doc='zerver/integrations/email.md'), + 'email': Integration('email', 'email', ['communication'], + doc='zerver/integrations/email.md'), 'errbot': Integration('errbot', 'errbot', ['meta-integration', 'bots'], doc='zerver/integrations/errbot.md'), 'git': Integration('git', 'git', ['version-control'], diff --git a/zerver/tests/test_docs.py b/zerver/tests/test_docs.py index 050eecf055..5de2d8da2f 100644 --- a/zerver/tests/test_docs.py +++ b/zerver/tests/test_docs.py @@ -206,17 +206,6 @@ class DocPageTest(ZulipTestCase): self._test(url, title, doc_html_str=True) self._test(url, description, doc_html_str=True) - def test_email_integration(self) -> None: - self._test('/integrations/doc-html/email', - 'support.abcd1234@testserver', doc_html_str=True) - - with self.settings(EMAIL_GATEWAY_PATTERN=''): - result = self.get_doc('integrations/doc-html/email', subdomain='zulip') - self.assertNotIn('support.abcd1234@testserver', str(result.content)) - # if EMAIL_GATEWAY_PATTERN is empty, the main /integrations page should - # be rendered instead - self._test('/integrations/', 'native integrations.') - def test_doc_html_str_non_ajax_call(self) -> None: # We don't need to test all the pages for 404 for integration in list(INTEGRATIONS.keys())[5]: diff --git a/zerver/views/documentation.py b/zerver/views/documentation.py index e9f45da2ed..bb5d3fc8f1 100644 --- a/zerver/views/documentation.py +++ b/zerver/views/documentation.py @@ -10,7 +10,7 @@ import random import re from zerver.lib.integrations import CATEGORIES, INTEGRATIONS, HubotIntegration, \ - WebhookIntegration, EmailIntegration + WebhookIntegration from zerver.lib.request import has_request_variables, REQ from zerver.lib.subdomains import get_subdomain from zerver.models import Realm @@ -193,9 +193,6 @@ def integration_doc(request: HttpRequest, integration_name: str=REQ(default=None context['integration_url'] = integration.url[3:] if isinstance(integration, HubotIntegration): context['hubot_docs_url'] = integration.hubot_docs_url - if isinstance(integration, EmailIntegration): - context['email_gateway_example'] = settings.EMAIL_GATEWAY_EXAMPLE - context['email_gateway_example_with_options'] = settings.EMAIL_GATEWAY_EXAMPLE_WITH_OPTIONS doc_html_str = render_markdown_path(integration.doc, context) diff --git a/zproject/settings.py b/zproject/settings.py index d4b9b5dd40..0a636d35e3 100644 --- a/zproject/settings.py +++ b/zproject/settings.py @@ -827,14 +827,6 @@ for bot in INTERNAL_BOTS + REALM_INTERNAL_BOTS + DISABLED_REALM_INTERNAL_BOTS: bot_email = bot['email_template'] % (INTERNAL_BOT_DOMAIN,) vars()[bot['var_name']] = bot_email -if EMAIL_GATEWAY_PATTERN != "": - EMAIL_GATEWAY_EXAMPLE = EMAIL_GATEWAY_PATTERN % ("support.abcd1234",) - EMAIL_GATEWAY_EXAMPLE_WITH_OPTIONS = EMAIL_GATEWAY_PATTERN % ( - "support.abcd1234.first-option.second-option",) -else: - EMAIL_GATEWAY_EXAMPLE = "" - EMAIL_GATEWAY_EXAMPLE_WITH_OPTIONS = "" - ######################################################################## # STATSD CONFIGURATION ########################################################################