Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
4cbe80f
implement email logic
Zahed-Riyaz Jun 24, 2025
9ef7fcc
Add templates + refine email logic
Zahed-Riyaz Jun 25, 2025
850c516
Add tests for paid plans email feature
Zahed-Riyaz Jun 26, 2025
20e8cf6
Omit debugs
Zahed-Riyaz Jul 2, 2025
41f0b3e
Update utils.ppy
Zahed-Riyaz Jul 2, 2025
c057444
implement email logic
Zahed-Riyaz Jun 24, 2025
fb91c17
Add templates + refine email logic
Zahed-Riyaz Jun 25, 2025
c694e42
Add tests for paid plans email feature
Zahed-Riyaz Jun 26, 2025
66933ac
Omit debugs
Zahed-Riyaz Jul 2, 2025
210d8d1
Update utils.ppy
Zahed-Riyaz Jul 2, 2025
e77ef40
Refine tests
Zahed-Riyaz Jul 3, 2025
a17f453
Merge branch 'email-plan' of https://github.com/Zahed-Riyaz/EvalAI in…
Zahed-Riyaz Jul 3, 2025
952cb64
Modify tests
Zahed-Riyaz Jul 3, 2025
c360077
remove unnecessary imports
Zahed-Riyaz Jul 3, 2025
9c6cd0d
Update docker-compose.yml
Zahed-Riyaz Jul 3, 2025
6d8f6dc
Handle undefined variables
Zahed-Riyaz Jul 3, 2025
d61cecf
Update test_views.py
Zahed-Riyaz Jul 3, 2025
963ccea
Update env variables and tests
Zahed-Riyaz Jul 5, 2025
42db7bc
Update env variables and tests
Zahed-Riyaz Jul 5, 2025
8a91943
Update email
Zahed-Riyaz Jul 5, 2025
e9802a6
Merge branch 'master' into email-plan
Zahed-Riyaz Jul 5, 2025
0fadd8d
fix isort checks
Zahed-Riyaz Jul 5, 2025
5784799
Resolve Flake8 checks
Zahed-Riyaz Jul 5, 2025
bc60d74
Merge branch 'master' into email-plan
Zahed-Riyaz Jul 10, 2025
98c06bc
Merge branch 'master' into email-plan
Zahed-Riyaz Jul 15, 2025
065cdb3
Merge branch 'master' into email-plan
Zahed-Riyaz Jul 21, 2025
b0d9085
Merge branch 'Cloud-CV:master' into email-plan
Zahed-Riyaz Jul 30, 2025
8effb2d
Update email template
Zahed-Riyaz Jul 30, 2025
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
Prev Previous commit
Next Next commit
Update utils.ppy
  • Loading branch information
Zahed-Riyaz committed Jul 2, 2025
commit 41f0b3e8befaad45abd04a74006c147d7addb88f
4 changes: 2 additions & 2 deletions apps/challenges/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,8 +510,8 @@ def send_subscription_plans_email(challenge):
emails_sent = 0
for email in challenge_host_emails:
try:
# TEMPORARY: Always send emails even in DEBUG mode for testing
# Create email message
# Send emails in production mode, or in debug mode if explicitly enabled
# This allows testing email functionality with MailHog in development
email_message = EmailMultiAlternatives(
subject=subject,
body="Please view this email in HTML format.", # Plain text fallback
Expand Down
110 changes: 78 additions & 32 deletions apps/challenges/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4809,28 +4809,26 @@ def update_allowed_email_ids(request, challenge_pk, phase_pk):
@authentication_classes((JWTAuthentication, ExpiringTokenAuthentication))
def request_challenge_approval_by_pk(request, challenge_pk):
"""
Send approval request for the challenge
(Temporarily disabled submission requirement check for testing)
Checks if all challenge phases have finished submissions for the given challenge
and send approval request for the challenge
"""
challenge = get_challenge_model(challenge_pk)

# TEMPORARY: Comment out submission requirement check for testing
# challenge_phases = ChallengePhase.objects.filter(challenge=challenge)
# unfinished_phases = []
challenge_phases = ChallengePhase.objects.filter(challenge=challenge)
unfinished_phases = []

# for challenge_phase in challenge_phases:
# submissions = Submission.objects.filter(
# challenge_phase=challenge_phase, status="finished"
# )
for challenge_phase in challenge_phases:
submissions = Submission.objects.filter(
challenge_phase=challenge_phase, status="finished"
)

# if not submissions.exists():
# unfinished_phases.append(challenge_phase.name)
if not submissions.exists():
unfinished_phases.append(challenge_phase.name)

# if unfinished_phases:
# error_message = f"The following challenge phases do not have finished submissions: {', '.join(unfinished_phases)}"
# return Response(
# {"error": error_message}, status=status.HTTP_406_NOT_ACCEPTABLE
# )
if unfinished_phases:
error_message = f"The following challenge phases do not have finished submissions: {', '.join(unfinished_phases)}"
return Response(
{"error": error_message}, status=status.HTTP_406_NOT_ACCEPTABLE
)

# Send subscription plans email to challenge hosts
try:
Expand All @@ -4848,20 +4846,68 @@ def request_challenge_approval_by_pk(request, challenge_pk):
)
# Continue with the approval process even if email fails

# TEMPORARY: Simplified approval for testing - just send email and return success
# Removed Slack webhook completely for cleaner testing
response_data = {
"message": "Approval request processed! Subscription plans email sent to challenge hosts.",
}
return Response(response_data, status=status.HTTP_200_OK)
# TEMPORARY: Commented out the DEBUG mode restriction for testing
# else:
# error_message = (
# "Please approve the challenge using admin for local deployments."
# )
# return Response(
# {"error": error_message}, status=status.HTTP_406_NOT_ACCEPTABLE
# )
if not settings.DEBUG:
try:
evalai_api_server = settings.EVALAI_API_SERVER
approval_webhook_url = settings.APPROVAL_WEBHOOK_URL

if not evalai_api_server:
raise ValueError(
"EVALAI_API_SERVER environment variable is missing."
)
if not approval_webhook_url:
raise ValueError(
"APPROVAL_WEBHOOK_URL environment variable is missing."
)
except: # noqa: E722
error_message = "Sorry, there was an error fetching required data for approval requests."
return Response(
{"error": error_message}, status=status.HTTP_406_NOT_ACCEPTABLE
)

message = {
"text": f"Challenge {challenge_pk} has finished submissions and has requested for approval!",
"fields": [
{
"title": "Admin URL",
"value": f"{evalai_api_server}/api/admin/challenges/challenge/{challenge_pk}",
"short": False,
},
{
"title": "Challenge title",
"value": challenge.title,
"short": False,
},
],
}

webhook_response = send_slack_notification(
webhook=approval_webhook_url, message=message
)
if webhook_response:
if webhook_response.content.decode("utf-8") == "ok":
response_data = {
"message": "Approval request sent! You should also receive an email with subscription plan details.",
}
return Response(response_data, status=status.HTTP_200_OK)
else:
error_message = f"Sorry, there was an error sending approval request: {str(webhook_response.content.decode('utf-8'))}. Please try again."
return Response(
{"error": error_message},
status=status.HTTP_406_NOT_ACCEPTABLE,
)
else:
error_message = "Sorry, there was an error sending approval request: No response received. Please try again."
return Response(
{"error": error_message}, status=status.HTTP_406_NOT_ACCEPTABLE
)
else:
error_message = (
"Please approve the challenge using admin for local deployments."
)
return Response(
{"error": error_message}, status=status.HTTP_406_NOT_ACCEPTABLE
)


@api_view(["GET"])
Expand Down Expand Up @@ -5046,4 +5092,4 @@ def modify_leaderboard_data(request):

# Serialize and return the updated data
response_data = {"message": "Leaderboard data updated successfully!"}
return Response(response_data, status=status.HTTP_200_OK)
return Response(response_data, status=status.HTTP_200_OK)