def copy_and_create_report(report: Report, subject_id: SubjectId) -> Report: report_service.redress_storable_id(report) report.subjectId = subject_id report.connectId = connected_space.connectId report.userId = connected_space.userId report.tenantId = connected_space.tenantId report.lastVisitTime = now # remove thumbnail report.simulateThumbnail = None # noinspection PyTypeChecker return report_service.create(report)
def action(report: Report) -> Report: report.userId = principal_service.get_user_id() report.tenantId = principal_service.get_tenant_id() report.lastVisitTime = get_current_time_in_seconds() if report.simulating is None: report.simulating = False if report_service.is_storable_id_faked(report.reportId): subject_id = report.subjectId if is_blank(subject_id): raise_400('Subject id is required.') subject_service = get_subject_service(report_service) existing_subject: Optional[Subject] = subject_service.find_by_id(subject_id) if existing_subject is None: raise_400('Incorrect subject id.') elif existing_subject.tenantId != report.tenantId or existing_subject.userId != report.userId: raise_403() else: report.connectId = existing_subject.connectId report_service.redress_storable_id(report) # noinspection PyTypeChecker report: Report = report_service.create(report) else: # noinspection PyTypeChecker existing_report: Optional[Report] = report_service.find_by_id(report.reportId) if existing_report is not None: if existing_report.tenantId != report.tenantId: raise_403() if existing_report.userId != report.userId: raise_403() report.subjectId = existing_report.subjectId report.connectId = existing_report.connectId # noinspection PyTypeChecker report: Report = report_service.update(report) return report