diff --git a/api/aws_lambdas/scorer_api_passport/v1/stamps/bulk_POST.py b/api/aws_lambdas/scorer_api_passport/v1/stamps/bulk_POST.py index f640f36fa..55ddaae89 100644 --- a/api/aws_lambdas/scorer_api_passport/v1/stamps/bulk_POST.py +++ b/api/aws_lambdas/scorer_api_passport/v1/stamps/bulk_POST.py @@ -22,7 +22,7 @@ def _handler(event, context): payload = [CacheStampPayload(**p) for p in body] return format_response( - handle_add_stamps(address, payload, CeramicCache.StampCreator.PASSPORT) + handle_add_stamps(address, payload, CeramicCache.SourceApp.PASSPORT) ) diff --git a/api/ceramic_cache/admin.py b/api/ceramic_cache/admin.py index cf535471d..91a9bc5ae 100644 --- a/api/ceramic_cache/admin.py +++ b/api/ceramic_cache/admin.py @@ -60,11 +60,11 @@ class CeramicCacheAdmin(ScorerModelAdmin): "compose_db_save_status", "compose_db_stream_id", "proof_value", - "stamp_created_by", - "scorer_id", + "source_app", + "source_scorer_id", "stamp", ) - list_filter = ("deleted_at", "compose_db_save_status", "stamp_created_by") + list_filter = ("deleted_at", "compose_db_save_status", "source_app") search_fields = ("address__exact", "compose_db_stream_id__exact", "proof_value") search_help_text = ( "This will perform a search by 'address' and 'compose_db_stream_id'" diff --git a/api/ceramic_cache/api/v1.py b/api/ceramic_cache/api/v1.py index 3560f6bc7..64e201be6 100644 --- a/api/ceramic_cache/api/v1.py +++ b/api/ceramic_cache/api/v1.py @@ -145,7 +145,7 @@ def cache_stamps(request, payload: List[CacheStampPayload]): return handle_add_stamps( address, payload, - CeramicCache.StampCreator.PASSPORT, + CeramicCache.SourceApp.PASSPORT, settings.CERAMIC_CACHE_SCORER_ID, ) @@ -156,7 +156,7 @@ def cache_stamps(request, payload: List[CacheStampPayload]): def handle_add_stamps_only( address, payload: List[CacheStampPayload], - stamp_creator: CeramicCache.StampCreator, + source_app: CeramicCache.SourceApp, alternate_scorer_id: Optional[int] = None, ) -> GetStampResponse: if len(payload) > settings.MAX_BULK_CACHE_SIZE: @@ -184,8 +184,8 @@ def handle_add_stamps_only( compose_db_save_status=CeramicCache.ComposeDBSaveStatus.PENDING, issuance_date=p.stamp.get("issuanceDate", None), expiration_date=p.stamp.get("expirationDate", None), - stamp_created_by=stamp_creator, - scorer_id=alternate_scorer_id, + source_app=source_app, + source_scorer_id=alternate_scorer_id, ) for p in payload ] @@ -216,7 +216,7 @@ def handle_add_stamps_only( def handle_add_stamps( address, payload: List[CacheStampPayload], - stamp_creator: CeramicCache.StampCreator, + stamp_creator: CeramicCache.SourceApp, alternate_scorer_id: Optional[int] = None, ) -> GetStampsWithScoreResponse: stamps_response = handle_add_stamps_only( diff --git a/api/ceramic_cache/migrations/0030_ceramiccache_scorer_id_ceramiccache_stamp_created_by.py b/api/ceramic_cache/migrations/0030_ceramiccache_source_app_and_more.py similarity index 91% rename from api/ceramic_cache/migrations/0030_ceramiccache_scorer_id_ceramiccache_stamp_created_by.py rename to api/ceramic_cache/migrations/0030_ceramiccache_source_app_and_more.py index 4cc1283a6..61ef9e8a7 100644 --- a/api/ceramic_cache/migrations/0030_ceramiccache_scorer_id_ceramiccache_stamp_created_by.py +++ b/api/ceramic_cache/migrations/0030_ceramiccache_source_app_and_more.py @@ -1,4 +1,4 @@ -# Generated by Django 4.2.6 on 2025-01-10 15:00 +# Generated by Django 4.2.6 on 2025-01-14 14:35 from django.db import migrations, models @@ -15,25 +15,25 @@ class Migration(migrations.Migration): operations = [ migrations.AddField( model_name="ceramiccache", - name="scorer_id", - field=models.BigIntegerField( + name="source_app", + field=models.IntegerField( blank=True, + choices=[(1, "Passport"), (2, "Embed")], db_index=True, - help_text="This is field is only used to indicate for analytic purposes which scorer was targeted \n when claiming the users credential (when used from embed, it will indicate what scorer id was set in \n the embed component)", + help_text="Which entity created the stamp. At the moment there are 2 options: the 'Passport App' and 'Embed Widget'", null=True, - verbose_name="Scorer ID", + verbose_name="Creating Enity", ), ), migrations.AddField( model_name="ceramiccache", - name="stamp_created_by", - field=models.IntegerField( + name="source_scorer_id", + field=models.BigIntegerField( blank=True, - choices=[(1, "Passport"), (2, "Embed")], db_index=True, - help_text="Which entity created the stamp. At the moment there are 2 options: the 'Passport App' and 'Embed Widget'", + help_text="This is field is only used to indicate for analytic purposes which scorer was targeted \n when claiming the users credential (when used from embed, it will indicate what scorer id was set in \n the embed component)", null=True, - verbose_name="Creating Enity", + verbose_name="Scorer ID", ), ), ] diff --git a/api/ceramic_cache/models.py b/api/ceramic_cache/models.py index cde864b30..9e24d3844 100644 --- a/api/ceramic_cache/models.py +++ b/api/ceramic_cache/models.py @@ -16,7 +16,7 @@ class StampType(IntEnum): V1 = 1 V2 = 2 - class StampCreator(models.IntegerChoices): + class SourceApp(models.IntegerChoices): PASSPORT = 1 EMBED = 2 @@ -85,7 +85,10 @@ class ComposeDBSaveStatus(models.TextChoices): null=True, db_index=True ) # stamp['expirationDate'] - scorer_id = models.BigIntegerField( + ################################################################################################ + # Begin metadata fields, to determine the scorer that initiated the creation of a stamp + ################################################################################################# + source_scorer_id = models.BigIntegerField( verbose_name="Scorer ID", help_text="""This is field is only used to indicate for analytic purposes which scorer was targeted when claiming the users credential (when used from embed, it will indicate what scorer id was set in @@ -94,14 +97,17 @@ class ComposeDBSaveStatus(models.TextChoices): blank=True, db_index=True, ) - stamp_created_by = models.IntegerField( + source_app = models.IntegerField( verbose_name="Creating Enity", help_text="""Which entity created the stamp. At the moment there are 2 options: the 'Passport App' and 'Embed Widget'""", - choices=StampCreator.choices, + choices=SourceApp.choices, null=True, blank=True, db_index=True, ) + ################################################################################################ + # End metadata fields + ################################################################################################# class Meta: unique_together = ["type", "address", "provider", "deleted_at"] diff --git a/api/ceramic_cache/test/test_bulk_updates_v1.py b/api/ceramic_cache/test/test_bulk_updates_v1.py index 53cc62cd1..1f903d154 100644 --- a/api/ceramic_cache/test/test_bulk_updates_v1.py +++ b/api/ceramic_cache/test/test_bulk_updates_v1.py @@ -106,7 +106,7 @@ def test_bulk_create( "provider": provider, "scorer_id": ui_scorer, "stamp": stamp, - "stamp_created_by": CeramicCache.StampCreator.PASSPORT.value, + "source_app": CeramicCache.SourceApp.PASSPORT.value, "type": 1, } @@ -219,9 +219,9 @@ def test_bulk_update( "issuance_date": datetime.fromisoformat(stamp["issuanceDate"]), "proof_value": stamp["proof"]["proofValue"], "provider": provider, - "scorer_id": ui_scorer, + "source_scorer_id": ui_scorer, "stamp": stamp, - "stamp_created_by": CeramicCache.StampCreator.PASSPORT.value, + "source_app": CeramicCache.SourceApp.PASSPORT.value, "type": 1, } @@ -345,9 +345,9 @@ def test_bulk_patch_partial_update( "issuance_date": datetime.fromisoformat(stamp["issuanceDate"]), "proof_value": stamp["proof"]["proofValue"], "provider": provider, - "scorer_id": ui_scorer, + "source_scorer_id": ui_scorer, "stamp": stamp, - "stamp_created_by": CeramicCache.StampCreator.PASSPORT.value, + "source_app": CeramicCache.SourceApp.PASSPORT.value, "type": 1, } @@ -378,9 +378,9 @@ def test_bulk_patch_partial_update( "issuance_date": datetime.fromisoformat(stamp["issuanceDate"]), "proof_value": stamp["proof"]["proofValue"], "provider": provider, - "scorer_id": ui_scorer, + "source_scorer_id": ui_scorer, "stamp": stamp, - "stamp_created_by": CeramicCache.StampCreator.PASSPORT.value, + "source_app": CeramicCache.SourceApp.PASSPORT.value, "type": 1, } @@ -425,8 +425,8 @@ def test_successful_bulk_delete( address=sample_address, provider=stamp["credentialSubject"]["provider"], stamp=stamp, - stamp_created_by=CeramicCache.StampCreator.PASSPORT.value, - scorer_id=ui_scorer, + source_app=CeramicCache.SourceApp.PASSPORT.value, + source_scorer_id=ui_scorer, compose_db_save_status="pending", expiration_date=datetime.fromisoformat(stamp["expirationDate"]), issuance_date=datetime.fromisoformat(stamp["issuanceDate"]), @@ -493,9 +493,9 @@ def test_successful_bulk_delete( "issuance_date": datetime.fromisoformat(stamp["issuanceDate"]), "proof_value": stamp["proof"]["proofValue"], "provider": provider, - "scorer_id": ui_scorer, + "source_scorer_id": ui_scorer, "stamp": stamp, - "stamp_created_by": CeramicCache.StampCreator.PASSPORT.value, + "source_app": CeramicCache.SourceApp.PASSPORT.value, "type": 1, } diff --git a/api/embed/api.py b/api/embed/api.py index 0a24c0851..3029bf909 100644 --- a/api/embed/api.py +++ b/api/embed/api.py @@ -83,7 +83,7 @@ def handle_embed_add_stamps( try: added_stamps = handle_add_stamps_only( - address, add_stamps_payload, CeramicCache.StampCreator.EMBED, payload.scorer_id + address, add_stamps_payload, CeramicCache.SourceApp.EMBED, payload.scorer_id ) user_account = Community.objects.get(id=payload.scorer_id).account score = async_to_sync(handle_scoring)(address, payload.scorer_id, user_account) diff --git a/api/embed/test/test_api_stamps.py b/api/embed/test/test_api_stamps.py index 635d02849..3837ca7ad 100644 --- a/api/embed/test/test_api_stamps.py +++ b/api/embed/test/test_api_stamps.py @@ -329,8 +329,8 @@ def test_submitted_stamps_are_saved_properly(self, _test_submit_valid_stamps): "expiration_date": datetime.fromisoformat(m["expirationDate"]), "issuance_date": datetime.fromisoformat(m["issuanceDate"]), "proof_value": m["proof"]["proofValue"], - "stamp_created_by": CeramicCache.StampCreator.EMBED.value, - "scorer_id": self.community.id, + "source_app": CeramicCache.SourceApp.EMBED.value, + "source_scorer_id": self.community.id, "stamp": m, "type": 1, } diff --git a/api/embed/test/test_lambda_stamps.py b/api/embed/test/test_lambda_stamps.py index 11077b2f7..35e7b504b 100644 --- a/api/embed/test/test_lambda_stamps.py +++ b/api/embed/test/test_lambda_stamps.py @@ -186,8 +186,8 @@ def test_storing_stamps_and_score( "expiration_date": datetime.fromisoformat(m["expirationDate"]), "issuance_date": datetime.fromisoformat(m["issuanceDate"]), "proof_value": m["proof"]["proofValue"], - "stamp_created_by": CeramicCache.StampCreator.EMBED.value, - "scorer_id": self.community.id, + "source_app": CeramicCache.SourceApp.EMBED.value, + "source_scorer_id": self.community.id, "stamp": m, "type": 1, } diff --git a/api/registry/api/v1.py b/api/registry/api/v1.py index 8dc6a2821..a6199d882 100644 --- a/api/registry/api/v1.py +++ b/api/registry/api/v1.py @@ -183,34 +183,6 @@ async def a_submit_passport( ) from e -def sync_test_function(): - account_api_keys = [] - for api_key in AccountAPIKey.objects.all(): - account_api_keys.append(api_key) - - print("account_api_keys", account_api_keys) - - users = [] - for user in User.objects.all(): - users.append(user) - - print("user", users) - - -async def async_test_function(): - account_api_keys = [] - async for api_key in AccountAPIKey.objects.all(): - account_api_keys.append(api_key) - - print("account_api_keys", account_api_keys) - - users = [] - async for user in User.objects.all(): - users.append(user) - - print("user", users) - - async def ahandle_submit_passport( payload: SubmitPassportPayload, account: Account ) -> DetailedScoreResponse: diff --git a/api/registry/tasks.py b/api/registry/tasks.py index a8d250ad9..c5a7655fe 100644 --- a/api/registry/tasks.py +++ b/api/registry/tasks.py @@ -46,14 +46,6 @@ def save_api_key_analytics( log.error("Failed to save analytics. Error: '%s'", e, exc_info=True) -def score_passport_passport(community_id: int, address: str): - score_passport(community_id, address) - - -def score_registry_passport(community_id: int, address: str): - score_passport(community_id, address) - - def score_passport(community_id: int, address: str): passport = load_passport_record(community_id, address) diff --git a/api/registry/test/test_score_passport.py b/api/registry/test/test_score_passport.py index eb40f170e..e43dee99a 100644 --- a/api/registry/test/test_score_passport.py +++ b/api/registry/test/test_score_passport.py @@ -16,7 +16,7 @@ from registry.api.schema import StatusEnum from registry.api.v1 import SubmitPassportPayload, a_submit_passport, get_score from registry.models import Event, HashScorerLink, Passport, Score, Stamp -from registry.tasks import score_passport_passport, score_registry_passport +from registry.tasks import score_passport from scorer_weighted.models import Scorer, WeightedScorer User = get_user_model() @@ -135,7 +135,7 @@ def setUp(self): def test_no_passport(self): with patch("registry.atasks.aget_passport", return_value=None): - score_passport_passport(self.community.pk, self.account.address) + score_passport(self.community.pk, self.account.address) passport = Passport.objects.get( address=self.account.address, community_id=self.community.pk @@ -174,7 +174,7 @@ def __init__(self): mock_request.GET = {} mock_request.headers = {} - with patch("registry.api.v1.score_passport_passport", return_value=None): + with patch("registry.api.v1.ascore_passport", return_value=None): async_to_sync(a_submit_passport)( mock_request, SubmitPassportPayload( @@ -187,7 +187,7 @@ def __init__(self): with patch( "registry.atasks.validate_credential", side_effect=mock_validate ): - score_passport_passport(self.community.pk, address) + score_passport(self.community.pk, address) Passport.objects.get(address=address, community_id=self.community.pk) @@ -228,7 +228,7 @@ def test_cleaning_stale_stamps(self): with patch( "registry.atasks.validate_credential", side_effect=mock_validate ): - score_passport_passport(self.community.pk, self.account.address) + score_passport(self.community.pk, self.account.address) my_stamps = Stamp.objects.filter(passport=passport) assert len(my_stamps) == 3 @@ -263,8 +263,8 @@ def test_deduplication_of_scoring_tasks(self): ): with patch("registry.tasks.log.info") as mock_log: # Call score_passport_passport twice, but only one of them should actually execute the scoring calculation - score_passport_passport(self.community.pk, self.account.address) - score_passport_passport(self.community.pk, self.account.address) + score_passport(self.community.pk, self.account.address) + score_passport(self.community.pk, self.account.address) expected_call = call( "Passport no passport found for address='%s', community_id='%s' that has requires_calculation=True or None", @@ -316,7 +316,7 @@ def test_lifo_duplicate_stamp_scoring(self): "registry.atasks.aget_passport", return_value=mock_passport_data, ): - score_registry_passport(self.community.pk, passport.address) + score_passport(self.community.pk, passport.address) original_stamps = Stamp.objects.filter(passport=passport) assert len(original_stamps) == len(mocked_non_duplicate_stamps["stamps"]) @@ -382,7 +382,7 @@ def test_score_expiration_time(self): with patch( "registry.atasks.validate_credential", side_effect=mock_validate ): - score_passport_passport(self.community.pk, self.account.address) + score_passport(self.community.pk, self.account.address) score = Score.objects.get(passport=passport) @@ -421,7 +421,7 @@ def test_score_expiration_time_when_all_stamps_expired(self): with patch( "registry.atasks.validate_credential", side_effect=mock_validate ): - score_passport_passport(self.community.pk, self.account.address) + score_passport(self.community.pk, self.account.address) score = Score.objects.get(passport=passport) @@ -445,7 +445,7 @@ def test_score_expiration_time_when_all_stamps_expired(self): with patch( "registry.atasks.validate_credential", side_effect=mock_validate ): - score_passport_passport(self.community.pk, self.account.address) + score_passport(self.community.pk, self.account.address) score = Score.objects.get(passport=passport) diff --git a/api/scorer/test/test_choose_binary_scorer.py b/api/scorer/test/test_choose_binary_scorer.py index 4ad179e52..0f6081102 100644 --- a/api/scorer/test/test_choose_binary_scorer.py +++ b/api/scorer/test/test_choose_binary_scorer.py @@ -10,7 +10,7 @@ from pytest_bdd import given, scenario, then, when from account.models import Community -from registry.tasks import score_passport_passport +from registry.tasks import score_passport from registry.test.test_passport_submission import mock_passport, mock_utc_timestamp from registry.weight_models import WeightConfiguration from scorer_weighted.models import BinaryWeightedScorer @@ -169,7 +169,7 @@ def _(scorer_community_with_binary_scorer, scorer_api_key): ) # execute the task - score_passport_passport( + score_passport( scorer_community_with_binary_scorer.id, "0x71ad3e3057ca74967239c66ca6d3a9c2a43a58fc", )