Skip to content
Merged
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
2 changes: 1 addition & 1 deletion server/shared
Submodule shared updated 35 files
+10 −0 .github/skills/ops-tracking/SKILL.md
+26 −0 .github/workflows/test.yml
+2 −0 .gitignore
+3 −1 AGENTS.md
+4 −2 app/base-app.module.ts
+3 −3 auth/__tests__/auth.service.spec.ts
+0 −1 auth/__tests__/local-register-auth.guard.spec.ts
+1 −2 base-entity/__tests__/base-entity.module.spec.ts
+44 −0 base-entity/__tests__/base-entity.service.get-selected-ids.spec.ts
+43 −8 base-entity/__tests__/base-entity.service.spec.ts
+27 −11 base-entity/base-entity.service.ts
+11 −0 jest.config.js
+106 −14 mcp/__tests__/mcp.controller.spec.ts
+4 −1 mcp/mcp.module.ts
+16 −0 mcp/mcp.types.ts
+1 −1 mcp/oauth/mcp-auth.middleware.ts
+64 −15 mcp/oauth/mcp-login-page.ts
+44 −5 mcp/oauth/mcp-oauth.controller.ts
+39 −6 mcp/oauth/mcp-oauth.provider.ts
+82 −0 package.json
+25 −0 tsconfig.json
+2 −2 utils/entity/fixTimezoneShift.util.ts
+0 −5 utils/exporter/__tests__/exporter.util.spec.ts
+0 −1 utils/importer/__tests__/importer.util.spec.ts
+21 −0 utils/logging/__tests__/all-exceptions.filter.spec.ts
+18 −0 utils/logging/all-exceptions.filter.ts
+1 −2 utils/report/__tests__/bulk-mail-file.util.spec.ts
+117 −11 utils/report/__tests__/markup-to-pdf.generator.spec.ts
+174 −0 utils/report/__tests__/pdf-render.queue.spec.ts
+160 −0 utils/report/__tests__/pdf-render.scope.spec.ts
+15 −9 utils/report/bulk-to-pdf.generator.ts
+126 −45 utils/report/markup-to-pdf.generator.ts
+218 −0 utils/report/pdf-render.queue.ts
+1 −1 utils/reportData.util.ts
+8,637 −0 yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,14 @@ describe('att-report-with-report-month.config', () => {
// Mock getOne on the service instance itself since it calls this.getOne()
service.getOne = jest.fn().mockResolvedValue({ id: 1, reportDate: '2022-01-01' });
// By default every selected id is accessible to the caller
service.getManyByIds = jest.fn().mockImplementation((req, ids) => Promise.resolve(ids.map((id) => ({ id }))));
service.getSelectedIds = jest.fn().mockImplementation((req) =>
Promise.resolve(
String(req.parsed.extra.ids ?? '')
.split(',')
.filter(Boolean)
.map(Number),
),
);

mockBaseCreateOne.mockClear();
mockBaseCreateMany.mockClear();
Expand Down Expand Up @@ -155,19 +162,19 @@ describe('att-report-with-report-month.config', () => {
});

it('bulkKnownAbsences should only use ids the caller can access', async () => {
service.getManyByIds.mockResolvedValueOnce([{ id: 1 }]);
service.getSelectedIds.mockResolvedValueOnce([1]);
mockRepo.findBy.mockResolvedValueOnce([]);
const req = { parsed: { extra: { action: 'bulkKnownAbsences', ids: '1,99' } } } as any;

// An empty insert fails validation; only the lookup matters here
await service.doAction(req, {}).catch(() => undefined);

expect(service.getManyByIds).toHaveBeenCalledWith(req, [1, 99]);
expect(service.getSelectedIds).toHaveBeenCalledWith(req);
expect(mockRepo.findBy.mock.calls[0][0].id.value).toEqual([1]);
});

it('bulkKnownAbsences should do nothing when no selected id is accessible', async () => {
service.getManyByIds.mockResolvedValueOnce([]);
service.getSelectedIds.mockResolvedValueOnce([]);
const req = { parsed: { extra: { action: 'bulkKnownAbsences', ids: '99' } } } as any;

const result = await service.doAction(req, {});
Expand Down
11 changes: 9 additions & 2 deletions server/src/entity-modules/__tests__/student-klass.config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,14 @@ describe('StudentKlassConfig', () => {
const Service = config.service;
service = new Service(mockRepository as Repository<StudentKlass>, mockMailService);
service.dataSource = mockDataSource as DataSource;
service.getManyByIds = jest.fn().mockImplementation((req, ids) => Promise.resolve(ids.map((id) => ({ id }))));
service.getSelectedIds = jest.fn().mockImplementation((req) =>
Promise.resolve(
String(req.parsed.extra.ids ?? '')
.split(',')
.filter(Boolean)
.map(Number),
),
);
});

describe('getReportData', () => {
Expand Down Expand Up @@ -228,7 +235,7 @@ describe('StudentKlassConfig', () => {

it('should only fix references of ids the caller can access', async () => {
const req = createMockCrudRequest({ action: 'fixReferences', ids: '1,99' });
service.getManyByIds.mockResolvedValueOnce([{ id: 1 }]);
service.getSelectedIds.mockResolvedValueOnce([1]);
mockRepository.findBy.mockResolvedValueOnce([createMockStudentKlass({ id: 1, studentTz: '123', klassId: 1 })]);

await service.doAction(req, {});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { validateBulk } from '@shared/base-entity/base-entity.util';
import { fixReferences } from '@shared/utils/entity/fixReference.util';
import { getHebrewDateFormatter } from '@shared/utils/formatting/formatter.util';
import { shouldShowTopic } from './att-report.config';
import { getAsDate, getAsNumber, getAsBoolean, getAsString, getAsNumberArray } from '@shared/utils/queryParam.util';
import { getAsDate, getAsNumber, getAsBoolean, getAsString } from '@shared/utils/queryParam.util';

function getConfig(): BaseEntityModuleOptions {
return {
Expand Down Expand Up @@ -139,9 +139,7 @@ class AttReportWithReportMonthService<T extends Entity | AttReportWithReportMont
// Keeps only the selected ids the caller may access (crudAuth filter), so a
// caller-supplied id from another user's data is never touched.
private async getOwnedIds(req: CrudRequest<any, any>): Promise<number[]> {
const ids = getAsNumberArray(req.parsed.extra.ids);
const entities = await this.getManyByIds(req, ids);
return entities.map((entity: any) => entity.id);
return this.getSelectedIds(req);
}

private async bulkKnownAbsences(extra: Record<string, string>, ids: number[]): Promise<string> {
Expand Down
4 changes: 1 addition & 3 deletions server/src/entity-modules/klass.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ class KlassService<T extends Entity | Klass> extends BaseEntityService<T> {
async doAction(req: CrudRequest<any, any>, body: any): Promise<any> {
switch (req.parsed.extra.action) {
case 'fixReferences': {
const ids = (await this.getManyByIds(req, getAsNumberArray(req.parsed.extra.ids))).map(
(entity: any) => entity.id,
);
const ids = await this.getSelectedIds(req);
if (!ids.length) return 'לא נבחרו רשומות';
const referenceFields = {
klassTypeId: 'klassTypeReferenceId',
Expand Down
4 changes: 1 addition & 3 deletions server/src/entity-modules/report-group-session.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ class ReportGroupSessionService<T extends Entity | ReportGroupSession> extends B
async doAction(req: CrudRequest<any, any>, body: any): Promise<any> {
switch (req.parsed.extra.action) {
case 'adjustTime': {
const ids = (await this.getManyByIds(req, getAsNumberArray(req.parsed.extra.ids))).map(
(entity: any) => entity.id,
);
const ids = await this.getSelectedIds(req);
const hoursAdjustment = getAsNumber(req.parsed.extra.hoursAdjustment) || 0;

if (hoursAdjustment === 0) {
Expand Down
4 changes: 1 addition & 3 deletions server/src/entity-modules/report-group.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ class ReportGroupService<T extends Entity | ReportGroup> extends BaseEntityServi
async doAction(req: CrudRequest<any, any>, body: any): Promise<any> {
switch (req.parsed.extra.action) {
case 'updateSignatureData': {
const ids = (await this.getManyByIds(req, getAsNumberArray(req.parsed.extra.ids))).map(
(entity: any) => entity.id,
);
const ids = await this.getSelectedIds(req);
if (!ids.length) return 'לא נבחרו רשומות';
const signatureData = getAsString(req.parsed.extra.signatureData);
await this.updateSignatureData(ids, signatureData);
Expand Down
4 changes: 1 addition & 3 deletions server/src/entity-modules/student-klass.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ class StudentKlassService<T extends Entity | StudentKlass> extends BaseEntitySer
async doAction(req: CrudRequest<any, any>, body: any): Promise<any> {
switch (req.parsed.extra.action) {
case 'fixReferences': {
const ids = (await this.getManyByIds(req, getAsNumberArray(req.parsed.extra.ids))).map(
(entity: any) => entity.id,
);
const ids = await this.getSelectedIds(req);
if (!ids.length) return 'לא נבחרו רשומות';
const referenceFields = {
studentTz: 'studentReferenceId',
Expand Down
4 changes: 0 additions & 4 deletions server/src/reports/lessonSignaturePdfReport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,6 @@ const LessonSignatureReport: React.FunctionComponent<LessonSignaturePdfData | Er
<StudentRecordsTable
studentRecords={sessionData.records}
entityConfig={entityConfig}
entityName={entityName}
/>
</React.Fragment>
);
Expand All @@ -519,7 +518,6 @@ const LessonSignatureReport: React.FunctionComponent<LessonSignaturePdfData | Er
<StudentRecordsTable
studentRecords={studentRecords}
entityConfig={entityConfig}
entityName={entityName}
/>
</>
)}
Expand Down Expand Up @@ -695,13 +693,11 @@ const LessonDetailsSection: React.FC<LessonDetailsSectionProps> = ({
interface StudentRecordsTableProps {
studentRecords: LessonSignaturePdfData['studentRecords'];
entityConfig: ReturnType<typeof getEntityConfig>;
entityName: string;
}

const StudentRecordsTable: React.FC<StudentRecordsTableProps> = ({
studentRecords,
entityConfig,
entityName
}) => {
const containerStyle: React.CSSProperties = {
marginBottom: '30px',
Expand Down
2 changes: 1 addition & 1 deletion server/src/reports/studentReportCardReact.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ function getReports(
): AppProps['reports'] {
const dataMap = groupDataByKeys(reports, ['teacherReferenceId', 'klassReferenceId', 'lessonReferenceId']);

const data = Object.entries(dataMap).map(([key, val]) => {
const data = Object.entries(dataMap).map(([, val]) => {
const { userId, year, studentReferenceId, klassReferenceId, lessonReferenceId, teacherReferenceId } = val[0];
const knownAbsences = knownAbsMap[klassReferenceId]?.[lessonReferenceId];
const { lessonsCount, absCount, approvedAbsCount, attPercents, absPercents, gradeAvg, lastGrade, maxGrade } = calcReportsData(val, [{ absnceCount: knownAbsences }]);
Expand Down
Loading