fix(qa): resolver diagnosticos estaticos, sincronizacion moodle y actualizar docs v3.6.4
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
from flask import Blueprint, jsonify, request, g
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timezone
|
||||
import re
|
||||
from app.utils.jwt_decorators import jwt_required
|
||||
from app.models.user import User
|
||||
@@ -599,7 +599,17 @@ def create_role():
|
||||
data = request.get_json(silent=True) or request.form.to_dict() or {}
|
||||
name = data.get('name', '').strip()
|
||||
description = data.get('description', '').strip()
|
||||
permissions = data.get('permissions', {})
|
||||
raw_perms = data.get('permissions', {})
|
||||
if isinstance(raw_perms, str):
|
||||
try:
|
||||
import json
|
||||
permissions = json.loads(raw_perms)
|
||||
except Exception:
|
||||
permissions = {}
|
||||
elif isinstance(raw_perms, dict):
|
||||
permissions = raw_perms
|
||||
else:
|
||||
permissions = {}
|
||||
|
||||
if not name:
|
||||
return jsonify({'error': 'ValidationError', 'message': 'El nombre del rol es obligatorio.'}), 400
|
||||
@@ -1938,7 +1948,7 @@ def get_all_settings():
|
||||
|
||||
smtp_config = {
|
||||
'host': SystemSetting.get_value('smtp_host', 'smtp.gmail.com'),
|
||||
'port': int(SystemSetting.get_value('smtp_port', 587)),
|
||||
'port': int(SystemSetting.get_value('smtp_port', 587) or 587),
|
||||
'user': SystemSetting.get_value('smtp_user', ''),
|
||||
'password': SystemSetting.get_masked_value('smtp_password', ''),
|
||||
'security': SystemSetting.get_value('smtp_security', 'STARTTLS'),
|
||||
@@ -1966,9 +1976,9 @@ def get_all_settings():
|
||||
moodle_config = {
|
||||
'server_url': SystemSetting.get_value('moodle_server_url', 'http://10.0.0.207/moodle'),
|
||||
'ws_token': SystemSetting.get_masked_value('moodle_ws_token', ''),
|
||||
'timeout': int(SystemSetting.get_value('moodle_timeout', 10)),
|
||||
'timeout': int(SystemSetting.get_value('moodle_timeout', 10) or 10),
|
||||
'auto_sync_enabled': SystemSetting.get_value('moodle_auto_sync_enabled', 'true') in ['true', 'True', '1', True],
|
||||
'sync_interval_minutes': int(SystemSetting.get_value('moodle_sync_interval_minutes', 15))
|
||||
'sync_interval_minutes': int(SystemSetting.get_value('moodle_sync_interval_minutes', 15) or 15)
|
||||
}
|
||||
|
||||
ui_config = {
|
||||
@@ -2051,13 +2061,14 @@ def test_smtp_connection():
|
||||
test_recipient = data.get('test_email') or g.jwt_user.email
|
||||
|
||||
host = data.get('host') or SystemSetting.get_value('smtp_host', 'smtp.gmail.com')
|
||||
port = int(data.get('port') or SystemSetting.get_value('smtp_port', 587))
|
||||
port = int(data.get('port') or SystemSetting.get_value('smtp_port', 587) or 587)
|
||||
user = data.get('user') or SystemSetting.get_value('smtp_user', '')
|
||||
password = data.get('password')
|
||||
if not password or password == '••••••••••••':
|
||||
password = SystemSetting.get_decrypted_value('smtp_password', '')
|
||||
security = (data.get('security') or SystemSetting.get_value('smtp_security', 'STARTTLS')).upper()
|
||||
sender_email = data.get('sender_email') or SystemSetting.get_value('smtp_sender_email', user)
|
||||
security_val = data.get('security') or SystemSetting.get_value('smtp_security', 'STARTTLS') or 'STARTTLS'
|
||||
security = str(security_val).upper()
|
||||
sender_email = str(data.get('sender_email') or SystemSetting.get_value('smtp_sender_email', user) or 'notificaciones@unicaba.edu.ar')
|
||||
sender_name = data.get('sender_name') or SystemSetting.get_value('smtp_sender_name', 'Edu-Space UniCABA')
|
||||
|
||||
if not host or not port:
|
||||
@@ -2719,7 +2730,7 @@ def update_building(id):
|
||||
building.is_active = is_active.lower() in ['true', '1', 'on']
|
||||
else:
|
||||
building.is_active = bool(is_active)
|
||||
building.updated_at = datetime.utcnow()
|
||||
building.updated_at = datetime.now(timezone.utc).replace(tzinfo=None)
|
||||
|
||||
if old_name != name:
|
||||
Classroom.query.filter_by(building_id=building.id).update({'building': name})
|
||||
@@ -2750,7 +2761,7 @@ def toggle_building(id):
|
||||
return jsonify({'error': 'NotFound', 'message': f'Edificio con ID {id} no encontrado.'}), 404
|
||||
|
||||
building.is_active = not building.is_active
|
||||
building.updated_at = datetime.utcnow()
|
||||
building.updated_at = datetime.now(timezone.utc).replace(tzinfo=None)
|
||||
db.session.commit()
|
||||
|
||||
AuditService.log(
|
||||
|
||||
@@ -7,7 +7,7 @@ OPENAPI_SPEC = {
|
||||
"info": {
|
||||
"title": "Edu-Space REST API",
|
||||
"description": "Enterprise Academic & Physical Space Management REST API with JWT Authentication and Role-Based Access Control.",
|
||||
"version": "3.6.3"
|
||||
"version": "3.6.4"
|
||||
},
|
||||
"servers": [
|
||||
{
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from flask import Blueprint, request, jsonify, g
|
||||
from datetime import datetime, timedelta, date
|
||||
from datetime import datetime, timedelta, date, timezone
|
||||
from pydantic import ValidationError
|
||||
|
||||
from app import db
|
||||
@@ -20,7 +20,7 @@ def list_reservations():
|
||||
end_str = request.args.get('end_date')
|
||||
classroom_id = request.args.get('classroom_id', type=int)
|
||||
|
||||
now = datetime.utcnow()
|
||||
now = datetime.now(timezone.utc).replace(tzinfo=None)
|
||||
try:
|
||||
start_dt = datetime.strptime(start_str, '%Y-%m-%d') if start_str else now.replace(hour=0, minute=0, second=0)
|
||||
except ValueError:
|
||||
@@ -42,7 +42,7 @@ def list_reservations():
|
||||
is_virt = bool(r.is_virtual or (r.classroom and r.classroom.is_virtual))
|
||||
if hide_virtual and is_virt:
|
||||
continue
|
||||
if floor and r.classroom and str(r.classroom.floor).strip().lower() != str(floor).strip().lower():
|
||||
if floor and r.classroom and str(r.classroom.floor or '').strip().lower() != floor.strip().lower():
|
||||
continue
|
||||
if shift and r.shift and shift.lower() not in r.shift.lower():
|
||||
continue
|
||||
|
||||
@@ -127,9 +127,9 @@ def update_theme_api():
|
||||
def change_password():
|
||||
"""Change user password"""
|
||||
if request.method == 'POST':
|
||||
current_password = request.form.get('current_password')
|
||||
new_password = request.form.get('new_password')
|
||||
confirm_password = request.form.get('confirm_password')
|
||||
current_password = request.form.get('current_password') or ''
|
||||
new_password = request.form.get('new_password') or ''
|
||||
confirm_password = request.form.get('confirm_password') or ''
|
||||
|
||||
if not current_user.check_password(current_password):
|
||||
flash('Current password is incorrect.', 'error')
|
||||
|
||||
@@ -5,7 +5,7 @@ from app.models.building import Building
|
||||
from app.models.classroom import Classroom
|
||||
from app.forms.building import BuildingForm
|
||||
from app.utils.decorators import permission_required
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timezone
|
||||
|
||||
buildings_bp = Blueprint('buildings', __name__, url_prefix='/buildings')
|
||||
|
||||
@@ -139,7 +139,7 @@ def edit_building(id):
|
||||
building.floors = form.floors.data
|
||||
building.description = form.description.data.strip() if form.description.data else None
|
||||
building.is_active = form.is_active.data
|
||||
building.updated_at = datetime.utcnow()
|
||||
building.updated_at = datetime.now(timezone.utc).replace(tzinfo=None)
|
||||
|
||||
# If name changed, update string building on classrooms
|
||||
if old_name != new_name:
|
||||
@@ -162,7 +162,7 @@ def toggle_building(id):
|
||||
building = Building.query.get_or_404(id)
|
||||
try:
|
||||
building.is_active = not building.is_active
|
||||
building.updated_at = datetime.utcnow()
|
||||
building.updated_at = datetime.now(timezone.utc).replace(tzinfo=None)
|
||||
db.session.commit()
|
||||
status_text = 'activado' if building.is_active else 'desactivado'
|
||||
flash(f'Edificio "{building.name}" {status_text} con éxito.', 'success')
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from flask import Blueprint, render_template, redirect, url_for, flash, request, jsonify
|
||||
from flask_login import login_required, current_user
|
||||
from datetime import datetime, date
|
||||
from datetime import datetime, date, timezone, timedelta
|
||||
import calendar
|
||||
from app.models.classroom import Classroom
|
||||
from app.models.user import User
|
||||
from app.forms.classroom import ClassroomForm
|
||||
@@ -119,13 +120,13 @@ def list_classrooms():
|
||||
virtual_bldg_id = virtual_building.id if virtual_building else None
|
||||
|
||||
# Si el usuario seleccionó "Campus Virtual" en el filtro de edificios, conmutar a pestaña virtual
|
||||
if building_filter and str(building_filter) == str(virtual_bldg_id):
|
||||
if building_filter and building_filter == str(virtual_bldg_id):
|
||||
view_mode = 'virtual'
|
||||
elif not view_mode:
|
||||
view_mode = 'physical'
|
||||
|
||||
# Fechas operativas (Día, Semana, Mes)
|
||||
today = datetime.utcnow().date()
|
||||
today = datetime.now(timezone.utc).date()
|
||||
today_start = datetime.combine(today, datetime.min.time())
|
||||
today_end = datetime.combine(today, datetime.max.time())
|
||||
|
||||
@@ -156,11 +157,11 @@ def list_classrooms():
|
||||
|
||||
physical_count = physical_query.count()
|
||||
|
||||
if building_filter and building_filter.isdigit() and str(building_filter) != str(virtual_bldg_id):
|
||||
if building_filter and building_filter.isdigit() and building_filter != str(virtual_bldg_id):
|
||||
physical_query = physical_query.filter(Classroom.building_id == int(building_filter))
|
||||
|
||||
if floor_filter:
|
||||
flr = str(floor_filter).strip()
|
||||
flr = floor_filter.strip()
|
||||
if flr.upper() in ['0', 'PB', 'PLANTA BAJA']:
|
||||
physical_query = physical_query.filter(db.or_(Classroom.floor == '0', Classroom.floor.ilike('%PB%'), Classroom.floor.ilike('%Planta Baja%')))
|
||||
else:
|
||||
@@ -209,14 +210,14 @@ def list_classrooms():
|
||||
c_res = [r for r in month_reservations if r.classroom_id == c.id]
|
||||
day_res = [r for r in c_res if today_start <= r.start_time <= today_end]
|
||||
day_mins = sum((min(r.end_time, today_end) - max(r.start_time, today_start)).total_seconds() / 60 for r in day_res)
|
||||
day_pct = min(100, int(round((day_mins / DAILY_OP_MINS) * 100)))
|
||||
day_pct = min(100, round((day_mins / DAILY_OP_MINS) * 100))
|
||||
|
||||
week_res = [r for r in c_res if week_start <= r.start_time <= week_end]
|
||||
week_mins = sum((min(r.end_time, week_end) - max(r.start_time, week_start)).total_seconds() / 60 for r in week_res)
|
||||
week_pct = min(100, int(round((week_mins / WEEKLY_OP_MINS) * 100)))
|
||||
week_pct = min(100, round((week_mins / WEEKLY_OP_MINS) * 100))
|
||||
|
||||
month_mins = sum((min(r.end_time, month_end) - max(r.start_time, month_start)).total_seconds() / 60 for r in c_res)
|
||||
month_pct = min(100, int(round((month_mins / MONTHLY_OP_MINS) * 100)))
|
||||
month_pct = min(100, round((month_mins / MONTHLY_OP_MINS) * 100))
|
||||
|
||||
occupancy_metrics[c.id] = {
|
||||
'day_pct': day_pct,
|
||||
@@ -348,7 +349,7 @@ def view_classroom(id):
|
||||
|
||||
upcoming_reservations = Reservation.query.filter(
|
||||
Reservation.classroom_id == id,
|
||||
Reservation.start_time > datetime.utcnow(),
|
||||
Reservation.start_time > datetime.now(timezone.utc).replace(tzinfo=None),
|
||||
Reservation.status == ReservationStatus.CONFIRMED.value
|
||||
).order_by(Reservation.start_time).limit(10).all()
|
||||
|
||||
@@ -432,7 +433,7 @@ def edit_classroom(id):
|
||||
classroom.capacity = cap_val
|
||||
classroom.description = form.description.data
|
||||
classroom.is_active = form.is_active.data
|
||||
classroom.updated_at = datetime.utcnow()
|
||||
classroom.updated_at = datetime.now(timezone.utc).replace(tzinfo=None)
|
||||
|
||||
db.session.commit()
|
||||
|
||||
@@ -453,7 +454,7 @@ def toggle_classroom(id):
|
||||
|
||||
try:
|
||||
classroom.is_active = not classroom.is_active
|
||||
classroom.updated_at = datetime.utcnow()
|
||||
classroom.updated_at = datetime.now(timezone.utc).replace(tzinfo=None)
|
||||
db.session.commit()
|
||||
|
||||
status = 'activated' if classroom.is_active else 'deactivated'
|
||||
|
||||
+12
-10
@@ -5,7 +5,7 @@ from app.models.reservation import Reservation
|
||||
from app.models.classroom import Classroom
|
||||
from app.models.subject import Subject
|
||||
from app.models.subject import Commission
|
||||
from datetime import datetime, timedelta
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from sqlalchemy import func
|
||||
from flask_babel import gettext as _
|
||||
|
||||
@@ -28,7 +28,7 @@ def dashboard():
|
||||
else:
|
||||
role = actual_role
|
||||
|
||||
today = datetime.utcnow().date()
|
||||
today = datetime.now(timezone.utc).date()
|
||||
|
||||
# Common core statistics
|
||||
try:
|
||||
@@ -87,9 +87,10 @@ def dashboard():
|
||||
recent_audits = []
|
||||
|
||||
try:
|
||||
now_dt = datetime.now(timezone.utc).replace(tzinfo=None)
|
||||
upcoming_reservations = Reservation.query.filter(
|
||||
Reservation.start_time >= datetime.utcnow(),
|
||||
Reservation.start_time <= datetime.utcnow() + timedelta(days=7)
|
||||
Reservation.start_time >= now_dt,
|
||||
Reservation.start_time <= now_dt + timedelta(days=7)
|
||||
).order_by(Reservation.start_time.asc()).limit(8).all()
|
||||
except Exception:
|
||||
upcoming_reservations = []
|
||||
@@ -158,7 +159,7 @@ def dashboard():
|
||||
try:
|
||||
my_upcoming_reservations = Reservation.query.filter(
|
||||
Reservation.user_id == current_user.id,
|
||||
Reservation.start_time >= datetime.utcnow()
|
||||
Reservation.start_time >= datetime.now(timezone.utc).replace(tzinfo=None)
|
||||
).order_by(Reservation.start_time.asc()).limit(8).all()
|
||||
except Exception:
|
||||
my_upcoming_reservations = []
|
||||
@@ -200,7 +201,7 @@ def dashboard():
|
||||
|
||||
try:
|
||||
upcoming_milestones = AcademicMilestone.query.filter(
|
||||
AcademicMilestone.date >= datetime.utcnow(),
|
||||
AcademicMilestone.date >= datetime.now(timezone.utc).replace(tzinfo=None),
|
||||
AcademicMilestone.is_active == True
|
||||
).order_by(AcademicMilestone.date.asc()).limit(6).all()
|
||||
except Exception:
|
||||
@@ -227,9 +228,10 @@ def dashboard():
|
||||
upcoming_reservations = role_data.get('upcoming_reservations', [])
|
||||
if not upcoming_reservations:
|
||||
try:
|
||||
now_dt = datetime.now(timezone.utc).replace(tzinfo=None)
|
||||
upcoming_reservations = Reservation.query.filter(
|
||||
Reservation.start_time >= datetime.utcnow(),
|
||||
Reservation.start_time <= datetime.utcnow() + timedelta(days=7)
|
||||
Reservation.start_time >= now_dt,
|
||||
Reservation.start_time <= now_dt + timedelta(days=7)
|
||||
).order_by(Reservation.start_time.asc()).limit(6).all()
|
||||
except Exception:
|
||||
upcoming_reservations = []
|
||||
@@ -246,7 +248,7 @@ def dashboard():
|
||||
def dashboard_stats_api():
|
||||
"""API endpoint for dashboard statistics"""
|
||||
# Get today's data
|
||||
today = datetime.utcnow().date()
|
||||
today = datetime.now(timezone.utc).date()
|
||||
today_reservations = Reservation.query.filter(
|
||||
func.date(Reservation.start_time) == today
|
||||
).count()
|
||||
@@ -260,7 +262,7 @@ def dashboard_stats_api():
|
||||
).count()
|
||||
|
||||
# Get monthly data for chart
|
||||
current_date = datetime.utcnow()
|
||||
current_date = datetime.now(timezone.utc).replace(tzinfo=None)
|
||||
monthly_data = []
|
||||
|
||||
for i in range(12):
|
||||
|
||||
@@ -99,14 +99,14 @@ def my_subject_detail(commission_id):
|
||||
# Try to get classroom info from reservations linked to this commission
|
||||
from app.models.reservation import Reservation
|
||||
from sqlalchemy import func
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timezone
|
||||
|
||||
# Recent or upcoming reservation linked to this commission
|
||||
recent_reservation = (
|
||||
Reservation.query
|
||||
.filter(
|
||||
Reservation.commission_id == commission_id,
|
||||
Reservation.start_time >= datetime.utcnow()
|
||||
Reservation.start_time >= datetime.now(timezone.utc).replace(tzinfo=None)
|
||||
)
|
||||
.order_by(Reservation.start_time.asc())
|
||||
.first()
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
from flask import Blueprint, render_template, request, redirect, url_for, flash, jsonify
|
||||
from flask_login import login_required, current_user
|
||||
from flask_babel import gettext as _
|
||||
from app import db
|
||||
from app.models.reservation import Reservation, ReservationStatus
|
||||
from app.models.classroom import Classroom
|
||||
from app.models.subject import Subject, Commission
|
||||
from app.forms.reservation import ReservationForm
|
||||
from datetime import datetime, timedelta, date
|
||||
from datetime import datetime, timedelta, date, timezone
|
||||
from typing import Dict, Any
|
||||
from sqlalchemy import func, or_
|
||||
from sqlalchemy.orm import joinedload
|
||||
|
||||
@@ -15,7 +17,7 @@ schedule_bp = Blueprint('schedule', __name__, url_prefix='/schedule')
|
||||
@login_required
|
||||
def today_schedule():
|
||||
"""Show today's schedule with filters for virtual classrooms, floor, and shift"""
|
||||
today = datetime.utcnow().date()
|
||||
today = datetime.now(timezone.utc).date()
|
||||
today_start = datetime.combine(today, datetime.min.time())
|
||||
today_end = datetime.combine(today, datetime.max.time())
|
||||
|
||||
@@ -26,7 +28,7 @@ def today_schedule():
|
||||
# Base query for today's reservations
|
||||
query = Reservation.query.options(
|
||||
joinedload(Reservation.classroom),
|
||||
joinedload(Reservation.commission).joinedload(Commission.subject),
|
||||
joinedload(Reservation.commission),
|
||||
joinedload(Reservation.user)
|
||||
).join(Reservation.classroom).filter(
|
||||
Reservation.start_time >= today_start,
|
||||
@@ -41,7 +43,7 @@ def today_schedule():
|
||||
)
|
||||
|
||||
if floor_filter:
|
||||
flr = str(floor_filter).strip()
|
||||
flr = floor_filter.strip()
|
||||
if flr.upper() in ['0', 'PB', 'PLANTA BAJA']:
|
||||
query = query.filter(or_(Classroom.floor == '0', Classroom.floor.ilike('%PB%'), Classroom.floor.ilike('%Planta Baja%')))
|
||||
else:
|
||||
@@ -609,7 +611,7 @@ def list_reservations():
|
||||
|
||||
query = Reservation.query.options(
|
||||
joinedload(Reservation.classroom),
|
||||
joinedload(Reservation.commission).joinedload(Commission.subject),
|
||||
joinedload(Reservation.commission),
|
||||
joinedload(Reservation.user)
|
||||
).join(Reservation.classroom).outerjoin(Reservation.commission).outerjoin(Commission.subject)
|
||||
|
||||
@@ -640,7 +642,7 @@ def list_reservations():
|
||||
)
|
||||
|
||||
if floor_filter:
|
||||
flr = str(floor_filter).strip()
|
||||
flr = floor_filter.strip()
|
||||
if flr.upper() in ['0', 'PB', 'PLANTA BAJA']:
|
||||
query = query.filter(or_(Classroom.floor == '0', Classroom.floor.ilike('%PB%'), Classroom.floor.ilike('%Planta Baja%')))
|
||||
else:
|
||||
@@ -742,7 +744,7 @@ def classroom_availability_api():
|
||||
best_recommendation = best_classrooms[0] # Most efficient one
|
||||
|
||||
# Format response
|
||||
response = {
|
||||
response: Dict[str, Any] = {
|
||||
'availability': {
|
||||
'available': [
|
||||
{
|
||||
@@ -829,7 +831,7 @@ def calendar_data():
|
||||
|
||||
query = Reservation.query.join(Reservation.commission).join(Commission.subject).outerjoin(Reservation.classroom).options(
|
||||
joinedload(Reservation.classroom),
|
||||
joinedload(Reservation.commission).joinedload(Commission.subject).joinedload(Subject.career_obj)
|
||||
joinedload(Reservation.commission)
|
||||
).filter(
|
||||
Reservation.start_time >= start_date,
|
||||
Reservation.start_time <= end_date
|
||||
@@ -850,7 +852,7 @@ def calendar_data():
|
||||
query = query.filter(
|
||||
or_(
|
||||
Classroom.building.ilike(f'%{building}%'),
|
||||
Classroom.building_entity.has(Building.name.ilike(f'%{building}%'))
|
||||
Classroom.building_id.in_(db.session.query(Building.id).filter(Building.name.ilike(f'%{building}%')))
|
||||
)
|
||||
)
|
||||
|
||||
@@ -864,7 +866,7 @@ def calendar_data():
|
||||
)
|
||||
|
||||
if floor:
|
||||
flr = str(floor).strip()
|
||||
flr = floor.strip()
|
||||
if flr.upper() in ['0', 'PB', 'PLANTA BAJA']:
|
||||
query = query.filter(or_(Classroom.floor == '0', Classroom.floor.ilike('%PB%'), Classroom.floor.ilike('%Planta Baja%')))
|
||||
else:
|
||||
@@ -939,7 +941,7 @@ def api_today_events():
|
||||
|
||||
reservations = Reservation.query.options(
|
||||
joinedload(Reservation.classroom),
|
||||
joinedload(Reservation.commission).joinedload(Commission.subject).joinedload(Subject.career_obj)
|
||||
joinedload(Reservation.commission)
|
||||
).filter(
|
||||
Reservation.start_time >= today_start,
|
||||
Reservation.start_time <= today_end
|
||||
|
||||
Reference in New Issue
Block a user