Skip to content

Commit

Permalink
Merge pull request #2406 from Sarthak5598/weekly_mail
Browse files Browse the repository at this point in the history
Develop a custom command to send weekly reports via email. #2207
  • Loading branch information
Sarthak5598 authored Jul 6, 2024
2 parents 8aa28e9 + 9403aed commit 5be4e9e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
2 changes: 2 additions & 0 deletions blt/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
submit_pr,
subscribe_to_domains,
vote_count,
weekly_report,
)

favicon_view = RedirectView.as_view(url="/static/favicon.ico", permanent=True)
Expand Down Expand Up @@ -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<slug>[\w\s]+)",
website.views.trademark_detailview,
Expand Down
41 changes: 41 additions & 0 deletions website/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")

0 comments on commit 5be4e9e

Please sign in to comment.