-
Notifications
You must be signed in to change notification settings - Fork 81
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
Twilio Integration and More update notification #1719
Conversation
41 tests are failing for this PR. You need to fix them before we can proceed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a few small things in the code. I also can't get it to run in the dev VM, the wrong SMS gateway is imported in utils
.
cadasta/config/settings/default.py
Outdated
SMS_GATEWAY = 'accounts.gateways.TwilioGateway' | ||
TWILIO_ACCOUNT_SID = os.environ['TWILIO_ACCOUNT_SID'] | ||
TWILIO_AUTH_TOKEN = os.environ['TWILIO_AUTH_TOKEN'] | ||
TWILIO_PHONE_NUMBER_LIST = ['+15005550006'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't be hardcoded.
@@ -0,0 +1,65 @@ | |||
from django.test import TestCase | |||
from django.conf import settings | |||
# from accounts.gateways.twilio import TwilioGateway |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comments need to be removed
cadasta/config/settings/default.py
Outdated
@@ -574,3 +574,8 @@ | |||
|
|||
TOTP_TOKEN_VALIDITY = 3600 | |||
TOTP_DIGITS = 6 | |||
|
|||
SMS_GATEWAY = 'accounts.gateways.TwilioGateway' | |||
TWILIO_ACCOUNT_SID = os.environ['TWILIO_ACCOUNT_SID'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you're overwriting SMS_GATEWAY
in the dev settings this breaks in the dev environment. We're not actually using Twilio for dev so there's no need to set this by default. Move these settings to the production settings.
|
||
|
||
def send_sms(to, body): | ||
twilioobj = (import_string(settings.SMS_GATEWAY))() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the dev VM accounts.gateways.FakeGateway
should be imported but it isn't. Instead, accounts.gateways.TwilioGateway
is imported and everything breaks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not know that dev settings were used for testing up until now. I think the system should work fine now, and there should be no breakage.
@oliverroick Updates from my conversation with @amplifi :
|
👍 and the Ansible provisioning task is updated to populate the Twilio SID and auth token vars. Great work, @valaparthvi! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good now, thanks for making the changes. Also, thanks @amplifi for helping out with this.
There's only one small thing with the settings now that still breaks in the dev VM.
cadasta/config/settings/default.py
Outdated
|
||
SMS_GATEWAY = 'accounts.gateways.FakeGateway' | ||
|
||
TWILIO_ACCOUNT_SID = os.environ['TWILIO_ACCOUNT_SID'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I don't have the Twilio account settings exported in my dev VM this breaks. We have two options how we can deal with it:
- Add this and the next line to both
production.py
andtravis.py
and remove them from here. - Write
os.environ.get('TWILIO_ACCOUNT_SID')
instead. In that caseTWILIO_ACCOUNT_SID
will be set toNone
and no exception is thrown.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, that is what you meant when you said dev VM breaks. I was under the assumption that we will always have credentials exported in the dev VM so I did not completely understand the problem earlier, but I like the second idea better. Although exceptions will be thrown in the dev VM when tests are run. These exceptions will be thrown by accounts/tests/test_gateways.py
since it uses TwilioGateway
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks!
…nce we have phone numbers, remove unnecessary settings from default settings
… to settings/default.py
d10329c
to
160a03f
Compare
* Twilio Gateway * Enable Twilio test account for Travis * Pass twilio settings into tox env * Pass all the tests * 100% test coverage * Remove unnecessary lines of code * Currently removed TWILIO_PHONE_NUMBER from settings, add that later once we have phone numbers, remove unnecessary settings from default settings * Remove comments * Make tests pass * Make tests pass, remove TwilioGateway logger, move FakeGateway logger to settings/default.py * Send email/sms regardless of phone/email('s) verification status * Add changes addressed to PR * Rebasing and changes
* Twilio Gateway * Enable Twilio test account for Travis * Pass twilio settings into tox env * Pass all the tests * 100% test coverage * Remove unnecessary lines of code * Currently removed TWILIO_PHONE_NUMBER from settings, add that later once we have phone numbers, remove unnecessary settings from default settings * Remove comments * Make tests pass * Make tests pass, remove TwilioGateway logger, move FakeGateway logger to settings/default.py * Send email/sms regardless of phone/email('s) verification status * Add changes addressed to PR * Rebasing and changes
* VerificationDevice model and Removal of 48hr email verification period (#1606) * Registration with Phone number (#1662) * Add phone to User Profile (#1698) * Add Ansible provisioning for Twilio * Allow user to login with phone and add Resend Token Page (#1708) * Reset Password with Phone (#1717) * Twilio Integration and More update notification (#1719) * Add API endpoint for phone verification(2) (#1748)
* VerificationDevice model and Removal of 48hr email verification period (#1606) * Registration with Phone number (#1662) * Add phone to User Profile (#1698) * Add Ansible provisioning for Twilio * Allow user to login with phone and add Resend Token Page (#1708) * Reset Password with Phone (#1717) * Twilio Integration and More update notification (#1719) * Add API endpoint for phone verification(2) (#1748)
* VerificationDevice model and Removal of 48hr email verification period (#1606) * Registration with Phone number (#1662) * Add phone to User Profile (#1698) * Add Ansible provisioning for Twilio * Allow user to login with phone and add Resend Token Page (#1708) * Reset Password with Phone (#1717) * Twilio Integration and More update notification (#1719) * Add API endpoint for phone verification(2) (#1748)
* VerificationDevice model and Removal of 48hr email verification period (#1606) * Registration with Phone number (#1662) * Add phone to User Profile (#1698) * Add Ansible provisioning for Twilio * Allow user to login with phone and add Resend Token Page (#1708) * Reset Password with Phone (#1717) * Twilio Integration and More update notification (#1719) * Add API endpoint for phone verification(2) (#1748)
* VerificationDevice model and Removal of 48hr email verification period (#1606) * Registration with Phone number (#1662) * Add phone to User Profile (#1698) * Add Ansible provisioning for Twilio * Allow user to login with phone and add Resend Token Page (#1708) * Reset Password with Phone (#1717) * Twilio Integration and More update notification (#1719) * Add API endpoint for phone verification(2) (#1748)
* VerificationDevice model and Removal of 48hr email verification period (#1606) * Registration with Phone number (#1662) * Add phone to User Profile (#1698) * Add Ansible provisioning for Twilio * Allow user to login with phone and add Resend Token Page (#1708) * Reset Password with Phone (#1717) * Twilio Integration and More update notification (#1719) * Add API endpoint for phone verification(2) (#1748)
* VerificationDevice model and Removal of 48hr email verification period (#1606) * Registration with Phone number (#1662) * Add phone to User Profile (#1698) * Add Ansible provisioning for Twilio * Allow user to login with phone and add Resend Token Page (#1708) * Reset Password with Phone (#1717) * Twilio Integration and More update notification (#1719) * Add API endpoint for phone verification(2) (#1748)
* VerificationDevice model and Removal of 48hr email verification period (#1606) * Registration with Phone number (#1662) * Add phone to User Profile (#1698) * Add Ansible provisioning for Twilio * Allow user to login with phone and add Resend Token Page (#1708) * Reset Password with Phone (#1717) * Twilio Integration and More update notification (#1719) * Add API endpoint for phone verification(2) (#1748)
* VerificationDevice model and Removal of 48hr email verification period (#1606) * Registration with Phone number (#1662) * Add phone to User Profile (#1698) * Add Ansible provisioning for Twilio * Allow user to login with phone and add Resend Token Page (#1708) * Reset Password with Phone (#1717) * Twilio Integration and More update notification (#1719) * Add API endpoint for phone verification(2) (#1748)
* VerificationDevice model and Removal of 48hr email verification period (#1606) * Registration with Phone number (#1662) * Add phone to User Profile (#1698) * Add Ansible provisioning for Twilio * Allow user to login with phone and add Resend Token Page (#1708) * Reset Password with Phone (#1717) * Twilio Integration and More update notification (#1719) * Add API endpoint for phone verification(2) (#1748)
* VerificationDevice model and Removal of 48hr email verification period (#1606) * Registration with Phone number (#1662) * Add phone to User Profile (#1698) * Add Ansible provisioning for Twilio * Allow user to login with phone and add Resend Token Page (#1708) * Reset Password with Phone (#1717) * Twilio Integration and More update notification (#1719) * Add API endpoint for phone verification(2) (#1748)
* VerificationDevice model and Removal of 48hr email verification period (#1606) * Registration with Phone number (#1662) * Add phone to User Profile (#1698) * Add Ansible provisioning for Twilio * Allow user to login with phone and add Resend Token Page (#1708) * Reset Password with Phone (#1717) * Twilio Integration and More update notification (#1719) * Add API endpoint for phone verification(2) (#1748)
* VerificationDevice model and Removal of 48hr email verification period (#1606) * Registration with Phone number (#1662) * Add phone to User Profile (#1698) * Add Ansible provisioning for Twilio * Allow user to login with phone and add Resend Token Page (#1708) * Reset Password with Phone (#1717) * Twilio Integration and More update notification (#1719) * Add API endpoint for phone verification(2) (#1748)
* VerificationDevice model and Removal of 48hr email verification period (#1606) * Registration with Phone number (#1662) * Add phone to User Profile (#1698) * Add Ansible provisioning for Twilio * Allow user to login with phone and add Resend Token Page (#1708) * Reset Password with Phone (#1717) * Twilio Integration and More update notification (#1719) * Add API endpoint for phone verification(2) (#1748)
* VerificationDevice model and Removal of 48hr email verification period (#1606) * Registration with Phone number (#1662) * Add phone to User Profile (#1698) * Add Ansible provisioning for Twilio * Allow user to login with phone and add Resend Token Page (#1708) * Reset Password with Phone (#1717) * Twilio Integration and More update notification (#1719) * Add API endpoint for phone verification(2) (#1748)
* VerificationDevice model and Removal of 48hr email verification period (#1606) * Registration with Phone number (#1662) * Add phone to User Profile (#1698) * Add Ansible provisioning for Twilio * Allow user to login with phone and add Resend Token Page (#1708) * Reset Password with Phone (#1717) * Twilio Integration and More update notification (#1719) * Add API endpoint for phone verification(2) (#1748)
* VerificationDevice model and Removal of 48hr email verification period (#1606) * Registration with Phone number (#1662) * Add phone to User Profile (#1698) * Add Ansible provisioning for Twilio * Allow user to login with phone and add Resend Token Page (#1708) * Reset Password with Phone (#1717) * Twilio Integration and More update notification (#1719) * Add API endpoint for phone verification(2) (#1748)
* VerificationDevice model and Removal of 48hr email verification period (#1606) * Registration with Phone number (#1662) * Add phone to User Profile (#1698) * Add Ansible provisioning for Twilio * Allow user to login with phone and add Resend Token Page (#1708) * Reset Password with Phone (#1717) * Twilio Integration and More update notification (#1719) * Add API endpoint for phone verification(2) (#1748)
* VerificationDevice model and Removal of 48hr email verification period (#1606) * Registration with Phone number (#1662) * Add phone to User Profile (#1698) * Add Ansible provisioning for Twilio * Allow user to login with phone and add Resend Token Page (#1708) * Reset Password with Phone (#1717) * Twilio Integration and More update notification (#1719) * Add API endpoint for phone verification(2) (#1748)
* VerificationDevice model and Removal of 48hr email verification period (#1606) * Registration with Phone number (#1662) * Add phone to User Profile (#1698) * Add Ansible provisioning for Twilio * Allow user to login with phone and add Resend Token Page (#1708) * Reset Password with Phone (#1717) * Twilio Integration and More update notification (#1719) * Add API endpoint for phone verification(2) (#1748)
* VerificationDevice model and Removal of 48hr email verification period (#1606) * Registration with Phone number (#1662) * Add phone to User Profile (#1698) * Add Ansible provisioning for Twilio * Allow user to login with phone and add Resend Token Page (#1708) * Reset Password with Phone (#1717) * Twilio Integration and More update notification (#1719) * Add API endpoint for phone verification(2) (#1748)
* VerificationDevice model and Removal of 48hr email verification period (#1606) * Registration with Phone number (#1662) * Add phone to User Profile (#1698) * Add Ansible provisioning for Twilio * Allow user to login with phone and add Resend Token Page (#1708) * Reset Password with Phone (#1717) * Twilio Integration and More update notification (#1719) * Add API endpoint for phone verification(2) (#1748)
Proposed changes in this pull request
Send update notification via sms with Twilio
[List all changes you want to add here. If you fixed an issue, please
add a reference to that issue as well.]
Add
gateways.py
toaccounts
. There are 2 gateways,TwilioGateway
andFakeGateway
.TwilioGateway
is used to send actual messages and in testing,FakeGateway
is used for local development.The testing environment will use Test Credentials provided by Twilio, while production environment will Live Credentials provided by Twilio and a list of real phone numbers bought on Twilio.
Add tests for the gateways.
Add new messages to
accounts/messages.py
. This message will be sent via sms to user's phone.Make changes to
ProfileForm
. When user changes/deletes email, send an SMS update notification if verified email is linked to user account. When user changes/deletes phone, send an email update notification if a verified phone is linked to user account. Make corresponding changes to tests.Add new functions:
send_phone_deleted_notification
,send_email_deleted_notification
,send_phone_changed_notification
toaccounts/utils.py
.Add Gateway settings to the settings file.
Make changes to
AccountUser
inaccounts/views/api.py
. Send update notification to the user's verified phone/email whenever the user changes/deletes phone/email. Add tests for the same.When should this PR be merged
Currently, test setting uses Twilio Test credentials. These Test Credentials have limited access to resources. So there is no sure way to check if messages are actually sent during tests. This issue needs fixing.
Currently, there are no credentials, so tests using Twilio are failing. Once Twilio credentials are exported, and all test passes.
Risks
-None
Follow-up actions
Live Credentials:
TWILIO_ACCOUNT_SID
andTWILIO_AUTH_TOKEN
.Checklist (for reviewing)
General
migration
label if a new migration is added.Functionality
Code
Tests
Security
Documentation