Skip to content

Add pending invite flow for collaboration rooms#3182

Open
rachel-d-07 wants to merge 1 commit into
Priyanshu-byte-coder:mainfrom
rachel-d-07:fix/room-invite-consent-3176
Open

Add pending invite flow for collaboration rooms#3182
rachel-d-07 wants to merge 1 commit into
Priyanshu-byte-coder:mainfrom
rachel-d-07:fix/room-invite-consent-3176

Conversation

@rachel-d-07

Copy link
Copy Markdown

Summary

Room owners could add anyone to a collaboration room just by typing a real GitHub username — no invite step, no notification, and no way to accept or decline. The person would wake up as a full member with their username/avatar visible to the whole room and access to chat history they never agreed to join.

Closes #3176


Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 💥 Breaking change (fix or feature that changes existing behavior)
  • 📝 Documentation update
  • ♻️ Refactor / code cleanup (no functional change)
  • ⚡ Performance improvement
  • 🔒 Security fix
  • 🧪 Tests only

What Changed

  • Added a room_invites table (pending / accepted / declined / cancelled) — supabase/migrations/20260712000000_add_room_invites.sql
  • src/lib/supabase-rooms.ts: added createRoomInvite, getPendingInvite, getPendingInvitesForUser, getInviteById, acceptRoomInvite, declineRoomInvite, getUserIdByGithubUsername
  • src/app/api/rooms/[roomId]/invite/route.ts: now creates a pending invite and fires a notification instead of calling addRoomMember directly
  • New endpoints: GET /api/rooms/invites (list my pending invites), POST /api/rooms/invites/[inviteId]/accept, POST /api/rooms/invites/[inviteId]/decline — both accept/decline verify the invite belongs to the requesting user before acting
  • src/components/rooms/InviteModal.tsx: copy now says "Invite sent, they'll need to accept" instead of implying instant membership
  • src/components/rooms/MembersPanel.tsx: removed the optimistic onMemberAdded call on invite success — the invited user isn't a member yet, so the UI shouldn't show them as one
  • New src/components/rooms/PendingInvites.tsx, mounted on src/app/rooms/RoomsListClient.tsx, so invited users can actually see and respond to invites

How to Test

  1. Log in as User A, create a room, invite User B by GitHub username
  2. Confirm User B does not appear in the members list, and the modal shows "Invite sent" instead of adding them
  3. Check the room_invites table - a row should exist with status = 'pending'
  4. Log in as User B (if they've logged into DevTrack before) - confirm a "Pending Room Invites" banner appears on /rooms with Accept/Decline buttons
  5. Click Accept - confirm a room_members row is created and the invite flips to status = 'accepted'
  6. On a separate invite, click Decline - confirm no room_members row is created and the invite flips to status = 'declined'
  7. Try inviting an existing member - still returns the original 'User is already a member' 409
  8. Try inviting the same pending username twice - returns 'An invite is already pending for this user' instead of creating a duplicate row

Expected result: No one is ever added to a room without explicitly accepting an invite.

Checklist

  • Linked the related issue above
  • Self-reviewed my own diff
  • No unnecessary console.log, debug code, or commented-out blocks
  • npm run lint passes locally
  • No TypeScript errors (npm run type-check)
  • Added or updated tests where applicable
  • Updated documentation / comments if behavior changed

Additional Context

If an invited username has never logged into DevTrack, there's no users row yet to attach a notification to — the invite is still created and will show up if/when they log in, it just won't trigger a notification at invite time.

RLS is enabled on the new room_invites table for consistency with the existing collaboration_rooms/room_messages tables, but actual access control happens in the API route / lib layer, matching how the existing room tables are already enforced (all routes use the service-role client, which bypasses RLS).

No automated tests added this repo doesn't appear to have an existing test suite for the rooms feature to extend, so I tested manually per the steps above. Happy to add tests if there's a preferred pattern/framework you'd like me to follow.

Room owners could previously add any real GitHub user to a room
immediately, with no invite, no notification, and no way to decline.

- New room_invites table tracking pending/accepted/declined status
- Invite endpoint now creates a pending invite + notification instead
  of inserting directly into room_members
- New accept/decline endpoints, only usable by the invited user
- InviteModal no longer optimistically adds the invited user as a
  member in the UI
- New PendingInvites component so invited users can see and respond
  to invites from the rooms page

Fixes Priyanshu-byte-coder#3176
@github-actions github-actions Bot added gssoc26 GSSoC 2026 contribution type:feature GSSoC type bonus: new feature labels Jul 11, 2026
@github-actions

Copy link
Copy Markdown

GSSoC Label Checklist 🏷️

@Priyanshu-byte-coder — please apply the appropriate labels before merging:

Difficulty (pick one):

  • level:beginner — 20 pts
  • level:intermediate — 35 pts
  • level:advanced — 55 pts
  • level:critical — 80 pts

Quality (optional):

  • quality:clean — ×1.2 multiplier
  • quality:exceptional — ×1.5 multiplier

Validation (required to score):

  • gssoc:approved — counts for points
  • gssoc:invalid / gssoc:spam / gssoc:ai-slop — does not score

Type labels (type:*) are auto-detected from files and title. Review and adjust if needed.
Points formula: (difficulty × quality_multiplier) + type_bonus

@github-actions github-actions Bot added type:bug GSSoC type bonus: bug fix type:design GSSoC type bonus: UI/design (+10 pts) type:performance GSSoC type bonus: performance (+15 pts) labels Jul 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc26 GSSoC 2026 contribution type:bug GSSoC type bonus: bug fix type:design GSSoC type bonus: UI/design (+10 pts) type:feature GSSoC type bonus: new feature type:performance GSSoC type bonus: performance (+15 pts)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Room owners can add anyone to a collaboration room without asking them — no invite, no accept/decline, they're just in

1 participant