# Surveyor Role Implementation

## Summary
Added a new "SURVEYOR" role to the user management system for field surveyors who collect and enter tree data.

## Changes Made

### 1. Database Migration
- Created `add_surveyor_role.js` migration script
- Added SURVEYOR role to `user_master` table with ID: 6
- Fixed PostgreSQL sequence issue for auto-increment IDs

### 2. Role Permissions
The SURVEYOR role has the following permissions:
```json
{
  "can_collect_data": true,
  "can_enter_tree_details": true,
  "can_view_assigned_projects": true
}
```

### 3. Frontend Updates
- Updated `Frontend/src/contexts/RolesContext.jsx`
- CLIENT_ADMIN users can now create SURVEYOR users
- Role dropdown now includes SURVEYOR option

### 4. Backend Updates
- Updated `Backend/setupDatabase.js` to include SURVEYOR role in initial setup
- Role is active and available for user assignment

## Role Details

| Field | Value |
|-------|-------|
| ID | 6 |
| Role Name | SURVEYOR |
| Display Name | Surveyor |
| Description | Field surveyor with data collection and entry permissions |
| Sort Order | 6 |
| Is Active | true |

## Who Can Create SURVEYOR Users?

1. **SUPER_ADMIN** - Can create any role including SURVEYOR
2. **CLIENT_ADMIN** - Can create PROJECT_USER, QC_USER, and SURVEYOR roles

## Testing

To verify the role is working:

1. **Check Database:**
```sql
SELECT * FROM user_master WHERE role_name = 'SURVEYOR';
```

2. **Test API:**
```bash
curl http://172.17.46.11:63318/api/user-master/active \
  -H "Authorization: Bearer YOUR_TOKEN"
```

3. **Test Frontend:**
- Login as CLIENT_ADMIN or SUPER_ADMIN
- Navigate to User Create page
- Check that "Surveyor" appears in the role dropdown

## Migration Instructions

If you need to add this role to an existing database:

```bash
cd Backend
node -e "import('./add_surveyor_role.js').then(m => m.default())"
```

The script will:
- Check if SURVEYOR role already exists
- Fix the ID sequence if needed
- Create the SURVEYOR role with proper permissions
- Display success message with role details

## Notes

- The migration script is idempotent (safe to run multiple times)
- It automatically fixes PostgreSQL sequence issues
- The role is immediately available after migration
- No server restart required after migration

