|
| 1 | +import { NextAPI } from '@/service/middleware/entry'; |
| 2 | +import { authCert } from '@fastgpt/service/support/permission/auth/common'; |
| 3 | +import { NextApiRequest, NextApiResponse } from 'next'; |
| 4 | +import { MongoResourcePermission } from '@fastgpt/service/support/permission/schema'; |
| 5 | +import { TeamPermission } from '@fastgpt/global/support/permission/user/controller'; |
| 6 | +import { |
| 7 | + TeamApikeyCreatePermissionVal, |
| 8 | + TeamAppCreatePermissionVal, |
| 9 | + TeamDatasetCreatePermissionVal |
| 10 | +} from '@fastgpt/global/support/permission/user/constant'; |
| 11 | + |
| 12 | +async function handler(req: NextApiRequest, _res: NextApiResponse) { |
| 13 | + await authCert({ req, authRoot: true }); |
| 14 | + // 更新团队权限: |
| 15 | + // 目前所有有 TeamWritePermission 的,都需要添加三个新的权限。 |
| 16 | + |
| 17 | + const rps = await MongoResourcePermission.find({ |
| 18 | + resourceType: 'team', |
| 19 | + teamId: { $exists: true }, |
| 20 | + resourceId: null |
| 21 | + }); |
| 22 | + |
| 23 | + for (const rp of rps) { |
| 24 | + const per = new TeamPermission({ per: rp.permission }); |
| 25 | + if (per.hasWritePer) { |
| 26 | + const newPer = per.addPer( |
| 27 | + TeamAppCreatePermissionVal, |
| 28 | + TeamDatasetCreatePermissionVal, |
| 29 | + TeamApikeyCreatePermissionVal |
| 30 | + ); |
| 31 | + rp.permission = newPer.value; |
| 32 | + rp.save(); |
| 33 | + } |
| 34 | + } |
| 35 | + |
| 36 | + return { success: true }; |
| 37 | +} |
| 38 | + |
| 39 | +export default NextAPI(handler); |
0 commit comments