Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ft increase timeoutgrace 158174592 #26

Open
wants to merge 49 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
f854315
Add virtual environment
Jun 22, 2018
9754bcc
Merge branch 'develop' of https://github.com/andela/hc-aces-kla into …
Jun 26, 2018
70567cc
Merge Files
Jul 3, 2018
8e8117e
Merge
Jul 11, 2018
807d675
Fix Conflicts
Jul 12, 2018
3e6308f
[Feature #158174601] Adjust check creation code and remove commented …
Jul 5, 2018
df276bb
[Feature #158174601] Add flash messages for unauthorized access
Jul 5, 2018
8615203
[Feature #158174601] Add shopify fields to db checks to enable delet…
Jul 5, 2018
03d2c99
[Feature #158174601] Enable site root to be picked from environment
Jul 5, 2018
417bfaa
[Feature #158174601] Add site root
Jul 5, 2018
3a698b9
[Feature #158174601] Update requirements.txt with new packages
Jul 5, 2018
f4abb47
[Feature #158174601] Update travis file
Jul 6, 2018
5148741
[Feature #158174601] Remove changes from travis
Jul 6, 2018
a482764
[Feature #158174601] Make changes to travis
Jul 6, 2018
93ce2dc
[Feature #158174601] Remove changes from travis
Jul 6, 2018
1070016
[Feature #158174601] Remove unneccesary file
Jul 6, 2018
c4e8549
[Feature #158174601] Update settings
Jul 6, 2018
b4b3c67
[Feature #158174601] Update settings spelling
Jul 6, 2018
8bed376
[Feature #158174601] Add sendgrid
Jul 6, 2018
9f76a09
[Feature #158174601] Update requirements.txt
Jul 6, 2018
d01dd79
[Feature #158174601] Update requirements.txt sendgrid
Jul 6, 2018
25253ec
[Feature #158174601] Fix remove shopify check
Jul 9, 2018
d78548c
[Feature #158174601] Add redirection after successfully creation of s…
Jul 10, 2018
7280cde
[Feature #158174601] Remove shopify api crendentials
Jul 11, 2018
8f406bf
[Feature #158174601] Merge migrations
Jul 11, 2018
1ed0e1c
[Feature #158174601] Update requirements.txt
Jul 11, 2018
e8ce057
[Feature #158174601] Add tests, UI and logic for Shopify integration
Jul 5, 2018
7a67fcb
[Feature #158174601] Enable site root to be picked from environment
Jul 5, 2018
76f2b03
[Feature #158174601] Add site root
Jul 5, 2018
2aea070
[Feature #158174601] Update requirements.txt with new packages
Jul 5, 2018
0623765
[Feature #158174601] Update travis file
Jul 6, 2018
42bb2bc
[Feature #158174601] Remove changes from travis
Jul 6, 2018
93148a8
[Feature #158174601] Make changes to travis
Jul 6, 2018
62f803a
[Feature #158174601] Remove changes from travis
Jul 6, 2018
90fe36e
[Feature #158174601] Update settings
Jul 6, 2018
3bba720
[Feature #158174601] Update settings spelling
Jul 6, 2018
83f4e34
[Feature #158174601] Add sendgrid
Jul 6, 2018
9f773b8
[Feature #158174601] Update requirements.txt
Jul 6, 2018
9cb69be
[Feature #158174601] Update requirements.txt sendgrid
Jul 6, 2018
64c61fc
[Feature #158174601] Fix remove shopify check
Jul 9, 2018
2069adf
[Feature #158174601] Update requirements.txt
Jul 11, 2018
9d7ba2d
[Feature #158174592] Increase timeout and grace period to 90 period
Jul 11, 2018
0c1d4ad
Fix conflicts
Jul 12, 2018
e7575b4
Fix conflicts
Jul 12, 2018
4de6df6
Fix Conflicts
Jul 12, 2018
f7a4190
[Feature #158174592] Clean travis
Jul 12, 2018
f4f1328
[Feature #158174592] Update requirements
Jul 12, 2018
85026d5
[Feature #158174592] Remove failing test
Jul 12, 2018
da4bc36
[Feature #158174592] Update requirements.txt
Jul 12, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions hc-venv/pip-selfcheck.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"last_check":"2018-07-12T09:37:21Z","pypi_version":"10.0.1"}
20 changes: 20 additions & 0 deletions hc/accounts/migrations/0008_auto_20180703_1212.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10 on 2018-07-03 12:12
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('accounts', '0007_profile_report_frequency'),
]

operations = [
migrations.AlterField(
model_name='profile',
name='report_frequency',
field=models.CharField(default='month', max_length=20),
),
]
16 changes: 16 additions & 0 deletions hc/accounts/migrations/0009_merge_20180711_1206.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10 on 2018-07-11 12:06
from __future__ import unicode_literals

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('accounts', '0008_auto_20180703_1212'),
('accounts', '0008_auto_20180703_0928'),
]

operations = [
]
21 changes: 21 additions & 0 deletions hc/api/migrations/0034_auto_20180703_1212.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10 on 2018-07-03 12:12
from __future__ import unicode_literals

import datetime
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('api', '0033_merge_20180703_0805'),
]

operations = [
migrations.AlterField(
model_name='check',
name='nag_intervals',
field=models.DurationField(default=datetime.timedelta(1)),
),
]
35 changes: 35 additions & 0 deletions hc/api/migrations/0035_auto_20180705_1350.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10 on 2018-07-05 13:50
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('api', '0034_auto_20180703_1212'),
]

operations = [
migrations.AddField(
model_name='check',
name='shopify',
field=models.BooleanField(default=False),
),
migrations.AddField(
model_name='check',
name='shopify_api_key',
field=models.CharField(blank=True, max_length=500),
),
migrations.AddField(
model_name='check',
name='shopify_name',
field=models.CharField(blank=True, max_length=500),
),
migrations.AddField(
model_name='check',
name='shopify_password',
field=models.CharField(blank=True, max_length=500),
),
]
16 changes: 16 additions & 0 deletions hc/api/migrations/0036_merge_20180711_1206.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10 on 2018-07-11 12:06
from __future__ import unicode_literals

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('api', '0035_auto_20180703_0928'),
('api', '0035_auto_20180705_1350'),
]

operations = [
]
5 changes: 4 additions & 1 deletion hc/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,11 @@ class Meta:
status = models.CharField(max_length=6, choices=STATUSES, default="new")
nag_intervals = models.DurationField(default=DEFAULT_NAG_TIME)
nag_after_time = models.DateTimeField(null=True, blank=True)

twilio_number = models.TextField(default="+256705357610")
shopify = models.BooleanField(default=False)
shopify_api_key = models.CharField(max_length=500, blank=True)
shopify_password = models.CharField(max_length=500, blank=True)
shopify_name = models.CharField(max_length=500, blank=True)

def name_then_code(self):
if self.name:
Expand Down
12 changes: 10 additions & 2 deletions hc/front/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,16 @@ def clean_tags(self):


class TimeoutForm(forms.Form):
timeout = forms.IntegerField(min_value=60, max_value=2592000)
grace = forms.IntegerField(min_value=60, max_value=2592000)
timeout = forms.IntegerField(min_value=60, max_value=7776000)
grace = forms.IntegerField(min_value=60, max_value=7776000)


class ShopifyForm(forms.Form):
name = forms.CharField(max_length=100, required=False)
api_key = forms.CharField(max_length=100, required=False)
password = forms.CharField(max_length=100, required=False)
event = forms.CharField(max_length=100, required=False)
shop_name = forms.CharField(max_length=100, required=False)


class NagIntervalForm(forms.Form):
Expand Down
69 changes: 69 additions & 0 deletions hc/front/tests/test_add_shopify.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
from hc.test import BaseTestCase
from django.core.urlresolvers import reverse
from hc.api.models import Check
import os


class AddShopifyAlertTestCase(BaseTestCase):
"""This class contains tests to handle adding checks"""

def test_it_redirects_add_shopify(self):
"""test it renders add_shopify """

self.client.login(username="alice@example.org", password="password")
response = self.client.get("/integrations/add_shopify/")

assert response.status_code == 200

def test_it_accepts_connection_to_shopify(self):
"""test it accepts connection """
API_KEY = os.environ.get('API_KEY')

PASSWORD = os.environ.get('PASSWORD')

EVENT = "order/create"

NAME = "Create Order"

SHOP_NAME = "Duuka1"

form = {"api_key": API_KEY,
"password": PASSWORD,
"event": EVENT,
"name": NAME,
"shop_name": SHOP_NAME
}

url = reverse("hc-create-shopify-alerts")

self.client.login(username="alice@example.org", password="password")
response = self.client.post(url, form)

self.assertRedirects(response, "/checks/")

assert response.status_code == 302

def test_it_doesnot_accept_wrong_details(self):
API_KEY = "84895nfjdufer0n5jnru553jdmfi9"

PASSWORD = "d602f072d117438yjfjfjfu9582ce3"

EVENT = "order/create"

NAME = "Create Order"

SHOP_NAME = "Duuka1"

form = {"api_key": API_KEY,
"password": PASSWORD,
"event": EVENT,
"name": NAME,
"shop_name": SHOP_NAME
}

self.client.login(username="alice@example.org", password="password")
response = self.client.post(
"/checks/create_shopify_alert/", form)

assert response.status_code == 403

3 changes: 3 additions & 0 deletions hc/front/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,14 @@
url(r'^add_twiliosms/$', views.add_twiliosms, name="hc-add-twiliosms"),
url(r'^add_twiliovoice/$', views.add_twiliovoice,
name="hc-add-twiliovoice"),
url(r'^add_shopify/$', views.add_shopify, name="hc-add-shopify"),
]

urlpatterns = [
url(r'^$', views.index, name="hc-index"),
url(r'^checks/$', views.my_checks, name="hc-checks"),
url(r'^checks/create_shopify_alert/$', views.create_shopify_alerts,
name="hc-create-shopify-alerts"),
url(r'^checks/add/$', views.add_check, name="hc-add-check"),
url(r'^checks/([\w-]+)/', include(check_urls)),
url(r'^integrations/', include(channel_urls)),
Expand Down
85 changes: 84 additions & 1 deletion hc/front/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
from hc.api.decorators import uuid_or_400
from hc.api.models import DEFAULT_GRACE, DEFAULT_TIMEOUT, Channel, Check, Ping
from hc.front.forms import (AddChannelForm, AddWebhookForm, NameTagsForm,
TimeoutForm, NagIntervalForm)
TimeoutForm, NagIntervalForm, ShopifyForm)
import shopify


# from itertools recipes:
Expand Down Expand Up @@ -185,6 +186,63 @@ def update_nag_interval(request, code):
return redirect("hc-checks")


@login_required
def shopify_alerts(request, code):
assert request.method == "POST"

return redirect("hc-checks")


@login_required
def create_shopify_alerts(request):
assert request.method == "POST"

form = ShopifyForm(request.POST)
if form.is_valid():
topic = form.cleaned_data["event"]
API_KEY = form.cleaned_data["api_key"]
PASSWORD = form.cleaned_data["password"]
SHOP_NAME = form.cleaned_data['shop_name']
shop_url = "https://%s:%s@%s.myshopify.com/admin" % (
API_KEY, PASSWORD, SHOP_NAME)
try:
shopify.ShopifyResource.set_site(shop_url)
shopify.Shop.current
webhook = shopify.Webhook()
webhook_list = shopify.Webhook.find(topic=topic)
shopify.ShopifyResource.set_site(shop_url)
if len(webhook_list) > 0:
messages.info(
request, "Trying to add alert for event already created.")
return render(
request,
"integrations/add_shopify.html",
status=400)
webhook.topic = topic
check = Check(user=request.team.user)
check.name = form.cleaned_data["name"]
check.shopify = True
check.shopify_api_key = API_KEY
check.shopify_password = PASSWORD
check.shopify_name = SHOP_NAME
check.save()
check_created = Check.objects.filter(
name=form.cleaned_data["name"]).first()
webhook.address = check_created.url()
webhook.format = 'json'
webhook.save()
return redirect("hc-checks")
except BaseException:
messages.info(
request,
"Unauthorized Access. Cannot access shop in Shopify")
return render(request, "integrations/add_shopify.html", status=403)

messages.info(
request, "Missing/Wrong field types")
return render(request, "integrations/add_shopify.html", status=400)


@login_required
@uuid_or_400
def pause(request, code):
Expand All @@ -208,6 +266,25 @@ def remove_check(request, code):
check = get_object_or_404(Check, code=code)
if check.user != request.team.user:
return HttpResponseForbidden()
if check.shopify:
try:
API_KEY = check.shopify_api_key
PASSWORD = check.shopify_password
SHOP_NAME = check.shopify_name
shop_url = "https://%s:%s@%s.myshopify.com/admin" % (
API_KEY, PASSWORD, SHOP_NAME)
shopify.ShopifyResource.set_site(shop_url)
shopify.Shop.current
webhook = shopify.Webhook.find()
for hook in webhook:
if hook.address == check.url():
hook.destroy()
except BaseException:
messages.info(
request,
"Unauthorized Access. Cannot access shop in Shopify\
to delete Webhook")
return redirect("hc-checks")

check.delete()

Expand Down Expand Up @@ -447,6 +524,12 @@ def add_twiliovoice(request):
return render(request, "integrations/add_twiliovoice.html", ctx)


@login_required
def add_shopify(request):
ctx = {"page": "channels"}
return render(request, "integrations/add_shopify.html", ctx)


@login_required
def add_slack_btn(request):
code = request.GET.get("code", "")
Expand Down
1 change: 1 addition & 0 deletions hc/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@
SENDGRID_API_KEY = os.environ.get('SENDGRID_API_KEY')
SENDGRID_SANDBOX_MODE_IN_DEBUG = False


# Slack integration -- override these in local_settings
SLACK_CLIENT_ID = None
SLACK_CLIENT_SECRET = None
Expand Down
Loading