diff --git a/blt/urls.py b/blt/urls.py index d41784aa6..37bc2f7d2 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) @@ -511,6 +512,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 c34755968..c61f40fa3 100644 --- a/website/views.py +++ b/website/views.py @@ -4629,3 +4629,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: + return HttpResponse("An error occurred while sending the weekly report") + + return HttpResponse("Weekly report sent successfully.")