12 KiB
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.createdByequals the teacher ID, regardless of member count. - The API guard is authoritative; UI disablement is only user feedback.
- Do not add database columns;
hasCreatedClassis a response-onlyUserinfoproperty. - 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), existingteacherHasCreatedClass(String). -
Produces:
Userinfo.getHasCreatedClass(): Boolean;selectTeacher(..., operatorId)list rows marked with that value; update/delete returnBAD_REQUESTwithout writing when the target owns a class. -
Step 1: Write failing backend tests
Add tests to
UserControllerTeacherAdminTestusingcontrollerWithCommonMocks():@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 existingcanManageSchoolStructurecheck is exercised. Add the local helper used above: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:
mvn -q -Dtest=UserControllerTeacherAdminTest testExpected: compilation failure because
getHasCreatedClass()and theoperatorIdlist 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:@ApiModelProperty("是否已创建班级,教师管理列表展示用") private Boolean hasCreatedClass = false; public Boolean getHasCreatedClass() { return hasCreatedClass; } public void setHasCreatedClass(Boolean hasCreatedClass) { this.hasCreatedClass = hasCreatedClass; }Extend
selectTeacherwith optionaloperatorId. When supplied by a teacher, load that operator, reject absent/non-teacher operators, and replace any clientschoolIdwithoperator.getSchoolId(). Keep platform-admin list behavior unchanged. After selecting the page, gather teacher IDs, perform oneSchoolClassExamplequery withandCreatedByIn(teacherIds), build aSet<String>of owners, then assign each row:teacher.setHasCreatedClass(classOwnerIds.contains(teacher.getUserId()));Do not issue one query per teacher and do not run
andCreatedByInfor an empty list. -
Step 4: Protect update and delete at the API boundary
In
updateTeacher, return a bad request ifexistingis absent or ifteacherHasCreatedClass(existing.getUserId())is true, before assigning fields or invokingupdateByPrimaryKey. Retain the current school-management permission check and teacher-admin normalization.Keep the existing delete check but use the same message as update:
return new ResultEntity<>(HttpStatus.BAD_REQUEST, "该教师已创建班级,不允许编辑或删除"); -
Step 5: Run focused backend tests
Run:
mvn -q -Dtest=UserControllerTeacherAdminTest testExpected: PASS, including existing class-management authorization coverage.
-
Step 6: Commit the backend change
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/selectTeacherresponse rowhasCreatedClass: boolean; currentuserStore.userInfo.schoolProductConfigandcurrentUserId. -
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.cjsto readsrc/views/teacherEnd/teacher/index.vueandsrc/api/teacher.js. Assert: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:
node tests/teacher-management-class-lock.static.test.cjsExpected: 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:
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.valueingetList. IneditSchool, populate the selected row and return beforegetFacultyAndMajorNamewhen 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:
node tests/teacher-management-class-lock.static.test.cjs node tests/school-product-config.static.test.cjsExpected: PASS.
-
Step 5: Commit the frontend change
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_commerceande-commerce-internetworking 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
mvn -q testExpected: PASS. The evaluation rollback test logs an expected exception but Maven exits with code 0.
-
Step 2: Run every frontend static test
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
npm run build:prodExpected: build succeeds; existing deep-selector and bundle-size warnings may remain warnings only.
-
Step 4: Inspect final changes
git diff --check git status --shortExpected: no whitespace errors; only files from Tasks 1–2 and planned commits are present.