diff --git a/hc/api/models.py b/hc/api/models.py index 5318254b..562a9138 100644 --- a/hc/api/models.py +++ b/hc/api/models.py @@ -2,7 +2,6 @@ import hashlib import json -import time import uuid from datetime import datetime, timedelta as td @@ -14,7 +13,6 @@ from django.utils import timezone from hc.accounts.models import Project from hc.api import transports from hc.lib import emails -import requests import pytz STATUSES = ( @@ -470,37 +468,6 @@ class Channel(models.Model): doc = json.loads(self.value) return doc.get("name") - def refresh_hipchat_access_token(self): - assert self.kind == "hipchat" - if not self.value.startswith("{"): - return # Don't have OAuth credentials - - doc = json.loads(self.value) - if time.time() < doc.get("expires_at", 0): - return # Current access token is still valid - - url = "https://api.hipchat.com/v2/oauth/token" - auth = (doc["oauthId"], doc["oauthSecret"]) - r = requests.post(url, auth=auth, data={ - "grant_type": "client_credentials", - "scope": "send_notification" - }) - - doc.update(r.json()) - doc["expires_at"] = int(time.time()) + doc["expires_in"] - 300 - self.value = json.dumps(doc) - self.save() - - @property - def hipchat_webhook_url(self): - assert self.kind == "hipchat" - if not self.value.startswith("{"): - return self.value - - doc = json.loads(self.value) - tmpl = "https://api.hipchat.com/v2/room/%s/notification?auth_token=%s" - return tmpl % (doc["roomId"], doc.get("access_token")) - @property def pd_service_key(self): assert self.kind == "pd" diff --git a/hc/api/tests/test_channel_model.py b/hc/api/tests/test_channel_model.py deleted file mode 100644 index c16580db..00000000 --- a/hc/api/tests/test_channel_model.py +++ /dev/null @@ -1,24 +0,0 @@ -import json - -from hc.api.models import Channel -from hc.test import BaseTestCase -from mock import patch - - -class ChannelModelTestCase(BaseTestCase): - - @patch("hc.api.models.requests.post") - def test_it_refreshes_hipchat_access_token(self, mock_post): - mock_post.return_value.json.return_value = {"expires_in": 100} - - value = json.dumps({ - "oauthId": "foo", - "oauthSecret": "bar" - }) - - channel = Channel(kind="hipchat", project=self.project, value=value) - channel.refresh_hipchat_access_token() - - # It should request a token using a correct tokenUrl - mock_post.assert_called() - self.assertTrue("expires_at" in channel.value) diff --git a/hc/api/tests/test_notify.py b/hc/api/tests/test_notify.py index 13365d5a..641df621 100644 --- a/hc/api/tests/test_notify.py +++ b/hc/api/tests/test_notify.py @@ -354,15 +354,10 @@ class NotifyTestCase(BaseTestCase): @patch("hc.api.transports.requests.request") def test_hipchat(self, mock_post): self._setup_data("hipchat", "123") - mock_post.return_value.status_code = 204 self.channel.notify(self.check) - n = Notification.objects.first() - self.assertEqual(n.error, "") - - args, kwargs = mock_post.call_args - payload = kwargs["json"] - self.assertIn("DOWN", payload["message"]) + self.assertFalse(mock_post.called) + self.assertEqual(Notification.objects.count(), 0) @patch("hc.api.transports.requests.request") def test_opsgenie(self, mock_post): diff --git a/hc/api/transports.py b/hc/api/transports.py index b621d08d..72e21b05 100644 --- a/hc/api/transports.py +++ b/hc/api/transports.py @@ -202,11 +202,8 @@ class Slack(HttpTransport): class HipChat(HttpTransport): - def notify(self, check): - text = tmpl("hipchat_message.json", check=check) - payload = json.loads(text) - self.channel.refresh_hipchat_access_token() - return self.post(self.channel.hipchat_webhook_url, json=payload) + def is_noop(self, check): + return True class OpsGenie(HttpTransport): diff --git a/hc/front/tests/test_add_hipchat.py b/hc/front/tests/test_add_hipchat.py deleted file mode 100644 index 2703d5b8..00000000 --- a/hc/front/tests/test_add_hipchat.py +++ /dev/null @@ -1,37 +0,0 @@ -from hc.api.models import Channel -from hc.test import BaseTestCase -from mock import patch - - -class AddHipChatTestCase(BaseTestCase): - url = "/integrations/add_hipchat/" - - def test_instructions_work(self): - self.client.login(username="alice@example.org", password="password") - r = self.client.get(self.url) - self.assertContains(r, "appropriate HipChat room") - - def test_it_returns_capabilities(self): - r = self.client.get("/integrations/hipchat/capabilities/") - self.assertContains(r, "installedUrl") - - @patch("hc.front.views.Channel.refresh_hipchat_access_token") - @patch("hc.front.views.requests.get") - def test_it_adds_channel(self, mock_get, mock_refresh): - mock_get.return_value.json.return_value = { - "oauthId": "test-id" - } - mock_get.return_value.text = "{}" - - self.client.login(username="alice@example.org", password="password") - - s = "https://api.hipchat.com/foo" - r = self.client.post(self.url + "?installable_url=%s" % s) - self.assertEqual(r.status_code, 302) - - self.assertTrue(mock_refresh.called) - - c = Channel.objects.get() - self.assertEqual(c.kind, "hipchat") - self.assertEqual(c.value, "{}") - self.assertEqual(c.project, self.project) diff --git a/hc/front/urls.py b/hc/front/urls.py index f2ddf2a6..ef3fad79 100644 --- a/hc/front/urls.py +++ b/hc/front/urls.py @@ -26,8 +26,6 @@ channel_urls = [ path('add_pagertree/', views.add_pagertree, name="hc-add-pagertree"), path('add_slack/', views.add_slack, name="hc-add-slack"), path('add_slack_btn/', views.add_slack_btn, name="hc-add-slack-btn"), - path('add_hipchat/', views.add_hipchat, name="hc-add-hipchat"), - path('hipchat/capabilities/', views.hipchat_capabilities, name="hc-hipchat-capabilities"), path('add_pushbullet/', views.add_pushbullet, name="hc-add-pushbullet"), path('add_discord/', views.add_discord, name="hc-add-discord"), path('add_pushover/', views.add_pushover, name="hc-add-pushover"), diff --git a/hc/front/views.py b/hc/front/views.py index 2cd70a9f..070248ec 100644 --- a/hc/front/views.py +++ b/hc/front/views.py @@ -1,6 +1,6 @@ from datetime import datetime, timedelta as td import json -from urllib.parse import urlencode, quote +from urllib.parse import urlencode from croniter import croniter from django.conf import settings @@ -800,42 +800,6 @@ def add_slack_btn(request): return redirect("hc-channels") -@login_required -def add_hipchat(request): - if "installable_url" in request.GET: - url = request.GET["installable_url"] - assert url.startswith("https://api.hipchat.com") - response = requests.get(url) - if "oauthId" not in response.json(): - messages.warning(request, "Something went wrong!") - return redirect("hc-channels") - - channel = Channel(kind="hipchat", project=request.project) - channel.user = request.project.owner - channel.value = response.text - channel.save() - - channel.refresh_hipchat_access_token() - channel.assign_all_checks() - messages.success(request, "The HipChat integration has been added!") - return redirect("hc-channels") - - install_url = "https://www.hipchat.com/addons/install?" + urlencode({ - "url": settings.SITE_ROOT + reverse("hc-hipchat-capabilities") - }) - - ctx = { - "page": "channels", - "install_url": install_url - } - return render(request, "integrations/add_hipchat.html", ctx) - - -def hipchat_capabilities(request): - return render(request, "integrations/hipchat_capabilities.json", {}, - content_type="application/json") - - @login_required def add_pushbullet(request): if settings.PUSHBULLET_CLIENT_ID is None: diff --git a/static/css/channels.css b/static/css/channels.css index 6e7bb82e..dce02ec2 100644 --- a/static/css/channels.css +++ b/static/css/channels.css @@ -2,6 +2,12 @@ margin-top: 36px; } + +.channel-row.kind-hipchat { + filter: grayscale(100%); + opacity: 0.5; +} + .channels-table .channel-row > td { padding-top: 10px; padding-bottom: 10px; diff --git a/static/img/integrations/setup_hipchat_1.png b/static/img/integrations/setup_hipchat_1.png deleted file mode 100644 index 511bf606..00000000 Binary files a/static/img/integrations/setup_hipchat_1.png and /dev/null differ diff --git a/static/img/integrations/setup_hipchat_2.png b/static/img/integrations/setup_hipchat_2.png deleted file mode 100644 index d43de71e..00000000 Binary files a/static/img/integrations/setup_hipchat_2.png and /dev/null differ diff --git a/static/img/integrations/setup_hipchat_3.png b/static/img/integrations/setup_hipchat_3.png deleted file mode 100644 index d3a31812..00000000 Binary files a/static/img/integrations/setup_hipchat_3.png and /dev/null differ diff --git a/static/img/integrations/setup_hipchat_4.png b/static/img/integrations/setup_hipchat_4.png deleted file mode 100644 index 77396052..00000000 Binary files a/static/img/integrations/setup_hipchat_4.png and /dev/null differ diff --git a/templates/front/channels.html b/templates/front/channels.html index ba50e0ab..8fa1ae05 100644 --- a/templates/front/channels.html +++ b/templates/front/channels.html @@ -27,7 +27,7 @@ {% for ch in channels %} {% with n=ch.latest_notification %} -
Group and private chat, file sharing, and integrations.
- - Add Integration -If your team uses HipChat, - you can set up {% site_name %} to post status updates directly to an - appropriate HipChat room.
- -- After - clicking on "Connect HipChat", you will be - asked to log into HipChat. -
-- Next, HipChat will let you select the chat room - for receiving {% site_name %} notifications. -
-- Next, HipChat will show you the permissions - requested by {% site_name %}. There's only one permission - needed: "Send Notification". -
-- That is all! You will now be redirected back to - "Integrations" page on {% site_name %} and see - the new integration! -
-