From b2f033c6f7e41bdcf96df7c97115c0798b373eec Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 21 May 2025 15:19:12 +0000 Subject: [PATCH 1/5] Initial plan for issue From 3860a1622be36b2949b0e83402ff6ff80cbd8782 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 21 May 2025 15:22:22 +0000 Subject: [PATCH 2/5] Add notification signal for payment processing Co-authored-by: DonnieBLT <128622481+DonnieBLT@users.noreply.github.com> --- website/notification_signals.py | 52 ++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/website/notification_signals.py b/website/notification_signals.py index 8ae7c7f6bc..369a4a9dff 100644 --- a/website/notification_signals.py +++ b/website/notification_signals.py @@ -2,7 +2,7 @@ from django.dispatch import receiver from django.urls import reverse -from website.models import JoinRequest, Kudos, Notification, Points, Post, User, UserBadge +from website.models import GitHubIssue, JoinRequest, Kudos, Notification, Points, Post, User, UserBadge @receiver(post_save, sender=Points) @@ -78,3 +78,53 @@ def notify_user_on_badge_recieved(sender, instance, created, **kwargs): link = f"/profile/{instance.user.username}" Notification.objects.create(user=instance.user, message=message, notification_type="reward", link=link) + + +@receiver(post_save, sender=GitHubIssue) +def notify_on_payment_processed(sender, instance, **kwargs): + """ + Signal to notify users and admins when a payment is processed. + This triggers whenever a GitHubIssue with payment information is saved. + """ + # Check if this is a payment update (either sponsors_tx_id or bch_tx_id is updated) + if instance.p2p_payment_created_at and (instance.sponsors_tx_id or instance.bch_tx_id): + payment_type = "GitHub Sponsors" if instance.sponsors_tx_id else "Bitcoin Cash" + tx_id = instance.sponsors_tx_id or instance.bch_tx_id + + # Create notification for the issue reporter + if instance.user: + message = ( + f"Your bounty for issue #{instance.issue_id} has been paid via {payment_type}. " + f"Transaction ID: {tx_id}" + ) + link = instance.html_url + + Notification.objects.create( + user=instance.user, + message=message, + notification_type="reward", + link=link + ) + + # Notify superusers (admin team) about the payment + superusers = User.objects.filter(is_superuser=True) + for admin in superusers: + # Don't notify the admin who made the payment + if instance.sent_by_user and admin.id == instance.sent_by_user.id: + continue + + message = ( + f"Payment processed for issue #{instance.issue_id} via {payment_type}. " + f"Transaction ID: {tx_id}" + ) + if instance.sent_by_user: + message += f" (by {instance.sent_by_user.username})" + + link = instance.html_url + + Notification.objects.create( + user=admin, + message=message, + notification_type="alert", + link=link + ) From e89ade5b3a22e7839bf47e9de9b22bf1a0563446 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 21 May 2025 15:24:18 +0000 Subject: [PATCH 3/5] Complete payment notification system implementation Co-authored-by: DonnieBLT <128622481+DonnieBLT@users.noreply.github.com> --- website/notification_signals.py | 83 +++++++++++++++++++-------------- website/views/organization.py | 4 ++ 2 files changed, 53 insertions(+), 34 deletions(-) diff --git a/website/notification_signals.py b/website/notification_signals.py index 369a4a9dff..280c604873 100644 --- a/website/notification_signals.py +++ b/website/notification_signals.py @@ -1,9 +1,12 @@ from django.db.models.signals import post_save from django.dispatch import receiver from django.urls import reverse +import logging from website.models import GitHubIssue, JoinRequest, Kudos, Notification, Points, Post, User, UserBadge +logger = logging.getLogger(__name__) + @receiver(post_save, sender=Points) def create_notification_on_points_reward(sender, instance, created, **kwargs): @@ -81,7 +84,7 @@ def notify_user_on_badge_recieved(sender, instance, created, **kwargs): @receiver(post_save, sender=GitHubIssue) -def notify_on_payment_processed(sender, instance, **kwargs): +def notify_on_payment_processed(sender, instance, created, update_fields, **kwargs): """ Signal to notify users and admins when a payment is processed. This triggers whenever a GitHubIssue with payment information is saved. @@ -91,40 +94,52 @@ def notify_on_payment_processed(sender, instance, **kwargs): payment_type = "GitHub Sponsors" if instance.sponsors_tx_id else "Bitcoin Cash" tx_id = instance.sponsors_tx_id or instance.bch_tx_id - # Create notification for the issue reporter - if instance.user: - message = ( - f"Your bounty for issue #{instance.issue_id} has been paid via {payment_type}. " - f"Transaction ID: {tx_id}" - ) - link = instance.html_url + # Only send notifications if the payment was just added/updated + if (created or + (update_fields and + ('sponsors_tx_id' in update_fields or 'bch_tx_id' in update_fields or 'p2p_payment_created_at' in update_fields))): - Notification.objects.create( - user=instance.user, - message=message, - notification_type="reward", - link=link - ) - - # Notify superusers (admin team) about the payment - superusers = User.objects.filter(is_superuser=True) - for admin in superusers: - # Don't notify the admin who made the payment - if instance.sent_by_user and admin.id == instance.sent_by_user.id: - continue - - message = ( - f"Payment processed for issue #{instance.issue_id} via {payment_type}. " - f"Transaction ID: {tx_id}" + logger.info( + f"Payment notification processing: Issue #{instance.issue_id}, " + f"Type: {payment_type}, TX: {tx_id}" ) - if instance.sent_by_user: - message += f" (by {instance.sent_by_user.username})" + + # Create notification for the issue reporter + if instance.user: + message = ( + f"Your bounty for issue #{instance.issue_id} has been paid via {payment_type}. " + f"Transaction ID: {tx_id}" + ) + link = instance.html_url - link = instance.html_url + Notification.objects.create( + user=instance.user, + message=message, + notification_type="reward", + link=link + ) + logger.info(f"Created payment notification for issue reporter: {instance.user.username}") - Notification.objects.create( - user=admin, - message=message, - notification_type="alert", - link=link - ) + # Notify superusers (admin team) about the payment + superusers = User.objects.filter(is_superuser=True) + for admin in superusers: + # Don't notify the admin who made the payment + if instance.sent_by_user and admin.id == instance.sent_by_user.id: + continue + + message = ( + f"Payment processed for issue #{instance.issue_id} via {payment_type}. " + f"Transaction ID: {tx_id}" + ) + if instance.sent_by_user: + message += f" (by {instance.sent_by_user.username})" + + link = instance.html_url + + Notification.objects.create( + user=admin, + message=message, + notification_type="alert", + link=link + ) + logger.info(f"Created payment notification for admin: {admin.username}") diff --git a/website/views/organization.py b/website/views/organization.py index 7a86441d87..ebc1e814bb 100644 --- a/website/views/organization.py +++ b/website/views/organization.py @@ -3032,6 +3032,10 @@ def post(self, request, *args, **kwargs): success_message += ". Labels added on GitHub" if comment_success: success_message += ". Comment added on GitHub" + + # Note: Notifications to the admin team and users are automatically + # created by the post_save signal on GitHubIssue model + success_message += ". Notifications sent to admin team and issue reporter" messages.success(request, success_message) From 69be971bab38d9a15a2d37d4563d155496f0f9e7 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sun, 16 Nov 2025 21:55:15 +0000 Subject: [PATCH 4/5] Apply pre-commit fixes --- website/notification_signals.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/website/notification_signals.py b/website/notification_signals.py index 280c604873..49a5f4ab9f 100644 --- a/website/notification_signals.py +++ b/website/notification_signals.py @@ -1,7 +1,8 @@ +import logging + from django.db.models.signals import post_save from django.dispatch import receiver from django.urls import reverse -import logging from website.models import GitHubIssue, JoinRequest, Kudos, Notification, Points, Post, User, UserBadge From 7a2d249d753e6f8e70d3fdd3f76bdda2ab1ad066 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sun, 16 Nov 2025 22:31:32 +0000 Subject: [PATCH 5/5] Apply pre-commit fixes --- website/notification_signals.py | 46 ++++++++++++++------------------- website/views/organization.py | 4 +-- 2 files changed, 21 insertions(+), 29 deletions(-) diff --git a/website/notification_signals.py b/website/notification_signals.py index 49a5f4ab9f..dea0e31cef 100644 --- a/website/notification_signals.py +++ b/website/notification_signals.py @@ -94,17 +94,20 @@ def notify_on_payment_processed(sender, instance, created, update_fields, **kwar if instance.p2p_payment_created_at and (instance.sponsors_tx_id or instance.bch_tx_id): payment_type = "GitHub Sponsors" if instance.sponsors_tx_id else "Bitcoin Cash" tx_id = instance.sponsors_tx_id or instance.bch_tx_id - + # Only send notifications if the payment was just added/updated - if (created or - (update_fields and - ('sponsors_tx_id' in update_fields or 'bch_tx_id' in update_fields or 'p2p_payment_created_at' in update_fields))): - + if created or ( + update_fields + and ( + "sponsors_tx_id" in update_fields + or "bch_tx_id" in update_fields + or "p2p_payment_created_at" in update_fields + ) + ): logger.info( - f"Payment notification processing: Issue #{instance.issue_id}, " - f"Type: {payment_type}, TX: {tx_id}" + f"Payment notification processing: Issue #{instance.issue_id}, " f"Type: {payment_type}, TX: {tx_id}" ) - + # Create notification for the issue reporter if instance.user: message = ( @@ -112,35 +115,24 @@ def notify_on_payment_processed(sender, instance, created, update_fields, **kwar f"Transaction ID: {tx_id}" ) link = instance.html_url - - Notification.objects.create( - user=instance.user, - message=message, - notification_type="reward", - link=link - ) + + Notification.objects.create(user=instance.user, message=message, notification_type="reward", link=link) logger.info(f"Created payment notification for issue reporter: {instance.user.username}") - + # Notify superusers (admin team) about the payment superusers = User.objects.filter(is_superuser=True) for admin in superusers: # Don't notify the admin who made the payment if instance.sent_by_user and admin.id == instance.sent_by_user.id: continue - + message = ( - f"Payment processed for issue #{instance.issue_id} via {payment_type}. " - f"Transaction ID: {tx_id}" + f"Payment processed for issue #{instance.issue_id} via {payment_type}. " f"Transaction ID: {tx_id}" ) if instance.sent_by_user: message += f" (by {instance.sent_by_user.username})" - + link = instance.html_url - - Notification.objects.create( - user=admin, - message=message, - notification_type="alert", - link=link - ) + + Notification.objects.create(user=admin, message=message, notification_type="alert", link=link) logger.info(f"Created payment notification for admin: {admin.username}") diff --git a/website/views/organization.py b/website/views/organization.py index ce7199029d..684150da4a 100644 --- a/website/views/organization.py +++ b/website/views/organization.py @@ -3089,8 +3089,8 @@ def post(self, request, *args, **kwargs): success_message += ". Labels added on GitHub" if comment_success: success_message += ". Comment added on GitHub" - - # Note: Notifications to the admin team and users are automatically + + # Note: Notifications to the admin team and users are automatically # created by the post_save signal on GitHubIssue model success_message += ". Notifications sent to admin team and issue reporter"