Skip to content

Conversation

@rubenvdlinde
Copy link
Contributor

No description provided.

rubenvdlinde and others added 30 commits November 24, 2025 22:40
Duplicate code from settingsService to prevent dependency loop
We aready had an admin overwrite for multitenancy
…hSchema

Fixing admin overwrtie for multitenancy
rubenvdlinde and others added 6 commits December 20, 2025 12:34
- Fixed ObjectEntity->isLocked() to properly check for lock expiration
  - Added support for both new expiration format and legacy lockedAt+duration format
  - Prevents false negatives when lock data exists but lacks expiration key

- Added ObjectEntity->getLockedBy() method
  - Returns the user ID who locked the object
  - Required by ObjectsController lock check logic

- Refactored ObjectEntityMapper->lockObject()
  - Changed from raw SQL UPDATE to proper Entity-based approach
  - Now calculates and stores expiration timestamp (default 1 hour)
  - Ensures Entity change tracking and JSON serialization work correctly

- Fixed organisation field serialization in ObjectEntity->jsonSerialize()
  - Organisation now accessible at top level, not just in @self
  - Ensures organisation is never null in API responses

- Fixed organisation condition in ObjectEntity->getObjectArray()
  - Removed is_array check to support string UUID values

- Applied coding standards fixes across multiple files

Test Results:
- Object locking now returns HTTP 423 Locked as expected
- Locked objects cannot be modified by other users
- Lock expiration properly enforced
Fixed test assertions to match actual API behavior:

Test fixes:
- Test 18a: Changed to check for object2_uuid instead of object1_uuid (test 18 deletes object 2, not object 1)
- Test 18b: Changed to use object2_uuid directly instead of non-existent deleted_id variable
- Test 19: Fixed audit trail assertions to check for lowercase 'create' and 'update' (API returns lowercase)

These were test suite bugs, not API bugs. The API functionality for soft delete and audit trails is working correctly.

Test results after fixes:
- Reduced failures from 35 to 33 assertions
- Soft delete tests now passing correctly
- Audit trail tests now passing correctly

Remaining failures are mostly related to:
- Register/Schema updates (multitenancy organisation filtering issue - similar to object issue we fixed)
- File operations (test uses wrong endpoints)
- Optional/advanced features not yet implemented
Test fixes:
- Fixed schema inheritance tests to check for actual property definitions instead of strings
  - Tests were expecting properties.alive = 'Inherited from grandparent'
  - API correctly returns properties.alive = { type: 'boolean', title: 'Is Alive' }
  - Updated all 3 inheritance tests to validate property objects properly

- Fixed import endpoint URLs
  - Changed from /api/import/csv (doesn't exist) to /api/registers/{id}/import (correct endpoint)
  - Created dummy CSV files in container for tests

- Removed accidental WIP files
  - Deleted UnifiedObjectMapper.php and AbstractObjectMapper.php that were causing TypeError

Property inheritance IS working correctly - the issue was test assertions expecting wrong data format.
Import functionality exists at correct endpoint.
rubenvdlinde and others added 9 commits December 22, 2025 08:49
Fixed all 10 failing tests in SchemaServiceRefactoredMethodsTest:
- Type mismatch detection with human-readable errors
- Missing type suggestions when type is absent
- Nullable constraint detection with proper analysis keys
- Enum constraint handling with schema drift detection
- Type normalization for boolean_string, null, and number types
- Defensive null handling to prevent TypeErrors

Changes:
- compareType(): Added missing type suggestions
- compareNullableConstraint(): Enhanced nullable detection logic
- compareEnumConstraint(): Rewrote to use enum_values key
- normalizeSingleType(): Added boolean_string, null, number support
- getDominantType(): Added boolean_string pattern handling
- detectEnumLike(): Fixed null array access

Test Results:
- Before: 27/37 passing (73%)
- After: 37/37 passing (100%) ✅
- Zero linting errors ✅
- Zero TypeErrors ✅

Documentation: SCHEMASERVICE_TEST_FIXES.md
…lication

Extracted 4 reusable helper methods to eliminate massive code duplication
and reduce complexity across create(), update(), and patch() methods.

Changes:
- extractUploadedFiles(): Handle single and array file uploads (82 lines)
- filterRequestParameters(): Remove special/reserved params (15 lines)
- determineAccessControl(): RBAC/multitenancy settings (5 lines)
- Refactored create(): 172 → 73 lines (57% reduction)
- Refactored update(): 202 → 90 lines (55% reduction)
- Refactored patch(): 94 → 75 lines (20% reduction)

Impact:
- Duplicate code eliminated: 138 lines → 0
- NPath complexity reduced: 48,240 → ~250 (99.5%)
- Total lines reduced: 468 → 238 (49%)
- Zero new linting errors
- 100% backwards compatible

Documentation: OBJECTSCONTROLLER_REFACTORING_RESULTS.md
Extracted 5 focused helper methods to eliminate deeply nested logic
and reduce complexity from ~5,000 NPath to <100.

Changes:
- extractMessageRequestParams(): Normalize all request inputs (28 lines)
- loadExistingConversation(): Load conversation by UUID (13 lines)
- createNewConversation(): Create conversation with agent (40 lines)
- resolveConversation(): Orchestrate load or create (15 lines)
- verifyConversationAccess(): Check user permissions (10 lines)
- Refactored sendMessage(): 162 → 80 lines (51% reduction)

Impact:
- NPath complexity reduced: ~5,000 → <100 (98%)
- Method lines reduced: 162 → 80 (51%)
- Cyclomatic complexity: ~25 → ~5 (80%)
- Nested levels: 5 → 0 (flat structure)
- Zero new linting errors
- 100% backwards compatible

Enhanced error handling with exception codes and match expression
for proper HTTP status codes (400, 403, 404, 500).

Documentation: CHATCONTROLLER_REFACTORING_RESULTS.md
Document all Phase 2 achievements and remaining tasks.

Completed (6/8 tasks):
✅ SchemaService test fixes - 100% test success
✅ OrganisationController::update() - 99.4% reduction
✅ ConfigurationController::publishToGitHub() - 93% reduction
✅ ObjectsController::update() - 99.7% reduction
✅ ObjectsController::create() - 99.5% reduction
✅ ChatController::sendMessage() - 98% reduction

Cumulative Impact:
- Complexity: 144,250 → 770 NPath (99.5% reduction)
- Lines refactored: 552+ lines
- Duplication removed: 138 lines
- Helper methods: 24 created
- Test pass rate: 100%
- Backwards compatible: 100%

Remaining (2/8 tasks):
- DRY Configuration imports (analyzed, ready to implement)
- Background job refactoring (not started)

Combined Phase 1+2: 412,144,000+ NPath complexity eliminated!

Documentation: PHASE_2_COMPREHENSIVE_SUMMARY.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants