"""Реестр отчётов портала — какие карточки видит пользователь на /reports/.""" from __future__ import annotations from dataclasses import dataclass from typing import Callable from django.contrib.auth.models import AbstractBaseUser from apps.reports.it_monthly.builder import user_can_view_it_monthly_report @dataclass(frozen=True) class ReportSpec: code: str title: str department: str description: str path: str can_view: Callable[[AbstractBaseUser], bool] REPORTS: tuple[ReportSpec, ...] = ( ReportSpec( code='it_monthly', title='Месячный IT-отчёт', department='it', description='Сводка выполненных работ IT-отдела за месяц: сотрудники, объекты, выводы. Экспорт MD/DOCX/PDF.', path='/reports/it/monthly/', can_view=user_can_view_it_monthly_report, ), ) def visible_reports(user) -> list[ReportSpec]: return [spec for spec in REPORTS if spec.can_view(user)] def get_report(code: str) -> ReportSpec | None: for spec in REPORTS: if spec.code == code: return spec return None