97 lines
3.2 KiB
JavaScript
97 lines
3.2 KiB
JavaScript
const { PrismaClient } = require('@prisma/client');
|
||
|
||
async function fixUserPermissions() {
|
||
const prisma = new PrismaClient();
|
||
|
||
try {
|
||
console.log('🔧 修复用户权限设置...\n');
|
||
|
||
// 获取所有用户,按创建时间排序
|
||
const users = await prisma.user.findMany({
|
||
orderBy: { createdAt: 'asc' }
|
||
});
|
||
|
||
console.log(`📊 用户总数: ${users.length}`);
|
||
|
||
if (users.length === 0) {
|
||
console.log('❌ 用户表为空,无法修复权限');
|
||
return;
|
||
}
|
||
|
||
// 查找目标用户
|
||
const targetEmail = '549727955@qq.com';
|
||
const targetUser = users.find(u => u.email === targetEmail);
|
||
|
||
if (!targetUser) {
|
||
console.log(`❌ 未找到邮箱为 ${targetEmail} 的用户`);
|
||
return;
|
||
}
|
||
|
||
console.log(`\n👤 目标用户信息:`);
|
||
console.log(` 邮箱: ${targetUser.email}`);
|
||
console.log(` 用户名: ${targetUser.username}`);
|
||
console.log(` 当前角色: ${targetUser.role}`);
|
||
console.log(` 当前超级管理员: ${targetUser.isSuperAdmin ? '是' : '否'}`);
|
||
console.log(` 创建时间: ${targetUser.createdAt.toLocaleString()}`);
|
||
|
||
// 检查是否需要修复
|
||
const needsFix = targetUser.role !== 'ADMIN' || !targetUser.isSuperAdmin;
|
||
|
||
if (!needsFix) {
|
||
console.log('\n✅ 用户权限设置正确,无需修复');
|
||
console.log(` 角色: ${targetUser.role}`);
|
||
console.log(` 超级管理员: ${targetUser.isSuperAdmin}`);
|
||
return;
|
||
}
|
||
|
||
console.log('\n⚠️ 发现权限问题,开始修复...');
|
||
|
||
// 修复用户权限
|
||
const updatedUser = await prisma.user.update({
|
||
where: { id: targetUser.id },
|
||
data: {
|
||
role: 'ADMIN',
|
||
isSuperAdmin: true
|
||
}
|
||
});
|
||
|
||
console.log('\n✅ 权限修复成功!');
|
||
console.log(` 邮箱: ${updatedUser.email}`);
|
||
console.log(` 新的角色: ${updatedUser.role}`);
|
||
console.log(` 新的超级管理员: ${updatedUser.isSuperAdmin ? '✅ 是' : '❌ 否'}`);
|
||
|
||
console.log('\n🎯 修复完成后的操作:');
|
||
console.log('1. 重新登录系统');
|
||
console.log('2. 清除浏览器缓存或使用无痕模式');
|
||
console.log('3. 访问管理后台: http://45.249.208.118:4320/admin');
|
||
console.log('4. 确认"系统管理"菜单是否显示');
|
||
|
||
// 显示所有用户状态
|
||
console.log('\n📋 当前所有用户状态:');
|
||
console.log('='.repeat(60));
|
||
|
||
const allUsers = await prisma.user.findMany({
|
||
orderBy: { createdAt: 'asc' }
|
||
});
|
||
|
||
allUsers.forEach((user, index) => {
|
||
const badges = [];
|
||
if (index === 0) badges.push('👑 首位用户');
|
||
if (user.isSuperAdmin) badges.push('🛡️ 超级管理员');
|
||
if (user.role === 'ADMIN') badges.push('⚡ 管理员');
|
||
|
||
const badgeStr = badges.length > 0 ? ` [${badges.join(' ')}]` : '';
|
||
|
||
console.log(`${index + 1}. ${user.username} (${user.email})${badgeStr}`);
|
||
console.log(` 角色: ${user.role}, 超级管理员: ${user.isSuperAdmin ? '是' : '否'}`);
|
||
console.log('');
|
||
});
|
||
|
||
} catch (error) {
|
||
console.error('❌ 修复权限时出错:', error);
|
||
} finally {
|
||
await prisma.$disconnect();
|
||
}
|
||
}
|
||
|
||
fixUserPermissions(); |