Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 52 additions & 1 deletion src/BLL/send_emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down
20 changes: 13 additions & 7 deletions src/SLL/administration_approval.py
Original file line number Diff line number Diff line change
@@ -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')
Expand Down Expand Up @@ -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,
)
1 change: 1 addition & 0 deletions src/SLL/py_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -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};"
Expand Down
63 changes: 63 additions & 0 deletions src/templates/email/mudancas.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Requisitar Edição</title>
<style>
body {
font-family: Arial, sans-serif;
background: #f9f9f9;
margin: 0;
padding: 20px;
}
.container {
max-width: 600px;
margin: auto;
background: #fff;
border: 1px solid #ddd;
padding: 20px;
text-align: center;
}
.header {
background: #0D5580;
color: #fff;
padding: 10px;
margin: -20px -20px 20px;
}
.header h1 {
margin: 0;
}
.button {
text-decoration: none;
margin: 0 5px;
}
.button img {
vertical-align: middle;
border: none;
}
.icon {
margin: 20px 0;
}



</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>Mudanças no Evento</h1>
</div>
<p>Informe as mudanças para retornar ao requisitante:</p>

<p>Explique as mudanças:</p>
<form action="/store_changes" method="post">
<textarea name="mudancas" rows="4" cols="50" placeholder="Digite as mudanças aqui..."></textarea>
<br>
<button type="submit" style="background-color: #28a745; border: none; border-radius: 25px; padding: 10px 40px; color: #fff; font-size: 16px;">Send</button>
</form>

</div>

</body>
</html>
67 changes: 67 additions & 0 deletions src/templates/email/mudanças_prof.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<!DOCTYPE html>
<html lang="pt-BR">
<head>
<meta charset="UTF-8">
<title>Edição Requisitada pelo Coordenador</title>
<style>
body {
font-family: Arial, sans-serif;
background: #f9f9f9;
margin: 0;
padding: 20px;
}
.container {
max-width: 600px;
margin: auto;
background: #fff;
border: 1px solid #ddd;
padding: 20px;
text-align: center;
}
.header {
background: #0D5580;
color: #fff;
padding: 10px;
margin: -20px -20px 20px;
}
.header h1 {
margin: 0;
}
.button {
text-decoration: none;
margin: 0 5px;
}
.button img {
vertical-align: middle;
border: none;
}
.icon {
margin: 20px 0;
}



</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>Mudanças no Evento</h1>
</div>

<p>Oi Professor(a)</p>
<p>
A Coordenação do curso requisitou algumas mudanças.
</p>

<p>Mudanças solicitadas:</p>
<div style="background-color: #f5f5f5; border: 1px solid #ddd; padding: 15px; margin: 20px 0; text-align: left; border-radius: 5px;">
{{ mensagem }}
</div>

<a href="{{ os.getenv('REACT_APP') }}/event/type-selection?eventId={{ event_id }}" style="background-color: #28a745; border: none; border-radius: 25px; padding: 10px 40px; color: #fff; font-size: 16px; text-decoration: none; display: inline-block;">Ok</a>

</div>

</body>
</html>