mirror of
https://github.com/baz-scm/awesome-reviewers.git
synced 2025-08-20 18:58:52 +03:00
94 lines
16 KiB
JSON
94 lines
16 KiB
JSON
[
|
|
{
|
|
"discussion_id": "2273739168",
|
|
"pr_number": 36519,
|
|
"pr_file": "posthog/tasks/email.py",
|
|
"created_at": "2025-08-13T14:57:47+00:00",
|
|
"commented_code": "message.send()\n \n \n+@shared_task(**EMAIL_TASK_KWARGS)\n+def login_from_new_device_notification(\n+ user_id: int, login_time: datetime, short_user_agent: str, ip_address: str\n+) -> None:\n+ \"\"\"Send login notification email if login is from a new device\"\"\"\n+ if not is_email_available(with_absolute_urls=True):\n+ return\n+\n+ user: User = User.objects.get(pk=user_id)\n+\n+ # Send email if feature flag is enabled or in tests\n+ if settings.TEST:\n+ enabled = True\n+ elif user.current_organization is None:\n+ enabled = False\n+ else:\n+ enabled = posthoganalytics.feature_enabled(\n+ key=\"login-from-new-device-notification\",\n+ distinct_id=str(user.distinct_id),\n+ groups={\"organization\": str(user.current_organization.id)},\n+ )\n+\n+ if not enabled:\n+ return\n+\n+ is_new_device = check_and_cache_login_device(user_id, ip_address, short_user_agent)\n+ if not is_new_device:\n+ return\n+\n+ login_time_str = login_time.strftime(\"%B %-d, %Y at %H:%M UTC\")\n+ geoip_data = get_geoip_properties(ip_address)\n+\n+ # Compose location as \"City, Country\" (omit city if missing)\n+ location = \", \".join(\n+ part\n+ for part in [geoip_data.get(\"$geoip_city_name\", \"\"), geoip_data.get(\"$geoip_country_name\", \"Unknown\")]\n+ if part\n+ )\n+\n+ message = EmailMessage(\n+ use_http=True,\n+ campaign_key=f\"login_notification_{user.uuid}-{timezone.now().timestamp()}\",\n+ template_name=\"login_notification\",\n+ subject=\"A new device logged into your account\",\n+ template_context={\n+ \"login_time\": login_time_str,\n+ \"ip_address\": ip_address,\n+ \"location\": location,\n+ \"browser\": short_user_agent,\n+ },\n+ )\n+ message.add_recipient(user.email)\n+ message.send()\n+ report_user_action(user=user, event=\"login notification sent\")",
|
|
"repo_full_name": "PostHog/posthog",
|
|
"discussion_comments": [
|
|
{
|
|
"comment_id": "2273739168",
|
|
"repo_full_name": "PostHog/posthog",
|
|
"pr_number": 36519,
|
|
"pr_file": "posthog/tasks/email.py",
|
|
"discussion_id": "2273739168",
|
|
"commented_code": "@@ -453,6 +456,62 @@ def send_two_factor_auth_backup_code_used_email(user_id: int) -> None:\n message.send()\n \n \n+@shared_task(**EMAIL_TASK_KWARGS)\n+def login_from_new_device_notification(\n+ user_id: int, login_time: datetime, short_user_agent: str, ip_address: str\n+) -> None:\n+ \"\"\"Send login notification email if login is from a new device\"\"\"\n+ if not is_email_available(with_absolute_urls=True):\n+ return\n+\n+ user: User = User.objects.get(pk=user_id)\n+\n+ # Send email if feature flag is enabled or in tests\n+ if settings.TEST:\n+ enabled = True\n+ elif user.current_organization is None:\n+ enabled = False\n+ else:\n+ enabled = posthoganalytics.feature_enabled(\n+ key=\"login-from-new-device-notification\",\n+ distinct_id=str(user.distinct_id),\n+ groups={\"organization\": str(user.current_organization.id)},\n+ )\n+\n+ if not enabled:\n+ return\n+\n+ is_new_device = check_and_cache_login_device(user_id, ip_address, short_user_agent)\n+ if not is_new_device:\n+ return\n+\n+ login_time_str = login_time.strftime(\"%B %-d, %Y at %H:%M UTC\")\n+ geoip_data = get_geoip_properties(ip_address)\n+\n+ # Compose location as \"City, Country\" (omit city if missing)\n+ location = \", \".join(\n+ part\n+ for part in [geoip_data.get(\"$geoip_city_name\", \"\"), geoip_data.get(\"$geoip_country_name\", \"Unknown\")]\n+ if part\n+ )\n+\n+ message = EmailMessage(\n+ use_http=True,\n+ campaign_key=f\"login_notification_{user.uuid}-{timezone.now().timestamp()}\",\n+ template_name=\"login_notification\",\n+ subject=\"A new device logged into your account\",\n+ template_context={\n+ \"login_time\": login_time_str,\n+ \"ip_address\": ip_address,\n+ \"location\": location,\n+ \"browser\": short_user_agent,\n+ },\n+ )\n+ message.add_recipient(user.email)\n+ message.send()\n+ report_user_action(user=user, event=\"login notification sent\")",
|
|
"comment_created_at": "2025-08-13T14:57:47+00:00",
|
|
"comment_author": "zlwaterfield",
|
|
"comment_body": "Can we add some properties here for debugging this?",
|
|
"pr_file_module": null
|
|
},
|
|
{
|
|
"comment_id": "2273739958",
|
|
"repo_full_name": "PostHog/posthog",
|
|
"pr_number": 36519,
|
|
"pr_file": "posthog/tasks/email.py",
|
|
"discussion_id": "2273739168",
|
|
"commented_code": "@@ -453,6 +456,62 @@ def send_two_factor_auth_backup_code_used_email(user_id: int) -> None:\n message.send()\n \n \n+@shared_task(**EMAIL_TASK_KWARGS)\n+def login_from_new_device_notification(\n+ user_id: int, login_time: datetime, short_user_agent: str, ip_address: str\n+) -> None:\n+ \"\"\"Send login notification email if login is from a new device\"\"\"\n+ if not is_email_available(with_absolute_urls=True):\n+ return\n+\n+ user: User = User.objects.get(pk=user_id)\n+\n+ # Send email if feature flag is enabled or in tests\n+ if settings.TEST:\n+ enabled = True\n+ elif user.current_organization is None:\n+ enabled = False\n+ else:\n+ enabled = posthoganalytics.feature_enabled(\n+ key=\"login-from-new-device-notification\",\n+ distinct_id=str(user.distinct_id),\n+ groups={\"organization\": str(user.current_organization.id)},\n+ )\n+\n+ if not enabled:\n+ return\n+\n+ is_new_device = check_and_cache_login_device(user_id, ip_address, short_user_agent)\n+ if not is_new_device:\n+ return\n+\n+ login_time_str = login_time.strftime(\"%B %-d, %Y at %H:%M UTC\")\n+ geoip_data = get_geoip_properties(ip_address)\n+\n+ # Compose location as \"City, Country\" (omit city if missing)\n+ location = \", \".join(\n+ part\n+ for part in [geoip_data.get(\"$geoip_city_name\", \"\"), geoip_data.get(\"$geoip_country_name\", \"Unknown\")]\n+ if part\n+ )\n+\n+ message = EmailMessage(\n+ use_http=True,\n+ campaign_key=f\"login_notification_{user.uuid}-{timezone.now().timestamp()}\",\n+ template_name=\"login_notification\",\n+ subject=\"A new device logged into your account\",\n+ template_context={\n+ \"login_time\": login_time_str,\n+ \"ip_address\": ip_address,\n+ \"location\": location,\n+ \"browser\": short_user_agent,\n+ },\n+ )\n+ message.add_recipient(user.email)\n+ message.send()\n+ report_user_action(user=user, event=\"login notification sent\")",
|
|
"comment_created_at": "2025-08-13T14:58:03+00:00",
|
|
"comment_author": "zlwaterfield",
|
|
"comment_body": "Like IP and User Agent and Geo",
|
|
"pr_file_module": null
|
|
},
|
|
{
|
|
"comment_id": "2279502001",
|
|
"repo_full_name": "PostHog/posthog",
|
|
"pr_number": 36519,
|
|
"pr_file": "posthog/tasks/email.py",
|
|
"discussion_id": "2273739168",
|
|
"commented_code": "@@ -453,6 +456,62 @@ def send_two_factor_auth_backup_code_used_email(user_id: int) -> None:\n message.send()\n \n \n+@shared_task(**EMAIL_TASK_KWARGS)\n+def login_from_new_device_notification(\n+ user_id: int, login_time: datetime, short_user_agent: str, ip_address: str\n+) -> None:\n+ \"\"\"Send login notification email if login is from a new device\"\"\"\n+ if not is_email_available(with_absolute_urls=True):\n+ return\n+\n+ user: User = User.objects.get(pk=user_id)\n+\n+ # Send email if feature flag is enabled or in tests\n+ if settings.TEST:\n+ enabled = True\n+ elif user.current_organization is None:\n+ enabled = False\n+ else:\n+ enabled = posthoganalytics.feature_enabled(\n+ key=\"login-from-new-device-notification\",\n+ distinct_id=str(user.distinct_id),\n+ groups={\"organization\": str(user.current_organization.id)},\n+ )\n+\n+ if not enabled:\n+ return\n+\n+ is_new_device = check_and_cache_login_device(user_id, ip_address, short_user_agent)\n+ if not is_new_device:\n+ return\n+\n+ login_time_str = login_time.strftime(\"%B %-d, %Y at %H:%M UTC\")\n+ geoip_data = get_geoip_properties(ip_address)\n+\n+ # Compose location as \"City, Country\" (omit city if missing)\n+ location = \", \".join(\n+ part\n+ for part in [geoip_data.get(\"$geoip_city_name\", \"\"), geoip_data.get(\"$geoip_country_name\", \"Unknown\")]\n+ if part\n+ )\n+\n+ message = EmailMessage(\n+ use_http=True,\n+ campaign_key=f\"login_notification_{user.uuid}-{timezone.now().timestamp()}\",\n+ template_name=\"login_notification\",\n+ subject=\"A new device logged into your account\",\n+ template_context={\n+ \"login_time\": login_time_str,\n+ \"ip_address\": ip_address,\n+ \"location\": location,\n+ \"browser\": short_user_agent,\n+ },\n+ )\n+ message.add_recipient(user.email)\n+ message.send()\n+ report_user_action(user=user, event=\"login notification sent\")",
|
|
"comment_created_at": "2025-08-15T17:01:37+00:00",
|
|
"comment_author": "a-lider",
|
|
"comment_body": "Added this",
|
|
"pr_file_module": null
|
|
},
|
|
{
|
|
"comment_id": "2279507571",
|
|
"repo_full_name": "PostHog/posthog",
|
|
"pr_number": 36519,
|
|
"pr_file": "posthog/tasks/email.py",
|
|
"discussion_id": "2273739168",
|
|
"commented_code": "@@ -453,6 +456,62 @@ def send_two_factor_auth_backup_code_used_email(user_id: int) -> None:\n message.send()\n \n \n+@shared_task(**EMAIL_TASK_KWARGS)\n+def login_from_new_device_notification(\n+ user_id: int, login_time: datetime, short_user_agent: str, ip_address: str\n+) -> None:\n+ \"\"\"Send login notification email if login is from a new device\"\"\"\n+ if not is_email_available(with_absolute_urls=True):\n+ return\n+\n+ user: User = User.objects.get(pk=user_id)\n+\n+ # Send email if feature flag is enabled or in tests\n+ if settings.TEST:\n+ enabled = True\n+ elif user.current_organization is None:\n+ enabled = False\n+ else:\n+ enabled = posthoganalytics.feature_enabled(\n+ key=\"login-from-new-device-notification\",\n+ distinct_id=str(user.distinct_id),\n+ groups={\"organization\": str(user.current_organization.id)},\n+ )\n+\n+ if not enabled:\n+ return\n+\n+ is_new_device = check_and_cache_login_device(user_id, ip_address, short_user_agent)\n+ if not is_new_device:\n+ return\n+\n+ login_time_str = login_time.strftime(\"%B %-d, %Y at %H:%M UTC\")\n+ geoip_data = get_geoip_properties(ip_address)\n+\n+ # Compose location as \"City, Country\" (omit city if missing)\n+ location = \", \".join(\n+ part\n+ for part in [geoip_data.get(\"$geoip_city_name\", \"\"), geoip_data.get(\"$geoip_country_name\", \"Unknown\")]\n+ if part\n+ )\n+\n+ message = EmailMessage(\n+ use_http=True,\n+ campaign_key=f\"login_notification_{user.uuid}-{timezone.now().timestamp()}\",\n+ template_name=\"login_notification\",\n+ subject=\"A new device logged into your account\",\n+ template_context={\n+ \"login_time\": login_time_str,\n+ \"ip_address\": ip_address,\n+ \"location\": location,\n+ \"browser\": short_user_agent,\n+ },\n+ )\n+ message.add_recipient(user.email)\n+ message.send()\n+ report_user_action(user=user, event=\"login notification sent\")",
|
|
"comment_created_at": "2025-08-15T17:03:38+00:00",
|
|
"comment_author": "a-lider",
|
|
"comment_body": "Also changed `report_user_action` to `ph_client.capture`\r\nIn v1, events weren\u2019t captured, Yasen suggested this might be because capture has its own queue and events don\u2019t always get sent before the Celery task finishes. ",
|
|
"pr_file_module": null
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"discussion_id": "2269054010",
|
|
"pr_number": 36472,
|
|
"pr_file": "posthog/api/wizard/http.py",
|
|
"created_at": "2025-08-12T08:10:11+00:00",
|
|
"commented_code": ")\n \n project_api_token = project.passthrough_team.api_token\n- except Project.DoesNotExist:\n- raise serializers.ValidationError({\"projectId\": [\"This project does not exist.\"]}, code=\"not_found\")\n+ except Project.DoesNotExist as e:\n+ capture_exception(\n+ e,\n+ {\n+ \"project_id\": project_id,\n+ \"user_id\": request.user.id if request.user else None,\n+ \"user_distinct_id\": request.user.distinct_id if request.user else None,",
|
|
"repo_full_name": "PostHog/posthog",
|
|
"discussion_comments": [
|
|
{
|
|
"comment_id": "2269054010",
|
|
"repo_full_name": "PostHog/posthog",
|
|
"pr_number": 36472,
|
|
"pr_file": "posthog/api/wizard/http.py",
|
|
"discussion_id": "2269054010",
|
|
"commented_code": "@@ -295,8 +333,16 @@ def authenticate(self, request, **kwargs):\n )\n \n project_api_token = project.passthrough_team.api_token\n- except Project.DoesNotExist:\n- raise serializers.ValidationError({\"projectId\": [\"This project does not exist.\"]}, code=\"not_found\")\n+ except Project.DoesNotExist as e:\n+ capture_exception(\n+ e,\n+ {\n+ \"project_id\": project_id,\n+ \"user_id\": request.user.id if request.user else None,\n+ \"user_distinct_id\": request.user.distinct_id if request.user else None,",
|
|
"comment_created_at": "2025-08-12T08:10:11+00:00",
|
|
"comment_author": "JonathanLab",
|
|
"comment_body": "```suggestion\n \"user_distinct_id\": request.user.distinct_id if request.user else None,\n \"ai_product\": \"wizard\"\n```\n\nSuggest we maybe also set `\"team\": \"growth\"` on all of these exceptions? Makes it easier for us to auto-assign these to us in our error tracker",
|
|
"pr_file_module": null
|
|
},
|
|
{
|
|
"comment_id": "2270188107",
|
|
"repo_full_name": "PostHog/posthog",
|
|
"pr_number": 36472,
|
|
"pr_file": "posthog/api/wizard/http.py",
|
|
"discussion_id": "2269054010",
|
|
"commented_code": "@@ -295,8 +333,16 @@ def authenticate(self, request, **kwargs):\n )\n \n project_api_token = project.passthrough_team.api_token\n- except Project.DoesNotExist:\n- raise serializers.ValidationError({\"projectId\": [\"This project does not exist.\"]}, code=\"not_found\")\n+ except Project.DoesNotExist as e:\n+ capture_exception(\n+ e,\n+ {\n+ \"project_id\": project_id,\n+ \"user_id\": request.user.id if request.user else None,\n+ \"user_distinct_id\": request.user.distinct_id if request.user else None,",
|
|
"comment_created_at": "2025-08-12T15:01:59+00:00",
|
|
"comment_author": "daniloc",
|
|
"comment_body": "oh nice",
|
|
"pr_file_module": null
|
|
}
|
|
]
|
|
}
|
|
] |