Permissions System
User roles and permissions
Permission System Documentation
Complete guide to the DBK Gaming Platform permission and rank system.
Overview
The platform uses a two-tiered permission system:
- Rank-Based Permissions: Users have a rank (MEMBER, MODERATOR, ADMIN) that grants baseline permissions
- Granular Permission Overrides: Individual permissions can be granted or revoked to override rank defaults
This provides flexibility to:
- Grant moderators access to specific features without full admin access
- Revoke specific permissions from users who otherwise have high ranks
- Create custom permission sets for specific users
Rank System
Rank Hierarchy
| Rank | Level | Description |
|---|---|---|
| MEMBER | 1 | Default rank for all users. Basic platform access. |
| MODERATOR | 50 | Can moderate content, manage forum, approve submissions. |
| ADMIN | 100 | Full platform access. Can manage users, permissions, and system settings. |
Rank Enforcement
- Higher ranks inherit all permissions of lower ranks
- Users cannot promote others to their own rank or higher
- Users cannot modify the rank of users at or above their level
- ADMINs can promote users to MODERATOR
- ADMINs cannot demote other ADMINs
User Rank Assignment
Every user automatically receives a MEMBER rank upon first login. ADMINs can promote users through:
API Endpoint: PATCH /api/ranks/users/:id
Example:
{
"rank": "MODERATOR"
}
Permission Types
Platform Permissions
These permissions control access to platform-wide features:
| Permission | Description | Default Ranks |
|---|---|---|
MANAGE_USERS | Manage user accounts and roles | ADMIN |
MANAGE_SERVERS | Manage Discord servers in the system | ADMIN |
MANAGE_ANNOUNCEMENTS | Create and manage announcements | ADMIN, MODERATOR |
VIEW_AUDIT_LOGS | View admin audit logs | ADMIN |
MANAGE_SYSTEM | Manage system settings and configuration | ADMIN |
MANAGE_LIVECHAT_SETTINGS | Manage livechat Discord integration settings | ADMIN |
ACCESS_ADMIN_PANEL | Access admin panel | ADMIN, MODERATOR |
Forum Permissions
These permissions control forum access and moderation:
| Permission | Description | Default Ranks |
|---|---|---|
VIEW_CATEGORY | View forum categories | ALL |
CREATE_THREAD | Create forum threads | ALL |
REPLY_TO_THREAD | Reply to forum threads | ALL |
EDIT_OWN_POST | Edit own forum posts | ALL |
DELETE_OWN_POST | Delete own forum posts | ALL |
MODERATE_FORUM | Moderate forum content (all categories) | MODERATOR, ADMIN |
MODERATE_CATEGORY | Moderate specific forum category | MODERATOR, ADMIN |
PIN_THREAD | Pin forum threads | MODERATOR, ADMIN |
LOCK_THREAD | Lock forum threads | MODERATOR, ADMIN |
Game Server Permissions
These permissions control game server submissions:
| Permission | Description | Default Ranks |
|---|---|---|
SUBMIT_GAME_SERVER | Submit game servers | ALL |
EDIT_OWN_SERVER | Edit own game servers | ALL |
APPROVE_GAME_SERVER | Approve game servers | MODERATOR, ADMIN |
APPROVE_GAME_SERVERS | Approve game servers (alias) | MODERATOR, ADMIN |
Server-Specific Permissions
These permissions control per-server access:
| Permission | Description | Server Ranks |
|---|---|---|
SERVER_OWNER | Server owner permissions | SERVER_OWNER |
SERVER_ADMIN | Server admin permissions | SERVER_OWNER, SERVER_ADMIN |
SERVER_MEMBER | Server member permissions | ALL |
Granular Permission Overrides
Admins can grant or revoke individual permissions to fine-tune access.
Grant Permission
API Endpoint: POST /api/ranks/permissions
Example - Grant forum moderation for specific category:
{
"userId": "123456789012345678",
"permission": "moderate_category",
"granted": true,
"scope": "category_clxyz123"
}
Example - Revoke announcement management:
{
"userId": "123456789012345678",
"permission": "manage_announcements",
"granted": false,
"scope": null
}
Permission Scopes
Permissions can be scoped to specific resources:
- Category-scoped: Permission applies only to a specific forum category
scope:"category_id"
- Server-scoped: Permission applies only to a specific Discord server
scope:"server_id"
- Global: Permission applies platform-wide
scope:null
Example: A user could have MODERATE_CATEGORY permission for the "General Discussion" category but not other categories.
Server Membership System
Each Discord server listing can have its own members with server-specific ranks.
Server Ranks
| Rank | Description |
|---|---|
| SERVER_OWNER | Full control over server listing and members |
| SERVER_ADMIN | Can manage server settings and members |
| SERVER_MODERATOR | Can moderate server-specific content |
| SERVER_MEMBER | Basic server access (can view and interact) |
Server Member Management
Add Member: POST /api/servers/:id/members
{
"userId": "user_id",
"rank": "SERVER_MEMBER"
}
Update Member Rank: PATCH /api/servers/:id/members/:userId
{
"rank": "SERVER_ADMIN"
}
Remove Member: DELETE /api/servers/:id/members/:userId
Server Access Control
- Only SERVER_ADMINs and SERVER_OWNERs can manage members
- Only SERVER_OWNERs can promote users to SERVER_ADMIN
- Platform ADMINs can override all server permissions
- Server members can view private server information
Forum Category Permissions
Forum categories can have custom permission requirements.
Category-Level Access Control
Each forum category has:
minReadRank: Minimum rank to view threads (default: MEMBER)minWriteRank: Minimum rank to create threads (default: MEMBER)
Example:
{
"name": "Staff Discussions",
"slug": "staff",
"minReadRank": "MODERATOR",
"minWriteRank": "MODERATOR"
}
Category Permission Overrides
Admins can create per-category permission overrides for specific ranks:
Model: ForumCategoryPermission
Fields:
categoryId: Category this permission applies torank: Rank this permission applies tocanRead: Can view threads (default: true)canWrite: Can create threads/posts (default: true)canModerate: Can pin/lock/delete (default: false)
Example: Allow MEMBERs to read but not write in "Announcements" category:
{
"categoryId": "category_announcements",
"rank": "MEMBER",
"canRead": true,
"canWrite": false,
"canModerate": false
}
Permission Resolution
When checking if a user can perform an action, the system follows this priority:
- Platform ADMIN: Always has full access
- Granular Permission Override: Check if user has specific permission granted/revoked
- Rank-Based Permission: Check if user's rank grants the permission
- Category-Specific Permission: Check category permission overrides
- Ownership: Check if user owns the resource (can edit own posts, etc.)
Example Permission Check Flow:
Can user create thread in category "General Discussion"?
1. Is user ADMIN? → NO, continue
2. Does user have REVOKED "create_thread" for this category? → NO, continue
3. Does user have GRANTED "create_thread" for this category? → NO, continue
4. Does user's rank >= category.minWriteRank? → YES (MEMBER >= MEMBER)
→ ALLOW
Permission Checking Utilities
The platform provides utility functions for permission checks:
Backend Functions
checkUserPermission(userId, permission, scope)
- Returns:
{ allowed: boolean, reason?: string } - Checks if user has specific permission with optional scope
hasRank(userId, minRank)
- Returns:
boolean - Checks if user has at least the specified rank
checkServerMembership(userId, serverId, minRank)
- Returns:
boolean - Checks if user is a member of server with at least minRank
canAccessCategory(userId, categoryId, action)
- Returns:
{ allowed: boolean, reason?: string } - Checks if user can perform action ('read' or 'write') in category
canModerateCategory(userId, categoryId)
- Returns:
boolean - Checks if user can moderate specific category
Frontend Hooks
useAuth() context provides:
const { user, hasRank, hasPermission } = useAuth();
if (hasRank('MODERATOR')) {
// Show moderation UI
}
if (hasPermission('manage_announcements')) {
// Show announcement management
}
Middleware
The backend uses middleware to enforce permissions on routes:
requireAuth
Requires user to be authenticated.
router.get('/protected', requireAuth, async (req, res) => {
// req.user is available
});
requireRank(minRank)
Requires user to have at least specified rank.
router.post('/admin/action', requireAuth, requireRank('ADMIN'), async (req, res) => {
// Only ADMINs can access
});
requirePermission(permission, scopeKey)
Requires user to have specific permission.
router.post('/forum/moderate', requireAuth, requirePermission('moderate_forum'), async (req, res) => {
// Only users with moderate_forum permission
});
requireServerMembership(minRank, paramKey)
Requires user to be a server member with minimum rank.
router.get('/servers/:id/settings', requireAuth, requireServerMembership('SERVER_ADMIN', 'id'), async (req, res) => {
// Only SERVER_ADMINs of this server
});
Audit Logging
All permission changes are logged to AdminAuditLog:
Logged Actions
UPDATE_USER_RANK: User rank changedGRANT_PERMISSION: Permission granted to userREVOKE_PERMISSION: Permission revoked from user
Audit Log Entry:
{
"id": "log_id",
"adminId": "admin_user_id",
"action": "UPDATE_USER_RANK",
"targetType": "user",
"targetId": "target_user_id",
"metadata": "{\"oldRank\":\"MEMBER\",\"newRank\":\"MODERATOR\"}",
"createdAt": "2024-01-01T00:00:00.000Z"
}
Caching
Permissions are cached for performance:
- User Rank Cache: 5 minute TTL
- User Permissions Cache: 5 minute TTL
- Server Membership Cache: 5 minute TTL
Cache is automatically invalidated when:
- User rank is changed
- Permission is granted/revoked
- Server membership is modified
Security Considerations
Best Practices
- Principle of Least Privilege: Grant minimum permissions needed
- Regular Audits: Review audit logs for suspicious permission changes
- Scope Permissions: Use scoped permissions when possible (category-specific, server-specific)
- Test Permissions: Verify permission enforcement in development before production
Security Rules
- Users cannot promote others to or above their own rank
- Users cannot modify permissions for users at or above their level
- Platform ADMINs can override all permissions
- Permission checks happen on both frontend (UX) and backend (security)
- All permission changes are logged with admin ID and timestamp
Migration from Legacy System
The platform previously used a simple User.role field with only "MEMBER" and "ADMIN" values.
Migration Process
-
Automatic Migration: All users receive a
UserRankrecord on first access- Existing
ADMINusers →ADMINrank (level 100) - All other users →
MEMBERrank (level 1)
- Existing
-
Manual Migration Script:
scripts/migrate-user-ranks.jsnode scripts/migrate-user-ranks.js -
Backward Compatibility:
User.rolefield still exists for legacy code but should not be used
Deprecation Timeline
- Current: Both
User.roleandUserRankexist - Future:
User.rolewill be removed in a future update - Action Required: Update all code to use rank-based permission checks
Examples
Example 1: Promote User to Moderator
// Admin promotes user
const response = await fetch('/api/ranks/users/123456789', {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
credentials: 'include',
body: JSON.stringify({ rank: 'MODERATOR' })
});
const user = await response.json();
console.log(user.rank); // { rank: 'MODERATOR', level: 50 }
Example 2: Grant Category Moderation Permission
// Admin grants category-specific moderation
const response = await fetch('/api/ranks/permissions', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
credentials: 'include',
body: JSON.stringify({
userId: '123456789',
permission: 'moderate_category',
granted: true,
scope: 'category_general'
})
});
Example 3: Check Permission in Frontend
import { useAuth } from '@/contexts/AuthContext';
function ModerateButton({ categoryId }) {
const { user, hasPermission } = useAuth();
if (!hasPermission('moderate_category', categoryId)) {
return null; // Hide button if no permission
}
return <button>Moderate</button>;
}
Example 4: Add User as Server Admin
// Server owner adds user as admin
const response = await fetch('/api/servers/987654321/members', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
credentials: 'include',
body: JSON.stringify({
userId: '123456789',
rank: 'SERVER_ADMIN'
})
});
Troubleshooting
User Can't Access Feature They Should Have Access To
- Check user rank:
GET /api/ranks/users?search=username - Check user permissions: Look for revoked permissions
- Check cache: Permission cache may be stale (wait 5 minutes or clear cache)
- Check category permissions: If forum-related, check category-specific permissions
Permission Changes Not Taking Effect
- Clear cache: Invalidate user permission cache
- Check audit logs: Verify permission change was logged
- Verify scope: Ensure scope matches (null vs specific ID)
- Refresh session: User may need to log out and back in
Cannot Promote User
- Verify your rank: You must be higher rank than target
- Verify target rank: Cannot promote users at or above your level
- Verify target rank level: Cannot promote to your rank or higher
API Reference
See API.md for complete API documentation of permission endpoints:
GET /api/ranks/usersPATCH /api/ranks/users/:idGET /api/ranks/permissionsPOST /api/ranks/permissionsDELETE /api/ranks/permissions/:id
Last Updated: February 17, 2026