feat: add user override match for material validation in cleaner page
Add Priority 3 matching logic that allows User type users to override material assignments with their own typeKeywords from MaterialsTypeToBeDeleted. Changes: - Add session manager integration to get current user context - Implement Priority 3: User Override Match (only for non-admin users) - Filter typeKeywords by current username and force override on match - Maintain existing Priority 1 (exact match) and Priority 2 (type match) behavior - Admin users bypass override logic and see original matching results - Update cleaner-validation-flow.md with new matching algorithm flow This ensures User users see materials assigned to themselves first when their configured typeKeywords match, while Admin users maintain full visibility. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -215,7 +215,28 @@ export function registerValidationHandlers(): void {
|
||||
let dbService: MySqlService | SqlServerService | null = null
|
||||
|
||||
try {
|
||||
log.info('Starting validation', { mode: request.mode })
|
||||
// Get current user info
|
||||
const sessionManager = (
|
||||
await import('../services/user/session-manager')
|
||||
).SessionManager.getInstance()
|
||||
|
||||
const userInfo = sessionManager.getUserInfo()
|
||||
if (!userInfo) {
|
||||
return {
|
||||
success: false,
|
||||
error: '用户未登录',
|
||||
stats: {
|
||||
totalRecords: 0,
|
||||
matchedCount: 0,
|
||||
markedCount: 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const isAdmin = userInfo.userType === 'Admin'
|
||||
const username = userInfo.username
|
||||
|
||||
log.info('Starting validation', { mode: request.mode, user: username, isAdmin })
|
||||
|
||||
// Connect to database
|
||||
dbService = await getValidationDatabaseService()
|
||||
@@ -335,6 +356,19 @@ export function registerValidationHandlers(): void {
|
||||
}
|
||||
}
|
||||
|
||||
// Priority 3: User Override Match (only for non-admin users)
|
||||
// Override with current user's typeKeyword if available
|
||||
if (!isAdmin && username) {
|
||||
const userKeywords = typeKeywords.filter((tk) => tk.managerName === username)
|
||||
for (const userKeyword of userKeywords) {
|
||||
if (userKeyword.materialName && materialName.includes(userKeyword.materialName)) {
|
||||
matchedTypeKeyword = userKeyword.materialName
|
||||
managerName = userKeyword.managerName
|
||||
break // Force override with first match
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
results.push({
|
||||
materialName,
|
||||
materialCode,
|
||||
|
||||
Reference in New Issue
Block a user