# Quick Start: User Role Setup

## What Was Done

✅ **All organization users now have proper User role permissions**

### Changes Made:
1. Updated 6 files to use `role_id: 5` as default User role
2. Assigned User role to 140 existing users across 2 organizations
3. Created scripts for future user role management

## Organizations Updated

| Organization | Users Updated | Current Stats |
|--------------|---------------|---------------|
| Bangladesh Navy | 137 | 1 Super Admin, 2 Admins, 137 Users |
| Bangladesh Police | 3 | 0 Super Admins, 0 Admins, 3 Users |

## User Permissions

All users (role_id: 5) now have **39 basic permissions** including:
- ✅ View organizational structure
- ✅ Send and receive messages
- ✅ Manage their own profile
- ✅ Access directory and dashboard
- ✅ Upload/download files
- ✅ Submit feedback

## How to Create New Users

New users will automatically get the User role:

```javascript
// API call to create user
POST /api/users
{
  "name": "Officer Name",
  "organization_id": 1,
  "email": "officer@navy.mil.bd",
  // role_id defaults to 5 (User)
}
```

## Scripts Available

### 1. Assign User Role to All Organizations
```bash
cd backend
node assign_user_role_to_organization_users.js
```

### 2. Assign User Role to Specific Organization
```bash
cd backend
node assign_user_role_to_organization_users.js --org 2
```

### 3. Check Current Role Structure
```bash
cd backend
node check_roles_structure.js
```

### 4. Rebuild Roles (if needed)
```bash
cd backend
node clean_and_rebuild_roles_permissions.js
```

## ⚠️ Important Note

There's a naming issue in the database:
- Role ID 5 is named "Manager" but actually has **User permissions**
- This doesn't affect functionality, but the name is misleading

To fix this, run `clean_and_rebuild_roles_permissions.js`

## Files Modified

1. `backend/src/controllers/authController.js`
2. `backend/src/controllers/userController.js`
3. `backend/src/controllers/contactController.js`
4. `backend/src/controllers/contactTreeController.js`
5. `backend/src/controllers/superAdminController.js`
6. `backend/src/models/Contact.js`

## Verification

All users now have role_id 5 with proper User permissions across all organizations.

For detailed information, see `INITIAL_USER_ROLE_SETUP_GUIDE.md`

