Skip to content

Commit ae37d8c

Browse files
authored
Remove api.isStudent and all connected code/DB (#17275)
* [server, dashboard] Remove isStudent * [server] Remove hasEducationalInstitutionSuffix and swot-js * [db] Clean EduEmailDomainDB model * [db] Drop d_b_edu_email_domain * [yarn] Remove swot-js from yarn.lock * [db] Remove d_b_edu_email_domain from tables.ts * Fix
1 parent 2655733 commit ae37d8c

24 files changed

+27
-401
lines changed

components/dashboard/src/admin/UserDetail.tsx

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,12 @@ export default function UserDetail(p: { user: User }) {
3535
const [editSpendingLimit, setEditSpendingLimit] = useState<boolean>(false);
3636
const [creditNote, setCreditNote] = useState<{ credits: number; note?: string }>({ credits: 0 });
3737
const [editAddCreditNote, setEditAddCreditNote] = useState<boolean>(false);
38-
const [isStudent, setIsStudent] = useState<boolean>();
3938
const [editFeatureFlags, setEditFeatureFlags] = useState(false);
4039
const [editRoles, setEditRoles] = useState(false);
4140
const userRef = useRef(user);
4241

4342
const initialize = () => {
4443
setUser(user);
45-
getGitpodService().server.adminIsStudent(user.id).then(setIsStudent);
4644
const attributionId = AttributionId.render(AttributionId.create(user));
4745
getGitpodService().server.adminGetBillingMode(attributionId).then(setBillingMode);
4846
getGitpodService().server.adminGetCostCenter(attributionId).then(setCostCenter);
@@ -69,21 +67,6 @@ export default function UserDetail(p: { user: User }) {
6967
}
7068
};
7169

72-
const addStudentDomain = async () => {
73-
if (!emailDomain) {
74-
console.log("cannot add student's email domain because there is none!");
75-
return;
76-
}
77-
78-
await updateUser(async (u) => {
79-
await getGitpodService().server.adminAddStudentEmailDomain(u.id, emailDomain);
80-
await getGitpodService()
81-
.server.adminIsStudent(u.id)
82-
.then((isStud) => setIsStudent(isStud));
83-
return u;
84-
});
85-
};
86-
8770
const verifyUser = async () => {
8871
await updateUser(async (u) => {
8972
return await getGitpodService().server.adminVerifyUser(u.id);
@@ -117,24 +100,7 @@ export default function UserDetail(p: { user: User }) {
117100
return <></>; // nothing to show here atm
118101
}
119102

120-
const properties: JSX.Element[] = [
121-
<Property
122-
name="Student"
123-
actions={
124-
!isStudent && emailDomain && !["gmail.com", "yahoo.com", "hotmail.com"].includes(emailDomain)
125-
? [
126-
{
127-
label: `Make '${emailDomain}' a student domain`,
128-
onClick: addStudentDomain,
129-
},
130-
]
131-
: undefined
132-
}
133-
>
134-
{isStudent === undefined ? "---" : isStudent ? "Enabled" : "Disabled"}
135-
</Property>,
136-
renderBillingModeProperty(billingMode),
137-
];
103+
const properties: JSX.Element[] = [renderBillingModeProperty(billingMode)];
138104

139105
switch (billingMode?.mode) {
140106
case "usage-based":

components/dashboard/src/menu/Menu.tsx

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,16 @@ interface Entry {
3232
export default function Menu() {
3333
const user = useCurrentUser();
3434
const location = useLocation();
35-
const { setCurrency, setIsStudent } = useContext(PaymentContext);
35+
const { setCurrency } = useContext(PaymentContext);
3636
const [isFeedbackFormVisible, setFeedbackFormVisible] = useState<boolean>(false);
3737

3838
useEffect(() => {
3939
const { server } = getGitpodService();
40-
Promise.all([
41-
server.getClientRegion().then((v) => () => {
42-
// @ts-ignore
43-
setCurrency(countries[v]?.currency === "EUR" ? "EUR" : "USD");
44-
}),
45-
server.isStudent().then((v) => () => setIsStudent(v)),
46-
]).then((setters) => setters.forEach((s) => s()));
47-
}, [setCurrency, setIsStudent]);
40+
server.getClientRegion().then((v) => {
41+
// @ts-ignore
42+
setCurrency(countries[v]?.currency === "EUR" ? "EUR" : "USD");
43+
});
44+
}, [setCurrency]);
4845

4946
const adminMenu: Entry = useMemo(
5047
() => ({

components/dashboard/src/payment-context.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,19 @@ import { Currency } from "@gitpod/gitpod-protocol/lib/plans";
1010
const PaymentContext = createContext<{
1111
currency: Currency;
1212
setCurrency: React.Dispatch<Currency>;
13-
isStudent?: boolean;
14-
setIsStudent: React.Dispatch<boolean>;
1513
}>({
1614
currency: "USD",
1715
setCurrency: () => null,
18-
setIsStudent: () => null,
1916
});
2017

2118
const PaymentContextProvider: React.FC = ({ children }) => {
2219
const [currency, setCurrency] = useState<Currency>("USD");
23-
const [isStudent, setIsStudent] = useState<boolean>();
2420

2521
return (
2622
<PaymentContext.Provider
2723
value={{
2824
currency,
2925
setCurrency,
30-
isStudent,
31-
setIsStudent,
3226
}}
3327
>
3428
{children}

components/dashboard/src/service/service-mock.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,6 @@ const gitpodServiceMock = createServiceMock({
233233
getClientRegion: async () => {
234234
return "europe-west-1";
235235
},
236-
isStudent: async () => {
237-
return false;
238-
},
239236
getSuggestedContextURLs: async () => {
240237
return [];
241238
},

components/gitpod-db/src/container-module.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ import { AuthProviderEntryDBImpl } from "./typeorm/auth-provider-entry-db-impl";
3838
import { TeamSubscriptionDB } from "./team-subscription-db";
3939
import { AccountingDB, TransactionalAccountingDBFactory } from "./accounting-db";
4040
import { EmailDomainFilterDB } from "./email-domain-filter-db";
41-
import { EduEmailDomainDB } from "./edu-email-domain-db";
42-
import { EduEmailDomainDBImpl } from "./typeorm/edu-email-domain-db-impl";
4341
import { EmailDomainFilterDBImpl } from "./typeorm/email-domain-filter-db-impl";
4442
import { TeamSubscriptionDBImpl } from "./typeorm/team-subscription-db-impl";
4543
import { TransactionalAccountingDBImpl, TypeORMAccountingDBImpl } from "./typeorm/accounting-db-impl";
@@ -146,7 +144,6 @@ export const dbContainerModule = new ContainerModule((bind, unbind, isBound, reb
146144
bind(TeamSubscriptionDB).to(TeamSubscriptionDBImpl).inSingletonScope();
147145
bind(TeamSubscription2DB).to(TeamSubscription2DBImpl).inSingletonScope();
148146
bind(EmailDomainFilterDB).to(EmailDomainFilterDBImpl).inSingletonScope();
149-
bind(EduEmailDomainDB).to(EduEmailDomainDBImpl).inSingletonScope();
150147
bind(UserToTeamMigrationService).toSelf().inSingletonScope();
151148
bind(WorkspaceOrganizationIdMigration).toSelf().inSingletonScope();
152149
bind(Synchronizer).toSelf().inSingletonScope();

components/gitpod-db/src/edu-email-domain-db.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.

components/gitpod-db/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ export * from "./typeorm/typeorm";
2828
export * from "./accounting-db";
2929
export * from "./team-subscription-db";
3030
export * from "./team-subscription-2-db";
31-
export * from "./edu-email-domain-db";
3231
export * from "./email-domain-filter-db";
3332
export * from "./typeorm/entity/db-account-entry";
3433
export * from "./project-db";

components/gitpod-db/src/tables.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,6 @@ export class GitpodTableDescriptionProvider implements TableDescriptionProvider
175175
primaryKeys: ["id"],
176176
timeColumn: "_lastModified",
177177
},
178-
{
179-
name: "d_b_edu_email_domain",
180-
primaryKeys: ["domain"],
181-
timeColumn: "_lastModified",
182-
},
183178
{
184179
name: "d_b_user_env_var",
185180
primaryKeys: ["id", "userId"],

components/gitpod-db/src/typeorm/edu-email-domain-db-impl.ts

Lines changed: 0 additions & 37 deletions
This file was deleted.

components/gitpod-db/src/typeorm/entity/db-edu-email-domain.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Copyright (c) 2023 Gitpod GmbH. All rights reserved.
3+
* Licensed under the GNU Affero General Public License (AGPL).
4+
* See License.AGPL.txt in the project root for license information.
5+
*/
6+
7+
import { MigrationInterface, QueryRunner } from "typeorm";
8+
9+
export class DeleteEduEmailDomain1681824758658 implements MigrationInterface {
10+
public async up(queryRunner: QueryRunner): Promise<void> {
11+
await queryRunner.query("DROP TABLE IF EXISTS `d_b_edu_email_domain`");
12+
}
13+
14+
public async down(queryRunner: QueryRunner): Promise<void> {
15+
await queryRunner.query(
16+
`CREATE TABLE IF NOT EXISTS d_b_edu_email_domain ( domain varchar(255) NOT NULL, _lastModified timestamp(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), PRIMARY KEY (domain), KEY ind_dbsync (_lastModified)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4`,
17+
);
18+
}
19+
}

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ export interface AdminServer {
4444

4545
adminFindPrebuilds(params: FindPrebuildsParams): Promise<PrebuildWithStatus[]>;
4646

47-
adminIsStudent(userId: string): Promise<boolean>;
48-
adminAddStudentEmailDomain(userId: string, domain: string): Promise<void>;
4947
adminGetBillingMode(attributionId: string): Promise<BillingMode>;
5048

5149
adminGetSettings(): Promise<InstallationAdminSettings>;

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -228,11 +228,6 @@ export interface GitpodServer extends JsonRpcServer<GitpodClient>, AdminServer,
228228

229229
guessGitTokenScopes(params: GuessGitTokenScopesParams): Promise<GuessedGitTokenScopes>;
230230

231-
/**
232-
* gitpod.io concerns
233-
*/
234-
isStudent(): Promise<boolean>;
235-
236231
/**
237232
* Stripe/Usage
238233
*/

components/gitpod-protocol/src/protocol.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -685,10 +685,6 @@ export interface EmailDomainFilterEntry {
685685
negative: boolean;
686686
}
687687

688-
export interface EduEmailDomain {
689-
domain: string;
690-
}
691-
692688
export type AppInstallationPlatform = "github";
693689
export type AppInstallationState = "claimed.user" | "claimed.platform" | "installed" | "uninstalled";
694690
export interface AppInstallation {

components/server/ee/src/auth/email-domain-service.spec.ts

Lines changed: 0 additions & 37 deletions
This file was deleted.

components/server/ee/src/auth/email-domain-service.ts

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,61 +5,26 @@
55
*/
66

77
import { injectable, inject } from "inversify";
8-
import * as SwotJs from "swot-js";
9-
108
import { EmailDomainFilterDB } from "@gitpod/gitpod-db/lib/email-domain-filter-db";
11-
import { EduEmailDomainDB } from "@gitpod/gitpod-db/lib/edu-email-domain-db";
129
import { BlockedUserFilter } from "../../../src/auth/blocked-user-filter";
1310

1411
export const EMailDomainService = Symbol("EMailDomainService");
15-
export interface EMailDomainService extends BlockedUserFilter {
16-
hasEducationalInstitutionSuffix(email: string): Promise<boolean>;
17-
}
12+
export interface EMailDomainService extends BlockedUserFilter {}
1813

1914
@injectable()
2015
export class EMailDomainServiceImpl implements EMailDomainService {
2116
@inject(EmailDomainFilterDB) protected readonly domainFilterDb: EmailDomainFilterDB;
22-
@inject(EduEmailDomainDB) protected readonly eduDomainDb: EduEmailDomainDB;
23-
24-
protected readonly swotJsPromise = this.initSwotJs();
2517

2618
async isBlocked(email: string): Promise<boolean> {
2719
const { domain } = this.parseMail(email);
2820
return this.domainFilterDb.isBlocked(domain);
2921
}
3022

31-
async hasEducationalInstitutionSuffix(email: string): Promise<boolean> {
32-
const { domain } = this.parseMail(email);
33-
34-
if (await this.checkSwotJsForEducationalInstitutionSuffix(domain)) {
35-
return true;
36-
}
37-
return this.checkDBForEducationalInstitutionSuffix(domain);
38-
}
39-
40-
protected async checkDBForEducationalInstitutionSuffix(domain: string): Promise<boolean> {
41-
const entries = await this.eduDomainDb.readEducationalInstitutionDomains();
42-
const domains = entries.map((entry) => entry.domain);
43-
return domains.some((d) => domain === d);
44-
}
45-
46-
protected async checkSwotJsForEducationalInstitutionSuffix(email: string): Promise<boolean> {
47-
const swotJs = await this.swotJsPromise;
48-
return !!swotJs.check(email);
49-
}
50-
5123
protected parseMail(email: string): { user: string; domain: string } {
5224
const parts = email.split("@");
5325
if (parts.length !== 2) {
5426
throw new Error("Invalid E-Mail address: " + email);
5527
}
5628
return { user: parts[0], domain: parts[1].toLowerCase() };
5729
}
58-
59-
protected initSwotJs(): Promise<any> {
60-
return new Promise((resolve, reject) => {
61-
const swotCallback = () => resolve(result);
62-
const result = new SwotJs(swotCallback);
63-
});
64-
}
6530
}

components/server/ee/src/container-module.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import { StartPrebuildContextParser } from "./prebuilds/start-prebuild-context-p
2424
import { WorkspaceFactory } from "../../src/workspace/workspace-factory";
2525
import { WorkspaceFactoryEE } from "./workspace/workspace-factory";
2626
import { StripeService } from "./user/stripe-service";
27-
import { EligibilityService } from "./user/eligibility-service";
2827
import { UserDeletionService } from "../../src/user/user-deletion-service";
2928
import { BlockedUserFilter } from "../../src/auth/blocked-user-filter";
3029
import { EMailDomainService, EMailDomainServiceImpl } from "./auth/email-domain-service";
@@ -62,7 +61,6 @@ export const productionEEContainerModule = new ContainerModule((bind, unbind, is
6261

6362
// GitpodServerImpl (stateful per user)
6463
rebind(GitpodServerImpl).to(GitpodServerEEImpl).inRequestScope();
65-
bind(EligibilityService).toSelf().inRequestScope();
6664

6765
// various
6866
rebind(HostContainerMapping).to(HostContainerMappingEE).inSingletonScope();

0 commit comments

Comments
 (0)