Jelajahi Sumber

用户禁用触发所有映射禁用

liuq 5 hari lalu
induk
melakukan
32bed2c2c8

+ 20 - 0
backend/app/api/v1/endpoints/users.py

@@ -384,6 +384,26 @@ def update_user(
         setattr(user, field, value)
         setattr(user, field, value)
         
         
     db.add(user)
     db.add(user)
+
+    # 用户禁用时关闭其全部应用映射;重新启用(含审核通过)时恢复为启用
+    if "status" in update_data:
+        if update_data["status"] == "DISABLED":
+            n = (
+                db.query(AppUserMapping)
+                .filter(AppUserMapping.user_id == user.id)
+                .update({"is_active": False}, synchronize_session=False)
+            )
+            if n:
+                logger.info(f"用户禁用:已关闭 {n} 条应用映射 (user_id={user.id})")
+        elif update_data["status"] == "ACTIVE":
+            n = (
+                db.query(AppUserMapping)
+                .filter(AppUserMapping.user_id == user.id)
+                .update({"is_active": True}, synchronize_session=False)
+            )
+            if n:
+                logger.info(f"用户启用:已恢复 {n} 条应用映射 (user_id={user.id})")
+
     db.commit()
     db.commit()
     db.refresh(user)
     db.refresh(user)
     
     

+ 20 - 2
frontend/src/views/apps/MappingImport.vue

@@ -19,8 +19,8 @@
           <el-table-column prop="user_mobile" label="用户手机号" />
           <el-table-column prop="user_mobile" label="用户手机号" />
           <el-table-column prop="user_status" label="统一认证账号状态" width="150">
           <el-table-column prop="user_status" label="统一认证账号状态" width="150">
             <template #default="scope">
             <template #default="scope">
-                <el-tag :type="scope.row.user_status === 'ACTIVE' ? 'success' : 'danger'">
-                    {{ scope.row.user_status === 'ACTIVE' ? '已激活' : scope.row.user_status }}
+                <el-tag :type="userStatusTagType(scope.row.user_status)">
+                    {{ userStatusLabel(scope.row.user_status) }}
                 </el-tag>
                 </el-tag>
             </template>
             </template>
           </el-table-column>
           </el-table-column>
@@ -407,6 +407,24 @@ const appName = route.query.name as string
 
 
 const activeTab = ref('list')
 const activeTab = ref('list')
 
 
+const USER_STATUS_LABELS: Record<string, string> = {
+  ACTIVE: '已激活',
+  PENDING: '待审核',
+  DISABLED: '已禁用'
+}
+
+function userStatusLabel(status: string | undefined | null): string {
+  if (!status) return '—'
+  return USER_STATUS_LABELS[status] ?? status
+}
+
+function userStatusTagType(status: string | undefined | null): 'success' | 'warning' | 'danger' | 'info' {
+  if (status === 'ACTIVE') return 'success'
+  if (status === 'PENDING') return 'warning'
+  if (status === 'DISABLED') return 'danger'
+  return 'info'
+}
+
 // --- List Logic ---
 // --- List Logic ---
 const mappings = ref<MappingResponse[]>([])
 const mappings = ref<MappingResponse[]>([])
 const loading = ref(false)
 const loading = ref(false)