Repository: zulip/zulip

Issue:
integrations: Add Dropbox integration.
It seems fitting for us to support a Dropbox integration!
The Dropbox API supports webhooks to notify when a file has been modified, which could be potentially useful for organizations with shared files.

If anyone has any other suggestions for what such an integration could do, let me know.


Discussion:
@zulipbot claim
Hello @zulip/server-integrations members, this issue was labeled with the **area: integrations** label, so you may want to check it out!
Hello @cory2067, you have been unassigned from this issue because you have not updated this issue or any referenced pull requests for over 10 days.

You can reclaim this issue or claim any other issue by commenting `@zulipbot claim` on that issue.

Thanks for your contributions, and hope to see you again soon!

@zulipbot claim

Resolving patch:
diff --git a/zerver/lib/integrations.py b/zerver/lib/integrations.py
--- a/zerver/lib/integrations.py
+++ b/zerver/lib/integrations.py
@@ -284,6 +284,7 @@ def __init__(self, name: str, *args: Any, **kwargs: Any) -> None:
         display_name='Desk.com',
         stream_name='desk'
     ),
+    WebhookIntegration('dropbox', ['productivity'], display_name='Dropbox'),
     WebhookIntegration('freshdesk', ['customer-support']),
     GithubIntegration(
         'github',
diff --git a/zerver/webhooks/dropbox/__init__.py b/zerver/webhooks/dropbox/__init__.py
new file mode 100644
diff --git a/zerver/webhooks/dropbox/view.py b/zerver/webhooks/dropbox/view.py
new file mode 100644
--- /dev/null
+++ b/zerver/webhooks/dropbox/view.py
@@ -0,0 +1,18 @@
+from typing import Text
+from django.http import HttpRequest, HttpResponse
+from zerver.lib.actions import check_send_stream_message
+from zerver.lib.response import json_success
+from zerver.decorator import REQ, has_request_variables, api_key_only_webhook_view
+from zerver.models import UserProfile
+
+@api_key_only_webhook_view('Dropbox')
+@has_request_variables
+def api_dropbox_webhook(request: HttpRequest, user_profile: UserProfile,
+                        stream: Text=REQ(default='test'),
+                        topic: Text=REQ(default='Dropbox')) -> HttpResponse:
+    if request.method == 'GET':
+        return HttpResponse(request.GET['challenge'])
+    elif request.method == 'POST':
+        check_send_stream_message(user_profile, request.client,
+                                  stream, topic, "File has been updated on Dropbox!")
+        return json_success()


Test patch:
diff --git a/zerver/webhooks/dropbox/tests.py b/zerver/webhooks/dropbox/tests.py
new file mode 100644
--- /dev/null
+++ b/zerver/webhooks/dropbox/tests.py
@@ -0,0 +1,28 @@
+# -*- coding: utf-8 -*-
+from typing import Text
+
+from zerver.lib.test_classes import WebhookTestCase
+
+class DropboxHookTests(WebhookTestCase):
+    STREAM_NAME = 'test'
+    URL_TEMPLATE = "/api/v1/external/dropbox?&api_key={api_key}"
+    FIXTURE_DIR_NAME = 'dropbox'
+
+    def test_file_updated(self) -> None:
+        expected_subject = u"Dropbox"
+        expected_message = u"File has been updated on Dropbox!"
+
+        self.send_and_test_stream_message('file_updated', expected_subject, expected_message,
+                                          content_type="application/x-www-form-urlencoded")
+
+    def get_body(self, fixture_name: Text) -> Text:
+        return self.fixture_data("dropbox", fixture_name, file_type="json")
+
+    def test_verification_request(self) -> None:
+        self.subscribe(self.test_user, self.STREAM_NAME)
+        get_params = {'stream_name': self.STREAM_NAME,
+                      'challenge': '9B2SVL4orbt5DxLMqJHI6pOTipTqingt2YFMIO0g06E',
+                      'api_key': self.test_user.api_key}
+        result = self.client_get(self.url, get_params)
+
+        self.assert_in_response('9B2SVL4orbt5DxLMqJHI6pOTipTqingt2YFMIO0g06E', result)