Skip to content

Commit 248a00e

Browse files
authored
[server] clean up org-only migration code (#17939)
1 parent 21ab5d4 commit 248a00e

33 files changed

+92
-1254
lines changed

components/dashboard/src/components/UsageBasedBillingConfig.tsx

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,6 @@ export default function UsageBasedBillingConfig({ hideSubheading = false }: Prop
197197
const showBalance = !showSpinner;
198198
const showUpgradeTeam =
199199
!showSpinner && AttributionId.parse(attributionId)?.kind === "team" && !stripeSubscriptionId;
200-
const showUpgradeUser =
201-
!showSpinner && AttributionId.parse(attributionId)?.kind === "user" && !stripeSubscriptionId;
202200
const showManageBilling = !showSpinner && !!stripeSubscriptionId;
203201

204202
const updateUsageLimit = useCallback(
@@ -231,13 +229,7 @@ export default function UsageBasedBillingConfig({ hideSubheading = false }: Prop
231229

232230
return (
233231
<div className="mb-16">
234-
{!hideSubheading && (
235-
<Subheading>
236-
{attributionId && AttributionId.parse(attributionId)?.kind === "user"
237-
? "Manage billing for your personal account."
238-
: "Manage billing for your organization."}
239-
</Subheading>
240-
)}
232+
{!hideSubheading && <Subheading>Manage billing for your organization.</Subheading>}
241233
<div className="max-w-xl flex flex-col">
242234
{errorMessage && (
243235
<Alert className="max-w-xl mt-2" closable={false} showIcon={true} type="error">
@@ -305,7 +297,7 @@ export default function UsageBasedBillingConfig({ hideSubheading = false }: Prop
305297
</div>
306298
</div>
307299
)}
308-
{(showUpgradeTeam || showUpgradeUser) && (
300+
{showUpgradeTeam && (
309301
<>
310302
<div className="flex flex-col mt-4 p-4 rounded-t-xl bg-gray-50 dark:bg-gray-800">
311303
<div className="uppercase text-sm text-gray-400 dark:text-gray-500">Current Plan</div>
@@ -391,11 +383,7 @@ export default function UsageBasedBillingConfig({ hideSubheading = false }: Prop
391383
)}
392384
{showUpdateLimitModal && (
393385
<UpdateLimitModal
394-
minValue={
395-
AttributionId.parse(attributionId || "")?.kind === "user"
396-
? BASE_USAGE_LIMIT_FOR_STRIPE_USERS
397-
: 0
398-
}
386+
minValue={0}
399387
currentValue={usageLimit}
400388
onClose={() => setShowUpdateLimitModal(false)}
401389
onUpdate={async (newLimit) => await updateUsageLimit(newLimit)}

components/dashboard/src/workspaces/CreateWorkspacePage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ export function CreateWorkspacePage() {
181181
const [selectAccountError, setSelectAccountError] = useState<SelectAccountPayload | undefined>(undefined);
182182

183183
const createWorkspace = useCallback(
184-
async (options?: Omit<GitpodServer.CreateWorkspaceOptions, "contextUrl">) => {
184+
async (options?: Omit<GitpodServer.CreateWorkspaceOptions, "contextUrl" | "organizationId">) => {
185185
// add options from search params
186186
const opts = options || {};
187187

components/gitpod-db/src/project-db.spec.db.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class ProjectDBSpec {
5151
slug: "some-project",
5252
cloneUrl: "some-random-clone-url",
5353
userId: user.id,
54+
teamId: "team-1",
5455
appInstallationId: "app-1",
5556
});
5657
const searchTerm = "rand";

components/gitpod-db/src/typeorm/entity/db-project.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export class DBProject {
3030
transformer: Transformer.MAP_EMPTY_STR_TO_UNDEFINED,
3131
})
3232
@Index("ind_teamId")
33-
teamId?: string;
33+
teamId: string;
3434

3535
@Column({
3636
default: "",

components/gitpod-db/src/typeorm/entity/db-workspace.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export class DBWorkspace implements Workspace {
3636
transformer: Transformer.MAP_NULL_TO_UNDEFINED,
3737
})
3838
@Index()
39-
organizationId?: string;
39+
organizationId: string;
4040

4141
@Column(TypeORM.UUID_COLUMN_TYPE)
4242
@Index()

components/gitpod-db/src/user-db.spec.db.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ namespace TestData {
287287
deleted: false,
288288
readonly: false,
289289
};
290+
export const organizationId: string = "org1";
290291
export const ID1: Identity = { ...DEFAULT, authId: "2345" };
291292
export const ID2: Identity = { ...DEFAULT, authId: "3456", authProviderId: "Public-GitLab" };
292293
export const ID3: Identity = { ...DEFAULT, authId: "4567", authProviderId: "ACME" };
@@ -301,6 +302,7 @@ namespace TestData {
301302
image: "",
302303
tasks: [],
303304
},
305+
organizationId,
304306
context: { title: "example" },
305307
contextURL: "example.org",
306308
description: "blabla",

components/gitpod-db/src/workspace-db.spec.db.ts

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import * as chai from "chai";
88
const expect = chai.expect;
99
import { suite, test, timeout } from "mocha-typescript";
1010
import { fail } from "assert";
11-
import { v4 as uuidv4 } from "uuid";
1211

1312
import { WorkspaceInstance, Workspace, PrebuiltWorkspace, CommitContext } from "@gitpod/gitpod-protocol";
1413
import { testContainer } from "./test-container";
@@ -192,27 +191,6 @@ class WorkspaceDBSpec {
192191
await mnr.getRepository(DBPrebuiltWorkspace).delete({});
193192
}
194193

195-
@test(timeout(10000))
196-
public async testStoreUndefinedOrganizationId() {
197-
const workspace: Workspace = {
198-
...this.ws,
199-
organizationId: undefined,
200-
};
201-
const instance = {
202-
...this.wsi1,
203-
};
204-
205-
await this.db.store(workspace);
206-
await this.db.storeInstance(instance);
207-
let fetchedWs = await this.db.findWorkspaceAndInstance(workspace.id);
208-
expect(fetchedWs).to.not.be.undefined;
209-
expect(fetchedWs!.organizationId).to.be.undefined;
210-
workspace.organizationId = uuidv4();
211-
await this.db.store(workspace);
212-
fetchedWs = await this.db.findWorkspaceAndInstance(workspace.id);
213-
expect(fetchedWs?.organizationId).to.eq(workspace.organizationId);
214-
}
215-
216194
@test(timeout(10000))
217195
public async testFindInstancesLast() {
218196
try {
@@ -273,6 +251,7 @@ class WorkspaceDBSpec {
273251
description: "something",
274252
contextURL: "https://github.com/foo/bar",
275253
ownerId: "1221423",
254+
organizationId: "org123",
276255
context: {
277256
title: "my title",
278257
},
@@ -297,6 +276,7 @@ class WorkspaceDBSpec {
297276
description: "something",
298277
contextURL: "https://github.com/foo/bar",
299278
ownerId: "1221423",
279+
organizationId: "org123",
300280
context: {
301281
title: "my title",
302282
},
@@ -592,6 +572,7 @@ class WorkspaceDBSpec {
592572
description: "something",
593573
contextURL: "http://github.com/myorg/inactive",
594574
ownerId: "1221423",
575+
organizationId: "org123",
595576
context: <CommitContext>{
596577
title: "my title",
597578
repository: {
@@ -607,6 +588,7 @@ class WorkspaceDBSpec {
607588
description: "something",
608589
contextURL: "http://github.com/myorg/active",
609590
ownerId: "1221423",
591+
organizationId: "org123",
610592
context: <CommitContext>{
611593
title: "my title",
612594
repository: {
@@ -692,6 +674,7 @@ class WorkspaceDBSpec {
692674
public async findWorkspacesForPurging() {
693675
const creationTime = "2018-01-01T00:00:00.000Z";
694676
const ownerId = "1221423";
677+
const organizationId = "org123";
695678
const purgeDate = new Date("2019-02-01T00:00:00.000Z");
696679
const d20180202 = "2018-02-02T00:00:00.000Z";
697680
const d20180201 = "2018-02-01T00:00:00.000Z";
@@ -703,6 +686,7 @@ class WorkspaceDBSpec {
703686
description: "something",
704687
contextURL: "http://github.com/myorg/inactive",
705688
ownerId,
689+
organizationId,
706690
context: {
707691
title: "my title",
708692
},
@@ -716,6 +700,7 @@ class WorkspaceDBSpec {
716700
description: "something",
717701
contextURL: "http://github.com/myorg/active",
718702
ownerId,
703+
organizationId,
719704
context: {
720705
title: "my title",
721706
},
@@ -729,6 +714,7 @@ class WorkspaceDBSpec {
729714
description: "something",
730715
contextURL: "http://github.com/myorg/active",
731716
ownerId,
717+
organizationId,
732718
context: {
733719
title: "my title",
734720
},
@@ -742,6 +728,7 @@ class WorkspaceDBSpec {
742728
description: "something",
743729
contextURL: "http://github.com/myorg/active",
744730
ownerId,
731+
organizationId,
745732
context: {
746733
title: "my title",
747734
},

components/gitpod-protocol/src/attribution.ts

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,11 @@
44
* See License.AGPL.txt in the project root for license information.
55
*/
66

7-
import { User } from "./protocol";
8-
import { Team } from "./teams-projects-protocol";
7+
import { Organization } from "./teams-projects-protocol";
98

10-
export type AttributionId = UserAttributionId | TeamAttributionId;
9+
export type AttributionId = TeamAttributionId;
1110
export type AttributionTarget = "user" | "team";
1211

13-
export interface UserAttributionId {
14-
kind: "user";
15-
userId: string;
16-
}
1712
export interface TeamAttributionId {
1813
kind: "team";
1914
teamId: string;
@@ -22,19 +17,15 @@ export interface TeamAttributionId {
2217
export namespace AttributionId {
2318
const SEPARATOR = ":";
2419

25-
export function createFromOrganizationId(organizationId?: string): AttributionId | undefined {
26-
return organizationId ? { kind: "team", teamId: organizationId } : undefined;
20+
export function createFromOrganizationId(organizationId: string): AttributionId {
21+
return { kind: "team", teamId: organizationId };
2722
}
2823

29-
export function create(userOrTeam: User | Team): AttributionId {
30-
if (User.is(userOrTeam)) {
31-
return { kind: "user", userId: userOrTeam.id };
32-
} else {
33-
return { kind: "team", teamId: userOrTeam.id };
34-
}
24+
export function create(organization: Organization): AttributionId {
25+
return createFromOrganizationId(organization.id);
3526
}
3627

37-
export function parse(s: string): UserAttributionId | TeamAttributionId | undefined {
28+
export function parse(s: string): AttributionId | undefined {
3829
if (!s) {
3930
return undefined;
4031
}
@@ -43,22 +34,19 @@ export namespace AttributionId {
4334
return undefined;
4435
}
4536
switch (parts[0]) {
46-
case "user":
47-
return { kind: "user", userId: parts[1] };
4837
case "team":
4938
return { kind: "team", teamId: parts[1] };
50-
default:
51-
return undefined;
5239
}
40+
return undefined;
5341
}
5442

5543
export function render(id: AttributionId): string {
5644
switch (id.kind) {
57-
case "user":
58-
return `user${SEPARATOR}${id.userId}`;
5945
case "team":
6046
return `team${SEPARATOR}${id.teamId}`;
6147
}
48+
// allthough grayed as unreachable it is reachable at runtime
49+
throw new Error("invalid attributionId kind : " + id.kind);
6250
}
6351

6452
export function equals(a: AttributionId, b: AttributionId): boolean {

components/gitpod-protocol/src/gitpod-service.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,6 @@ export interface GitpodServer extends JsonRpcServer<GitpodClient>, AdminServer,
237237

238238
listUsage(req: ListUsageRequest): Promise<ListUsageResponse>;
239239

240-
setUsageAttribution(usageAttribution: string): Promise<void>;
241-
listAvailableUsageAttributionIds(): Promise<string[]>;
242-
243240
getBillingModeForUser(): Promise<BillingMode>;
244241
getBillingModeForTeam(teamId: string): Promise<BillingMode>;
245242

@@ -398,7 +395,7 @@ export namespace GitpodServer {
398395
}
399396
export interface CreateWorkspaceOptions extends StartWorkspaceOptions {
400397
contextUrl: string;
401-
organizationId?: string;
398+
organizationId: string;
402399

403400
// whether running workspaces on the same context should be ignored. If false (default) users will be asked.
404401
//TODO(se) remove this option and let clients do that check if they like. The new create workspace page does it already

components/gitpod-protocol/src/protocol.ts

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { WorkspaceInstance, PortVisibility, PortProtocol } from "./workspace-ins
88
import { RoleOrPermission } from "./permission";
99
import { Project } from "./teams-projects-protocol";
1010
import { createHash } from "crypto";
11-
import { AttributionId } from "./attribution";
1211
import { WorkspaceRegion } from "./workspace-cluster";
1312

1413
export interface UserInfo {
@@ -209,17 +208,6 @@ export namespace User {
209208
return user;
210209
}
211210

212-
export function getDefaultAttributionId(user: User): AttributionId {
213-
if (user.usageAttributionId) {
214-
const result = AttributionId.parse(user.usageAttributionId);
215-
if (!result) {
216-
throw new Error("Invalid attribution ID: " + user.usageAttributionId);
217-
}
218-
return result;
219-
}
220-
return AttributionId.create(user);
221-
}
222-
223211
// TODO: refactor where this is referenced so it's more clearly tied to just analytics-tracking
224212
// Let other places rely on the ProfileDetails type since that's what we store
225213
// This is the profile data we send to our Segment analytics tracking pipeline
@@ -279,8 +267,6 @@ export interface AdditionalUserData extends Partial<WorkspaceTimeoutSetting> {
279267
workspaceClasses?: WorkspaceClasses;
280268
// additional user profile data
281269
profile?: ProfileDetails;
282-
// whether the user has been migrated to team attribution.
283-
isMigratedToTeamOnlyAttribution?: boolean;
284270
shouldSeeMigrationMessage?: boolean;
285271

286272
// remembered workspace auto start options
@@ -806,10 +792,7 @@ export type SnapshotState = "pending" | "available" | "error";
806792
export interface Workspace {
807793
id: string;
808794
creationTime: string;
809-
/**
810-
* undefined means it is owned by the user (legacy mode, soon to be removed)
811-
*/
812-
organizationId?: string;
795+
organizationId: string;
813796
contextURL: string;
814797
description: string;
815798
ownerId: string;

0 commit comments

Comments
 (0)