diff --git a/src/BLL/send_emails.py b/src/BLL/send_emails.py index df36e5f..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, _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,6 +230,57 @@ def send_event_status(event_id, is_approved: bool, who: str, token:str): response = requests.post(url, json=payload, headers=headers) return response +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', + token=token) + + #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) + 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/mudancas.html", + event_id=event_id, + ) + 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..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 +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,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,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 send_changes_request(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/mudancas.html b/src/templates/email/mudancas.html new file mode 100644 index 0000000..baa3f3e --- /dev/null +++ b/src/templates/email/mudancas.html @@ -0,0 +1,63 @@ + + + + + Requisitar Edição + + + +
+
+

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..8cd3560 --- /dev/null +++ "b/src/templates/email/mudan\303\247as_prof.html" @@ -0,0 +1,67 @@ + + + + + Edição Requisitada pelo Coordenador + + + +
+
+

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