fix(sms): stop the SMS settings screen editing the login number - #552
Open
MOHITKOURAV01 wants to merge 1 commit into
Open
fix(sms): stop the SMS settings screen editing the login number#552MOHITKOURAV01 wants to merge 1 commit into
MOHITKOURAV01 wants to merge 1 commit into
Conversation
`POST /sms/settings` wrote the number it was given into `phone` as well
as `sms_phone_number`. `phone` is what `firebase_login` resolves an
account by, so an SMS preferences screen was editing the credential —
and `phone or ""` meant clearing the box and unticking the toggle erased
it, leaving the user unable to sign in and her history stranded under an
id nothing reaches.
The route now writes only where summaries go, and only when the caller
said something about it: sending just `{"enabled": false}` turns
summaries off without forgetting the number, while an explicit empty
string still clears it.
`registered_phone` prefers `sms_phone_number` and falls back to `phone`.
The order is reversed from before, which was correct only while both
fields held the same value; keeping `phone` first would have made saving
an SMS number a no-op for anyone with a login number. The fallback keeps
accounts that have never opened this screen behaving exactly as before.
Closes ishita2740#547
|
@MOHITKOURAV01 is attempting to deploy a commit to the ishita2740's projects Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #547.
POST /sms/settingswrote the number it was given into three fields:phoneis not an SMS field. It is whatfirebase_loginresolves anaccount by, through
UserService.get_user_by_phone. So the SMSpreferences screen was editing the credential, and
phone or ""meant auser who cleared the box and unticked the toggle erased it — the next
sign-in with her own number matched nothing, took the create-a-new-account
branch, and left her cycle history under an id nothing reaches.
What changed
phoneis no longer written here. The two fields now mean exactlyone thing each:
phoneis who the account is,sms_phone_numberiswhere its summaries go. That also removes the collision described in the
issue — one account writing another's login number over its own — rather
than guarding against it, since the field a uniqueness check would
protect is no longer touched by this route.
A toggle is not a deletion. Turning summaries off and forgetting the
number are different intentions and only one costs the user retyping.
SMSSettings.phone_was_submittedreadsmodel_fields_set, so{"enabled": false}leaves the saved number alone while{"phoneNumber": "", "enabled": false}clears it. Both arrive asnormalized_phone is Noneonce parsed, so the difference has to comefrom which keys the JSON actually carried.
registered_phonepreferssms_phone_number, falling back tophone. This reverses the previous order, and the reversal isrequired by the change above rather than incidental to it: the old order
was correct only while
POST /settingswrote both fields to the samevalue. With that write removed, preferring
phonewould make saving anSMS number a no-op for every account that has a login number — the
screen would keep showing, and the summary keep going to, the number she
did not choose. The fallback is what keeps accounts that have never
opened this screen behaving exactly as before.
The response is re-read rather than echoed. What comes back has to be
the number a summary would actually go to; after a request that cleared
sms_phone_numberthat is the account number the fallback resolves to,not the empty string the caller submitted.
Tests
backend/tests/test_sms_settings_identity.py— 12 cases. Two notes onhow they are written:
A 200 says the request was accepted; only
users/{id}.phonesayswhether the login number survived, and a response-body test would have
passed against the original code, which echoed the number back either
way.
test_the_account_can_still_sign_in_after_the_settings_are_cleareddrives the real
firebase_loginroute. "You can no longer log in" isthe actual failure; a field assertion is a proxy for it, and a proxy is
what let this ship. It checks
is_new_userand confirms the sameaccount id from the other side via
/auth/me, so it does not rest onthat one flag being reported correctly.
One existing assertion in
test_sms_destination_binding.pyis reversed —test_registered_phone_prefers_the_same_field_the_settings_screen_showsbecomes
test_registered_phone_prefers_the_number_chosen_for_sms. Itencoded the old precedence, which this change deliberately inverts for
the reason above; the property it was actually protecting (the settings
screen and the send path agree with each other) still holds, since both
still call the same function, and
test_settings_and_send_agree_on_the_destinationstill asserts it end toend.
Full backend suite green.
Out of scope
PATCH /auth/profilealso acceptsphonewith no uniqueness check —the same shape as #531 for
email. Noted in the issue so it is not lost;not touched here.