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 priority team members #158174599 #36

Open
wants to merge 113 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
113 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
bb43380
[Feature #158174601] Add tests, UI and logic for Shopify integration
Jul 5, 2018
c51ae19
[Feature #158174601] Adjust check creation code and remove commented …
Jul 5, 2018
b2392d3
[Feature #158174601] Add flash messages for unauthorized access
Jul 5, 2018
b7e50a5
[Feature #158174601] Add shopify fields to db checks to enable delet…
Jul 5, 2018
b13ce18
[Feature #158174601] Enable site root to be picked from environment
Jul 5, 2018
7fbf115
[Feature #158174601] Add site root
Jul 5, 2018
96e9056
[Feature #158174601] Update requirements.txt with new packages
Jul 5, 2018
bccf06e
[Feature #158174601] Update travis file
Jul 6, 2018
71ac27b
[Feature #158174601] Remove changes from travis
Jul 6, 2018
b4219c1
[Feature #158174601] Make changes to travis
Jul 6, 2018
45903b6
[Feature #158174601] Remove changes from travis
Jul 6, 2018
8c20c2d
[Feature #158174601] Remove unneccesary file
Jul 6, 2018
db9438f
[Feature #158174601] Update settings
Jul 6, 2018
a0b5251
[Feature #158174601] Update settings spelling
Jul 6, 2018
a400187
[Feature #158174601] Add sendgrid
Jul 6, 2018
10c75cb
[Feature #158174601] Update requirements.txt
Jul 6, 2018
36b6c50
[Feature #158174601] Update requirements.txt sendgrid
Jul 6, 2018
ac1db53
[Feature #158174601] Fix remove shopify check
Jul 9, 2018
6f5fb15
[Feature #158174601] Add redirection after successfully creation of s…
Jul 10, 2018
dc265de
[Feature #158174601] Remove shopify api crendentials
Jul 11, 2018
d49311a
Merge branch 'develop' into ft-alerts-thirdparty-application-158174601
archbishop12 Jul 11, 2018
030ed38
[Feature #158174601] Merge migrations
Jul 11, 2018
22a0cb1
[Feature #158174601] Update requirements.txt
Jul 11, 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
b780455
[Feature #158174601] Update requirements.txt
Jul 11, 2018
eaba2fa
Fix conflicts
Jul 12, 2018
cf6bbf5
[Feature #158174601] Fix test and use mock
Jul 12, 2018
82c864d
[Feature #158174601] Fix test and use mock
Jul 12, 2018
56ca1dc
Merge branch 'ft-alerts-thirdparty-application-158174601' of https://…
Jul 12, 2018
1d71109
Merge branch 'develop' into ft-alerts-thirdparty-application-158174601
archbishop12 Jul 12, 2018
003b3f5
[Feature #158174601] Merge migrations
Jul 12, 2018
25b4003
[Feature #158174601] Add priority form
Jul 12, 2018
679fe3d
[Feature #158174601] Make variables used in shopify test global
Jul 13, 2018
c0cc056
Merge branch 'develop' into ft-alerts-thirdparty-application-158174601
archbishop12 Jul 16, 2018
0266758
Merge branch 'develop' of https://github.com/andela/hc-aces-kla into …
Jul 16, 2018
f3bb52d
[Feature #158174601] Add tests, UI and logic for Shopify integration
Jul 5, 2018
3d92745
[Feature #158174601] Adjust check creation code and remove commented …
Jul 5, 2018
f72314f
[Feature #158174601] Add flash messages for unauthorized access
Jul 5, 2018
14b86ab
[Feature #158174601] Add shopify fields to db checks to enable delet…
Jul 5, 2018
4412062
[Feature #158174601] Update requirements.txt with new packages
Jul 5, 2018
3501f07
[Feature #158174601] Update travis file
Jul 6, 2018
6d7a904
[Feature #158174601] Remove changes from travis
Jul 6, 2018
3ee252f
[Feature #158174601] Make changes to travis
Jul 6, 2018
89e4d73
[Feature #158174601] Remove changes from travis
Jul 6, 2018
cb35b54
[Feature #158174601] Remove unneccesary file
Jul 6, 2018
4581d6d
[Feature #158174601] Update settings
Jul 6, 2018
f563d9b
[Feature #158174601] Update settings spelling
Jul 6, 2018
aa36d56
[Feature #158174601] Update requirements.txt sendgrid
Jul 6, 2018
fb7992d
[Feature #158174601] Fix remove shopify check
Jul 9, 2018
6e451ff
[Feature #158174601] Add redirection after successfully creation of s…
Jul 10, 2018
501ead6
[Feature #158174601] Remove shopify api crendentials
Jul 11, 2018
78eea84
[Feature #158174601] Merge migrations
Jul 11, 2018
64be820
Fix Conflicts
Jul 12, 2018
f27bf32
[Feature #158174601] Adjust check creation code and remove commented …
Jul 5, 2018
44fb1b6
[Feature #158174601] Add flash messages for unauthorized access
Jul 5, 2018
67e8424
[Feature #158174601] Enable site root to be picked from environment
Jul 5, 2018
e29d176
[Feature #158174601] Add site root
Jul 5, 2018
5695508
[Feature #158174601] Update requirements.txt with new packages
Jul 5, 2018
afc1d6b
[Feature #158174601] Update travis file
Jul 6, 2018
5ea068c
[Feature #158174601] Remove changes from travis
Jul 6, 2018
70f7fbc
[Feature #158174601] Make changes to travis
Jul 6, 2018
4f67ce4
[Feature #158174601] Remove changes from travis
Jul 6, 2018
9d53cdb
[Feature #158174601] Remove unneccesary file
Jul 6, 2018
70fd10b
[Feature #158174601] Update settings
Jul 6, 2018
8ea4fe8
[Feature #158174601] Update settings spelling
Jul 6, 2018
a8f06c1
[Feature #158174601] Add sendgrid
Jul 6, 2018
d770c0a
[Feature #158174601] Update requirements.txt
Jul 6, 2018
986364b
[Feature #158174601] Update requirements.txt sendgrid
Jul 6, 2018
956d229
[Feature #158174601] Fix remove shopify check
Jul 9, 2018
8374e49
[Feature #158174601] Update requirements.txt
Jul 11, 2018
a109200
[Feature #158174601] Fix test and use mock
Jul 12, 2018
54b5d70
[Feature #158174601] Merge migrations
Jul 12, 2018
6bab7e7
[Feature #158174601] Make variables used in shopify test global
Jul 13, 2018
2ba58f9
Fix conflicts
Jul 16, 2018
5bca68f
Fix Conflicts
Jul 16, 2018
173fa00
Fix Conflicts
Jul 16, 2018
9c8f0d2
Fix Conflicts
Jul 16, 2018
d12e45a
Fix Conflicts
Jul 16, 2018
51ee8c6
Fix Conflicts
Jul 16, 2018
83878ca
Fix migrations conflicts
Jul 16, 2018
4aace9b
Merge Migrations
Jul 16, 2018
9591335
Fix settings
Jul 16, 2018
4a29283
[Feature #158174599] Write tests for task
Jul 18, 2018
3d884fb
[Feature #158174599] Add UI for the task
Jul 23, 2018
81d5de9
[Feature #158174599] Fix tests
Jul 23, 2018
a227d2f
[Feature #158174599] Fix settings.py file
Jul 23, 2018
a00d477
[Feature #158174599] Fix settings.py
Jul 23, 2018
46d00ea
[Feature #158174599] Remove unnecessary code
Jul 23, 2018
ceee829
Add manage.py migrate
Jul 23, 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
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
release: bash ./pre-release.sh
release: ./manage.py migrate
web: gunicorn hc.wsgi:application
11 changes: 11 additions & 0 deletions hc/accounts/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,16 @@ class RemoveTeamMemberForm(forms.Form):
email = LowercaseEmailField()


class AssignChecksForm(forms.Form):
email = LowercaseEmailField()
check_code = forms.UUIDField(required=False)
priority = forms.IntegerField(min_value=0, max_value=5)


class UnAssignChecksForm(forms.Form):
email = LowercaseEmailField()
check_code = forms.UUIDField(required=False)


class TeamNameForm(forms.Form):
team_name = forms.CharField(max_length=200, required=True)
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 = [
]
16 changes: 16 additions & 0 deletions hc/accounts/migrations/0010_merge_20180712_1640.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-12 16:40
from __future__ import unicode_literals

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('accounts', '0009_merge_20180711_1206'),
('accounts', '0009_merge_20180704_1359'),
]

operations = [
]
16 changes: 16 additions & 0 deletions hc/accounts/migrations/0011_merge_20180716_1253.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-16 12:53
from __future__ import unicode_literals

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('accounts', '0010_merge_20180714_0612'),
('accounts', '0010_merge_20180712_1640'),
]

operations = [
]
20 changes: 20 additions & 0 deletions hc/accounts/migrations/0012_auto_20180717_0704.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-17 07:04
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('accounts', '0011_merge_20180716_1253'),
]

operations = [
migrations.AlterField(
model_name='profile',
name='report_frequency',
field=models.CharField(default='month', max_length=20),
),
]
75 changes: 74 additions & 1 deletion hc/accounts/tests/test_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from hc.test import BaseTestCase
from hc.accounts.models import Member
from hc.api.models import Check
from hc.api.models import Check, Assigned


class ProfileTestCase(BaseTestCase):
Expand Down Expand Up @@ -203,3 +203,76 @@ def test_it_loads_reports(self):
self.client.login(username="[email protected]", password="password")
response = self.client.get(reverse("hc-reports"))
self.assertIn(b"Today's Report", response.content)

def test_it_assigns_check_to_member(self):
"""test that a team member can be removed"""
self.check = Check(user=self.alice)
self.check.save()
self.client.login(username="[email protected]", password="password")
assigned_list = []
assigned_list.append(self.check.code)
form = {"assign_checks": "1", "email": "[email protected]",
"check_code": self.check.code,
"priority": 3, "assigned_list": assigned_list}
r = self.client.post("/accounts/profile/", form)
assert r.status_code == 200

self.assertEqual(Assigned.objects.count(), 1)
assigned = Assigned.objects.filter(check_assigned=self.check).first()
self.assertEqual(assigned.priority, 3)

def test_it_assigns_2_checks_to_one_member(self):
"""test that a team member can be removed"""
self.check = Check(user=self.alice)
self.check.save()
self.check2 = Check(user=self.alice)
self.check2.save()
self.client.login(username="[email protected]", password="password")
assigned_list = []
assigned_list.append(self.check.code)
assigned_list.append(self.check2.code)
form = {"assign_checks": "1", "email": "[email protected]",
"check_code": self.check.code,
"priority": "3", "assigned_list": assigned_list}
response = self.client.post("/accounts/profile/", form)
assert response.status_code == 200

self.assertEqual(Assigned.objects.count(), 2)

def test_it_unassign_check_from_members(self):
"""test that a team member can be removed"""
self.check = Check(user=self.alice)
self.check.save()
self.client.login(username="[email protected]", password="password")
assigned_list = []
assigned_list.append(self.check.code)
form = {"assign_checks": "1", "email": "[email protected]",
"check_code": self.check.code,
"priority": 3, "assigned_list": assigned_list}
self.client.post("/accounts/profile/", form)
self.assertEqual(Assigned.objects.count(), 1)
assigned_empty = []
form = {"assign_checks": "1", "email": "[email protected]",
"check_code": self.check.code,
"assigned_list": assigned_empty}
self.client.post("/accounts/profile/", form)
self.assertEqual(Assigned.objects.count(), 0)

def test_it_doesnt_assign_check_to_same_user_twice(self):
"""test that a team member can be removed"""
self.check = Check(user=self.alice)
self.check.save()
self.client.login(username="[email protected]", password="password")
assigned_list = []
assigned_list.append(self.check.code)
form = {"assign_checks": "1", "email": "[email protected]",
"check_code": self.check.code,
"priority": 3, "assigned_list": assigned_list}
self.client.post("/accounts/profile/", form)
self.assertEqual(Assigned.objects.count(), 1)

form = {"unassign_check": "1", "email": "[email protected]",
"check_code": self.check.code,
"assigned_list": assigned_list}
self.client.post("/accounts/profile/", form)
self.assertEqual(Assigned.objects.count(), 1)
55 changes: 48 additions & 7 deletions hc/accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@
from django.core import signing
from django.http import HttpResponseForbidden, HttpResponseBadRequest
from django.shortcuts import redirect, render
from hc.accounts.forms import (EmailPasswordForm, InviteTeamMemberForm,
RemoveTeamMemberForm, ReportSettingsForm,
SetPasswordForm, TeamNameForm)
from hc.accounts.forms import (EmailPasswordForm,
InviteTeamMemberForm,
RemoveTeamMemberForm,
ReportSettingsForm,
SetPasswordForm,
TeamNameForm)
from hc.accounts.models import Profile, Member
from hc.api.models import Channel, Check
from hc.api.models import Channel, Check, Assigned
from hc.lib.badges import get_badge_url


Expand Down Expand Up @@ -155,7 +158,6 @@ def profile(request):
elif "show_api_key" in request.POST:
show_api_key = True
elif "update_reports_allowed" in request.POST:
# print(request.POST)
form = ReportSettingsForm(request.POST)
if form.is_valid():
profile.reports_allowed = form.cleaned_data["reports_allowed"]
Expand Down Expand Up @@ -191,6 +193,30 @@ def profile(request):
user=farewell_user).delete()

messages.info(request, "%s removed from team!" % email)
elif "assign_checks" in request.POST:
email_show = request.POST.get('email')
assigned_show = request.POST.getlist('assigned_list')
priority = request.POST.get('priority')
user = User.objects.filter(email=email_show).first()
delete_list = Assigned.objects.filter(user_id=user.id)
for value in delete_list:
if str(value.check_assigned.code) not in assigned_show:
assigned_check = Check.objects.filter(
code=value.check_assigned.code).first()
Assigned.objects.filter(check_assigned=assigned_check,
user_id=user.id).delete()
for check_code in assigned_show:
user = User.objects.filter(email=email_show).first()
assigned_check = Check.objects.filter(code=check_code).first()
minus_list = Assigned.objects.filter(
check_assigned=assigned_check, user_id=user.id)
if len(list(minus_list)) == 0:
assign = Assigned(
check_assigned=assigned_check,
priority=priority, user_id=user.id)
assign.save()
messages.success(request,
"Team member has been assigned to check")
elif "set_team_name" in request.POST:
if not profile.team_access_allowed:
return HttpResponseForbidden()
Expand All @@ -212,12 +238,27 @@ def profile(request):
continue

badge_urls.append(get_badge_url(username, tag))

checks = Check.objects.filter(user=request.team.user)
assigned = Assigned.objects.all()
assigned_list = []

for member in profile.member_set.all():
for check in checks:
is_assigned = Assigned.objects.filter(check_assigned=check,
user_id=member.user.id).\
first()
if is_assigned:
assigned_list.append(1)
else:
assigned_list.append(0)
ctx = {
"page": "profile",
"badge_urls": badge_urls,
"profile": profile,
"show_api_key": show_api_key
"show_api_key": show_api_key,
"checks": checks,
"assigned": assigned,
"assigned_list": assigned_list
}

return render(request, "accounts/profile.html", ctx)
Expand Down
12 changes: 6 additions & 6 deletions hc/api/management/commands/sendalerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import time
from concurrent.futures import ThreadPoolExecutor
from django.core.management.base import BaseCommand
from django.db.models import Q
from django.db import connection
from django.utils import timezone
from hc.api.models import Check
Expand All @@ -19,10 +18,12 @@ def handle_many(self):

query = Check.objects.filter(user__isnull=False).select_related("user")

running_checks = running_checks = query.filter(
Q(status="up") | Q(status="down"))
# running_checks = running_checks = query.filter(
# Q(status="up") | Q(status="down"))

now = timezone.now()
going_down = query.filter(alert_after__lt=now, status="up")
going_up = query.filter(alert_after__gt=now, status="down")
repeat_list_approved = query.filter(
alert_after__lt=now,
status="down",
Expand All @@ -47,12 +48,11 @@ def handle_many(self):

if repeat_list_approved:
checks = (
list(
running_checks.iterator()) +
list(going_down.iterator()) + list(going_up.iterator()) +
list(repeat_list_approved))
else:
checks = (
list(running_checks.iterator()) +
list(going_down.iterator()) + list(going_up.iterator()) +
list(repeat_list_approved.iterator()))

if not checks:
Expand Down
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 = [
]
16 changes: 16 additions & 0 deletions hc/api/migrations/0051_merge_20180716_1254.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-16 12:54
from __future__ import unicode_literals

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('api', '0036_merge_20180711_1206'),
('api', '0050_merge_20180716_0922'),
]

operations = [
]
21 changes: 21 additions & 0 deletions hc/api/migrations/0052_auto_20180717_0704.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-17 07:04
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('api', '0051_merge_20180716_1254'),
]

operations = [
migrations.AlterField(
model_name='check',
name='twilio_number',
field=models.TextField(blank=True,
default='+00000000000', null=True),
),
]
Loading