From e42b29e09887c0ed891afff8f769e9cc7a7aca48 Mon Sep 17 00:00:00 2001 From: Joel Ros Date: Mon, 4 Nov 2024 11:38:39 +0100 Subject: [PATCH] fix --- src/impl/Event/router_v1.py | 4 ++++ src/impl/Event/service.py | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/impl/Event/router_v1.py b/src/impl/Event/router_v1.py index f95138f..d751e87 100644 --- a/src/impl/Event/router_v1.py +++ b/src/impl/Event/router_v1.py @@ -354,6 +354,10 @@ def get_pending_hackers_gruped(event_id: int, token: BaseToken = Depends(JWTBearer())): return event_service.get_pending_hackers_gruped(event_id, token) +@router.get("/{event_id}/resend-accepted-mails") +def resend_accept_mails(event_id: int, + token: BaseToken = Depends(JWTBearer())): + return event_service.resend_mails(event_id,token) # @router.post("/{event_id}/send_remember") # def send_remember( diff --git a/src/impl/Event/service.py b/src/impl/Event/service.py index cf48d3d..3da001b 100644 --- a/src/impl/Event/service.py +++ b/src/impl/Event/service.py @@ -685,3 +685,29 @@ def accept_group(self, event_id: int, group_id: int, data: BaseToken): raise InvalidDataException("Hacker not registered") hacker_user = self.hacker_service.get_by_id(hacker.id) self.accept_hacker(event.id, hacker_user.id, data) + + @BaseService.needs_service(MailClient) + def resend_mails(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") + for hacker in event.accepted_hackers: + hacker_registration = db.session.query(HackerRegistration).filter( + HackerRegistration.user_id == hacker.id, + HackerRegistration.event_id == event.id).first() + token = AssistenceToken(hacker, event.id).to_token() + hacker_registration.confirm_assistance_token = token + + mail = self.mail_client.create_mail( + MailCreate(template_id=self.mail_client.get_internall_template_id( + InternalTemplate.EVENT_HACKER_ACCEPTED), + subject='You have been accepted', + receiver_id=str(hacker.id), + receiver_mail=str(hacker.email), + fields=f'{hacker.name},{event.name},5,{token}')) + + db.session.commit() +