# Permission Management

## Purpose
Permission Management provides granular control over what actions each role can perform within the system. It displays a comprehensive matrix of permissions organized by module, allowing administrators to assign specific capabilities to each role. This is the core of the RBAC (Role-Based Access Control) system.

## Components
- Page header with icon and title
- Role selector dropdown
- Permission summary (Selected/Total/Coverage)
- Permission cards organized by module (16 modules)
- Each card contains multiple permission checkboxes
- Save/Reset buttons
- Business Rules section

## Header
- **Title**: "Permission Management"
- **Subtitle**: "Configure role-based access control"
- **Page Icon**: Blue background with lock icon

## Filters
| Filter | Type | Options |
|--------|------|---------|
| Role Selector | select | Super Admin, Operations, Agent, Merchant, Support Manager, Finance Manager, Customer Support |

## Search
None

## Buttons
| Button | Action | Location |
|--------|--------|----------|
| Save Permissions | Save current permission configuration | Top bar |
| Reset | Reset to default permissions | Top bar |
| Select All | Select all permissions in a module | Per card header |

## Forms

### Permission Cards

#### Dashboard Module
| Permission | Key |
|------------|-----|
| View Dashboard | `view` |
| View Statistics | `statistics` |
| View Reports | `reports` |
| View Charts | `charts` |
| Export Dashboard | `export` |

#### User Management Module
| Permission | Key |
|------------|-----|
| View Users | `view` |
| Create Users | `create` |
| Edit Users | `edit` |
| Delete Users | `delete` |
| Enable/Disable Users | `enable` |
| Reset Passwords | `reset_password` |
| Export Users | `export` |

#### Agent Management Module
| Permission | Key |
|------------|-----|
| View Agents | `view` |
| Create Agents | `create` |
| Edit Agents | `edit` |
| Delete Agents | `delete` |
| Manage Commissions | `commission` |
| Agent Balance Adjustment | `balance` |
| Export Agents | `export` |

#### Merchant Management Module
| Permission | Key |
|------------|-----|
| View Merchants | `view` |
| Create Merchants | `create` |
| Edit Merchants | `edit` |
| Delete Merchants | `delete` |
| Assign Agents | `assign` |
| Merchant Balance | `balance` |
| Commission Settings | `commission` |
| Merchant Adjustment | `adjustment` |
| Export Merchants | `export` |

#### Role Management Module
| Permission | Key |
|------------|-----|
| View Roles | `view` |
| Create Roles | `create` |
| Edit Roles | `edit` |
| Delete Roles | `delete` |

#### Permission Management Module
| Permission | Key |
|------------|-----|
| View Permissions | `view` |
| Edit Permissions | `edit` |
| Update Permissions | `update` |

#### IP Management Module
| Permission | Key |
|------------|-----|
| View IPs | `view` |
| Add IPs | `add` |
| Delete IPs | `delete` |
| Toggle IP Status | `toggle` |
| Export IPs | `export` |

#### Payment Integration Module
| Permission | Key |
|------------|-----|
| View Providers | `view` |
| Add Providers | `add` |
| Generate Keys | `generate` |
| Download Credentials | `download` |
| Test Connection | `test` |
| Manage Webhooks | `webhook` |

#### Hosted Payment Module
| Permission | Key |
|------------|-----|
| View Configuration | `view` |
| Edit Configuration | `edit` |
| Generate Code | `generate` |
| Download SDK | `download` |

#### Transaction Orders Module
| Permission | Key |
|------------|-----|
| View Orders | `view` |
| Search Orders | `search` |
| Manual Process | `process` |
| Retry Notification | `retry` |
| Export Orders | `export` |

#### Transaction Details Module
| Permission | Key |
|------------|-----|
| View Transactions | `view` |
| Search Transactions | `search` |
| Export Ledger | `export` |

#### Withdrawal Orders Module
| Permission | Key |
|------------|-----|
| View Withdrawals | `view` |
| Approve Withdrawals | `approve` |
| Reject Withdrawals | `reject` |
| Export Withdrawals | `export` |

#### Customer Support Module
| Permission | Key |
|------------|-----|
| View Tickets | `view` |
| Create Tickets | `create` |
| Edit Tickets | `edit` |
| Assign Tickets | `assign` |
| Close Tickets | `close` |
| Export Tickets | `export` |

#### Notifications Module
| Permission | Key |
|------------|-----|
| View Notifications | `view` |
| Send Notifications | `send` |
| Broadcast | `broadcast` |
| Clear Notifications | `clear` |

#### Activity Logs Module
| Permission | Key |
|------------|-----|
| View Logs | `view` |
| Search Logs | `search` |
| Export Logs | `export` |

#### Profile Module
| Permission | Key |
|------------|-----|
| View Profile | `view` |
| Edit Profile | `edit` |
| Change Password | `password` |

## Tables
None (uses card-based layout)

## Action Buttons
| Button | Function |
|--------|----------|
| Save Permissions | Persist permission changes to database |
| Reset | Revert to default permissions |
| Select All | Toggle all permissions in a module |

## Workflow
1. Admin navigates to Permission Management page
2. Selects a role from the dropdown (e.g., "Operations")
3. Views permission cards organized by module
4. "Select All" checkbox toggles all permissions in a module
5. Individual checkboxes enable/disable specific permissions
6. Permission summary shows Selected/Total/Coverage %
7. Admin checks/unchecks permissions as needed
8. Clicks "Save Permissions" to persist changes
9. Can click "Reset" to revert to defaults

### Role Presets
| Role | Description |
|------|-------------|
| Super Admin | Full access to all modules |
| Operations | Operational management access |
| Agent | Limited agent-specific access |
| Merchant | Merchant dashboard access |
| Support Manager | Customer support access |
| Finance Manager | Financial reporting access |
| Customer Support | Ticket management access |

## Translation Requirements
| Key | English | Description |
|-----|---------|-------------|
| `permission_management` | Permission Management | Page title |
| `role` | Role | Selector label |
| `permissions` | Permissions | Summary label |
| `save` | Save | Button text |
| `reset` | Reset | Button text |
| `select_all` | Select All | Checkbox label |
| `dashboard` | Dashboard | Module name |
| `user_management` | User Management | Module name |
| `agent_management` | Agent Management | Module name |
| `merchant_management` | Merchant Management | Module name |
| `role_management` | Role Management | Module name |
| `permission_management` | Permission Management | Module name |
| `ip_management` | IP Management | Module name |
| `payment_integration` | Payment Integration | Module name |
| `hosted_payment` | Hosted Payment | Module name |
| `transaction_orders` | Transaction Orders | Module name |
| `transaction_details` | Transaction Details | Module name |
| `withdrawal_orders` | Withdrawal Orders | Module name |
| `customer_support` | Customer Support | Module name |
| `notifications` | Notifications | Module name |
| `activity_logs` | Activity Logs | Module name |
| `profile` | Profile | Module name |
| `view` | View | Permission |
| `create` | Create | Permission |
| `edit` | Edit | Permission |
| `delete` | Delete | Permission |
| `export` | Export | Permission |
| `statistics` | Statistics | Permission |
| `reports` | Reports | Permission |
| `charts` | Charts | Permission |
| `enable` | Enable | Permission |
| `disable` | Disable | Permission |
| `reset_password` | Reset Password | Permission |
| `commission` | Commission | Permission |
| `balance` | Balance | Permission |
| `assign` | Assign | Permission |
| `adjustment` | Adjustment | Permission |
| `add` | Add | Permission |
| `toggle` | Toggle | Permission |
| `generate` | Generate | Permission |
| `download` | Download | Permission |
| `test` | Test | Permission |
| `webhook` | Webhook | Permission |
| `search` | Search | Permission |
| `process` | Process | Permission |
| `retry` | Retry | Permission |
| `approve` | Approve | Permission |
| `reject` | Reject | Permission |
| `send` | Send | Permission |
| `broadcast` | Broadcast | Permission |
| `clear` | Clear | Permission |
| `assign` | Assign | Permission |
| `close` | Close | Permission |
| `password` | Password | Permission |

## Responsive Requirements

### Desktop (≥1024px)
- Role selector and summary in top bar
- 3-column permission card grid
- Full-width cards with inline checkboxes

### Tablet (768px–1023px)
- 2-column permission card grid
- Stacked role selector

### Mobile (<768px)
- Single column permission cards
- Full-width cards
- Stacked layout

## API Dependency
- **Permissions API**: GET `/api/permissions/:role` — Get permissions for a role
- **Update Permissions**: PUT `/api/permissions/:role` — Update permissions for a role
- **Default Permissions**: GET `/api/permissions/defaults` — Get default permission sets
