Skip to content

Commit

Permalink
Patch verified user on creation (#6705)
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacsolo authored Nov 16, 2023
1 parent f0d7a57 commit bc48098
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -604,11 +604,30 @@ def test_index_invalid_users(app, mocker):
"QmInvalidArtistPick": {
"artist_pick_track_id": TRACK_ID_OFFSET + 1,
},
"QmInvalidVerified": {
"is_verified": True,
"is_deactivated": False,
"name": "verified name",
"handle": "verifiedhandle",
"profile_picture": None,
"profile_picture_sizes": "QmYRHAJ4YuLjT4fLLRMg5STnQA4yDpiBmzk5R3iCDTmkmk",
"cover_photo": None,
"cover_photo_sizes": "QmUk61QDUTzhNqjnCAWipSp3jnMmXBmtTUC2mtF5F6VvUy",
"bio": "🌞👄🌞",
"location": "verified location",
"creator_node_endpoint": "https://creatornode2.audius.co,https://creatornode3.audius.co,https://content-node.audius.co",
"associated_wallets": None,
"associated_sol_wallets": None,
"playlist_library": {"contents": []},
"events": {"is_mobile_user": True},
"user_id": USER_ID_OFFSET + 1,
},
}

create_user1_json = json.dumps(test_metadata["QmCreateUser1"])
invalid_update_user_json = json.dumps(test_metadata["QmInvalidUserMetadataFields"])
invalid_update_artist_pick_json = json.dumps(test_metadata["QmInvalidArtistPick"])
invalid_verified_user = json.dumps(test_metadata["QmInvalidVerified"])

tx_receipts = {
# invalid create
Expand All @@ -626,6 +645,20 @@ def test_index_invalid_users(app, mocker):
)
},
],
"CreateUserInvalidVerified": [
{
"args": AttributeDict(
{
"_entityId": USER_ID_OFFSET + 1,
"_entityType": "User",
"_userId": USER_ID_OFFSET + 1,
"_action": "Create",
"_metadata": f'{{"cid": "QmUpdateUser2", "data": {invalid_verified_user}}}',
"_signer": "user1wallet",
}
)
},
],
"CreateUserWithBadMetadataDoesNotExist": [
{
"args": AttributeDict(
Expand Down Expand Up @@ -827,14 +860,19 @@ def get_events_side_effect(_, tx_receipt):

# validate db records
all_users: List[User] = session.query(User).filter(User.is_current).all()
assert len(all_users) == 2 # no new users indexed
assert len(all_users) == 3

existing_user_after_index: List[User] = (
session.query(User).filter(User.user_id == 1).first()
)

assert existing_user == existing_user_after_index

invalid_verified_user: List[User] = (
session.query(User).filter(User.user_id == USER_ID_OFFSET + 1).first()
)
assert invalid_verified_user.is_verified == False # ignored invalid metadata


def test_index_verify_users(app, mocker):
"Tests user verify actions"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,15 +280,13 @@ def update_user_metadata(user_record: User, metadata: Dict, params):
redis = params.redis
web3 = params.web3
challenge_event_bus = params.challenge_bus
action = params.action
# Iterate over the user_record keys
user_record_attributes = user_record.get_attributes_dict()
for key, _ in user_record_attributes.items():
# Update the user_record when the corresponding field exists
# in metadata
if key in metadata:
if key in immutable_user_fields and action == Action.UPDATE:
# skip fields that cannot be modified after creation
if key in immutable_user_fields:
continue
setattr(user_record, key, metadata[key])

Expand Down

0 comments on commit bc48098

Please sign in to comment.