已完成管理后台第二批 ASP.NET Core 10 迁移:

学校创建、修改
班级创建、修改
管理员创建、修改
管理员密码重置
自主注册开关
写入与审计日志保持同一事务
停用或重置管理员后自动清除其会话
This commit is contained in:
2026-07-23 08:08:26 +08:00 Unverified
parent 712bd1a3a2
commit 875e59b6ce
12 changed files with 885 additions and 20 deletions
+116
View File
@@ -423,6 +423,7 @@ try {
CANDIDATE_NATIVE_ENABLED = 'true'
CANDIDATE_NATIVE_ALLOW_MEMORY = 'true'
ADMIN_NATIVE_READS_ENABLED = 'true'
ADMIN_NATIVE_ORGANIZATION_WRITES_ENABLED = 'true'
ADMIN_NATIVE_ALLOW_MEMORY = 'true'
LegacyNode__Enabled = 'true'
LegacyNode__BaseUrl = $legacyBaseUrl
@@ -736,6 +737,120 @@ try {
if ($classAdminsForbidden.StatusCode -ne 403) {
throw 'Native admins route did not preserve the class-admin boundary'
}
$schoolCreateBody = @{
name = '原生迁移测试学校'
code = 'NATIVE_SMOKE'
address = '迁移测试路 1 号'
isSourceSchool = $true
isAdmissionSchool = $true
} | ConvertTo-Json -Compress
$schoolCreateResponse = Invoke-WebRequest -Uri "$nativeAuthBaseUrl/api/admin/schools" -Method Post -ContentType 'application/json' -Body $schoolCreateBody -WebSession $nativeSession
if ($schoolCreateResponse.StatusCode -ne 201 -or $schoolCreateResponse.Headers['X-EIS-Implementation'] -ne 'aspnet-core') {
throw 'Native school creation did not use the ASP.NET Core endpoint'
}
$createdSchool = ($schoolCreateResponse.Content | ConvertFrom-Json).school
if ($createdSchool.code -ne 'NATIVE_SMOKE' -or $createdSchool.active -ne $true) {
throw 'Native school creation returned an unexpected projection'
}
$duplicateSchool = Invoke-WebRequest -Uri "$nativeAuthBaseUrl/api/admin/schools" -Method Post -ContentType 'application/json' -Body $schoolCreateBody -WebSession $nativeSession -SkipHttpErrorCheck
if ($duplicateSchool.StatusCode -ne 409) {
throw 'Native school creation did not reject a duplicate school code'
}
$schoolCreateForbidden = Invoke-WebRequest -Uri "$nativeAuthBaseUrl/api/admin/schools" -Method Post -ContentType 'application/json' -Body $schoolCreateBody -WebSession $nativeSchoolSession -SkipHttpErrorCheck
if ($schoolCreateForbidden.StatusCode -ne 403 -or $schoolCreateForbidden.Headers['X-EIS-Implementation'] -ne 'aspnet-core') {
throw 'Native school creation did not preserve the super-admin boundary'
}
$schoolPatchBody = @{ address = '迁移测试路 2 号'; isAdmissionSchool = $false } | ConvertTo-Json -Compress
$schoolPatch = Invoke-RestMethod -Uri "$nativeAuthBaseUrl/api/admin/schools/$($createdSchool.id)" -Method Patch -ContentType 'application/json' -Body $schoolPatchBody -WebSession $nativeSession
if ($schoolPatch.school.address -ne '迁移测试路 2 号' -or $schoolPatch.school.isAdmissionSchool -ne $false) {
throw 'Native school update did not persist the requested fields'
}
$newSchoolAdminBody = @{
username = 'native_school_writer'
password = '12345678'
displayName = '原生校级管理员'
adminLevel = 'school'
schoolId = $createdSchool.id
} | ConvertTo-Json -Compress
$newSchoolAdminResponse = Invoke-WebRequest -Uri "$nativeAuthBaseUrl/api/admin/admins" -Method Post -ContentType 'application/json' -Body $newSchoolAdminBody -WebSession $nativeSession
if ($newSchoolAdminResponse.StatusCode -ne 201 -or $newSchoolAdminResponse.Headers['X-EIS-Implementation'] -ne 'aspnet-core') {
throw 'Native administrator creation did not use the ASP.NET Core endpoint'
}
$createdSchoolAdmin = ($newSchoolAdminResponse.Content | ConvertFrom-Json).admin
$newSchoolAdminSession = [Microsoft.PowerShell.Commands.WebRequestSession]::new()
$newSchoolAdminLoginBody = @{ username = 'native_school_writer'; password = '12345678' } | ConvertTo-Json -Compress
Invoke-RestMethod -Uri "$nativeAuthBaseUrl/api/auth/login" -Method Post -ContentType 'application/json' -Body $newSchoolAdminLoginBody -WebSession $newSchoolAdminSession | Out-Null
$classCreateBody = @{ name = '迁移测试班'; grade = '2026级' } | ConvertTo-Json -Compress
$classCreateResponse = Invoke-WebRequest -Uri "$nativeAuthBaseUrl/api/admin/classes" -Method Post -ContentType 'application/json' -Body $classCreateBody -WebSession $newSchoolAdminSession
if ($classCreateResponse.StatusCode -ne 201 -or $classCreateResponse.Headers['X-EIS-Implementation'] -ne 'aspnet-core') {
throw 'Native class creation did not use the ASP.NET Core endpoint'
}
$createdClass = ($classCreateResponse.Content | ConvertFrom-Json).schoolClass
$superClassForbidden = Invoke-WebRequest -Uri "$nativeAuthBaseUrl/api/admin/classes" -Method Post -ContentType 'application/json' -Body $classCreateBody -WebSession $nativeSession -SkipHttpErrorCheck
if ($superClassForbidden.StatusCode -ne 403) {
throw 'Native class creation did not preserve the school-admin boundary'
}
$classPatchBody = @{ name = '迁移测试一班'; active = $true } | ConvertTo-Json -Compress
$classPatch = Invoke-RestMethod -Uri "$nativeAuthBaseUrl/api/admin/classes/$($createdClass.id)" -Method Patch -ContentType 'application/json' -Body $classPatchBody -WebSession $newSchoolAdminSession
if ($classPatch.schoolClass.name -ne '迁移测试一班') {
throw 'Native class update did not persist the requested name'
}
$newClassAdminBody = @{
username = 'native_class_writer'
password = '12345678'
displayName = '原生班级管理员'
adminLevel = 'super'
classId = $createdClass.id
} | ConvertTo-Json -Compress
$newClassAdminResponse = Invoke-RestMethod -Uri "$nativeAuthBaseUrl/api/admin/admins" -Method Post -ContentType 'application/json' -Body $newClassAdminBody -WebSession $newSchoolAdminSession
if ($newClassAdminResponse.admin.adminLevel -ne 'class' -or $newClassAdminResponse.admin.schoolId -ne $createdSchool.id) {
throw 'School admin did not create a class-scoped administrator'
}
$createdClassAdmin = $newClassAdminResponse.admin
$newClassAdminSession = [Microsoft.PowerShell.Commands.WebRequestSession]::new()
$newClassAdminLoginBody = @{ username = 'native_class_writer'; password = '12345678' } | ConvertTo-Json -Compress
Invoke-RestMethod -Uri "$nativeAuthBaseUrl/api/auth/login" -Method Post -ContentType 'application/json' -Body $newClassAdminLoginBody -WebSession $newClassAdminSession | Out-Null
$disableClassAdminBody = @{ active = $false; displayName = '原生班级管理员(停用)' } | ConvertTo-Json -Compress
$disabledClassAdmin = Invoke-RestMethod -Uri "$nativeAuthBaseUrl/api/admin/admins/$($createdClassAdmin.id)" -Method Patch -ContentType 'application/json' -Body $disableClassAdminBody -WebSession $newSchoolAdminSession
if ($disabledClassAdmin.admin.displayName -ne '原生班级管理员(停用)') {
throw 'Native administrator update did not persist the display name'
}
$invalidatedClassSession = Invoke-WebRequest -Uri "$nativeAuthBaseUrl/api/auth/me" -WebSession $newClassAdminSession -SkipHttpErrorCheck
$invalidatedClassIdentity = $invalidatedClassSession.Content | ConvertFrom-Json
if ($invalidatedClassSession.StatusCode -ne 200 -or $null -ne $invalidatedClassIdentity.user) {
throw 'Disabling an administrator did not invalidate existing sessions'
}
$resetClassAdmin = Invoke-RestMethod -Uri "$nativeAuthBaseUrl/api/admin/admins/$($createdClassAdmin.id)/reset-password" -Method Post -WebSession $newSchoolAdminSession
if ($resetClassAdmin.username -ne 'native_class_writer' -or $resetClassAdmin.temporaryPassword -notmatch '^Reset-[A-Za-z0-9_-]+$') {
throw 'Native administrator password reset returned an invalid temporary password'
}
$resetLoginBody = @{ username = 'native_class_writer'; password = $resetClassAdmin.temporaryPassword } | ConvertTo-Json -Compress
$resetLogin = Invoke-RestMethod -Uri "$nativeAuthBaseUrl/api/auth/login" -Method Post -ContentType 'application/json' -Body $resetLoginBody
if ($resetLogin.user.username -ne 'native_class_writer') {
throw 'The temporary administrator password is not compatible with native authentication'
}
$adminStateBeforeSetting = Invoke-RestMethod -Uri "$nativeAuthBaseUrl/api/admin/admins" -WebSession $nativeSession
$originalSelfRegistration = [bool]$adminStateBeforeSetting.selfRegistrationEnabled
$settingBody = @{ enabled = -not $originalSelfRegistration } | ConvertTo-Json -Compress
$settingUpdate = Invoke-WebRequest -Uri "$nativeAuthBaseUrl/api/admin/settings/self-registration" -Method Put -ContentType 'application/json' -Body $settingBody -WebSession $nativeSession
if ($settingUpdate.Headers['X-EIS-Implementation'] -ne 'aspnet-core' -or ($settingUpdate.Content | ConvertFrom-Json).enabled -eq $originalSelfRegistration) {
throw 'Native self-registration setting did not persist the requested value'
}
$settingForbidden = Invoke-WebRequest -Uri "$nativeAuthBaseUrl/api/admin/settings/self-registration" -Method Put -ContentType 'application/json' -Body $settingBody -WebSession $nativeSchoolSession -SkipHttpErrorCheck
if ($settingForbidden.StatusCode -ne 403) {
throw 'Native self-registration setting did not preserve the super-admin boundary'
}
$restoreSettingBody = @{ enabled = $originalSelfRegistration } | ConvertTo-Json -Compress
Invoke-RestMethod -Uri "$nativeAuthBaseUrl/api/admin/settings/self-registration" -Method Put -ContentType 'application/json' -Body $restoreSettingBody -WebSession $nativeSession | Out-Null
$adminCandidateRoute = Invoke-WebRequest -Uri "$nativeAuthBaseUrl/api/candidate/profile" -WebSession $nativeSession -SkipHttpErrorCheck
if ($adminCandidateRoute.StatusCode -ne 403) {
throw 'Native candidate API did not enforce the candidate role boundary'
@@ -819,6 +934,7 @@ try {
NativeCandidateDocuments = 'passed'
NativeCandidateAdmissions = 'passed'
NativeAdminReads = 'passed'
NativeAdminOrganizationWrites = 'passed'
} | Format-List
}
finally {