Skip to content

feat: implement per-dataset collaborator access - #6

Merged
neuromechanist merged 9 commits into
mainfrom
feature/per-dataset-access
Jan 16, 2026
Merged

neuromechanist merged 9 commits into
mainfrom
feature/per-dataset-access

Conversation

@neuromechanist

Copy link
Copy Markdown
Contributor

Summary

Changes

Backend

  • Migration: New dataset_collaborators table to track which users have access to which datasets
  • Removed: Auto-add all approved users as collaborators on dataset creation
  • Removed: Auto-add users to all repos on approval
  • Modified: Revoke now only removes from datasets in dataset_collaborators
  • Added: POST /datasets/:id/request-access - auto-grants for public repos
  • Added: POST /datasets/:id/invite - owner/admin can invite users
  • Added: GET /datasets/:id/collaborators - list dataset collaborators
  • Fixed: Approve endpoint now returns full response with user info and API key

CLI

  • Added: nemar dataset request-access <dataset-id>
  • Added: nemar dataset invite <username> <dataset-id>
  • Added: nemar dataset collaborators <dataset-id>
  • Updated: Approve/revoke messages to reflect new access model

Documentation

  • Updated docs/commands/dataset.md with new commands

Migration Note

After deployment, run the migration:

wrangler d1 migrations apply nemar-db

Test plan

  • Create a new user and approve them (verify no auto-add to repos)
  • Request access to a public dataset
  • Verify collaborator is added to GitHub and tracked in DB
  • Invite a user to a dataset as owner
  • List collaborators for a dataset
  • Revoke user and verify removal from tracked datasets only

Add CLI commands for per-dataset collaborator access:
- nemar dataset request-access <id>: request access to public repos
- nemar dataset invite <user> <id>: invite user (owner/admin only)
- nemar dataset collaborators <id>: list collaborators

Includes API client methods in src/lib/api.ts
- Backend now returns {message, user, api_key} on approve
- Update CLI approve/revoke messages to reflect new access model
- Fixes #3: CLI approve showing success then failure
- Add dataset_collaborators table migration
- Remove auto-add all users on dataset creation
- Add POST /datasets/:id/request-access endpoint
- Add POST /datasets/:id/invite endpoint
- Add GET /datasets/:id/collaborators endpoint
@neuromechanist

Copy link
Copy Markdown
Contributor Author

PR Review Summary

Comprehensive review completed using multiple specialized agents.

Critical Issues (Must Fix Before Merge)

# Issue Location
1 request-access auto-grants access without checking if repo is public/private - security concern datasets.ts:356-407
2 Revoke endpoint silently continues when GitHub removal fails; user may retain access admin.ts:263-274
3 Database insert after GitHub success has no error handling; can leave inconsistent state datasets.ts:394-399, 489-494
4 No tests for new API endpoints (authorization, edge cases) test/api.test.ts

Important Issues (Should Fix)

# Issue Location
5 github_repo.split("/")[1] can return undefined if malformed Multiple locations
6 Missing user status check in request-access datasets.ts:343-407
7 Approval/revocation email failures are silent; admin unaware admin.ts:163-167, 279-284
8 Inconsistent HTTP status codes (400 vs 409 for conflicts) datasets.ts
9 CLI commands missing help and auth-required tests test/cli.test.ts

Strengths

  • Well-structured architecture change from auto-collaborator to per-dataset access
  • Good use of union type for access_type: "requested" | "invited"
  • API client has proper error handling with ApiError class
  • Consistent patterns with existing codebase

Action Plan

Will fix in order:

  1. Add tests for new endpoints
  2. Add defensive checks for github_repo format
  3. Track and report failed GitHub removals in revoke
  4. Add error handling around database inserts
  5. Report email delivery status in responses
  6. Use 409 for conflict responses

- Add defensive checks for github_repo format (prevents undefined errors)
- Add try-catch around DB inserts after GitHub operations
- Use 409 Conflict for already-exists/conflict scenarios
- Track and report failed GitHub removals in revoke response
- Report email delivery status in approve/revoke responses
- Update tests to expect 409 for conflicts and handle spinner output
…dev env

- Add pull-requests: read permission for dorny/paths-filter to access PR files
- Enable workers_dev in wrangler dev environment for CI tests
- Add explicit type annotations to avoid implicit any lint errors
- Fix getDataset to properly extract dataset from API response wrapper
- Make root path test accept 200 or 404 (env-dependent)
- Make webhook tests accept 500 for missing secrets configuration
- Sort imports per biome rules
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.

Remove automatic collaborator addition on user approval CLI shows success then failure on admin approve

1 participant