Skip to content

Commit b730785

Browse files
jankeromnesroboquat
authored andcommitted
[server] When a user attributes all their usage to a team, but then leaves that team, reset their selected 'usageAttributionId'
1 parent 2afad51 commit b730785

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

components/server/ee/src/workspace/gitpod-server-impl.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,18 +1453,19 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
14531453

14541454
protected async onTeamMemberRemoved(userId: string, teamId: string, teamMembershipId: string): Promise<void> {
14551455
const now = new Date();
1456-
const teamSubscription = await this.teamSubscription2DB.findForTeam(teamId, now.toISOString());
1457-
if (!teamSubscription) {
1458-
// No team subscription, nothing to do 🌴
1459-
return;
1456+
const ts2 = await this.teamSubscription2DB.findForTeam(teamId, now.toISOString());
1457+
if (ts2) {
1458+
await this.updateTeamSubscriptionQuantity(ts2);
1459+
await this.teamSubscription2Service.cancelTeamMemberSubscription(ts2, userId, teamMembershipId, now);
1460+
}
1461+
const user = await this.userDB.findUserById(userId);
1462+
if (user && user.additionalData?.usageAttributionId === `team:${teamId}`) {
1463+
// If the user previously attributed all their usage to a given team, but they are now leaving this
1464+
// team, then the currently selected usage attribution ID is no longer valid. In this case, we must
1465+
// reset this ID to the default value.
1466+
user.additionalData.usageAttributionId = undefined;
1467+
await this.userDB.updateUserPartial(user);
14601468
}
1461-
await this.updateTeamSubscriptionQuantity(teamSubscription);
1462-
await this.teamSubscription2Service.cancelTeamMemberSubscription(
1463-
teamSubscription,
1464-
userId,
1465-
teamMembershipId,
1466-
now,
1467-
);
14681469
}
14691470

14701471
protected async onTeamDeleted(teamId: string): Promise<void> {

0 commit comments

Comments
 (0)