Skip to content

Add dataset deletion with two-tier admin permissions #35

Closed

Description

@neuromechanist

Feature Request

Implement dataset deletion functionality with two-tier admin permission system.

Current State

  • No delete mechanism exists in CLI
  • Backend may have delete endpoints but not connected
  • All admins have same permissions

Proposed Solution

Two-tier admin system:

  1. Owner Admin (highest privilege)

    • Can delete ANY dataset (private, public, with/without DOI)
    • Ultimate authority over the system
  2. Regular Admin

    • Can delete private datasets
    • Can delete datasets without DOIs
    • CANNOT delete datasets with DOIs (permanent records)

Datasets with DOIs:

  • Can only be deleted by Owner Admin
  • Require explicit confirmation (DOIs are permanent identifiers)
  • May need special handling (soft delete vs hard delete)

Implementation Tasks

Backend:

  • Add is_owner field to users table (or similar mechanism)
  • Create/update DELETE endpoint for datasets
  • Implement permission checks based on admin tier
  • Add DOI status check before deletion
  • Handle cascading deletes (collaborators, S3 data, GitHub repo)

CLI:

  • Add nemar dataset delete <dataset-id> command
  • Add nemar admin delete-dataset <dataset-id> command
  • Implement permission error messages
  • Add confirmation prompts (use --yes flag)
  • Show warnings for DOI datasets

Edge Cases

  1. GitHub repo deletion: Requires GitHub PAT with delete permissions
  2. S3 data cleanup: Remove dataset files from S3
  3. Git-annex tracking: Update location tracking
  4. Audit trail: Log who deleted what and when
  5. Soft delete option: Mark as deleted but keep data for recovery

Security Considerations

  • Deletion is permanent and destructive
  • Require explicit confirmation
  • Log all deletions for audit
  • Consider soft delete for datasets with DOIs
  • Prevent accidental mass deletions

Related

Activity

  1. neuromechanist commented on Jan 19, 2026

    @neuromechanist
    ContributorAuthor

    Backend Fail-Safes Required (CRITICAL)

    Following the accidental deletion of datasets nm000103-nm000107 (now restored), we MUST implement backend fail-safes to prevent deletion of critical datasets.

    Fail-Safe Requirements

    1. Prevent Deletion of Datasets with DOIs

    Datasets with concept DOIs or version DOIs are preserved on Zenodo and MUST NOT be deletable:

    // backend/src/routes/datasets.ts - DELETE endpoint
    
    if (dataset.concept_doi || dataset.latest_version_doi) {
      throw new Error(
        `Cannot delete dataset ${dataset.dataset_id}: has DOI(s). ` +
        `Datasets with DOIs are preserved on Zenodo and cannot be deleted. ` +
        `Contact owner ([email protected]) if deletion is absolutely necessary.`
      );
    }

    2. Prevent Deletion of Public/Published Datasets

    if (dataset.status === 'published' || dataset.visibility === 'public') {
      throw new Error(
        `Cannot delete published/public dataset ${dataset.dataset_id}. ` +
        `Published datasets must remain available. ` +
        `Contact owner ([email protected]) if deletion is absolutely necessary.`
      );
    }

    3. Two-Tier Admin Permissions

    • Tier 1 (nemarAdmin): Can delete own datasets
    • Tier 2 (Owner): Can delete ANY dataset
    if (dataset.owner_user_id \!== requesting_user_id) {
      if (\!requesting_user_is_owner) {
        throw new Error(
          `Cannot delete dataset ${dataset.dataset_id}: ` +
          `Only the owner can delete datasets created by other users.`
        );
      }
    }

    4. Require Explicit Confirmation

    if (\!request.body.confirm_deletion || 
        request.body.confirmation_text \!== dataset.dataset_id) {
      throw new Error(
        `Deletion requires explicit confirmation. ` +
        `Set confirm_deletion=true and confirmation_text='${dataset.dataset_id}'`
      );
    }

    5. Audit Logging

    await logAuditEvent({
      user_id: requesting_user_id,
      action: 'dataset_delete_attempt',
      resource_type: 'dataset',
      resource_id: dataset.dataset_id,
      details: JSON.stringify({
        has_doi: \!\!dataset.concept_doi,
        status: dataset.status,
        owner: dataset.owner_user_id,
        approved: deletion_approved
      })
    });

    CLI Fail-Safes

    Also update src/commands/dataset.ts to:

    • Show warning for datasets with DOIs
    • Require typing dataset ID to confirm
    • Show what will be deleted
    • Require final confirmation with default=NO

    Test Cases

    describe('Dataset Deletion Fail-Safes', () => {
      it('should prevent deletion of datasets with concept DOI', async () => {
        // Test that deletion throws error
      });
      
      it('should prevent deletion of published datasets', async () => {
        // Test that deletion throws error
      });
      
      it('should prevent non-owner from deleting others datasets', async () => {
        // Test permission error
      });
      
      it('should require explicit confirmation', async () => {
        // Test that missing confirmation fails
      });
      
      it('should log all deletion attempts', async () => {
        // Test audit log entry created
      });
    });

    Implementation Priority

    Priority: P0 (Critical) - Implement ASAP

    These fail-safes would have prevented the accidental deletion on 2026-01-18.

    See also:

  2. neuromechanist commented on Feb 12, 2026

    @neuromechanist
    ContributorAuthor

    Superseded by #128. Full deletion system implemented with two-tier permissions (owner-only for published datasets, admin for unpublished).

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions