Skip to content
This repository has been archived by the owner on Oct 1, 2020. It is now read-only.

Commit

Permalink
add ability to stop replying to individuals
Browse files Browse the repository at this point in the history
 - closes #34
  • Loading branch information
monty5811 committed Apr 28, 2016
1 parent a13de5f commit 94b7f38
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 9 deletions.
1 change: 1 addition & 0 deletions api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ class Meta:
'full_name',
'is_archived',
'is_blocking',
'do_not_reply',
'last_sms',
)

Expand Down
6 changes: 5 additions & 1 deletion apostello/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ class KeywordAdmin(admin.ModelAdmin):
@admin.register(models.Recipient)
class RecipientAdmin(admin.ModelAdmin):
"""Admin class for apostello.models.Recipient."""
list_display = ('full_name', 'number', 'is_blocking', 'is_archived', )
list_display = ('full_name',
'number',
'is_blocking',
'is_archived',
'do_not_reply', )


@admin.register(models.RecipientGroup)
Expand Down
4 changes: 3 additions & 1 deletion apostello/assets/js/components/contact_row.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ const ContactRow = (props) => {
const className = props.is_blocking ? 'warning' : '';
const lastSms = props.contact.last_sms === null ?
{ content: '', time_received: '' } : props.contact.last_sms;
const doNotReplyElem = <div className="ui horizontal red label">No reply</div>;
const doNotReply = props.contact.do_not_reply ? doNotReplyElem : '';
return (
<tr className={className}>
<td>
<a href={props.contact.url}>{props.contact.full_name}</a>
<a href={props.contact.url}>{props.contact.full_name}</a> {doNotReply}
</td>
<td>{lastSms.content}</td>
<td>{lastSms.time_received}</td>
Expand Down
20 changes: 20 additions & 0 deletions apostello/migrations/0011_recipient_do_not_reply.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.5 on 2016-04-28 09:06
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('apostello', '0010_auto_20160421_1411'),
]

operations = [
migrations.AddField(
model_name='recipient',
name='do_not_reply',
field=models.BooleanField(default=False, help_text='Tick this box to disable automated replies for this person.', verbose_name='Do not reply'),
),
]
6 changes: 6 additions & 0 deletions apostello/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ class Recipient(models.Model):
validators=[not_twilio_num],
help_text="Cannot be our number, or we get an SMS loop."
)
do_not_reply = models.BooleanField(
"Do not reply",
default=False,
help_text=
"Tick this box to disable automated replies for this person.",
)
groups = models.ManyToManyField(RecipientGroup, blank=True)

def personalise(self, message):
Expand Down
3 changes: 3 additions & 0 deletions apostello/reply.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ def reply_to_name(self):
def construct_reply(self):
"""Construct appropriate reply."""

if self.contact.do_not_reply:
return ''

if self.keyword == "start":
reply = self.reply_to_start()
elif self.keyword == "stop":
Expand Down
8 changes: 4 additions & 4 deletions apostello/static/js/main.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/features.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Features
* Track sign ups, questions, etc using keywords.
* Manage access permissions - you can let anyone in you church have read only access.
* Spending safety net - you can set a limit (in $) for each person. No individual SMS can be sent that will cost more than this.
* Block auto replies to specific contacts.
* Receive daily digest emails of incoming messages.
* Live "wall" - curate and display incoming messages on a big screen. Great for a Q&A.
* Post all messages to a slack channel.
Expand Down
9 changes: 8 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,21 @@ def recipients():
last_name="Chalmers",
number='+15005550009'
) # can't recieve
beza = Recipient.objects.create(
first_name="Theodore",
last_name="Beza",
number='+447927411115',
do_not_reply=True
)

objs = {
'calvin': calvin,
'house_lamp': house_lamp,
'knox': knox,
'wesley': wesley,
'john_owen': john_owen,
'thomas_chalmers': thomas_chalmers
'thomas_chalmers': thomas_chalmers,
'beza': beza,
}
return objs

Expand Down
10 changes: 10 additions & 0 deletions tests/test_reply.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,13 @@ def test_is_blocking_reply(self, recipients):
)
reply = msg.construct_reply()
assert len(reply) == 0

def test_do_not_reply(self, recipients):
msg = InboundSms(
{
'From': str(recipients['beza'].number),
'Body': 'test'
}
)
reply = msg.construct_reply()
assert len(reply) == 0
4 changes: 2 additions & 2 deletions tests/test_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ def test_create_all_group_form(self, users, recipients):
assert resp.url == '/group/all/'
assert len(models.RecipientGroup.objects.all()) == 1
assert models.RecipientGroup.objects.all()[0].name == 'test'
assert len(models.RecipientGroup.objects.all()[0].all_recipients) == 5
assert len(models.RecipientGroup.objects.all()[0].all_recipients) == 6

def test_create_all_group_form_update(self, users, recipients, groups):
"""Test the form to create a group composed of all recipients.
Expand All @@ -346,7 +346,7 @@ def test_create_all_group_form_update(self, users, recipients, groups):
assert resp.status_code == 302
assert resp.url == '/group/all/'
g = models.RecipientGroup.objects.get(name='Empty Group')
assert len(g.all_recipients) == 5
assert len(g.all_recipients) == 6


@pytest.mark.slow
Expand Down

0 comments on commit 94b7f38

Please sign in to comment.