admin visibility
# Admin Colleague Visibility (Phase 4 & 5)
## Overview
Phase 4 extends the colleague visibility feature to give admins enhanced visibility of logged-in employees with timestamps. Phase 5 adds live updates that auto-refresh every 5 seconds.
## Key Features
### Admin View
- **Always On**: Admin always sees logged-in employees regardless of toggle setting
- **Enhanced Details**: Shows login timestamps and location (if enabled) in addition to names
- **Live Updates**: Auto-refreshes every 5 seconds without page reload (Phase 5)
- **Real-Time**: Shows only currently logged-in employees (not logged out)
- **Sorted**: Ordered by most recent login first
### Employee View
- **Toggle Controlled**: Can be enabled/disabled via admin settings
- **Privacy Focused**: Shows only first and last names
- **Live Updates**: Auto-refreshes every 5 seconds without page reload (Phase 5)
- **Real-Time**: Shows only currently logged-in colleagues (not logged out)
- **Alphabetically Sorted**: Easy to scan colleague list
## How It Works
### Admin Dashboard (`/<company>/admin`)
After HR authenticates, they see:
- Blue info box at top of page
- Table with columns: Name, Login Time, Location
- Count of employees currently logged in
- Auto-updates every 5 seconds
- Always visible regardless of settings
### Employee Dashboard (`/<company>/login`)
After employee logs in via face verification, they see:
- Blue info box with colleague names (if enabled)
- Simple list format: "FirstName LastName"
- Count of colleagues currently logged in
- Auto-updates every 5 seconds
- Hidden if admin disables the feature
### Settings Toggle (`/<company>/settings`)
Admin can control employee visibility:
- **Enabled (Show to Employees)**: Employees see colleague list
- **Disabled (Admin Only)**: Only admin sees the list
## Database
Uses existing `colleague_visibility_enabled` column in `companies` table:
- `true` (default): Employees see colleague list
- `false`: Only admin sees colleague list
## Technical Implementation
### Python Functions
```python
# Individual function (used by API for live updates)
get_employees_logged_in_today_with_times(company_slug)
# Returns: FirstName|LastName|UserID|LoginTime (one per line)
# Optimized combined function (used for admin page load)
admin_login_data(company_slug)
# Returns both logged-in employees AND all employees in single call
# Format:
# ---LOGGED_IN---
# FirstName|LastName|UserID|LoginTime
# ---ALL_EMPLOYEES---
# UserID|FirstName|LastName
```
### Go Handler (Optimized - January 2026)
`dynamicAdminHandler()` now uses **Go-native database functions** for sub-second response:
- `verifyHRCredentialsGo()` - Auth via Go PostgreSQL driver
- `getAdminLoginDataGo()` - Direct SQL queries, no Python subprocess
**Performance:** Admin operations now complete in <0.5s, colleague visibility updates in <0.2s
The API endpoint for live updates still uses Python for compatibility.
### Template
`company_admin.html` displays table with enhanced details for admin.
## Usage Example
**Admin Experience (Phase 5):**
1. HR visits `/<company>/admin`
2. Authenticates with credentials (<0.5s response)
3. Sees live employee table:
```
Employees Currently Logged In (2)
Name User ID Login Time
John Doe JD1456 09:15:23
Jane Smith JS1457 08:45:12
```
4. Table auto-updates every 5 seconds (<0.2s per update)
5. When employee logs out, they disappear within 5 seconds
6. Can toggle employee visibility in settings
7. Admin view remains visible regardless of toggle
**Employee Experience (Enabled - Phase 5):**
1. Employee logs in
2. Sees live colleague list:
```
Colleagues Currently Logged In (2)
- Jane Smith
- John Doe
```
3. List auto-updates every 5 seconds
4. When colleague logs out, they disappear within 5 seconds
**Employee Experience (Disabled):**
1. Employee logs in
2. No colleague list shown
3. Admin still sees full details with live updates
## Benefits
- **Real-Time Oversight**: HR sees live updates of who's currently logged in
- **Flexible Privacy**: Control employee visibility based on company culture
- **Enhanced Details**: Admin gets timestamps for attendance tracking
- **Team Awareness**: Employees can see colleagues in real-time (when enabled)
- **No Refresh Needed**: Updates happen automatically every 5 seconds