Skip to content

Remove api.isStudent and all connected code/DB #17275

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 1 addition & 35 deletions components/dashboard/src/admin/UserDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,12 @@ export default function UserDetail(p: { user: User }) {
const [editSpendingLimit, setEditSpendingLimit] = useState<boolean>(false);
const [creditNote, setCreditNote] = useState<{ credits: number; note?: string }>({ credits: 0 });
const [editAddCreditNote, setEditAddCreditNote] = useState<boolean>(false);
const [isStudent, setIsStudent] = useState<boolean>();
const [editFeatureFlags, setEditFeatureFlags] = useState(false);
const [editRoles, setEditRoles] = useState(false);
const userRef = useRef(user);

const initialize = () => {
setUser(user);
getGitpodService().server.adminIsStudent(user.id).then(setIsStudent);
const attributionId = AttributionId.render(AttributionId.create(user));
getGitpodService().server.adminGetBillingMode(attributionId).then(setBillingMode);
getGitpodService().server.adminGetCostCenter(attributionId).then(setCostCenter);
Expand All @@ -69,21 +67,6 @@ export default function UserDetail(p: { user: User }) {
}
};

const addStudentDomain = async () => {
if (!emailDomain) {
console.log("cannot add student's email domain because there is none!");
return;
}

await updateUser(async (u) => {
await getGitpodService().server.adminAddStudentEmailDomain(u.id, emailDomain);
await getGitpodService()
.server.adminIsStudent(u.id)
.then((isStud) => setIsStudent(isStud));
return u;
});
};

const verifyUser = async () => {
await updateUser(async (u) => {
return await getGitpodService().server.adminVerifyUser(u.id);
Expand Down Expand Up @@ -117,24 +100,7 @@ export default function UserDetail(p: { user: User }) {
return <></>; // nothing to show here atm
}

const properties: JSX.Element[] = [
<Property
name="Student"
actions={
!isStudent && emailDomain && !["gmail.com", "yahoo.com", "hotmail.com"].includes(emailDomain)
? [
{
label: `Make '${emailDomain}' a student domain`,
onClick: addStudentDomain,
},
]
: undefined
}
>
{isStudent === undefined ? "---" : isStudent ? "Enabled" : "Disabled"}
</Property>,
renderBillingModeProperty(billingMode),
];
const properties: JSX.Element[] = [renderBillingModeProperty(billingMode)];

switch (billingMode?.mode) {
case "usage-based":
Expand Down
15 changes: 6 additions & 9 deletions components/dashboard/src/menu/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,16 @@ interface Entry {
export default function Menu() {
const user = useCurrentUser();
const location = useLocation();
const { setCurrency, setIsStudent } = useContext(PaymentContext);
const { setCurrency } = useContext(PaymentContext);
const [isFeedbackFormVisible, setFeedbackFormVisible] = useState<boolean>(false);

useEffect(() => {
const { server } = getGitpodService();
Promise.all([
server.getClientRegion().then((v) => () => {
// @ts-ignore
setCurrency(countries[v]?.currency === "EUR" ? "EUR" : "USD");
}),
server.isStudent().then((v) => () => setIsStudent(v)),
]).then((setters) => setters.forEach((s) => s()));
}, [setCurrency, setIsStudent]);
server.getClientRegion().then((v) => {
// @ts-ignore
setCurrency(countries[v]?.currency === "EUR" ? "EUR" : "USD");
});
}, [setCurrency]);

const adminMenu: Entry = useMemo(
() => ({
Expand Down
6 changes: 0 additions & 6 deletions components/dashboard/src/payment-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,19 @@ import { Currency } from "@gitpod/gitpod-protocol/lib/plans";
const PaymentContext = createContext<{
currency: Currency;
setCurrency: React.Dispatch<Currency>;
isStudent?: boolean;
setIsStudent: React.Dispatch<boolean>;
}>({
currency: "USD",
setCurrency: () => null,
setIsStudent: () => null,
});

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

return (
<PaymentContext.Provider
value={{
currency,
setCurrency,
isStudent,
setIsStudent,
}}
>
{children}
Expand Down
3 changes: 0 additions & 3 deletions components/dashboard/src/service/service-mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,6 @@ const gitpodServiceMock = createServiceMock({
getClientRegion: async () => {
return "europe-west-1";
},
isStudent: async () => {
return false;
},
getSuggestedContextURLs: async () => {
return [];
},
Expand Down
3 changes: 0 additions & 3 deletions components/gitpod-db/src/container-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ import { AuthProviderEntryDBImpl } from "./typeorm/auth-provider-entry-db-impl";
import { TeamSubscriptionDB } from "./team-subscription-db";
import { AccountingDB, TransactionalAccountingDBFactory } from "./accounting-db";
import { EmailDomainFilterDB } from "./email-domain-filter-db";
import { EduEmailDomainDB } from "./edu-email-domain-db";
import { EduEmailDomainDBImpl } from "./typeorm/edu-email-domain-db-impl";
import { EmailDomainFilterDBImpl } from "./typeorm/email-domain-filter-db-impl";
import { TeamSubscriptionDBImpl } from "./typeorm/team-subscription-db-impl";
import { TransactionalAccountingDBImpl, TypeORMAccountingDBImpl } from "./typeorm/accounting-db-impl";
Expand Down Expand Up @@ -146,7 +144,6 @@ export const dbContainerModule = new ContainerModule((bind, unbind, isBound, reb
bind(TeamSubscriptionDB).to(TeamSubscriptionDBImpl).inSingletonScope();
bind(TeamSubscription2DB).to(TeamSubscription2DBImpl).inSingletonScope();
bind(EmailDomainFilterDB).to(EmailDomainFilterDBImpl).inSingletonScope();
bind(EduEmailDomainDB).to(EduEmailDomainDBImpl).inSingletonScope();
bind(UserToTeamMigrationService).toSelf().inSingletonScope();
bind(WorkspaceOrganizationIdMigration).toSelf().inSingletonScope();
bind(Synchronizer).toSelf().inSingletonScope();
Expand Down
14 changes: 0 additions & 14 deletions components/gitpod-db/src/edu-email-domain-db.ts

This file was deleted.

1 change: 0 additions & 1 deletion components/gitpod-db/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export * from "./typeorm/typeorm";
export * from "./accounting-db";
export * from "./team-subscription-db";
export * from "./team-subscription-2-db";
export * from "./edu-email-domain-db";
export * from "./email-domain-filter-db";
export * from "./typeorm/entity/db-account-entry";
export * from "./project-db";
Expand Down
5 changes: 0 additions & 5 deletions components/gitpod-db/src/tables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,6 @@ export class GitpodTableDescriptionProvider implements TableDescriptionProvider
primaryKeys: ["id"],
timeColumn: "_lastModified",
},
{
name: "d_b_edu_email_domain",
primaryKeys: ["domain"],
timeColumn: "_lastModified",
},
{
name: "d_b_user_env_var",
primaryKeys: ["id", "userId"],
Expand Down
37 changes: 0 additions & 37 deletions components/gitpod-db/src/typeorm/edu-email-domain-db-impl.ts

This file was deleted.

15 changes: 0 additions & 15 deletions components/gitpod-db/src/typeorm/entity/db-edu-email-domain.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Copyright (c) 2023 Gitpod GmbH. All rights reserved.
* Licensed under the GNU Affero General Public License (AGPL).
* See License.AGPL.txt in the project root for license information.
*/

import { MigrationInterface, QueryRunner } from "typeorm";

export class DeleteEduEmailDomain1681824758658 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query("DROP TABLE IF EXISTS `d_b_edu_email_domain`");
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`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`,
);
}
}
2 changes: 0 additions & 2 deletions components/gitpod-protocol/src/admin-protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ export interface AdminServer {

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

adminIsStudent(userId: string): Promise<boolean>;
adminAddStudentEmailDomain(userId: string, domain: string): Promise<void>;
adminGetBillingMode(attributionId: string): Promise<BillingMode>;

adminGetSettings(): Promise<InstallationAdminSettings>;
Expand Down
5 changes: 0 additions & 5 deletions components/gitpod-protocol/src/gitpod-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,6 @@ export interface GitpodServer extends JsonRpcServer<GitpodClient>, AdminServer,

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

/**
* gitpod.io concerns
*/
isStudent(): Promise<boolean>;

/**
* Stripe/Usage
*/
Expand Down
4 changes: 0 additions & 4 deletions components/gitpod-protocol/src/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -685,10 +685,6 @@ export interface EmailDomainFilterEntry {
negative: boolean;
}

export interface EduEmailDomain {
domain: string;
}

export type AppInstallationPlatform = "github";
export type AppInstallationState = "claimed.user" | "claimed.platform" | "installed" | "uninstalled";
export interface AppInstallation {
Expand Down
37 changes: 0 additions & 37 deletions components/server/ee/src/auth/email-domain-service.spec.ts

This file was deleted.

37 changes: 1 addition & 36 deletions components/server/ee/src/auth/email-domain-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,61 +5,26 @@
*/

import { injectable, inject } from "inversify";
import * as SwotJs from "swot-js";

import { EmailDomainFilterDB } from "@gitpod/gitpod-db/lib/email-domain-filter-db";
import { EduEmailDomainDB } from "@gitpod/gitpod-db/lib/edu-email-domain-db";
import { BlockedUserFilter } from "../../../src/auth/blocked-user-filter";

export const EMailDomainService = Symbol("EMailDomainService");
export interface EMailDomainService extends BlockedUserFilter {
hasEducationalInstitutionSuffix(email: string): Promise<boolean>;
}
export interface EMailDomainService extends BlockedUserFilter {}

@injectable()
export class EMailDomainServiceImpl implements EMailDomainService {
@inject(EmailDomainFilterDB) protected readonly domainFilterDb: EmailDomainFilterDB;
@inject(EduEmailDomainDB) protected readonly eduDomainDb: EduEmailDomainDB;

protected readonly swotJsPromise = this.initSwotJs();

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

async hasEducationalInstitutionSuffix(email: string): Promise<boolean> {
const { domain } = this.parseMail(email);

if (await this.checkSwotJsForEducationalInstitutionSuffix(domain)) {
return true;
}
return this.checkDBForEducationalInstitutionSuffix(domain);
}

protected async checkDBForEducationalInstitutionSuffix(domain: string): Promise<boolean> {
const entries = await this.eduDomainDb.readEducationalInstitutionDomains();
const domains = entries.map((entry) => entry.domain);
return domains.some((d) => domain === d);
}

protected async checkSwotJsForEducationalInstitutionSuffix(email: string): Promise<boolean> {
const swotJs = await this.swotJsPromise;
return !!swotJs.check(email);
}

protected parseMail(email: string): { user: string; domain: string } {
const parts = email.split("@");
if (parts.length !== 2) {
throw new Error("Invalid E-Mail address: " + email);
}
return { user: parts[0], domain: parts[1].toLowerCase() };
}

protected initSwotJs(): Promise<any> {
return new Promise((resolve, reject) => {
const swotCallback = () => resolve(result);
const result = new SwotJs(swotCallback);
});
}
}
2 changes: 0 additions & 2 deletions components/server/ee/src/container-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import { StartPrebuildContextParser } from "./prebuilds/start-prebuild-context-p
import { WorkspaceFactory } from "../../src/workspace/workspace-factory";
import { WorkspaceFactoryEE } from "./workspace/workspace-factory";
import { StripeService } from "./user/stripe-service";
import { EligibilityService } from "./user/eligibility-service";
import { UserDeletionService } from "../../src/user/user-deletion-service";
import { BlockedUserFilter } from "../../src/auth/blocked-user-filter";
import { EMailDomainService, EMailDomainServiceImpl } from "./auth/email-domain-service";
Expand Down Expand Up @@ -62,7 +61,6 @@ export const productionEEContainerModule = new ContainerModule((bind, unbind, is

// GitpodServerImpl (stateful per user)
rebind(GitpodServerImpl).to(GitpodServerEEImpl).inRequestScope();
bind(EligibilityService).toSelf().inRequestScope();

// various
rebind(HostContainerMapping).to(HostContainerMappingEE).inSingletonScope();
Expand Down
Loading