Skip to content

Commit 7974c05

Browse files
authored
Removing the ability to delete user properties by passing None (#320)
1 parent 030f6e6 commit 7974c05

File tree

2 files changed

+13
-27
lines changed

2 files changed

+13
-27
lines changed

firebase_admin/_user_mgt.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ def __init__(self, description):
3434
self.description = description
3535

3636

37-
# Use this internally, until sentinels are available in the public API.
38-
_UNSPECIFIED = Sentinel('No value specified')
39-
40-
4137
DELETE_ATTRIBUTE = Sentinel('Value used to delete an attribute from a user profile')
4238

4339

@@ -524,9 +520,9 @@ def create_user(self, uid=None, display_name=None, email=None, phone_number=None
524520
'Failed to create new user.', http_response=http_resp)
525521
return body.get('localId')
526522

527-
def update_user(self, uid, display_name=_UNSPECIFIED, email=None, phone_number=_UNSPECIFIED,
528-
photo_url=_UNSPECIFIED, password=None, disabled=None, email_verified=None,
529-
valid_since=None, custom_claims=_UNSPECIFIED):
523+
def update_user(self, uid, display_name=None, email=None, phone_number=None,
524+
photo_url=None, password=None, disabled=None, email_verified=None,
525+
valid_since=None, custom_claims=None):
530526
"""Updates an existing user account with the specified properties"""
531527
payload = {
532528
'localId': _auth_utils.validate_uid(uid, required=True),
@@ -538,27 +534,27 @@ def update_user(self, uid, display_name=_UNSPECIFIED, email=None, phone_number=_
538534
}
539535

540536
remove = []
541-
if display_name is not _UNSPECIFIED:
542-
if display_name is None or display_name is DELETE_ATTRIBUTE:
537+
if display_name is not None:
538+
if display_name is DELETE_ATTRIBUTE:
543539
remove.append('DISPLAY_NAME')
544540
else:
545541
payload['displayName'] = _auth_utils.validate_display_name(display_name)
546-
if photo_url is not _UNSPECIFIED:
547-
if photo_url is None or photo_url is DELETE_ATTRIBUTE:
542+
if photo_url is not None:
543+
if photo_url is DELETE_ATTRIBUTE:
548544
remove.append('PHOTO_URL')
549545
else:
550546
payload['photoUrl'] = _auth_utils.validate_photo_url(photo_url)
551547
if remove:
552548
payload['deleteAttribute'] = remove
553549

554-
if phone_number is not _UNSPECIFIED:
555-
if phone_number is None or phone_number is DELETE_ATTRIBUTE:
550+
if phone_number is not None:
551+
if phone_number is DELETE_ATTRIBUTE:
556552
payload['deleteProvider'] = ['phone']
557553
else:
558554
payload['phoneNumber'] = _auth_utils.validate_phone(phone_number)
559555

560-
if custom_claims is not _UNSPECIFIED:
561-
if custom_claims is None or custom_claims is DELETE_ATTRIBUTE:
556+
if custom_claims is not None:
557+
if custom_claims is DELETE_ATTRIBUTE:
562558
custom_claims = {}
563559
json_claims = json.dumps(custom_claims) if isinstance(
564560
custom_claims, dict) else custom_claims

tests/test_user_mgt.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -465,16 +465,6 @@ def test_delete_user_custom_claims(self, user_mgt_app):
465465
request = json.loads(recorder[0].body.decode())
466466
assert request == {'localId' : 'testuser', 'customAttributes' : json.dumps({})}
467467

468-
def test_update_user_delete_fields_with_none(self, user_mgt_app):
469-
user_mgt, recorder = _instrument_user_manager(user_mgt_app, 200, '{"localId":"testuser"}')
470-
user_mgt.update_user('testuser', display_name=None, photo_url=None, phone_number=None)
471-
request = json.loads(recorder[0].body.decode())
472-
assert request == {
473-
'localId' : 'testuser',
474-
'deleteAttribute' : ['DISPLAY_NAME', 'PHOTO_URL'],
475-
'deleteProvider' : ['phone'],
476-
}
477-
478468
def test_update_user_delete_fields(self, user_mgt_app):
479469
user_mgt, recorder = _instrument_user_manager(user_mgt_app, 200, '{"localId":"testuser"}')
480470
user_mgt.update_user(
@@ -561,9 +551,9 @@ def test_set_custom_user_claims_str(self, user_mgt_app):
561551
request = json.loads(recorder[0].body.decode())
562552
assert request == {'localId' : 'testuser', 'customAttributes' : claims}
563553

564-
def test_set_custom_user_claims_none(self, user_mgt_app):
554+
def test_set_custom_user_claims_remove(self, user_mgt_app):
565555
_, recorder = _instrument_user_manager(user_mgt_app, 200, '{"localId":"testuser"}')
566-
auth.set_custom_user_claims('testuser', None, app=user_mgt_app)
556+
auth.set_custom_user_claims('testuser', auth.DELETE_ATTRIBUTE, app=user_mgt_app)
567557
request = json.loads(recorder[0].body.decode())
568558
assert request == {'localId' : 'testuser', 'customAttributes' : json.dumps({})}
569559

0 commit comments

Comments
 (0)