Google Meet: delete a Google account's event subscription on disconnect

Merged
EH
2d ago
+223-33

Context

Follows https://github.com/twentyhq/twenty/pull/30604 in the Google Meet app series started in https://github.com/twentyhq/twenty/pull/30587.

https://github.com/twentyhq/twenty/pull/30604 subscribes to a Google account's Meet events on connect and claims the subscription for the workspace. This PR is the other half, raised in that PR's review: what was claimed on connect is released when the connection goes away.

What this PR does

  • Adds the google-meet-unregister-connection logic function and declares it as the provider's onDisconnectLogicFunction. Twenty runs it before the connection and its token are deleted.
  • It removes the connection's entry, then releases the subscription through releaseGoogleMeetEventSubscription, the helper the connect hook already uses for stale subscriptions, so there is one cleanup path.
  • The helper now deletes the subscription at Google first and removes the owner entry and the server-scope claim in a finally. The claim is held while Google answers, so no other workspace claims a subscription that is about to be deleted, and it is released even when the token or Google fails (for instance the member already revoked access), so another workspace can connect the account. Google stops an undeleted subscription itself at its 7-day expiry.
  • A subscription that another connection of the same Google account took over is left alone; only this connection's entry is removed.
  • The hook runs on disconnect and again on delete; the second run finds nothing and does nothing.

Known limit

Two connections of the same Google account in one workspace: if one registers between the other's ownership check and its deletion, the subscription is deleted under it. The key-value store has no compare-and-delete to close that window. The daily renewal job later in this series recreates a missing subscription within a day.

Checks

  • yarn lint, yarn typecheck, yarn test:unit (105 tests) and twenty app build pass locally.
  • Not run: integration tests (they need a running server, CI runs them), and no subscription was deleted against the real Google API.