Skip to content
Closed
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
35 changes: 28 additions & 7 deletions src/impl/Event/router_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

from fastapi import APIRouter, Depends

from src.configuration.Settings import settings
from src.error.AuthenticationException import AuthenticationException
from src.impl.Company.schema import CompanyGet
from src.impl.Event.schema import (
EventCreate,
HackerEventRegistration,
HackerEventRegistrationUpdate,
SlackInviteRequest,
)
from src.impl.Event.schema import EventGet
from src.impl.Event.schema import EventGetAll
Expand Down Expand Up @@ -212,7 +212,7 @@ def confirm_assistance(token: AssistenceToken = Depends(JWTBearer())):
Confirm assistance of a hacker to an event
"""
event_service.confirm_assistance(token)
#redirect to settings.others.front_url
# redirect to settings.others.front_url
return {"success": True}


Expand Down Expand Up @@ -347,18 +347,19 @@ def get_pending_hackers_gruped(event_id: int, token: BaseToken = Depends(JWTBear


@router.get("/{event_id}/hackers_participants_grouped_list")
def get_hackers_participants_grouped_list(event_id: int,
token: BaseToken = Depends(
JWTBearer())):
def get_hackers_participants_grouped_list(
event_id: int, token: BaseToken = Depends(JWTBearer())
):
"""
Get a grouped list of hacker participants for an event
"""
return event_service.get_hackers_participants_grouped_list(event_id, token)


@router.get("/{event_id}/hackers_participants_list")
def get_hackers_participants_list(event_id: int,
token: BaseToken = Depends(JWTBearer())):
def get_hackers_participants_list(
event_id: int, token: BaseToken = Depends(JWTBearer())
):
"""
Get a list of hacker participants for an event
"""
Expand All @@ -385,6 +386,26 @@ def send_slack_mail(event_id: int, token: BaseToken = Depends(JWTBearer())):
return {"success": True}


@router.post("/{event_id}/send_slack_invite/")
def send_slack_invite(
event_id: int, payload: SlackInviteRequest, token: BaseToken = Depends(JWTBearer())
):
"""
Send Slack invitation to all accepted hackers of an event
"""
result = event_service.send_slack_invite(event_id, payload.slack_url, token)
return {"success": True, "sent": result["sent"]}


@router.post("/{event_id}/send_confirmation_reminder/")
def send_confirmation_reminder(event_id: int, token: BaseToken = Depends(JWTBearer())):
"""
Send confirmation reminder to accepted hackers who haven't confirmed their attendance
"""
result = event_service.send_confirmation_reminder(event_id, token)
return {"success": True, "sent": result["sent"]}


# @router.post("/{event_id}/send_remember")
# def send_remember(
# event_id: int,
Expand Down
4 changes: 4 additions & 0 deletions src/impl/Event/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,7 @@ class HackerEventRegistrationUpdate(BaseSchema):
location: Optional[str] = None
how_did_you_meet_us: Optional[str] = None
wants_credit: Optional[bool] = False


class SlackInviteRequest(BaseSchema):
slack_url: str
77 changes: 77 additions & 0 deletions src/impl/Event/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -997,3 +997,80 @@ def send_slack_mail(self, event_id: int, data: BaseToken):
)

db.session.commit()

@BaseService.needs_service(MailClient)
def send_confirmation_reminder(self, event_id: int, data: BaseToken):
if not data.check([UserType.LLEIDAHACKER]):
raise AuthenticationException("Not authorized")
event = self.get_by_id(event_id)
if event.archived:
raise InvalidDataException(
"Unable to operate with an archived event, unarchive it first"
)

# Get accepted hackers who haven't confirmed yet
hackers = event.accepted_hackers
unconfirmed_hackers = []

for hacker in hackers:
hacker_registration = (
db.session.query(HackerRegistration)
.filter(
HackerRegistration.user_id == hacker.id,
HackerRegistration.event_id == event.id,
)
.first()
)
if hacker_registration and not hacker_registration.confirmed_assistance:
unconfirmed_hackers.append((hacker, hacker_registration))

# Send reminder emails to unconfirmed hackers
for hacker, hacker_registration in unconfirmed_hackers:
token = hacker_registration.confirm_assistance_token
if not token:
# Generate new token if one doesn't exist
token = AssistenceToken(hacker, event.id).to_token()
hacker_registration.confirm_assistance_token = token

self.mail_client.create_mail(
MailCreate(
template_id=self.mail_client.get_internall_template_id(
InternalTemplate.EVENT_CONFIRMATION_REMINDER
),
subject=f"Reminder: Confirm your attendance to {event.name}",
receiver_id=str(hacker.id),
receiver_mail=str(hacker.email),
fields=f"{hacker.name},{event.name},{token}",
)
)

db.session.commit()
return {"sent": len(unconfirmed_hackers)}

@BaseService.needs_service(MailClient)
def send_slack_invite(self, event_id: int, slack_url: str, data: BaseToken):
if not data.check([UserType.LLEIDAHACKER]):
raise AuthenticationException("Not authorized")
event = self.get_by_id(event_id)
if event.archived:
raise InvalidDataException(
"Unable to operate with an archived event, unarchive it first"
)

hackers = event.accepted_hackers

for hacker in hackers:
self.mail_client.create_mail(
MailCreate(
template_id=self.mail_client.get_internall_template_id(
InternalTemplate.EVENT_SLACK_INVITE
),
subject=f"{event.name} Slack invitation",
receiver_id=str(hacker.id),
receiver_mail=str(hacker.email),
fields=slack_url,
)
)

db.session.commit()
return {"sent": len(hackers)}
1 change: 1 addition & 0 deletions src/impl/Mail/internall_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class InternalTemplate(Enum):

EVENT_SLACK_INVITE = "event_slack_invite"
EVENT_REGISTRATION_REMINDER = "event_registration_reminder"
EVENT_CONFIRMATION_REMINDER = "event_confirmation_reminder"

EVENT_HACKER_REGISTERED = "event_hacker_registered"
EVENT_HACKER_ACCEPTED = "event_hacker_accepted"
Expand Down
Loading