@@ -972,7 +972,7 @@ def resend_mail(self, event_id: int, hacker_id: int, data: BaseToken):
972972 db .session .commit ()
973973
974974 @BaseService .needs_service (MailClient )
975- def send_slack_mail (self , event_id : int , data : BaseToken ):
975+ def send_slack_mail (self , event_id : int , slackUrl : str , data : BaseToken ):
976976 if not data .check ([UserType .LLEIDAHACKER ]):
977977 raise AuthenticationException ("Not authorized" )
978978 event = self .get_by_id (event_id )
@@ -984,16 +984,81 @@ def send_slack_mail(self, event_id: int, data: BaseToken):
984984 hackers = event .accepted_hackers
985985
986986 for hacker in hackers :
987- self .mail_client .create_mail (
987+ mail = self .mail_client .create_mail (
988988 MailCreate (
989989 template_id = self .mail_client .get_internall_template_id (
990990 InternalTemplate .EVENT_SLACK_INVITE
991991 ),
992992 subject = "HackEPS2024 slack invitation" ,
993993 receiver_id = str (hacker .id ),
994994 receiver_mail = str (hacker .email ),
995- fields = "https://join.slack.com/t/hackeps2024/shared_invite/zt-2usc9qny9-z3NkybNlCXFAI9m0Cl~FsQ" ,
995+ fields = slackUrl ,
996996 )
997997 )
998+ # send the created mail
999+ self .mail_client .send_mail_by_id (mail .id )
9981000
9991001 db .session .commit ()
1002+
1003+ @BaseService .needs_service (MailClient )
1004+ def send_reminder_mails (
1005+ self ,
1006+ event_id : int ,
1007+ data : BaseToken ,
1008+ ):
1009+ if not data .check ([UserType .LLEIDAHACKER ]):
1010+ raise AuthenticationException ("Not authorized" )
1011+ event = self .get_by_id (event_id )
1012+ if event .archived :
1013+ raise InvalidDataException (
1014+ "Unable to operate with an archived event, unarchive it first"
1015+ )
1016+
1017+ hackers = event .accepted_hackers
1018+
1019+ for hacker in hackers :
1020+ try :
1021+ reg = (
1022+ db .session .query (HackerRegistration )
1023+ .filter (
1024+ HackerRegistration .user_id == hacker .id ,
1025+ HackerRegistration .event_id == event .id ,
1026+ )
1027+ .first ()
1028+ )
1029+ # send reminder only if registration exists and assistance not confirmed
1030+ if reg is None or reg .confirmed_assistance :
1031+ continue
1032+
1033+ # ensure there is a confirmation token for this registration
1034+ if not reg .confirm_assistance_token :
1035+ reg .confirm_assistance_token = AssistenceToken (hacker , event .id ).to_token ()
1036+
1037+ # compute days left until event (rounded down)
1038+ try :
1039+ delta = event .start_date - datetime .now ()
1040+ days_left = max (0 , int (delta .total_seconds () // 86400 ))
1041+ except Exception :
1042+ days_left = 0
1043+
1044+ fields = f"{ hacker .name } ,{ event .name } ,{ days_left } ,{ reg .confirm_assistance_token } "
1045+
1046+ mail = self .mail_client .create_mail (
1047+ MailCreate (
1048+ template_id = self .mail_client .get_internall_template_id (
1049+ InternalTemplate .EVENT_HACKER_REMINDER
1050+ ),
1051+ subject = f"{ event .name } - Recordatori de confirmació d'assistència" ,
1052+ receiver_id = str (hacker .id ),
1053+ receiver_mail = str (hacker .email ),
1054+ fields = fields ,
1055+ )
1056+ )
1057+ # send the created mail
1058+ self .mail_client .send_mail_by_id (mail .id )
1059+ db .session .commit ()
1060+ except Exception as e :
1061+ db .session .rollback ()
1062+ # Optionally log the error here, e.g.:
1063+ # print(f"Failed to send reminder to hacker {hacker.id}: {e}")
1064+ continue
0 commit comments