Skip to content

Conversation

@VISHNUDAS-tunerlabs
Copy link
Collaborator

@VISHNUDAS-tunerlabs VISHNUDAS-tunerlabs commented Jan 20, 2026

staging code migration for 3.4 prod-release

Summary by CodeRabbit

  • New Features

    • Added admin-controlled entity deletion API supporting both recursive and non-recursive deletion modes
    • Introduced health check monitoring endpoints for system status and service health verification
  • Bug Fixes

    • Fixed Kafka health check failures occurring in multi-instance deployments
    • Corrected handling of entity data with 12-character external identifiers
  • Documentation

    • Added Entity Delete API documentation with authorization details and usage examples
    • Added data migration guide for organization ID normalization across collections

✏️ Tip: You can customize this high-level summary in your review settings.

priyanka-TL and others added 28 commits September 22, 2025 21:31
@coderabbitai
Copy link

coderabbitai bot commented Jan 20, 2026

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

This PR introduces entity deletion capabilities with optional recursive deletion, Kafka event streaming for deletion analytics, admin-role-based authorization, deletion audit logging, and enhanced sub-entity listing with sorting and parent information features. Service version bumped to 3.4.0 with dependency upgrades.

Changes

Cohort / File(s) Summary
Deployment & Configuration
deployment/ansible.yml, src/.env.sample, src/envVariables.js
Modified config.json output path; added Kafka environment variables (KAFKA_URL, KAFKA_GROUP_ID, RESOURCE_DELETION_TOPIC, KAFKA_HEALTH_CHECK_TOPIC); updated SERVICE_NAME to EntityManagementService
Kafka Integration
src/config/kafka.js, src/generics/kafka/producers.js, src/healthCheck/health.config.js
New Kafka client/producer setup with consumer group for deletion topic; producer module for pushing deletion events to Kafka; health check config extended with Kafka monitoring
Admin Authorization & Deletion
src/generics/middleware/checkAdminRole.js, src/controllers/v1/admin.js, src/module/admin/helper.js, src/module/admin/validator/v1.js
New middleware enforcing admin role via JWT/Keycloak validation; deleteEntity controller method; helper with recursive deletion logic, post-deletion task handling, and Kafka event emission; validator for deletion endpoint
Deletion Audit & Logging
src/models/deletionAuditLogs.js, src/databaseQueries/deletionAuditLogs.js, src/controllers/v1/deletionAuditLogs.js
New deletion audit log schema with entityId, deletedBy, deletedAt fields; database query layer for inserting audit records; controller class scaffold
Database Query Enhancements
src/databaseQueries/admin.js, src/databaseQueries/entities.js
Added pullEntityFromGroups for unlinking deleted entities from groups; removeDocuments for bulk entity deletion
API Documentation
src/api-doc/Entity Management API's.postman_collection.json, src/api-doc/Entity-Management LOCAL postman_environment, src/api-doc/api-doc.yaml
Renamed Postman collection; updated baseUrl and added admin auth variables; comprehensive OpenAPI spec updates with admin-auth-token/tenantId/orgId headers on endpoints, new admin deletion endpoints, health check endpoint, expanded response schemas with tenantId/orgId/metaInformation fields, tag reorganization
Entity Listing & Response Enhancements
src/controllers/v1/entityTypes.js, src/controllers/v1/entities.js, src/module/entities/helper.js, src/module/entities/validator/v1.js
EntityTypes responses now wrap data in message/status envelope; entities controller forwards roleLevel, parentInfoRequired, sortOrder, sortKey to helpers; helper extended with sorting support, parent hierarchy enrichment, improved roleLevel filtering, strictObjectIdCheck validation; validators enforce sortOrder/sortKey constraints
Utilities & Constants
src/generics/helpers/utils.js, src/generics/constants/api-responses.js, src/generics/constants/common.js, src/routes/index.js
New strictObjectIdCheck utility for 24-char hex validation; added api-response constants (ENTITIES_DELETED_SUCCESSFULLY, ADMIN_ROLE_REQUIRED, NOT_A_VALID_MONGOID, ENTITIES_UPDATE_FAILED); new SUBROLE_ENTITY_TYPE constant and /admin/deleteEntity to INTERNAL_ACCESS_URLS; routes wired with checkAdminRole middleware
Package & Release Management
src/package.json, release-notes/prod/release-3.4.md, release-notes/staging/release-3.3.13.1.md, release-notes/staging/release-3.3.13.2.md
Version bumped to 3.4; added kafka-node dependency; updated multiple package dependencies to newer pins; added release notes documenting DELETE API, health check feature, admin deletion modes, Kafka health fix, and data migration normalization
Migration & Health Check
src/migrations/normalizeOrgIdInCollections.js, src/healthCheck/health-check.js, src/healthCheck/README.md, src/config/connections.js, src/document/entityDelete/ReadMe.md
Migration script to normalize orgId across collections; health check extended with packageFile.version parameter, version field removed from responses; Kafka connection initialization in connections; documentation for entity delete API with authorization, recursive/non-recursive modes, Kafka events, and error mappings

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Route as Routes<br/>(Express)
    participant AuthMW as checkAdminRole<br/>(Middleware)
    participant Controller as Admin<br/>Controller
    participant Helper as AdminHelper
    participant Database as Database
    participant Kafka as Kafka<br/>Producer

    Client->>Route: DELETE /admin/deleteEntity/:id
    Route->>AuthMW: Validate admin role
    AuthMW->>AuthMW: Extract & verify JWT<br/>(Native/Keycloak)
    AuthMW->>AuthMW: Extract roles from token
    alt Admin Role Present
        AuthMW->>Controller: next()
    else Non-Admin
        AuthMW-->>Client: 403 Forbidden<br/>(ADMIN_ROLE_REQUIRED)
        Note over Client: Access denied
    end

    Controller->>Helper: allowRecursiveDelete<br/>(entityId, allowRecursiveDelete,<br/>tenantId, deletedBy)
    Helper->>Database: Check entity exists
    alt Entity Not Found
        Helper-->>Client: 400 Error<br/>(ENTITY_NOT_FOUND)
    end

    Helper->>Database: Find related entities<br/>(groups, linked entities)
    Helper->>Helper: Build deletion set<br/>(root + recursive)
    Helper->>Database: removeDocuments<br/>(deletion filter)

    par Post-Deletion Tasks
        Helper->>Database: pullEntityFromGroups<br/>(unlink from parent groups)
        Helper->>Database: deletionAuditLogs.create<br/>(log deletions)
        Helper->>Kafka: pushEntityDeleteKafkaEvent<br/>(entityIds, metadata)
        Kafka-->>Kafka: Publish to<br/>RESOURCE_DELETION_TOPIC
    end

    Helper-->>Controller: Return deletion summary<br/>(counts, IDs)
    Controller-->>Client: 200 OK<br/>(ENTITIES_DELETED_SUCCESSFULLY)
Loading
sequenceDiagram
    participant Client
    participant Controller as Entities<br/>Controller
    participant Helper as Entities<br/>Helper
    participant Database as Database
    participant Aggregation as MongoDB<br/>Aggregation

    Client->>Controller: GET /entities/subEntityList<br/>?parentInfoRequired=true<br/>&sortOrder=asc<br/>&sortKey=name
    
    Controller->>Helper: subEntityList<br/>(entityId, ..., parentInfoRequired,<br/>sortOrder, sortKey)
    
    Helper->>Helper: Validate sortOrder/sortKey<br/>(asc/desc, name/externalId)
    
    Helper->>Database: Fetch sub-entities<br/>with sorting
    
    alt parentInfoRequired = true
        Helper->>Aggregation: Fetch parent hierarchy<br/>(ancestors aggregation)
        Aggregation-->>Helper: Parent tree data
        Helper->>Helper: Compute hierarchy levels<br/>Build groupEntityMap
        Helper->>Helper: Enrich each result<br/>with parent type fields<br/>(labels/names)
    end
    
    Helper-->>Controller: Return enriched results<br/>(with parent info, sorted)
    Controller-->>Client: 200 OK<br/>(entities with parent details)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • Entity-delete-flow #172: Directly related — introduces the same entity deletion feature with Kafka integration, admin middleware, and deletion audit logging across shared files (kafka.js, admin helper, deletionAuditLogs, checkAdminRole).
  • middle-ware-added #175: Related to admin authorization enhancements — modifies checkAdminRole middleware and admin deletion helpers (pullEntityFromGroups, deletionAuditLogs.create methods).
  • Sorting in subEntityList API #202: Related to sub-entity listing enhancements — adds sortOrder and sortKey parameters to sub-entity fetch logic and helper method signatures.

Poem

🐰 Delete with grace, admin's embrace,
Kafka streams sing, deletions take place,
Sorted sub-entities, parent info flows,
Audit logs trail where the entity goes,
Version three-point-four hops ahead!

✨ Finishing touches
  • 📝 Generate docstrings

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ast-grep (0.40.5)
src/api-doc/Entity Management API's.postman_collection.json

/bin/bash: -c: line 1: unexpected EOF while looking for matching `''

🔧 Gitleaks (8.30.0)
src/api-doc/Entity Management API's.postman_collection.json

/bin/bash: -c: line 1: unexpected EOF while looking for matching `''

🔧 Biome (2.1.2)
src/api-doc/Entity Management API's.postman_collection.json

/bin/bash: -c: line 1: unexpected EOF while looking for matching `''

🔧 Checkov (3.2.334)
src/api-doc/Entity Management API's.postman_collection.json

/bin/bash: -c: line 1: unexpected EOF while looking for matching `''


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@VISHNUDAS-tunerlabs VISHNUDAS-tunerlabs merged commit c23bc49 into main Jan 20, 2026
1 of 2 checks passed
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