Skip to content

Commit

Permalink
Merge branch 'main' into suggestion-bot
Browse files Browse the repository at this point in the history
  • Loading branch information
DonnieBLT authored Jan 19, 2025
2 parents 40b0d4a + b59a909 commit e776631
Show file tree
Hide file tree
Showing 22 changed files with 1,328 additions and 1,403 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<p align="center"><a href="https://github.com/OWASP/BLT/actions" rel="noopener noreferrer" target="__blank"><img alt="Build" src="https://github.com/OWASP/BLT/actions/workflows/auto-merge.yml/badge.svg"></a> <a href="https://github.com/OWASP/BLT/blob/main/LICENSE.md" rel="noopener noreferrer"><img src="https://img.shields.io/badge/license-AGPL--3.0-blue"></a>
<a href="https://github.com/OWASP/BLT" rel="noopener noreferrer" target="__blank"><img alt="GitHub stars" src="https://img.shields.io/github/stars/OWASP/BLT?style=social"></a></p>

<img alt="Views" src="https://blt.owasp.org/projects/blt/badge"></a>
<img alt="Views" src="https://blt.owasp.org/repos/blt/badge/">

Everything is on our <a href="https://blt.owasp.org">homepage</a>

Expand Down
10 changes: 4 additions & 6 deletions blt/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,6 @@
)
from website.views.project import (
ProjectBadgeView,
ProjectDetailView,
ProjectListView,
ProjectsDetailView,
ProjectView,
RepoBadgeView,
Expand All @@ -187,6 +185,7 @@
distribute_bacon,
select_contribution,
)
from website.views.slack_handlers import slack_events
from website.views.teams import (
TeamOverview,
add_member,
Expand Down Expand Up @@ -554,8 +553,7 @@
TemplateView.as_view(template_name="coming_soon.html"),
name="googleplayapp",
),
re_path(r"^projects/$", ProjectListView.as_view(), name="project_list"),
re_path(r"^allprojects/$", ProjectView.as_view(), name="project_view"),
re_path(r"^projects/$", ProjectView.as_view(), name="project_view"),
re_path(r"^apps/$", TemplateView.as_view(template_name="apps.html"), name="apps"),
re_path(
r"^deletions/$",
Expand Down Expand Up @@ -605,7 +603,6 @@
re_path(r"^api/v1/createwallet/$", create_wallet, name="create_wallet"),
re_path(r"^api/v1/count/$", issue_count, name="api_count"),
re_path(r"^api/v1/contributors/$", contributors, name="api_contributor"),
path("project/<slug:slug>/", ProjectDetailView.as_view(), name="project_view"),
path("projects/<slug:slug>/badge/", ProjectBadgeView.as_view(), name="project-badge"),
path("repos/<slug:slug>/badge/", RepoBadgeView.as_view(), name="repo-badge"),
path("repository/<slug:slug>/", RepoDetailView.as_view(), name="repo_detail"),
Expand Down Expand Up @@ -854,7 +851,8 @@
name="similarity_scan",
),
path("projects/create/", create_project, name="create_project"),
path("projects/<slug:slug>/", ProjectsDetailView.as_view(), name="projects_detail"),
path("project/<slug:slug>/", ProjectsDetailView.as_view(), name="projects_detail"),
path("slack/events", slack_events, name="slack_events"),
]

if settings.DEBUG:
Expand Down
231 changes: 116 additions & 115 deletions poetry.lock

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ license = "AGPLv3"
python = "3.11.2"
python-dotenv = "^1.0.1"
toml = "^0.10.2"
Django = "^5.1.3"
Django = "^5.1.5"
dj-database-url = "^2.3.0"
django-allauth = "^0.61.1"
beautifulsoup4 = "^4.12.3"
colorthief = "^0.2.1"
django-email-obfuscator = "^0.1.5"
django-gravatar2 = "^1.4.5"
django-import-export = "^4.3.2"
django-import-export = "^4.3.4"
django-annoying = "^0.10.7"
dj-rest-auth = "^5.0.2"
tweepy = "^4.8.0"
tweepy = "^4.15.0"
Unidecode = "^1.3.8"
user-agents = "^2.2.0"
whitenoise = "^6.8.2"
Expand Down Expand Up @@ -53,19 +53,19 @@ django-tellme = "^0.7.3"
django-bootstrap-datepicker-plus = "^5.0.5"
django-star-ratings = "^0.9.2"
stripe = "^8.4.0"
django-environ = "^0.11.2"
django-environ = "^0.12.0"
django-humanize = "^0.1.2"
drf-yasg = "^1.21.8"
django-simple-captcha = "^0.6.0"
django-filter = "^24.3"
webdriver-manager = "^4.0.2"
pillow = "^10.4.0"
chromedriver-autoinstaller = "^0.6.4"
sentry-sdk = "^2.19.0"
sentry-sdk = "^2.20.0"
bitcash = "^1.0.2"
pydantic = "^2.10.5"
pydantic_core = "^2.18.4"
unstructured = "^0.16.12"
unstructured = "^0.16.13"
Markdown = "^3.6"
faiss-cpu = "^1.8.0"
psutil = "^5.9.8"
Expand All @@ -81,13 +81,13 @@ channels = "^4.2.0"
channels-redis = "^4.2.1"
async-timeout = "^5.0.1"
aiohttp = "^3.11.11"
scout-apm = "^3.2.1"
scout-apm = "^3.3.0"
newrelic = "^10.4.0"

[tool.poetry.group.dev.dependencies]
black = "^24.8.0"
isort = "^5.13.2"
ruff = "^0.9.0"
ruff = "^0.9.2"
pre-commit = "^3.8.0"

[tool.isort]
Expand Down
86 changes: 55 additions & 31 deletions website/api/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import smtplib
import uuid
from datetime import datetime
from urllib.parse import urlparse
Expand Down Expand Up @@ -652,45 +653,68 @@ def get(self, request, *args, **kwargs):


class InviteFriendApiViewset(APIView):
permission_classes = [IsAuthenticated]

def post(self, request, *args, **kwargs):
email = request.POST.get("email")
already_exists = User.objects.filter(email=email).exists()
email = request.data.get("email")

if already_exists:
return Response("USER EXISTS", status=409)
if not email:
return Response({"error": "Email is required"}, status=400)

site = get_current_site(self.request)
# Check if user already exists
if User.objects.filter(email=email).exists():
return Response({"error": "User already exists"}, status=400)

invite = InviteFriend.objects.create(sender=request.user, recipient=email, sent=False)
try:
current_site = get_current_site(request)
referral_code, created = InviteFriend.objects.get_or_create(sender=request.user)
referral_link = (
f"https://{current_site.domain}/referral/?ref={referral_code.referral_code}"
)

mail_status = send_mail(
"Inivtation to {site} from {user}".format(site=site.name, user=request.user.username),
"You have been invited by {user} to join {site} community.".format(
user=request.user.username, site=site.name
),
settings.DEFAULT_FROM_EMAIL,
[invite.recipient],
)
# Prepare email content
subject = f"Join me on {current_site.name}!"
message = render_to_string(
"email/invite_friend.txt",
{
"sender": request.user.username,
"referral_link": referral_link,
"site_name": current_site.name,
"site_domain": current_site.domain,
},
)

if mail_status:
invite.sent = True
invite.save()
# Send the invitation email
email_result = send_mail(
subject,
message,
settings.DEFAULT_FROM_EMAIL,
[email],
fail_silently=False,
)

if (
mail_status
and InviteFriend.objects.filter(sender=self.request.user, sent=True).count() == 2
):
Points.objects.create(user=self.request.user, score=1, reason="Invited friend")
InviteFriend.objects.filter(sender=self.request.user).delete()
if email_result == 1:
return Response(
{
"success": True,
"message": "Invitation sent successfully",
"referral_link": referral_link,
"email_status": "delivered",
}
)
else:
return Response(
{"error": "Email failed to send", "email_status": "failed"}, status=500
)

return Response(
{
"title": "SUCCESS",
"Points": "+1",
"message": "An email has been sent to your friend. Keep inviting your friends and get points!",
},
status=200,
)
except smtplib.SMTPException as e:
return Response(
{
"error": "Failed to send invitation email for an unexpected reason",
"email_status": "error",
},
status=500,
)


class OrganizationViewSet(viewsets.ModelViewSet):
Expand Down
Loading

0 comments on commit e776631

Please sign in to comment.