|
|
# Teacher Management Class Lock Implementation Plan
|
|
|
|
|
|
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
|
|
|
|
|
|
**Goal:** Let the current school's teacher management list show all teachers while preventing edits and deletions for accounts that still own classes.
|
|
|
|
|
|
**Architecture:** The legacy `UserController` remains the teacher-management API used by the teacher-side page. It derives the school from `operatorId`, decorates teacher list rows with a runtime `hasCreatedClass` flag, and rejects update/delete requests for locked accounts. The Vue page consumes that flag, skips obsolete faculty/major lookup in teaching-class-only mode, and disables locked actions before requests are sent.
|
|
|
|
|
|
**Tech Stack:** Spring MVC, MyBatis Example mappers, JUnit 5 + Mockito; Vue 3 Composition API, Element Plus, Node source-static tests.
|
|
|
|
|
|
## Global Constraints
|
|
|
|
|
|
- “学院所有老师” means every teacher in the current operator's school; there is no faculty, major, or administrative-class scope.
|
|
|
- A lock exists while at least one persisted `SchoolClass.createdBy` equals the teacher ID, regardless of member count.
|
|
|
- The API guard is authoritative; UI disablement is only user feedback.
|
|
|
- Do not add database columns; `hasCreatedClass` is a response-only `Userinfo` property.
|
|
|
- Preserve existing teacher creation, import, password-reset, and role rules.
|
|
|
|
|
|
---
|
|
|
|
|
|
### Task 1: Enforce class-owner locking in the teacher API
|
|
|
|
|
|
**Files:**
|
|
|
- Modify: `link_commerce/src/main/java/com/sztzjy/linkCommerce/entity/Userinfo.java`
|
|
|
- Modify: `link_commerce/src/main/java/com/sztzjy/linkCommerce/controller/stu/UserController.java:617-672, 698-719, 2228-2233`
|
|
|
- Modify: `link_commerce/src/test/java/com/sztzjy/linkCommerce/controller/stu/UserControllerTeacherAdminTest.java`
|
|
|
|
|
|
**Interfaces:**
|
|
|
- Consumes: `operatorId`, `SchoolClassMapper.selectByExample(SchoolClassExample)`, existing `teacherHasCreatedClass(String)`.
|
|
|
- Produces: `Userinfo.getHasCreatedClass(): Boolean`; `selectTeacher(..., operatorId)` list rows marked with that value; update/delete return `BAD_REQUEST` without writing when the target owns a class.
|
|
|
|
|
|
- [ ] **Step 1: Write failing backend tests**
|
|
|
|
|
|
Add tests to `UserControllerTeacherAdminTest` using `controllerWithCommonMocks()`:
|
|
|
|
|
|
```java
|
|
|
@Test
|
|
|
void managerTeacherListsOnlyItsSchoolTeachersAndMarksClassOwners() {
|
|
|
Userinfo manager = teacher("manager-1", true);
|
|
|
manager.setSchoolId("school-1");
|
|
|
Userinfo owner = teacher("owner-1", false);
|
|
|
owner.setSchoolId("school-1");
|
|
|
School school = new School();
|
|
|
school.setSchoolId("school-1");
|
|
|
school.setSchoolName("School One");
|
|
|
SchoolClass ownedClass = new SchoolClass();
|
|
|
ownedClass.setSchoolClassId("class-1");
|
|
|
ownedClass.setCreatedBy("owner-1");
|
|
|
when(controller.userinfoMapper.selectByPrimaryKey("manager-1")).thenReturn(manager);
|
|
|
when(controller.userinfoMapper.selectByExample(any(UserinfoExample.class))).thenReturn(Collections.singletonList(owner));
|
|
|
when(controller.schoolClassMapper.selectByExample(any(SchoolClassExample.class))).thenReturn(Collections.singletonList(ownedClass));
|
|
|
when(controller.schoolMapper.selectByPrimaryKey("school-1")).thenReturn(school);
|
|
|
|
|
|
ResultEntity<PageInfo<Userinfo>> result = controller.selectTeacher(null, null, null, 1, 10, "manager-1");
|
|
|
|
|
|
ArgumentCaptor<UserinfoExample> exampleCaptor = ArgumentCaptor.forClass(UserinfoExample.class);
|
|
|
verify(controller.userinfoMapper).selectByExample(exampleCaptor.capture());
|
|
|
assertEquals(HttpStatus.OK, result.getStatusCode());
|
|
|
assertTrue(hasUserCondition(exampleCaptor.getValue(), "school_id =", "school-1"));
|
|
|
assertTrue(result.getData().getList().get(0).getHasCreatedClass());
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
void managerTeacherCannotUpdateTeacherWhoCreatedAClass() {
|
|
|
when(controller.userinfoMapper.selectByPrimaryKey("manager-1")).thenReturn(teacher("manager-1", true));
|
|
|
when(controller.userinfoMapper.selectByPrimaryKey("owner-1")).thenReturn(teacher("owner-1", false));
|
|
|
SchoolClass ownedClass = new SchoolClass();
|
|
|
ownedClass.setCreatedBy("owner-1");
|
|
|
when(controller.schoolClassMapper.selectByExample(any(SchoolClassExample.class))).thenReturn(Collections.singletonList(ownedClass));
|
|
|
|
|
|
ResultEntity result = controller.updateTeacher(teacher("owner-1", false), "manager-1");
|
|
|
|
|
|
assertEquals(HttpStatus.BAD_REQUEST, result.getStatusCode());
|
|
|
verify(controller.userinfoMapper, never()).updateByPrimaryKey(any(Userinfo.class));
|
|
|
}
|
|
|
```
|
|
|
|
|
|
Add the symmetric delete assertion. Stub the manager with `schoolId = "school-1"` so the existing `canManageSchoolStructure` check is exercised. Add the local helper used above:
|
|
|
|
|
|
```java
|
|
|
private boolean hasUserCondition(UserinfoExample example, String condition, Object value) {
|
|
|
return example.getOredCriteria().stream()
|
|
|
.flatMap(criteria -> criteria.getAllCriteria().stream())
|
|
|
.anyMatch(item -> condition.equals(item.getCondition()) && value.equals(item.getValue()));
|
|
|
}
|
|
|
```
|
|
|
|
|
|
- [ ] **Step 2: Run backend tests to verify failure**
|
|
|
|
|
|
Run:
|
|
|
|
|
|
```powershell
|
|
|
mvn -q -Dtest=UserControllerTeacherAdminTest test
|
|
|
```
|
|
|
|
|
|
Expected: compilation failure because `getHasCreatedClass()` and the `operatorId` list signature do not yet exist; after adding the signature, lock tests fail because update currently writes.
|
|
|
|
|
|
- [ ] **Step 3: Add the response-only lock flag and list enrichment**
|
|
|
|
|
|
In `Userinfo`, add the field and ordinary accessor pair near other response-only display properties:
|
|
|
|
|
|
```java
|
|
|
@ApiModelProperty("是否已创建班级,教师管理列表展示用")
|
|
|
private Boolean hasCreatedClass = false;
|
|
|
|
|
|
public Boolean getHasCreatedClass() { return hasCreatedClass; }
|
|
|
public void setHasCreatedClass(Boolean hasCreatedClass) { this.hasCreatedClass = hasCreatedClass; }
|
|
|
```
|
|
|
|
|
|
Extend `selectTeacher` with optional `operatorId`. When supplied by a teacher, load that operator, reject absent/non-teacher operators, and replace any client `schoolId` with `operator.getSchoolId()`. Keep platform-admin list behavior unchanged. After selecting the page, gather teacher IDs, perform one `SchoolClassExample` query with `andCreatedByIn(teacherIds)`, build a `Set<String>` of owners, then assign each row:
|
|
|
|
|
|
```java
|
|
|
teacher.setHasCreatedClass(classOwnerIds.contains(teacher.getUserId()));
|
|
|
```
|
|
|
|
|
|
Do not issue one query per teacher and do not run `andCreatedByIn` for an empty list.
|
|
|
|
|
|
- [ ] **Step 4: Protect update and delete at the API boundary**
|
|
|
|
|
|
In `updateTeacher`, return a bad request if `existing` is absent or if `teacherHasCreatedClass(existing.getUserId())` is true, before assigning fields or invoking `updateByPrimaryKey`. Retain the current school-management permission check and teacher-admin normalization.
|
|
|
|
|
|
Keep the existing delete check but use the same message as update:
|
|
|
|
|
|
```java
|
|
|
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "该教师已创建班级,不允许编辑或删除");
|
|
|
```
|
|
|
|
|
|
- [ ] **Step 5: Run focused backend tests**
|
|
|
|
|
|
Run:
|
|
|
|
|
|
```powershell
|
|
|
mvn -q -Dtest=UserControllerTeacherAdminTest test
|
|
|
```
|
|
|
|
|
|
Expected: PASS, including existing class-management authorization coverage.
|
|
|
|
|
|
- [ ] **Step 6: Commit the backend change**
|
|
|
|
|
|
```powershell
|
|
|
git add src/main/java/com/sztzjy/linkCommerce/entity/Userinfo.java src/main/java/com/sztzjy/linkCommerce/controller/stu/UserController.java src/test/java/com/sztzjy/linkCommerce/controller/stu/UserControllerTeacherAdminTest.java
|
|
|
git commit -m "feat: lock teachers that own classes"
|
|
|
```
|
|
|
|
|
|
### Task 2: Make the teacher-management page respect roster mode and lock state
|
|
|
|
|
|
**Files:**
|
|
|
- Modify: `e-commerce-internet/src/api/teacher.js:399-433`
|
|
|
- Modify: `e-commerce-internet/src/views/teacherEnd/teacher/index.vue:55-229`
|
|
|
- Create: `e-commerce-internet/tests/teacher-management-class-lock.static.test.cjs`
|
|
|
|
|
|
**Interfaces:**
|
|
|
- Consumes: `GET/POST /api/user/selectTeacher` response row `hasCreatedClass: boolean`; current `userStore.userInfo.schoolProductConfig` and `currentUserId`.
|
|
|
- Produces: list requests with `operatorId`, disabled edit/delete actions for locked rows, no faculty-major name request while all three organization switches are disabled.
|
|
|
|
|
|
- [ ] **Step 1: Write a failing frontend source-static test**
|
|
|
|
|
|
Create `tests/teacher-management-class-lock.static.test.cjs` to read `src/views/teacherEnd/teacher/index.vue` and `src/api/teacher.js`. Assert:
|
|
|
|
|
|
```js
|
|
|
assert(page.includes('operatorId: currentUserId.value'));
|
|
|
assert(/:disabled="row\.hasCreatedClass"/.test(page));
|
|
|
assert(page.includes('该教师已创建班级,不允许编辑或删除'));
|
|
|
assert(/if \(!isOrganizationManagementEnabled\.value\) \{[\s\S]*?return;[\s\S]*?\}/.test(page));
|
|
|
assert(api.includes('url: "/api/user/selectTeacher"'));
|
|
|
```
|
|
|
|
|
|
- [ ] **Step 2: Run the static test to verify failure**
|
|
|
|
|
|
Run:
|
|
|
|
|
|
```powershell
|
|
|
node tests/teacher-management-class-lock.static.test.cjs
|
|
|
```
|
|
|
|
|
|
Expected: FAIL because the list query lacks `operatorId`, action buttons are always enabled, and edit always loads faculty/major names.
|
|
|
|
|
|
- [ ] **Step 3: Update request, form mode, and locked row controls**
|
|
|
|
|
|
Add computed booleans matching the class page's configuration conventions:
|
|
|
|
|
|
```js
|
|
|
const facultyManagementEnabled = computed(() => userStore.schoolProductConfig?.facultyManagementEnabled === true);
|
|
|
const majorManagementEnabled = computed(() => userStore.schoolProductConfig?.majorManagementEnabled === true);
|
|
|
const adminClassManagementEnabled = computed(() => userStore.schoolProductConfig?.adminClassManagementEnabled === true);
|
|
|
const isOrganizationManagementEnabled = computed(() => facultyManagementEnabled.value || majorManagementEnabled.value || adminClassManagementEnabled.value);
|
|
|
```
|
|
|
|
|
|
Pass `operatorId: currentUserId.value` in `getList`. In `editSchool`, populate the selected row and return before `getFacultyAndMajorName` when organization management is disabled. Render faculty/major display fields only when creating or organization management is enabled. Add `:disabled="row.hasCreatedClass"` to edit/delete buttons and a nearby disabled-state tip/tag with the agreed Chinese message. Keep ordinary teachers' existing read-only action branch unchanged.
|
|
|
|
|
|
- [ ] **Step 4: Run frontend static tests**
|
|
|
|
|
|
Run:
|
|
|
|
|
|
```powershell
|
|
|
node tests/teacher-management-class-lock.static.test.cjs
|
|
|
node tests/school-product-config.static.test.cjs
|
|
|
```
|
|
|
|
|
|
Expected: PASS.
|
|
|
|
|
|
- [ ] **Step 5: Commit the frontend change**
|
|
|
|
|
|
```powershell
|
|
|
git add src/api/teacher.js src/views/teacherEnd/teacher/index.vue tests/teacher-management-class-lock.static.test.cjs
|
|
|
git commit -m "feat: disable locked teacher actions"
|
|
|
```
|
|
|
|
|
|
### Task 3: Verify the integrated behavior
|
|
|
|
|
|
**Files:**
|
|
|
- Verify only: `link_commerce` and `e-commerce-internet` working trees.
|
|
|
|
|
|
**Interfaces:**
|
|
|
- Consumes: the backend lock API and frontend action-state contract from Tasks 1–2.
|
|
|
- Produces: evidence that both repositories remain green after the feature.
|
|
|
|
|
|
- [ ] **Step 1: Run the backend suite**
|
|
|
|
|
|
```powershell
|
|
|
mvn -q test
|
|
|
```
|
|
|
|
|
|
Expected: PASS. The evaluation rollback test logs an expected exception but Maven exits with code 0.
|
|
|
|
|
|
- [ ] **Step 2: Run every frontend static test**
|
|
|
|
|
|
```powershell
|
|
|
Get-ChildItem -Path tests -Filter '*.cjs' | Sort-Object Name | ForEach-Object { node $_.FullName; if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } }
|
|
|
```
|
|
|
|
|
|
Expected: every test prints its success message and PowerShell exits with code 0.
|
|
|
|
|
|
- [ ] **Step 3: Build the frontend production bundle**
|
|
|
|
|
|
```powershell
|
|
|
npm run build:prod
|
|
|
```
|
|
|
|
|
|
Expected: build succeeds; existing deep-selector and bundle-size warnings may remain warnings only.
|
|
|
|
|
|
- [ ] **Step 4: Inspect final changes**
|
|
|
|
|
|
```powershell
|
|
|
git diff --check
|
|
|
git status --short
|
|
|
```
|
|
|
|
|
|
Expected: no whitespace errors; only files from Tasks 1–2 and planned commits are present.
|