feat: Migrate allowedDomains to a Team Level Settings (#3489)

Fixes #3412

Previously the only way to restrict the domains for a Team were with the ALLOWED_DOMAINS environment variable for self hosted instances.
This PR migrates this to be a database backed setting on the Team object. This is done through the creation of a TeamDomain model that is associated with the Team and contains the domain name

This settings is updated on the Security Tab. Here domains can be added or removed from the Team.

On the server side, we take the code paths that previously were using ALLOWED_DOMAINS and switched them to use the Team allowed domains instead
This commit is contained in:
Corey Alexander
2022-05-17 20:26:29 -04:00
committed by GitHub
parent 18e0d936ef
commit 51001cfac1
27 changed files with 622 additions and 78 deletions

View File

@@ -6,17 +6,6 @@ import Logger from "@server/logging/logger";
import { User, Event, Team, Collection, View } from "@server/models";
import { getCookieDomain } from "@server/utils/domains";
export function getAllowedDomains(): string[] {
// GOOGLE_ALLOWED_DOMAINS included here for backwards compatability
const env = process.env.ALLOWED_DOMAINS || process.env.GOOGLE_ALLOWED_DOMAINS;
return env ? env.split(",") : [];
}
export function isDomainAllowed(domain: string): boolean {
const allowedDomains = getAllowedDomains();
return allowedDomains.includes(domain) || allowedDomains.length === 0;
}
export async function signIn(
ctx: Context,
user: User,