Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop a custom command to send weekly reports via email. #2207 #2406

Merged
merged 7 commits into from
Jul 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.")
Loading