|
| 1 | +# Admin Portal for Device Allocation - Implementation Plan |
| 2 | + |
| 3 | +## Current System Analysis |
| 4 | + |
| 5 | +The Appium Device Farm currently: |
| 6 | +- Manages devices for testing through a hub-node architecture |
| 7 | +- Has a React-based frontend dashboard |
| 8 | +- Uses Prisma with SQLite for data storage |
| 9 | +- Has APIs for device management (block/unblock, status checking) |
| 10 | +- Has no user authentication or team management system |
| 11 | + |
| 12 | +## Requirements |
| 13 | + |
| 14 | +1. Admin portal for device allocation |
| 15 | +2. Team-based access control for devices |
| 16 | +3. Admin users can allocate/deallocate devices to teams |
| 17 | +4. Team members can only access devices allocated to their team |
| 18 | +5. Simple authentication (no OAuth) |
| 19 | +6. Admin user management (universal admin with password change capability) |
| 20 | +7. Local database storage for user credentials |
| 21 | + |
| 22 | +## Implementation Plan |
| 23 | + |
| 24 | +### 1. Database Schema Updates |
| 25 | + |
| 26 | +We need to add new tables to the Prisma schema: |
| 27 | + |
| 28 | +```mermaid |
| 29 | +erDiagram |
| 30 | + User { |
| 31 | + String id PK |
| 32 | + String username |
| 33 | + String password |
| 34 | + String role |
| 35 | + DateTime createdAt |
| 36 | + DateTime updatedAt |
| 37 | + } |
| 38 | + Team { |
| 39 | + String id PK |
| 40 | + String name |
| 41 | + String description |
| 42 | + DateTime createdAt |
| 43 | + DateTime updatedAt |
| 44 | + } |
| 45 | + TeamMember { |
| 46 | + String id PK |
| 47 | + String userId FK |
| 48 | + String teamId FK |
| 49 | + DateTime createdAt |
| 50 | + DateTime updatedAt |
| 51 | + } |
| 52 | + DeviceAllocation { |
| 53 | + String id PK |
| 54 | + String deviceUdid |
| 55 | + String teamId FK |
| 56 | + DateTime createdAt |
| 57 | + DateTime updatedAt |
| 58 | + } |
| 59 | + User ||--o{ TeamMember : "has" |
| 60 | + Team ||--o{ TeamMember : "has" |
| 61 | + Team ||--o{ DeviceAllocation : "has" |
| 62 | +``` |
| 63 | + |
| 64 | +### 2. Authentication System |
| 65 | + |
| 66 | +1. Create authentication middleware |
| 67 | +2. Implement login/logout functionality |
| 68 | +3. Add password hashing for security |
| 69 | +4. Create session management (JWT-based) |
| 70 | +5. Add role-based access control (admin vs. team member) |
| 71 | + |
| 72 | +### 3. Backend API Endpoints |
| 73 | + |
| 74 | +Create new API endpoints for: |
| 75 | + |
| 76 | +1. **User Management** |
| 77 | + - Create/update/delete users |
| 78 | + - Change password |
| 79 | + - List users |
| 80 | + |
| 81 | +2. **Team Management** |
| 82 | + - Create/update/delete teams |
| 83 | + - Add/remove users from teams |
| 84 | + - List teams and their members |
| 85 | + |
| 86 | +3. **Device Allocation** |
| 87 | + - Allocate devices to teams |
| 88 | + - Deallocate devices from teams |
| 89 | + - List device allocations |
| 90 | + |
| 91 | +4. **Authentication** |
| 92 | + - Login |
| 93 | + - Logout |
| 94 | + - Get current user |
| 95 | + |
| 96 | +### 4. Frontend Components |
| 97 | + |
| 98 | +Add new pages and components to the dashboard: |
| 99 | + |
| 100 | +1. **Login Page** |
| 101 | + - Username/password form |
| 102 | + - Error handling |
| 103 | + |
| 104 | +2. **Admin Dashboard** |
| 105 | + - User management section |
| 106 | + - Team management section |
| 107 | + - Device allocation section |
| 108 | + |
| 109 | +3. **Team Member Dashboard** |
| 110 | + - View allocated devices |
| 111 | + - Access device details |
| 112 | + |
| 113 | +4. **Navigation Updates** |
| 114 | + - Add login/logout buttons |
| 115 | + - Show different navigation based on user role |
| 116 | + |
| 117 | +### 5. Integration with Existing System |
| 118 | + |
| 119 | +1. Modify device access control to check team allocations |
| 120 | +2. Update device listing to filter based on team membership |
| 121 | +3. Integrate authentication with existing API endpoints |
| 122 | + |
| 123 | +### 6. Implementation Steps |
| 124 | + |
| 125 | +#### Phase 1: Database and Authentication Setup |
| 126 | + |
| 127 | +1. Update Prisma schema with new models |
| 128 | +2. Create migration for the new tables |
| 129 | +3. Implement basic authentication system |
| 130 | +4. Create admin user management APIs |
| 131 | + |
| 132 | +#### Phase 2: Team Management |
| 133 | + |
| 134 | +1. Implement team CRUD operations |
| 135 | +2. Create team membership management |
| 136 | +3. Build team management UI |
| 137 | + |
| 138 | +#### Phase 3: Device Allocation |
| 139 | + |
| 140 | +1. Implement device allocation APIs |
| 141 | +2. Update device access control |
| 142 | +3. Create device allocation UI |
| 143 | + |
| 144 | +#### Phase 4: Integration and Testing |
| 145 | + |
| 146 | +1. Integrate authentication with existing endpoints |
| 147 | +2. Update device listing to respect team allocations |
| 148 | +3. Test all functionality |
| 149 | +4. Fix any issues |
| 150 | + |
| 151 | +## Technical Details |
| 152 | + |
| 153 | +### Authentication Flow |
| 154 | + |
| 155 | +```mermaid |
| 156 | +sequenceDiagram |
| 157 | + participant User |
| 158 | + participant Frontend |
| 159 | + participant AuthAPI |
| 160 | + participant Database |
| 161 | + |
| 162 | + User->>Frontend: Enter credentials |
| 163 | + Frontend->>AuthAPI: POST /api/auth/login |
| 164 | + AuthAPI->>Database: Verify credentials |
| 165 | + Database-->>AuthAPI: User data |
| 166 | + AuthAPI->>AuthAPI: Generate JWT |
| 167 | + AuthAPI-->>Frontend: Return JWT token |
| 168 | + Frontend->>Frontend: Store token in localStorage |
| 169 | + Frontend-->>User: Redirect to dashboard |
| 170 | +``` |
| 171 | + |
| 172 | +### Device Allocation Flow |
| 173 | + |
| 174 | +```mermaid |
| 175 | +sequenceDiagram |
| 176 | + participant Admin |
| 177 | + participant Frontend |
| 178 | + participant API |
| 179 | + participant Database |
| 180 | + |
| 181 | + Admin->>Frontend: Select devices and team |
| 182 | + Frontend->>API: POST /api/device-allocation |
| 183 | + API->>Database: Create allocation records |
| 184 | + Database-->>API: Confirmation |
| 185 | + API-->>Frontend: Success response |
| 186 | + Frontend-->>Admin: Show success message |
| 187 | +``` |
| 188 | + |
| 189 | +### Device Access Control Flow |
| 190 | + |
| 191 | +```mermaid |
| 192 | +sequenceDiagram |
| 193 | + participant User |
| 194 | + participant Frontend |
| 195 | + participant API |
| 196 | + participant Database |
| 197 | + |
| 198 | + User->>Frontend: Request device list |
| 199 | + Frontend->>API: GET /api/device with JWT |
| 200 | + API->>API: Extract user from JWT |
| 201 | + API->>Database: Get user's teams |
| 202 | + Database-->>API: Team IDs |
| 203 | + API->>Database: Get devices allocated to teams |
| 204 | + Database-->>API: Device list |
| 205 | + API-->>Frontend: Filtered device list |
| 206 | + Frontend-->>User: Display available devices |
| 207 | +``` |
| 208 | + |
| 209 | +## File Changes Required |
| 210 | + |
| 211 | +1. **Prisma Schema Update** |
| 212 | + - Add User, Team, TeamMember, and DeviceAllocation models |
| 213 | + |
| 214 | +2. **New Backend Files** |
| 215 | + - Authentication middleware |
| 216 | + - User controller |
| 217 | + - Team controller |
| 218 | + - Device allocation controller |
| 219 | + - Authentication controller |
| 220 | + |
| 221 | +3. **New Frontend Files** |
| 222 | + - Login page |
| 223 | + - Admin dashboard components |
| 224 | + - Team management components |
| 225 | + - Device allocation components |
| 226 | + - Authentication service |
| 227 | + |
| 228 | +4. **Existing File Modifications** |
| 229 | + - Update device service to check team allocations |
| 230 | + - Modify API routes to use authentication |
| 231 | + - Update frontend device listing to respect allocations |
| 232 | + |
| 233 | +## Security Considerations |
| 234 | + |
| 235 | +1. Password hashing using bcrypt |
| 236 | +2. JWT with appropriate expiration |
| 237 | +3. HTTPS for all communications |
| 238 | +4. Input validation and sanitization |
| 239 | +5. Protection against common attacks (CSRF, XSS) |
| 240 | + |
| 241 | +## Conclusion |
| 242 | + |
| 243 | +This implementation plan provides a comprehensive approach to adding an admin portal with team-based device allocation to the Appium Device Farm. The solution is designed to be simple yet secure, without requiring OAuth integration. |
0 commit comments