Skip to content

Commit 206e46f

Browse files
committed
Refactor LinkedInToken to LinkedInProfile
1 parent ef18c7c commit 206e46f

File tree

7 files changed

+38
-25
lines changed

7 files changed

+38
-25
lines changed

components/gitpod-db/src/linked-in-token-db.ts renamed to components/gitpod-db/src/linked-in-profile-db.ts

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

7-
export const LinkedInTokenDB = Symbol("LinkedInTokenDB");
8-
export interface LinkedInTokenDB {}
7+
export const LinkedInProfileDB = Symbol("LinkedInProfileDB");
8+
export interface LinkedInProfileDB {}

components/gitpod-db/src/tables.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ export class GitpodTableDescriptionProvider implements TableDescriptionProvider
341341
deletionColumn: "deleted",
342342
},
343343
{
344-
name: "d_b_linked_in_token",
344+
name: "d_b_linked_in_profile",
345345
primaryKeys: ["id"],
346346
timeColumn: "_lastModified",
347347
},

components/gitpod-db/src/typeorm/entity/db-linked-in-token.ts renamed to components/gitpod-db/src/typeorm/entity/db-linked-in-profile.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@
55
*/
66

77
import { Column, Entity, PrimaryColumn } from "typeorm";
8-
import { Transformer } from "../transformer";
98
import { TypeORM } from "../typeorm";
10-
import { encryptionService } from "../user-db-impl";
9+
import { LinkedInProfile } from "@gitpod/gitpod-protocol";
1110

1211
@Entity()
1312
// on DB but not Typeorm: @Index("ind_lastModified", ["_lastModified"]) // DBSync
14-
export class DBLinkedInToken {
13+
export class DBLinkedInProfile {
1514
@PrimaryColumn(TypeORM.UUID_COLUMN_TYPE)
1615
id: string;
1716

@@ -20,11 +19,7 @@ export class DBLinkedInToken {
2019

2120
@Column({
2221
type: "simple-json",
23-
transformer: Transformer.compose(
24-
Transformer.SIMPLE_JSON([]),
25-
// Relies on the initialization of the var in UserDbImpl
26-
Transformer.encrypted(() => encryptionService),
27-
),
22+
nullable: false,
2823
})
29-
token: { token: string };
24+
profile: LinkedInProfile;
3025
}

components/gitpod-db/src/typeorm/linked-in-token-db-impl.ts

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

7+
import { LinkedInProfile } from "@gitpod/gitpod-protocol";
78
import { inject, injectable } from "inversify";
89
import { Repository } from "typeorm";
9-
import { LinkedInTokenDB } from "../linked-in-token-db";
10-
import { DBLinkedInToken } from "./entity/db-linked-in-token";
10+
import { v4 as uuidv4 } from "uuid";
11+
import { LinkedInProfileDB } from "../linked-in-profile-db";
12+
import { DBLinkedInProfile } from "./entity/db-linked-in-profile";
1113
import { TypeORM } from "./typeorm";
1214

1315
@injectable()
14-
export class LinkedInTokenDBImpl implements LinkedInTokenDB {
16+
export class LinkedInProfileDBImpl implements LinkedInProfileDB {
1517
@inject(TypeORM) typeORM: TypeORM;
1618

1719
protected async getEntityManager() {
1820
return (await this.typeORM.getConnection()).manager;
1921
}
2022

21-
protected async getRepo(): Promise<Repository<DBLinkedInToken>> {
22-
return (await this.getEntityManager()).getRepository<DBLinkedInToken>(DBLinkedInToken);
23+
protected async getRepo(): Promise<Repository<DBLinkedInProfile>> {
24+
return (await this.getEntityManager()).getRepository<DBLinkedInProfile>(DBLinkedInProfile);
2325
}
2426

25-
public async storeToken(userId: string, token: string): Promise<void> {
27+
public async storeProfile(userId: string, profile: LinkedInProfile): Promise<void> {
2628
const repo = await this.getRepo();
27-
const dbToken = new DBLinkedInToken();
28-
dbToken.userId = userId;
29-
dbToken.token = { token };
30-
await repo.save(dbToken);
29+
// TODO(janx): check if profile with same LinkedIn ID already exists
30+
await repo.save({
31+
id: uuidv4(),
32+
userId,
33+
profile,
34+
});
3135
}
3236
}

components/gitpod-db/src/typeorm/migration/1680096507296-LinkedInToken.ts renamed to components/gitpod-db/src/typeorm/migration/1680096507296-LinkedInProfile.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
import { MigrationInterface, QueryRunner } from "typeorm";
88
import { tableExists } from "./helper/helper";
99

10-
const TABLE_NAME = "d_b_linked_in_token";
10+
const TABLE_NAME = "d_b_linked_in_profile";
1111

12-
export class LinkedInToken1680096507296 implements MigrationInterface {
12+
export class LinkedInProfile1680096507296 implements MigrationInterface {
1313
public async up(queryRunner: QueryRunner): Promise<void> {
1414
await queryRunner.query(
15-
`CREATE TABLE IF NOT EXISTS ${TABLE_NAME} (id char(36) NOT NULL, userId char(36) NOT NULL, token text NOT NULL, _lastModified timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), PRIMARY KEY (id)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;`,
15+
`CREATE TABLE IF NOT EXISTS ${TABLE_NAME} (id char(36) NOT NULL, userId char(36) NOT NULL, profile text NOT NULL, _lastModified timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), PRIMARY KEY (id)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;`,
1616
);
1717
}
1818

components/gitpod-protocol/src/protocol.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1591,3 +1591,11 @@ export interface StripeConfig {
15911591
individualUsagePriceIds: { [currency: string]: string };
15921592
teamUsagePriceIds: { [currency: string]: string };
15931593
}
1594+
1595+
export interface LinkedInProfile {
1596+
id: string;
1597+
firstName: string;
1598+
lastName: string;
1599+
profilePicture: string;
1600+
emailAddress: string;
1601+
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
import { ErrorCodes } from "@gitpod/gitpod-protocol/lib/messaging/error";
8+
import { LinkedInProfile } from "@gitpod/gitpod-protocol/src/protocol";
89
import { inject, injectable } from "inversify";
910
import fetch from "node-fetch";
1011
import { ResponseError } from "vscode-jsonrpc";
@@ -36,4 +37,9 @@ export class LinkedInService {
3637
}
3738
return data;
3839
}
40+
41+
// TODO(janx): retrieve LinkedIn profile, profile pic, and email address: https://learn.microsoft.com/en-us/linkedin/consumer/integrations/self-serve/sign-in-with-linkedin
42+
async getLinkedInProfile(): Promise<LinkedInProfile> {
43+
throw new Error("Not implemented");
44+
}
3945
}

0 commit comments

Comments
 (0)