From af969e7cf11ffe9a9bf809fefe9354b48ebcee1e Mon Sep 17 00:00:00 2001 From: Gabriel Faria Date: Mon, 28 Apr 2025 17:04:53 -0300 Subject: [PATCH 1/2] =?UTF-8?q?feat:adicionei=20novas=20telas=20html,=20um?= =?UTF-8?q?a=20nova=20fun=C3=A7=C3=A3o=20chamada=20changes=20e=20um=20novo?= =?UTF-8?q?=20endpoint=20que=20ir=C3=A1=20mostrar=20uma=20tela=20com=20a?= =?UTF-8?q?=20mensagem=20=20informada?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BLL/send_emails.py | 55 ++++++++++++++- src/SLL/administration_approval.py | 20 ++++-- src/SLL/py_log.py | 1 + "src/templates/email/mudan\303\247as.html" | 63 +++++++++++++++++ .../email/mudan\303\247as_prof.html" | 67 +++++++++++++++++++ 5 files changed, 198 insertions(+), 8 deletions(-) create mode 100644 "src/templates/email/mudan\303\247as.html" create mode 100644 "src/templates/email/mudan\303\247as_prof.html" diff --git a/src/BLL/send_emails.py b/src/BLL/send_emails.py index df36e5f..f841cb1 100644 --- a/src/BLL/send_emails.py +++ b/src/BLL/send_emails.py @@ -45,7 +45,7 @@ def send_to_coordenacao(event_id): # Example links (adjust to your routes) with current_app.test_request_context(): - request_changes_link = url_for('templates_bp.request_changes', eventId=event_id, tokenId=tokenId, _external=True) + request_changes_link = url_for('templates_bp.request_changes', eventId=event_id, tokenId=tokenId,who='coordenacao', _external=True) approve_link = url_for('templates_bp.approve', eventId=event_id, tokenId=tokenId, who='coordenacao', _external=True) reject_link = url_for('templates_bp.reject', eventId=event_id, tokenId=tokenId, who='coordenacao', _external=True) @@ -230,6 +230,59 @@ def send_event_status(event_id, is_approved: bool, who: str, token:str): response = requests.post(url, json=payload, headers=headers) return response +def changes(event_id, who: str, token:str): + AppLogger.log( + Logmessage.EVENT_REQUESTED_CHANGES_BY, + LogType.INFO, + event_id=event_id, + action='Request Changes', + who=who, + token=token) + + if who == 'coordenacao': + apply_token_action(0, "Request Changes", event_id, token) + event_status = EventStatus.REQUESTED_CHANGE.value + else: + apply_token_action(1, "Request Changes", event_id, token) + event_status = EventStatus.REQUESTED_CHANGE.value + + event = events_repository.find_by_id(event_id) + email = event["organizer"]["email"] + event.pop("_id", None) + event["status"] = event_status + + #Update event status + reservation_manager = ReservationManager() + reservation_manager.update_event(event_id, event_data=event) + + # Render the template with the appropriate data + html_content = render_template( + "email/mudanças.html", + ) + if os.getenv("FLASK_ENV") == "development": + return html_content + + # Subject line changes based on approval or denial + subject = "Evento Exige Alterações" + + # Prepare the email payload + url = f"{os.getenv('CLOUD_FUNCTION_URL')}/send-email" + payload = { + 'subject': subject, + 'content': html_content, + 'to': [email], + 'is_html': True + } + headers = { + 'X-API-Key': os.getenv('CLOUD_FUNCTION_API_KEY'), + 'Content-Type': 'application/json' + } + + # Send the request to your cloud function + response = requests.post(url, json=payload, headers=headers) + return response + + def verify_token_from_email(tokenId) -> bool: data = send_email_repository.get_send_email_by_token_id(tokenId) diff --git a/src/SLL/administration_approval.py b/src/SLL/administration_approval.py index 87bf9c7..9d863a8 100644 --- a/src/SLL/administration_approval.py +++ b/src/SLL/administration_approval.py @@ -1,7 +1,7 @@ import os -from flask import Blueprint, request, jsonify +from flask import Blueprint, request, jsonify, render_template from BLL import send_to_reitoria, send_to_coordenacao, send_event_status -from BLL.send_emails import verify_token_from_email, apply_token_action +from BLL.send_emails import verify_token_from_email, apply_token_action,changes from functools import wraps # Create a blueprint for handling templates and related routes. templates_bp = Blueprint('templates_bp', __name__, template_folder='../templates') @@ -74,9 +74,15 @@ def request_changes(): who = request.args.get('who') token = request.args.get('tokenId') - if who == 'coordenacao': - apply_token_action(0, "Request Changes", eventId, token) - else: - apply_token_action(1, "Request Changes", eventId, token) - return "Solicitando alterações no evento!" + return changes(eventId, who, token) +@templates_bp.route('/store_changes', methods=['POST']) +def store_changes(): + mudancas = request.form.get('mudancas') + if not mudancas: + return jsonify({'error': 'Faltou fornecer as mudanças.'}), 400 + else: + return render_template( + 'email/mudanças_prof.html', + mensagem=mudancas, + ) diff --git a/src/SLL/py_log.py b/src/SLL/py_log.py index d321485..a0aa9c0 100644 --- a/src/SLL/py_log.py +++ b/src/SLL/py_log.py @@ -40,6 +40,7 @@ class Logmessage(Enum): FAILED_SEND_EMAIL = "Email sender service unavailable: failed to send email; IP: {ip_address}; Email: {email};" SENDING_EMAIL = "Sending email; email: {email}; event: {event}; token: {token};" EVENT_APPROVED_REJECTED_BY = "Event {event_id} {action} by {who}; token: {token};" + EVENT_REQUESTED_CHANGES_BY = "Event {event_id} requested changes by {who}; token: {token};" MISSING_DATA = "Missing data;IP: {ip_address} ;" EVENTS_NOT_FOUND = "Events not found;IP: {ip_address} ;" RESERVATION_NOT_FOUND = "Reservation not found;IP: {ip_address};" diff --git "a/src/templates/email/mudan\303\247as.html" "b/src/templates/email/mudan\303\247as.html" new file mode 100644 index 0000000..3ade261 --- /dev/null +++ "b/src/templates/email/mudan\303\247as.html" @@ -0,0 +1,63 @@ + + + + + Edição Requisitada + + + +
+
+

Mudanças no Evento

+
+

Informe as mudanças para retornar ao requisitante:

+ +

Explique as mudanças:

+
+ +
+ +
+ +
+ + + \ No newline at end of file diff --git "a/src/templates/email/mudan\303\247as_prof.html" "b/src/templates/email/mudan\303\247as_prof.html" new file mode 100644 index 0000000..61b5d7b --- /dev/null +++ "b/src/templates/email/mudan\303\247as_prof.html" @@ -0,0 +1,67 @@ + + + + + Edição Requisitada + + + +
+
+

Mudanças no Evento

+
+ +

Oi Professor(a)

+

+ A Coordenação do curso requisitou algumas mudanças. +

+ +

Mudanças solicitadas:

+
+ {{ mensagem }} +
+ + Ok + +
+ + + \ No newline at end of file From e4d3f08b6afe04c3aa4233f576698e2c2a21dca2 Mon Sep 17 00:00:00 2001 From: Gabriel Faria Date: Wed, 7 May 2025 00:08:07 -0300 Subject: [PATCH 2/2] =?UTF-8?q?ffixcorrigindo=20as=20mudan=C3=A7as=20solic?= =?UTF-8?q?itadas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BLL/send_emails.py | 18 ++++++++---------- src/SLL/administration_approval.py | 4 ++-- .../templates/email/mudancas.html | 2 +- .../templates/email/mudan\303\247as_prof.html" | 4 ++-- 4 files changed, 13 insertions(+), 15 deletions(-) rename "src/templates/email/mudan\303\247as.html" => src/templates/email/mudancas.html (97%) diff --git a/src/BLL/send_emails.py b/src/BLL/send_emails.py index f841cb1..479fec2 100644 --- a/src/BLL/send_emails.py +++ b/src/BLL/send_emails.py @@ -45,7 +45,7 @@ def send_to_coordenacao(event_id): # Example links (adjust to your routes) with current_app.test_request_context(): - request_changes_link = url_for('templates_bp.request_changes', eventId=event_id, tokenId=tokenId,who='coordenacao', _external=True) + request_changes_link = url_for('templates_bp.request_changes', eventId=event_id, tokenId=tokenId,_external=True) approve_link = url_for('templates_bp.approve', eventId=event_id, tokenId=tokenId, who='coordenacao', _external=True) reject_link = url_for('templates_bp.reject', eventId=event_id, tokenId=tokenId, who='coordenacao', _external=True) @@ -230,22 +230,19 @@ def send_event_status(event_id, is_approved: bool, who: str, token:str): response = requests.post(url, json=payload, headers=headers) return response -def changes(event_id, who: str, token:str): +def send_changes_request(event_id, token:str) -> requests.Response: AppLogger.log( Logmessage.EVENT_REQUESTED_CHANGES_BY, LogType.INFO, event_id=event_id, action='Request Changes', - who=who, token=token) - if who == 'coordenacao': - apply_token_action(0, "Request Changes", event_id, token) - event_status = EventStatus.REQUESTED_CHANGE.value - else: - apply_token_action(1, "Request Changes", event_id, token) - event_status = EventStatus.REQUESTED_CHANGE.value + #Aplication of action and change status on DB + apply_token_action(0, "Request Changes", event_id, token) + event_status = EventStatus.REQUESTED_CHANGE.value + #Find event by event_id event = events_repository.find_by_id(event_id) email = event["organizer"]["email"] event.pop("_id", None) @@ -257,7 +254,8 @@ def changes(event_id, who: str, token:str): # Render the template with the appropriate data html_content = render_template( - "email/mudanças.html", + "email/mudancas.html", + event_id=event_id, ) if os.getenv("FLASK_ENV") == "development": return html_content diff --git a/src/SLL/administration_approval.py b/src/SLL/administration_approval.py index 9d863a8..9b53dc4 100644 --- a/src/SLL/administration_approval.py +++ b/src/SLL/administration_approval.py @@ -1,7 +1,7 @@ import os from flask import Blueprint, request, jsonify, render_template from BLL import send_to_reitoria, send_to_coordenacao, send_event_status -from BLL.send_emails import verify_token_from_email, apply_token_action,changes +from BLL.send_emails import verify_token_from_email, apply_token_action,send_changes_request from functools import wraps # Create a blueprint for handling templates and related routes. templates_bp = Blueprint('templates_bp', __name__, template_folder='../templates') @@ -74,7 +74,7 @@ def request_changes(): who = request.args.get('who') token = request.args.get('tokenId') - return changes(eventId, who, token) + return send_changes_request(eventId, who, token) @templates_bp.route('/store_changes', methods=['POST']) def store_changes(): diff --git "a/src/templates/email/mudan\303\247as.html" b/src/templates/email/mudancas.html similarity index 97% rename from "src/templates/email/mudan\303\247as.html" rename to src/templates/email/mudancas.html index 3ade261..baa3f3e 100644 --- "a/src/templates/email/mudan\303\247as.html" +++ b/src/templates/email/mudancas.html @@ -2,7 +2,7 @@ - Edição Requisitada + Requisitar Edição