Skip to content

Commit d916294

Browse files
committed
[server] When starting a workspace but usage attribution is unclear, prompt for explicit user choice
1 parent 5bdda8e commit d916294

File tree

2 files changed

+9
-19
lines changed

2 files changed

+9
-19
lines changed

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

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2008,20 +2008,6 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
20082008
id: attributionId,
20092009
spendingLimit: this.defaultSpendingLimit,
20102010
});
2011-
2012-
// For all team members that didn't explicitly choose yet where their usage should be attributed to,
2013-
// we simplify the UX by automatically attributing their usage to this recently-upgraded team.
2014-
// Note: This default choice can be changed at any time by members in their personal billing settings.
2015-
const members = await this.teamDB.findMembersByTeam(teamId);
2016-
await Promise.all(
2017-
members.map(async (m) => {
2018-
const u = await this.userDB.findUserById(m.userId);
2019-
if (u && !u.usageAttributionId) {
2020-
u.usageAttributionId = attributionId;
2021-
await this.userDB.storeUser(u);
2022-
}
2023-
}),
2024-
);
20252011
} catch (error) {
20262012
log.error(`Failed to subscribe team '${teamId}' to Stripe`, error);
20272013
throw new ResponseError(ErrorCodes.INTERNAL_SERVER_ERROR, `Failed to subscribe team '${teamId}' to Stripe`);

components/server/src/user/user-service.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,12 +229,16 @@ export class UserService {
229229
async getWorkspaceUsageAttributionId(user: User, projectId?: string): Promise<string | undefined> {
230230
// A. Billing-based attribution
231231
if (this.config.enablePayment) {
232-
if (!user.usageAttributionId) {
233-
// No explicit user attribution ID yet -- attribute all usage to the user by default (regardless of project/team).
234-
return AttributionId.render({ kind: "user", userId: user.id });
232+
if (user.usageAttributionId) {
233+
// Return the user's explicit attribution ID.
234+
// TODO(janx): Throw error if selected attribution ID is no longer valid (e.g. user left team, team deleted, team cancelled)
235+
return user.usageAttributionId;
235236
}
236-
// Return the user's explicit attribution ID.
237-
return user.usageAttributionId;
237+
// TODO(janx):
238+
// - If single team with Usage-Based billing enabled, auto-attribute to that team
239+
// - If multiple teams with Usage-Based, throw error to prompt for explicit user choice
240+
// No explicit user attribution ID yet -- attribute all usage to the user by default (regardless of project/team).
241+
return AttributionId.render({ kind: "user", userId: user.id });
238242
}
239243

240244
// B. Project-based attribution

0 commit comments

Comments
 (0)