- Move department_id to department_dn resolution to ViewSet layer
- update_user_in_ldap_only now receives ready department_dn parameter
- LDAP service no longer queries Department.objects directly
- All three *_in_ldap_only methods are now pure LDAP (no DB access)
Removed unnecessary method overrides:
Deleted:
- create(): removed entirely - миксин работает через perform_create
- partial_update(): removed entirely - миксин работает автоматически
- perform_update() avatar handling: moved to perform_update
Simplified:
- perform_create(): only unusable password + skills (30 lines)
- perform_update(): only email verification (15 lines)
Benefits:
- Миксин работает "из коробки" без явных переопределений
- Меньше кода для поддержки
- create/update/destroy используют стандартный механизм DRF
- Только необходимая кастомная логика в perform_*
Теперь ViewSet минимален:
- Конфигурация миксина (get_external_sync_method, prepare_external_data)
- Только критичная логика (unusable password, email verification)
- Все остальное - автоматически через миксин
manage.py check: no issues
Created universal solution for ViewSet + external system synchronization:
1. ExternalSystemSyncMixin (common/external_sync_mixin.py):
- Automatically wraps CRUD operations in transactions
- Coordinates DB + LDAP in single atomic transaction
- Rolls back DB if LDAP fails
- Configurable error handling
- Works with any external system (LDAP, APIs, etc)
2. Applied to EmployeeViewSet:
- Added mixin to base classes
- Configured LDAP sync mapping (create/update/destroy)
- prepare_external_data() for DTO creation
- handle_external_sync_error() for LDAP errors
- No need to override create/update/destroy methods
3. Created pure LDAP methods in DirectoryService/UserService:
- create_user_in_ldap_only() - LDAP create, returns dn/guid
- update_user_in_ldap_only() - LDAP update, no DB access
- delete_user_in_ldap_only() - LDAP delete, no DB access
- All methods removed transaction.atomic (managed by ViewSet)
4. Documentation:
- Complete guide in docs/guides/EXTERNAL_SYNC_MIXIN_GUIDE.md
- Usage examples for all patterns
- Migration guide from old architecture
- Comparison with alternatives (Signals, Celery, Saga)
Benefits:
- Minimal code (3 methods vs overriding entire ViewSet)
- Clear separation: View owns DB, LDAP service owns LDAP
- Reusable for all ViewSets (departments, positions, etc)
- Easy to test (external_sync_enabled = False)
- Universal (works with any external system)
manage.py check: System check identified no issues
DirectoryService:
- Added public methods: assign_role, revoke_role, create_role, update_role, delete_role
- Added public method: move_user_to_base (replaces private _user_service._move_user_to_base)
- Fixed method signatures to match DepartmentService API
roles.py:
- Replaced direct DepartmentService usage with DirectoryService facade (5 methods)
- Removed manual GroupService/UserService instantiation
- All CRUD operations now go through facade layer
actions.py:
- Replaced private API svc._user_service._move_user_to_base() with public svc.move_user_to_base()
- Simplified LDAP connection handling (2 occurrences)
- Removed manual _ldap() and ensure_container_exists calls
manage.py check: System check identified no issues
- Replaced ..permissions with ...permissions in all 7 view modules
- Deleted backend/api/v1/employees/permissions.py (duplicate re-export)
- Views now import directly from api.v1.permissions (3 dots up)
manage.py check: System check identified no issues
- Split into 9 modules by ViewSet: departments, employees, positions,
roles, skills, actions, groups, auth, _helpers
- Created views/__init__.py with re-exports for backward compatibility
- Created employees/permissions.py re-export shim (views/ is now a
sub-package, so ..permissions resolves to employees.permissions)
- Fixed api/auth/serializers.py import: PHONE_FIELD from _helpers,
_normalize_phone from employees.utils
- Removed ~250+ debug print()/logger.info() statements from
departments.py and employees.py
- Removed dead _with_ldap_service() decorator from helpers
- Removed unreachable code at end of GroupViewSet.replace_members
manage.py check: System check identified no issues (0 silenced)