3.7 KiB
3.7 KiB
Task D.1: Enquiry Assignment and CRM Role Stabilization
1. Files Added
src/app/api/crm/enquiries/[id]/_schemas.tssrc/app/api/crm/enquiries/[id]/assign/route.tssrc/app/api/crm/enquiries/[id]/reassign/route.tssrc/features/crm/enquiries/components/enquiry-assignment-dialog.tsxdrizzle/0008_clean_justin_hammer.sqldrizzle/meta/0008_snapshot.json
2. Files Modified
src/db/schema.tssrc/lib/auth/rbac.tssrc/app/dashboard/crm/enquiries/page.tsxsrc/app/dashboard/crm/enquiries/[id]/page.tsxsrc/features/crm/enquiries/api/types.tssrc/features/crm/enquiries/api/service.tssrc/features/crm/enquiries/api/mutations.tssrc/features/crm/enquiries/server/service.tssrc/features/crm/enquiries/components/enquiry-columns.tsxsrc/features/crm/enquiries/components/enquiries-table.tsxsrc/features/crm/enquiries/components/enquiry-listing.tsxsrc/features/crm/enquiries/components/enquiry-detail.tsxsrc/features/crm/enquiries/components/enquiry-cell-action.tsxsrc/features/users/api/types.tssrc/features/users/schemas/user.tssrc/features/users/components/user-form-sheet.tsxsrc/app/api/users/_lib.tssrc/app/api/users/route.tssrc/app/api/organizations/route.tssrc/features/foundation/auth-context/service.ts
3. Schema Added
Added assignment fields to crm_enquiries:
assigned_to_user_idassigned_atassigned_byassignment_remark
Rules implemented:
- assignee must belong to the same organization
- assigner is the current user
- latest assignment timestamp is persisted
- assignment remark is optional
4. API Routes Added
POST /api/crm/enquiries/[id]/assignPOST /api/crm/enquiries/[id]/reassign
Payload:
{
assignedToUserId: string;
remark?: string;
}
Behavior:
- requires organization access
- enforces
crm.enquiry.assignorcrm.enquiry.reassign - validates assignee organization membership
- rejects assign on already-assigned enquiry
- rejects reassign on unassigned enquiry
5. Permissions Added
crm.enquiry.assigncrm.enquiry.reassign
CRM business-role set was also stabilized around:
sales_managersalessales_supportdepartment_managertop_manager
Legacy IT-CENTER business roles were removed from active runtime paths and defaults.
6. UI Added
Enquiry detail now supports:
Assign SalesReassign Sales- assigned sales metadata display
Enquiry list now shows:
Assigned Salescolumn
Assignment dialog now includes:
Sales UserRemark
The sales-user dropdown is populated from organization memberships instead of hardcoded values.
7. Audit Integration
Assignment writes audit logs under:
entityType = crm_enquiry
Actions added:
assignreassign
Audit payload shape:
beforeData.oldAssignedToUserIdafterData.newAssignedToUserIdafterData.remark
8. Membership / Permission Stabilization
Workspace membership management now uses CRM-aligned business roles instead of the old template roles.
Updated areas:
- user API types and validation
- membership defaults
- organization-management fallbacks
- auth-context business-role fallback
9. Remaining Risks
- current
salesaccess still operates at organization scope; there is not yet a server-enforced “own or assigned only” data policy - old database rows that still carry removed legacy business-role strings may need a one-time data backfill if they exist in a real environment
- assignable-user filtering currently accepts organization admins plus sales-oriented roles; if future CRM staffing rules become stricter, that policy should move into a dedicated assignment rule layer
10. Verification
npx tsc --noEmitnpx oxlinton changed Task D.1 files