Skip to content
Closed
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
154 changes: 154 additions & 0 deletions TEACHER_PERSONAL_AREA.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
# Teacher Personal Area - Implementation Summary

## Overview
This implementation adds a Teacher Personal Area for users with the `inLessonReport.only` permission. Instead of directly accessing the report form, teachers must first identify themselves using their TZ (Israeli ID number), and then access a personalized dashboard.

## Components Created

### 1. TeacherIdentityGuard.jsx
- **Purpose**: Login/identification screen for teachers
- **Features**:
- Simple form requesting TZ (Teudat Zehut)
- Queries the `teacher` resource to validate the ID
- Shows error if teacher not found
- Material-UI styled for consistency

### 2. TeacherPersonalArea.jsx
- **Purpose**: Main dashboard with tabbed interface
- **Features**:
- Header showing "שלום, [Teacher Name]"
- Logout button to return to identification screen
- Four tabs:
1. **דיווח נוכחות** (Report Attendance) - InLessonReport form with pre-selected teacher
2. **היסטוריית דיווחים** (My History) - Filtered list of att_report records
3. **דוח סיכום נוכחות** (Pivot Report) - Student attendance pivot data
4. **דוח אחוזים** (Percentage Report) - Student percentage statistics

### 3. TeacherPersonalAreaWrapper.jsx
- **Purpose**: Orchestrates the flow between identification and dashboard
- **Features**:
- Manages identified teacher state
- Handles save hooks for report groups
- Provides all necessary data and callbacks to child components

### 4. Filtered List Components
Located in `client/src/components/teacher-personal-area/`:

#### FilteredAttReportList.jsx
- Shows attendance reports filtered by teacher ID
- Includes edit button for each record
- Uses existing att_report Datagrid component

#### FilteredStudentAttendanceList.jsx
- Shows student attendance pivot data
- Filtered by teacher through `extra.teacherReferenceId`
- Uses pivot resource with StudentAttendance aggregation

#### FilteredStudentPercentReport.jsx
- Shows student percentage statistics
- Filtered by teacher ID
- Custom Datagrid with all necessary fields

## Modifications to Existing Components

### InLessonReport (index.jsx)
- **New Prop**: `preSelectedTeacher`
- **Behavior**: When this prop is provided:
- Skips the TeacherSelector step
- Automatically sets selectedTeacher state
- Proceeds directly to LessonSelector

### App.jsx
- **Change**: Updated `onlyInLesson` routing block
- **Added Resources**:
- `att_report` with edit/create capabilities
- `student_percent_report` (read-only)
- `student_by_year` (read-only)
- **Routes**: Modified to use TeacherPersonalAreaWrapper instead of InLessonReport directly

## Security Considerations

✅ All filtered views use permanent filters that cannot be removed by the user
✅ Teacher can only see their own data (filtered by teacherReferenceId)
✅ No SQL injection risks - uses react-admin's dataProvider abstraction
✅ Teacher identification validated against database
✅ CodeQL scan found 0 security vulnerabilities

## Data Flow

1. User with `inLessonReport.only` permission logs in
2. App.jsx detects permission and renders TeacherPersonalAreaWrapper
3. Wrapper shows TeacherIdentityGuard
4. Teacher enters TZ → validated against teacher table
5. On success, wrapper shows TeacherPersonalArea with teacher object
6. Teacher can:
- Create new attendance reports (Tab 1)
- View and edit existing reports (Tab 2)
- View aggregated data (Tabs 3 & 4)
7. All views permanently filtered by teacher.id

## Testing

- ✅ Build passes successfully
- ✅ All 87 existing tests pass
- ✅ No TypeScript/JavaScript errors
- ✅ No security vulnerabilities (CodeQL)

## Known Limitations & Future Enhancements

1. **Edit via InLessonReport**: Currently, editing uses the standard edit form. The requirement mentions "preferably via in lesson report form" which would require:
- Pre-populating InLessonReport with existing report data
- Converting report records back to form structure
- More complex state management
- This could be a future enhancement

2. **Offline Support**: The app requires internet connection for teacher identification

3. **Session Persistence**: Teacher identification doesn't persist across page refreshes (by design for security)

4. **Multiple Reports**: When a teacher has reported for multiple lessons on the same date, all appear in the history but clicking edit opens the standard form, not the multi-lesson InLessonReport form

## Dependencies

No new dependencies were added. The implementation uses existing packages:
- react-admin 5.3.3
- @mui/material (existing version)
- react 18.2.0

## Files Changed

### New Files (8)
- `client/src/components/TeacherIdentityGuard.jsx`
- `client/src/components/TeacherPersonalArea.jsx`
- `client/src/components/TeacherPersonalAreaWrapper.jsx`
- `client/src/components/teacher-personal-area/FilteredAttReportList.jsx`
- `client/src/components/teacher-personal-area/FilteredStudentAttendanceList.jsx`
- `client/src/components/teacher-personal-area/FilteredStudentPercentReport.jsx`

### Modified Files (2)
- `client/src/App.jsx` - Added routing and resources for teacher-only users
- `client/src/reports/in-lesson-report/index.jsx` - Added preSelectedTeacher prop support

## Usage Instructions

### For Teachers (End Users)
1. Log in with credentials that have `inLessonReport.only` permission
2. Enter your Teudat Zehut (ID number) in the identification screen
3. Access your personal dashboard with 4 tabs
4. Create new reports or edit existing ones

### For Administrators
To grant a user teacher-only access:
1. Ensure the user has the `inLessonReport.only` permission
2. Ensure the user is NOT marked as admin
3. The user must have a corresponding record in the `teacher` table with their TZ

## Translation Keys

All UI strings use existing Hebrew translations from `domainTranslations.js`. No new translation keys were required.

## Performance Considerations

- Filtered lists use react-admin's built-in pagination
- Data fetching is lazy (only loads when tab is active)
- No unnecessary re-renders due to proper use of useCallback and useMemo
Loading