Skip to main content

Roles and Permissions

Related docs: SDLC/REQUIREMENTS · SDLC/DEVELOPMENT · Security Compliance


1. Role Hierarchy

Pakashop implements a comprehensive Role-Based Access Control (RBAC) system with 12 distinct roles. Roles are stored on the User.role field and enforced via middleware.

RoleIDDescriptionMFA Required
CUSTOMERcustomerEnd consumer; browses, purchases, tracks ordersOptional
SHOP_OWNERshop_ownerVendor with approved shop; manages products, inventory, ordersMandatory
SERVICE_PROVIDERservice_providerService-based vendor (e.g., repairs, consultations)Optional
DELIVERY_AGENTdelivery_agentIndividual or courier company driver; manages deliveriesMandatory
PLATFORM_ADMINplatform_adminFull platform administration; user management, system configMandatory
MODERATORmoderatorContent moderation; reviews flagged images, productsMandatory
FRAUD_ANALYSTfraud_analystReviews fraud detection queue; approves/rejects blocked paymentsMandatory
FINANCE_ADMINfinance_adminFinancial operations; settlements, reconciliation, payoutsMandatory
SUPPORT_AGENTsupport_agentCustomer support; views orders, handles ticketsOptional
SELLERsellerPending seller application; limited access until approvedOptional
FLEET_MANAGERfleet_managerCourier company admin; manages sub-agents, fleet operationsMandatory
SYSTEMsystemInternal system role; used by automated jobs, cron tasksN/A

2. Permissions Matrix

Legend

  • F Full access
  • 📝 Own resources only
  • 👁️ Read-only
  • ❌ No access

2.1 Core Business Operations

PermissionCUSTOMERSHOP_OWNERSERVICE_PROVIDERDELIVERY_AGENTPLATFORM_ADMINMODERATORFRAUD_ANALYSTFINANCE_ADMINSUPPORT_AGENTSELLERFLEET_MANAGERSYSTEM
Browse productsFFFFFFFFFFFF
Place ordersFFFFFFFFFFFF
View own ordersF📝📝📝F👁️👁️👁️📝📝📝F
Cancel own orderFFF
Manage cartFFFFFFFFFFFF
Apply couponsFFFFFFFFFFFF
Redeem loyalty pointsFFFFFFFFFFFF

2.2 Vendor Operations

PermissionCUSTOMERSHOP_OWNERSERVICE_PROVIDERDELIVERY_AGENTPLATFORM_ADMINMODERATORFRAUD_ANALYSTFINANCE_ADMINSUPPORT_AGENTSELLERFLEET_MANAGERSYSTEM
Create products📝📝FF
Edit own products📝📝FF
Delete own products📝📝FF
Manage inventory📝📝FF
View own shop analytics📝📝F👁️F
Set wholesale tiers📝FF
View own settlements📝📝F👁️F
Submit seller applicationF

2.3 Delivery Operations

PermissionCUSTOMERSHOP_OWNERSERVICE_PROVIDERDELIVERY_AGENTPLATFORM_ADMINMODERATORFRAUD_ANALYSTFINANCE_ADMINSUPPORT_AGENTSELLERFLEET_MANAGERSYSTEM
Apply as delivery agentF
Toggle availability📝F📝F
View assigned deliveries📝F📝F
Confirm delivery (PIN)📝FF
Capture digital signature📝FF
Manage fleet sub-agents📝
View delivery tracking📝📝📝📝F📝📝F

2.4 Admin Operations

PermissionCUSTOMERSHOP_OWNERSERVICE_PROVIDERDELIVERY_AGENTPLATFORM_ADMINMODERATORFRAUD_ANALYSTFINANCE_ADMINSUPPORT_AGENTSELLERFLEET_MANAGERSYSTEM
Manage usersFF
Manage rolesFF
Approve seller applicationsFF
Moderate contentFFF
Review fraud queueFFF
Release settlementsFFF
View reconciliation reportsFFF
Send broadcast notificationsFF
Manage feature flagsFF
View platform analyticsFFF
Manage ZRA invoicing configFFF
Generate reports📝📝FFF
View all ordersF👁️📝F
Cancel any orderFF
Approve/reject delivery agentsFF
Suspend/activate delivery agentsFF

2.5 System Operations

PermissionCUSTOMERSHOP_OWNERSERVICE_PROVIDERDELIVERY_AGENTPLATFORM_ADMINMODERATORFRAUD_ANALYSTFINANCE_ADMINSUPPORT_AGENTSELLERFLEET_MANAGERSYSTEM
Execute cron jobsF
Process BullMQ jobsF
Trigger database migrationsF
Access internal API endpointsF

3. Role Constraints and Business Rules

3.1 Mutually Exclusive Roles

The following role combinations are prohibited to prevent conflicts of interest:

Role ACannot Also BeReason
PLATFORM_ADMINSHOP_OWNER, DELIVERY_AGENTPrevents admin abuse of marketplace position
SHOP_OWNERDELIVERY_AGENTPrevents shipping conflicts of interest
DELIVERY_AGENTSHOP_OWNERSame as above
SELLERSHOP_OWNERSELLER is a transitional role; becomes SHOP_OWNER on approval

3.2 Role Transition Flow

SELLER

▼ (admin approves application)
SHOP_OWNER

▼ (can request additional role)
SERVICE_PROVIDER (optional dual-role)
CUSTOMER

▼ (submits delivery application)
DELIVERY_AGENT

▼ (assigned to courier company)
FLEET_MANAGER (if company admin)

3.3 MFA Enforcement

Role CategoryMFA RequiredMethods
Elevated (PLATFORM_ADMIN, SHOP_OWNER, DELIVERY_AGENT, MODERATOR, FRAUD_ANALYST, FINANCE_ADMIN, FLEET_MANAGER)MandatoryTOTP (speakeasy), Email OTP, SMS (Twilio)
Standard (CUSTOMER, SERVICE_PROVIDER, SUPPORT_AGENT)OptionalTOTP, Email OTP
Transitional (SELLER)N/ANot applicable until role upgrade
System (SYSTEM)N/AInternal API key authentication

4. Implementation

4.1 Middleware

// middleware/rbac.js
const ROLE_HIERARCHY = {
system: 100,
platform_admin: 90,
finance_admin: 80,
fraud_analyst: 75,
moderator: 70,
fleet_manager: 65,
shop_owner: 60,
service_provider: 55,
delivery_agent: 50,
support_agent: 40,
customer: 10,
seller: 5,
};

const MUTUALLY_EXCLUSIVE = [
['platform_admin', 'shop_owner'],
['platform_admin', 'delivery_agent'],
['shop_owner', 'delivery_agent'],
];

const requireRoles = (...allowedRoles) => {
return (req, res, next) => {
const userRole = req.user.role;

if (!allowedRoles.includes(userRole)) {
return res.status(403).json({
success: false,
code: 'AUTH_002',
message: 'Insufficient permissions'
});
}

next();
};
};

const requireMfa = (req, res, next) => {
const elevatedRoles = [
'platform_admin', 'shop_owner', 'delivery_agent',
'moderator', 'fraud_analyst', 'finance_admin', 'fleet_manager'
];

if (elevatedRoles.includes(req.user.role) && !req.user.mfaVerified) {
return res.status(403).json({
success: false,
code: 'MFA_001',
message: 'Multi-factor authentication required'
});
}

next();
};

module.exports = { requireRoles, requireMfa, ROLE_HIERARCHY };

4.2 Route Usage

// routes/admin.js
const { requireRoles } = require('../middleware/rbac');

router.get('/users',
authenticate,
requireRoles('PLATFORM_ADMIN'),
adminController.listUsers
);

router.patch('/seller-applications/:id/approve',
authenticate,
requireMfa,
requireRoles('PLATFORM_ADMIN', 'MODERATOR'),
adminController.approveSeller
);

router.get('/fraud-queue',
authenticate,
requireMfa,
requireRoles('PLATFORM_ADMIN', 'FRAUD_ANALYST'),
fraudController.listQueue
);

5. SYSTEM Role

The SYSTEM role is reserved for automated processes and should never be assigned to human users.

5.1 Use Cases

  • Cron job execution (scheduler service)
  • BullMQ job processing
  • Database migration triggers
  • Internal service-to-service communication
  • Automated report generation
  • Settlement batch processing

5.2 Authentication

SYSTEM role requests authenticate via the x-internal-key header (not JWT cookies):

// middleware/internal-auth.js
const authenticateInternal = (req, res, next) => {
const internalKey = req.headers['x-internal-key'];

if (internalKey !== process.env.INTERNAL_API_KEY) {
return res.status(401).json({
success: false,
code: 'AUTH_003',
message: 'Invalid internal API key'
});
}

req.user = { role: 'SYSTEM', id: 'system' };
next();
};

For internal use only. Do not distribute outside Pakashop engineering.