Spaces:
Running
Running
Download apps/api/dist/common/platform-admin.js from Benaah/MicProtocol: direct link, hf CLI and curl.
- Browser
- Download file 1.26 kB
-
https://huggingface.co/spaces/Benaah/MicProtocol/resolve/main/apps/api/dist/common/platform-admin.js
- Command line
-
hf download hf://spaces/Benaah/MicProtocol/apps/api/dist/common/platform-admin.js
-
curl -L -o platform-admin.js https://huggingface.co/spaces/Benaah/MicProtocol/resolve/main/apps/api/dist/common/platform-admin.js
1.26 kB
| ; | |
| Object.defineProperty(exports, "__esModule", { value: true }); | |
| exports.deriveAdminRole = deriveAdminRole; | |
| exports.assertPlatformAdmin = assertPlatformAdmin; | |
| exports.isPlatformAdmin = isPlatformAdmin; | |
| const common_1 = require("@nestjs/common"); | |
| const shared_types_1 = require("@micprotocol/shared-types"); | |
| function deriveAdminRole(user) { | |
| if (user.adminRole) | |
| return user.adminRole; | |
| if (user.isAdmin) | |
| return shared_types_1.AdminRole.SUPER_ADMIN; | |
| return null; | |
| } | |
| async function assertPlatformAdmin(prisma, userId) { | |
| const user = await prisma.user.findUnique({ | |
| where: { id: userId }, | |
| select: { isAdmin: true, adminRole: true, suspendedAt: true }, | |
| }); | |
| if (!user) { | |
| throw new common_1.ForbiddenException("Admin privileges required"); | |
| } | |
| if (user.suspendedAt) { | |
| throw new common_1.ForbiddenException("Account is suspended"); | |
| } | |
| if (!deriveAdminRole(user)) { | |
| throw new common_1.ForbiddenException("Admin privileges required"); | |
| } | |
| } | |
| async function isPlatformAdmin(prisma, userId) { | |
| try { | |
| await assertPlatformAdmin(prisma, userId); | |
| return true; | |
| } | |
| catch { | |
| return false; | |
| } | |
| } | |
| //# sourceMappingURL=platform-admin.js.map |