From c29eb0ae5f6973a2a90cd420f0a2eb3237075137 Mon Sep 17 00:00:00 2001 From: Sarthak5598 Date: Sat, 6 Jul 2024 19:26:04 +0530 Subject: [PATCH 1/3] Develop a custom command to send weekly reports via email. #2207 --- blt/urls.py | 2 ++ website/views.py | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/blt/urls.py b/blt/urls.py index 93d101312..8845ad851 100644 --- a/blt/urls.py +++ b/blt/urls.py @@ -93,6 +93,7 @@ submit_pr, subscribe_to_domains, vote_count, + weekly_report, ) favicon_view = RedirectView.as_view(url="/static/favicon.ico", permanent=True) @@ -509,6 +510,7 @@ path("fetch-current-bid/", fetch_current_bid, name="fetch_current_bid"), path("Submitpr/", submit_pr, name="submit_pr"), path("issue-auto-label/", AutoLabel, name="AutoLabel"), + path("weekly-report/", weekly_report, name="weekly_report"), re_path( r"^trademarks/query=(?P[\w\s]+)", website.views.trademark_detailview, diff --git a/website/views.py b/website/views.py index 931ab1faa..989eac855 100644 --- a/website/views.py +++ b/website/views.py @@ -4621,3 +4621,44 @@ def AutoLabel(request): return JsonResponse({"label": label}) return JsonResponse({"error": "Method not allowed"}, status=405) + + +def weekly_report(request): + domains = Domain.objects.all() + report_data = [ + "Hey This is a weekly report from OWASP BLT regarding the bugs reported for your company!" + ] + try: + for domain in domains: + open_issues = domain.open_issues + closed_issues = domain.closed_issues + total_issues = open_issues.count() + closed_issues.count() + issues = Issue.objects.filter(domain=domain) + email = domain.email + report_data.append( + "Hey This is a weekly report from OWASP BLT regarding the bugs reported for your company!" + f"\n\nCompany Name: {domain.name}" + f"Open issues: {open_issues.count()}" + f"Closed issues: {closed_issues.count()}" + f"Total issues: {total_issues}" + ) + for issue in issues: + description = issue.description + views = issue.views + label = issue.get_label_display() + report_data.append( + f"\n Description: {description} \n Views: {views} \n Labels: {label} \n" + ) + + report_string = "".join(report_data) + send_mail( + "Weekly Report!!!", + report_string, + settings.EMAIL_HOST_USER, + [email], + fail_silently=False, + ) + except Exception as e: + return HttpResponse(f"An error occurred while sending the weekly report: {str(e)}") + + return HttpResponse("Weekly report sent successfully.") From 6d7d5f2f712f3815653b955ff04dbd87efeb4263 Mon Sep 17 00:00:00 2001 From: Sarthak5598 Date: Sat, 6 Jul 2024 20:01:47 +0530 Subject: [PATCH 2/3] removed error message --- website/views.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/website/views.py b/website/views.py index e4a4c3882..cf338b4b4 100644 --- a/website/views.py +++ b/website/views.py @@ -4666,7 +4666,7 @@ def weekly_report(request): [email], fail_silently=False, ) - except Exception as e: - return HttpResponse(f"An error occurred while sending the weekly report: {str(e)}") + except: + return HttpResponse(f"An error occurred while sending the weekly report") return HttpResponse("Weekly report sent successfully.") From da3019461d884d911ce3bc92ee5efbe40c24bb7e Mon Sep 17 00:00:00 2001 From: Sarthak5598 Date: Sat, 6 Jul 2024 20:03:08 +0530 Subject: [PATCH 3/3] exception --- website/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/views.py b/website/views.py index cf338b4b4..c61f40fa3 100644 --- a/website/views.py +++ b/website/views.py @@ -4667,6 +4667,6 @@ def weekly_report(request): fail_silently=False, ) except: - return HttpResponse(f"An error occurred while sending the weekly report") + return HttpResponse("An error occurred while sending the weekly report") return HttpResponse("Weekly report sent successfully.")