Skip to content

feat(companies): invite and manage the company's users #146

Closed

Description

@allisonmahmood

Parent

Auth: Clerk, companies and machine tokens on tier 0, spec §8 and §11.

What to build

An admin runs the company from one page. /company lists users with roles and state and the pending invites; an admin invites an email with a role (Clerk sends the mail, Patchy owns the row), revokes or resends an invite, promotes, demotes, deactivates and reactivates; a member reads the same page with no actions. Deactivation ends the user's sign-in and machine tokens in one act; reactivation is on the same page. The last admin can neither demote nor deactivate themself.

Do

  • /company (Companies, behind RequireSession) and its six POST actions exactly as spec §8: POST /company/invites (email, role), POST /company/invites/:id/revoke, POST /company/invites/:id/resend, POST /company/users/:id/role, POST /company/users/:id/deactivate, POST /company/users/:id/reactivate; admin only, 303 back to /company; members see the list without actions; removing yourself is not offered; the last-admin refusals re-render with the reason. /login's default return and /join's "already in a company" destination become /company.
  • InviteMail in Companies over Clerk's POST /v1/invitations (ignore_existing), revoke, and resend as a second create: a live layer, a recording layer and a failing layer. A Clerk failure still writes the invite row with no Clerk id and tells the admin the email did not go out. An email already on a user row is refused with already in a company; a second live invite for the same email from the same company is refused, from another company allowed (spec §3).
  • Users gains what the page needs: setRole with the last-admin rule under a row lock, deactivate revoking every machine token of the user in the same transaction, reactivate.
  • Tests: the page for an admin and a member; each action through the recording and failing InviteMail layers; the last-admin rule, including two admins demoting each other at once leaving at least one admin; deactivation making the user's bearer a 401 and their next page load the deactivated page; reactivation reversing both.
  • Glossary: Companies' Invite (Clerk sends, Patchy owns, no expiry, revoke and resend, several companies may invite one address), Deactivation and Reactivation, Admin and Member say what is in code. docs/DEVELOPMENT.md notes that inviting on a dev instance sends real mail through the developer's Clerk application.

Surfaces

Served pages (ui-consistency); vocabulary and product shape; reverse states (invite and revoke, promote and demote, deactivate and reactivate, all on one page).

Done when

  • On a pnpm dev instance signed in as Patchy Dev's admin: inviting an address creates a Clerk invitation (visible in the dashboard) and a row; revoke clears both; a second sign-in with the invited +clerk_test address lands on /join with the invite and joins.
  • Deactivating that user makes pnpm patchy whoami with their token a 401 and their browser a deactivated page; reactivating restores both.
  • The last admin's demote and deactivate buttons are refused with the reason.
  • pnpm test, pnpm typecheck, pnpm lint and the packed e2e pass.

Decisions implemented

Company and user; Clerk Organizations as the company (invitations); The dev loop and tests with Clerk (InviteMail's three layers); spec §3, §8, §11.

Blocked by

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:docsarea:serverready-for-agent

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions