From e42b29e09887c0ed891afff8f769e9cc7a7aca48 Mon Sep 17 00:00:00 2001 From: Joel Ros Date: Mon, 4 Nov 2024 11:38:39 +0100 Subject: [PATCH 1/2] 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() + From 0bfa3461411e3c839490c09612e4469766c76c7f Mon Sep 17 00:00:00 2001 From: github-actions Date: Mon, 4 Nov 2024 10:39:43 +0000 Subject: [PATCH 2/2] Automated autoyapf fixes --- src/impl/Event/router_v1.py | 4 +++- src/impl/Event/service.py | 20 ++++++++++---------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/impl/Event/router_v1.py b/src/impl/Event/router_v1.py index d751e87..e4208dc 100644 --- a/src/impl/Event/router_v1.py +++ b/src/impl/Event/router_v1.py @@ -354,10 +354,12 @@ 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) + 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 ff158d7..17967dc 100644 --- a/src/impl/Event/service.py +++ b/src/impl/Event/service.py @@ -687,14 +687,14 @@ def accept_group(self, event_id: int, group_id: int, data: BaseToken): self.accept_hacker(event.id, hacker_user.id, data) @BaseService.needs_service(MailClient) - def resend_mails(self,event_id:int,data:BaseToken): + 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: + for hacker in event.accepted_hackers: hacker_registration = db.session.query(HackerRegistration).filter( HackerRegistration.user_id == hacker.id, HackerRegistration.event_id == event.id).first() @@ -702,12 +702,12 @@ def resend_mails(self,event_id:int,data:BaseToken): 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() + 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()