Closed jwhitlock closed 2 months ago
Your pull request is modifying functions with the following pre-existing issues:
📄 File: phones/models.py
Function | Unhandled Issue |
---|---|
relaynumber_post_save |
RealPhone.MultipleObjectsReturned: get() returned more than one RealPhone -- it returned 2! ... Event Count: 1 |
Did you find this useful? React with a 👍 or 👎
This PR adds managers with helper methods to
RealPhone
, and updates the code to use them. The managers and methods:RealPhone.objects
- The original, can still be used in tests or when working with allRealPhone
objects.RealPhone.verified_objects
-RealPhone
objects that the user has verified via a texted verification code..get_for_user(user)
- Return the verifiedRealPhone
object for the user, or raiseDoesNotExist
. Used to get theRealPhone
for a requesting user..exists_for_number(number)
- Returns True if there is a verifiedRealPhone
object for the phone number. Used to determine if a number is already claimed..country_code_for_user(user)
- Returns the country code of the user's verifiedRealPhone
. Used to limit the suggested Relay numbers to the user's country code.RealPhone.recent_objects
-RealPhone
objects where a verification code was recently sent.get_for_user_number_and_verification_code(user, number, code)
- Used to check that a verification code is the one sent by the authorized user to their phone number, and that it hasn't been too long since it was sent. To keep double submissions from being errors, theRealPhone
can already be verified.RealPhone.pending_objects
- Similar toRealPhone.recent_objects
, except only the unverifiedRealPhone
objects.exists_for_number(number)
- Check if a pending verification code is currently active for this number, to prevent having two pending codes at the same time and a potential abuse vector.RealPhone.expired_objects
- The opposite ofRealPhone.recent_objects
-RealPhone
objects where the verification code was sent a long time ago and is no longer valid.delete_for_number(number)
- Delete any expired records for a particular number. Used in theRealPhone
save method for ... reasons.This PR fixes a few bugs around
RealPhone
queries when a user has multipleRealPhone
records, like a verifiedRealPhone
and some unverifiedRealPhone
for other numbers they tried:/api/v1/profiles/
returns a 500 error, trying to determine when they subscribed to The code now only queries for the verifiedRealPhone
, and there should be one per user (enforced by code, not the database)send_welcome_message
, to send them their Relay number and contact info, fail. The codenow only queries for the verifiedRealPhone
../manage.py delete_phone_data
will fail. Now it deletes all the user'sRealPhone
records, and reports one per line.How to test: Unit tests should be sufficient. If you want to try live tests, ensure you add an unverified
RealPhone
before a verifiedRealPhone
. The code will not allow you to register a newRealPhone
if you have a verified one.