Skip to Content
Config folderpermissions.ts

permissions.ts — admin abilities

Path: src/config/permissions.ts

Not every admin can do everything. This file is the single registry of admin capability strings and the role → permission matrix. Routes call hasPermission(...) or use requirePermission(...) middleware instead of hard-coding role checks.

Identity types the server recognises

IdentityDetected byDefault permissions
Super adminUser.isAdmin === true (not a member of ADMIN_ROLES)ALL_PERMISSIONS — every key in PERMISSIONS
managerUser.adminRole === 'manager'full content + user management, no MANAGE_ADMINS and no MANAGE_RATE_LIMITS
creatorUser.adminRole === 'creator'content creation / editing, manage media + questions + PYQ + CA, no user / stats / admin / rate-limit power
Regular useradminRole null and isAdmin !== true[]

Permission constants

ConstantString valueUsed by
VIEW_USERSview_usersAdmin user list / detail
DELETE_USERSdelete_usersHard delete user (+ refresh tokens)
VIEW_STATSview_statsSignup chart, top exams/states, notification metrics, rate-limit reads, marketing list/read
VIEW_CONTENTview_contentAnnouncements / exam-info read
CREATE_CONTENTcreate_contentAnnouncement / exam-info create
EDIT_CONTENTedit_contentAnnouncement / exam-info update
DELETE_CONTENTdelete_contentAnnouncement / exam-info delete
MANAGE_VIDEOSmanage_videosVideos CRUD
MANAGE_QUESTIONSmanage_questionsVideo timestamps + MCQs + bulk import
MANAGE_PLAYLISTSmanage_playlistsPlaylist CRUD
MANAGE_MOCK_TESTSmanage_mock_testsMock test CRUD
MANAGE_PRACTICE_PYQSmanage_practice_pyqsPYQ bank taxonomy / questions
MANAGE_CURRENT_AFFAIRSmanage_current_affairsCA issues, items, MCQs, flashcards, entities
MANAGE_ADMINSmanage_adminsPromote/demote staff (super admin workflow)
MANAGE_RATE_LIMITSmanage_rate_limitsLive edits to /api/v1/admin/rate-limits policies (super admin only)

Role matrix

super adminmanagercreator
VIEW_USERS
DELETE_USERS
VIEW_STATS
VIEW_CONTENT
CREATE_CONTENT
EDIT_CONTENT
DELETE_CONTENT
MANAGE_VIDEOS
MANAGE_QUESTIONS
MANAGE_PLAYLISTS
MANAGE_MOCK_TESTS
MANAGE_PRACTICE_PYQS
MANAGE_CURRENT_AFFAIRS
MANAGE_ADMINS
MANAGE_RATE_LIMITS

How it’s used

  1. authMiddleware loads the user and stashes isAdmin + adminRole on c.get('user').
  2. adminMiddleware rejects non-admins (must be super admin or have an adminRole).
  3. Per-route requirePermission(PERMISSIONS.X) consults hasPermission(isAdmin, adminRole, X).
  4. If not allowed → 403 Forbidden.
// Inside admin.route.ts (example) adminRouter.delete( '/users/:id', requirePermission(PERMISSIONS.DELETE_USERS), async (c) => { /* … */ }, )

When you add a new admin feature

  1. Add a string constant under PERMISSIONS.
  2. Add it to the relevant role arrays in ROLE_PERMISSIONS (or leave it super-admin-only).
  3. Guard the new route with requirePermission(PERMISSIONS.YOUR_NEW_ONE).
  4. Update this page and routes/admin.mdx if it changes who sees the surface.

When you add a new role

  1. Add to the ADMIN_ROLES tuple.
  2. Add a full entry in ROLE_PERMISSIONS.
  3. Make sure the new role string is allowed in the POST /api/v1/admin/admins schema (assignRoleSchema in admin.route.ts).
  4. Update this matrix.
Last updated on