Skip to content

Conversation Atomic Edits and Hiding by Index #1612

@david-rocca

Description

@david-rocca

Ticket: Conversation Atomic Edits and Hiding by Index

Description,

We need to introduce the ability to atomically edit or hide individual conversation comments.
Unlike the previous "append-only" strictness, users (authors) need to be able to correct mistakes or hide inappropriate comments.
Crucially, these operations must target a comment by its index relative to the organization's conversation history (e.g., "edit the 3rd comment").

Acceptance Criteria / TODOs,

Database / Schema Changes (src/model/conversation.js)

  • Add Fields:
    • is_active: Boolean, default true. (Used for hiding/soft-deletion).
    • edited_at: Date. (Timestamp of last edit).
    • editor_uuid: String. (UUID of the user who performed the edit/hide).

Backend Logic (src/repositories/conversationRepository.js)

  • Implement findByTargetUUIDAndIndex:
    • Logic: Find all conversations for target_uuid, sort by created_at (ascending) + UUID (ascending) for stability.
    • Use .skip(index).limit(1) to retrieve the specific document.
    • Important: The index must apply to all records (active and inactive) to ensure indices remain stable even when items are hidden.
  • Implement editConversationByIndex:
    • Update the body, edited_at, and editor_uuid.
  • Implement hideConversationByIndex:
    • Set is_active to false, update editor_uuid.

API Changes (src/controller/registry-org.controller or conversation.controller)

  • New Endpoint: PUT /api/registryOrg/:shortname/conversation/:index (or similar path structure linked to Org).
    • Permissions:
      • Users can edit/hide their own comments.
      • Secretariat can edit/hide any comment? (Clarify if needed, assume yes for moderation).
    • Payload:
      • body: String (optional, for editing).
      • is_active: Boolean (optional, for hiding).
    • Logic:
      • Resolve Org UUID from shortname.
      • Call repo.findByTargetUUIDAndIndex.
      • Verify ownership/permissions.
      • Perform update.

Testing,

  • Unit Tests:
    • Verify index 0 returns the first comment, index 1 the second, even if index 0 is hidden.
    • Verify access controls (User A cannot edit User B's comment).
    • Verify atomic updates (body changes, timestamp updates).

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Status

Needs Triage

Status

In Progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions