fix(academic): commission subjects and shared careers mapping, role-based scoping and gradebook milestones (v3.8.20)
This commit is contained in:
@@ -5,6 +5,7 @@ Provides endpoints for listing, retrieving, creating, updating and toggling clas
|
||||
"""
|
||||
from typing import Optional
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query, status
|
||||
from sqlalchemy import or_
|
||||
|
||||
from app import db
|
||||
from app.models.classroom import Classroom
|
||||
@@ -60,11 +61,48 @@ def list_classrooms(
|
||||
|
||||
|
||||
@classrooms_router.get("/virtual-rooms")
|
||||
def get_virtual_rooms(current_user: User = Depends(get_current_user)):
|
||||
"""Retorna el catálogo consolidado de salas virtuales operativas en el Campus Virtual."""
|
||||
def get_virtual_rooms(
|
||||
teacher_id: Optional[int] = Query(None),
|
||||
student_id: Optional[int] = Query(None),
|
||||
mine: Optional[bool] = Query(None),
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""Retorna el catálogo consolidado de salas virtuales operativas en el Campus Virtual con scoping por rol."""
|
||||
user_role = (getattr(current_user, 'role', '') or '').lower()
|
||||
user_id = getattr(current_user, 'id', None)
|
||||
|
||||
# Scoping automático por rol
|
||||
target_teacher_id = teacher_id
|
||||
target_student_id = student_id
|
||||
if mine or (mine is None and user_role == 'docente'):
|
||||
target_teacher_id = user_id
|
||||
elif mine or (mine is None and user_role in ['alumno', 'estudiante']):
|
||||
target_student_id = user_id
|
||||
|
||||
stats = dashboard_service.get_stats(current_user=current_user)
|
||||
vrooms = stats.get('bedelia', {}).get('virtual_rooms', [])
|
||||
|
||||
if target_teacher_id:
|
||||
from app.models.commission import Commission, CommissionTeacher
|
||||
my_comm_ids = set(
|
||||
c.id for c in Commission.query.filter(
|
||||
or_(
|
||||
Commission.teacher_id == target_teacher_id,
|
||||
Commission.teachers_association.any(CommissionTeacher.user_id == target_teacher_id)
|
||||
)
|
||||
).all()
|
||||
)
|
||||
vrooms = [r for r in vrooms if r.get('commission_id') in my_comm_ids or r.get('id') in my_comm_ids]
|
||||
elif target_student_id:
|
||||
from app.models.academic import StudentEnrollment
|
||||
enrolled_comm_ids = set(
|
||||
e.commission_id for e in StudentEnrollment.query.filter(
|
||||
StudentEnrollment.student_id == target_student_id,
|
||||
StudentEnrollment.status.in_(['active', 'regular', 'enrolled', 'promoted'])
|
||||
).all()
|
||||
)
|
||||
vrooms = [r for r in vrooms if r.get('commission_id') in enrolled_comm_ids or r.get('id') in enrolled_comm_ids]
|
||||
|
||||
today_cnt = sum(r.get('today_classes', 0) for r in vrooms)
|
||||
week_cnt = sum(r.get('week_classes', 0) for r in vrooms)
|
||||
month_cnt = sum(r.get('month_classes', 0) for r in vrooms)
|
||||
|
||||
Reference in New Issue
Block a user