Skip to content

[Enhancement]: Convert Private Brain to a Shared Brain while maintaining member flow. #160

@kstij1

Description

@kstij1

Summary

Enable users to convert a private brain into a shared brain and add members/teams during the conversion. This involves a small backend extension (conversion endpoint + sharing logic) and frontend UI to trigger conversion and select invitees.

Why

  • Collaboration: teams can work on the same brain.
  • Smooth UX: convert and invite in one step.

Scope

  • Add a “Move to Shared” action for a private brain.
  • During conversion, allow selecting users and teams to share with.
  • Update state so the converted brain appears under shared brains.
  • Enforce permissions (owner/admin only).

Out of scope for this task:

  • Advanced auditing or activity history.
  • Converting back to private (can be a follow-up task).

Backend (Node.js)

Controllers

  • nodejs/src/controller/web/brainController.js

    • Add a new handler convertToShared or extend updateBrain to support conversion.
    • Responsibilities:
      • Authorize owner/admin.
      • Flip isShare to true.
      • Accept shareWith (users) and teams arrays.
      • Delegate to service to attach members/teams.
  • Optional (admin parity): nodejs/src/controller/admin/brainController.js

Routes

  • nodejs/src/routes/web/brains.js
    • Add: PUT /web/brains/convert-to-shared/:id (preferred), or extend PUT /web/brains/update/:id to accept conversion payload.
    • Apply authentication middleware and validation.

Services

  • nodejs/src/services/brain.js
    • Implement conversion flow:
      • Load brain, ensure ownership/admin.
      • Set isShare = true.
      • Attach users and teams using existing helpers:
        • shareBrainWithUser
        • shareBrainList
      • Confirm queries like workspaceWiseList, getShareBrains, getGeneralBrain reflect new state.
      • Ensure idempotency (no duplicate shares on repeated calls).

Validations

  • nodejs/src/utils/validations/brain
    • Accept payload for conversion/update:
      • { isShare: true, shareWith?: ShareUser[], teams?: ShareTeam[], customInstruction?: string }
    • ShareUser: { id, email, fname?, lname? }
    • ShareTeam: { id, teamName, teamUsers?: [] }

Models (reuse)

  • nodejs/src/models/shareBrain.js (mapping for shared access)
  • No schema changes expected for this task.

Suggested API Contract

  • Method: PUT /web/brains/convert-to-shared/:id
  • Body:
    • { isShare: true, shareWith: ShareUser[], teams: ShareTeam[], customInstruction?: string }
  • Response: updated brain record with isShare: true and assigned members/teams.

Frontend (Next.js)

Types

  • nextjs/src/types/brain.ts
    • Ensure BrainType.isShare and related types are used by the UI and actions.

Redux Slice

  • nextjs/src/lib/slices/brain/brainlist.ts
    • On successful conversion:
      • Remove brain from privateList.
      • Add brain to shareList.
      • Recompute combined to reflect the change.

Hooks

  • nextjs/src/hooks/brains/useBrains.ts
    • Extend to support a conversion flow:
      • Modal form defaults for members/teams.
      • Submit handler calls convertToSharedAction with payload.

Actions (API calls)

  • nextjs/src/actions/brains.ts
    • Add convertToSharedAction(brainId, { members, teams, customInstruction? }).
    • After success, revalidate tags similar to createBrainAction:
      • REVALIDATE_TAG_NAME.BRAIN
      • REVALIDATE_TAG_NAME.WORKSPACE

UI

  • Brains UI: nextjs/src/components/Brains/*
    • Add a “Move to Shared” action in the brain card/menu for private brains.
    • Modal for selecting users (emails) and teams (multi-select), optional customInstruction.
    • Toast notifications on success/failure; instant state update via slice.

Permissions and Edge Cases

  • Only brain owner or admin can convert.
  • Idempotent member/team assignment (no duplicates on repeated requests).
  • Rollback or consistent state on partial failures (aim for atomic update if infra permits).

Acceptance Criteria

  • Owner/admin can convert a private brain to shared in one flow.
  • During conversion, members and/or teams can be added.
  • Converted brain moves to shared list and is removed from private list for the owner.
  • Assigned users/teams can access associated prompts/agents/threads.
  • Proper error handling and user feedback (toasts) on the frontend.

Test Plan

  1. Convert a private brain with two users and one team; verify list placement and access.
  2. Attempt conversion by a non-owner; expect 403.
  3. Re-run conversion with same members; verify no duplicates.
  4. Remove a member post-conversion; verify access is revoked.

Tasks (Contributor Checklist)

  • BE: Add/extend route in nodejs/src/routes/web/brains.js for convert-to-shared.
  • BE: Implement controller method in nodejs/src/controller/web/brainController.js.
  • BE: Implement service logic in nodejs/src/services/brain.js (flip isShare, attach users/teams, idempotent).
  • BE: Update validations in nodejs/src/utils/validations/brain.
  • FE: Add convertToSharedAction in nextjs/src/actions/brains.ts with revalidation.
  • FE: Update nextjs/src/lib/slices/brain/brainlist.ts to move from private → shared.
  • FE: Add UI action + modal in nextjs/src/components/Brains/* to pick users/teams.
  • Tests: Manual/API verification per Test Plan.
  • Docs: Link this spec in contributions.md.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions