2022-03-02 18:18:50 +00:00
|
|
|
import { getAppsmithConfigs } from "@appsmith/configs";
|
2022-12-01 06:30:50 +00:00
|
|
|
import { ADMIN_SETTINGS_CATEGORY_DEFAULT_PATH } from "constants/routes";
|
|
|
|
|
import { User } from "constants/userConstants";
|
2022-03-02 18:18:50 +00:00
|
|
|
const {
|
|
|
|
|
disableLoginForm,
|
|
|
|
|
enableGithubOAuth,
|
|
|
|
|
enableGoogleOAuth,
|
|
|
|
|
} = getAppsmithConfigs();
|
|
|
|
|
|
|
|
|
|
export const connectedMethods = [
|
|
|
|
|
enableGoogleOAuth,
|
|
|
|
|
enableGithubOAuth,
|
|
|
|
|
!disableLoginForm,
|
|
|
|
|
].filter(Boolean);
|
|
|
|
|
|
2022-03-04 06:26:12 +00:00
|
|
|
/* settings is the updated & unsaved settings on Admin settings page */
|
2022-03-02 18:18:50 +00:00
|
|
|
export const saveAllowed = (settings: any) => {
|
2022-03-04 06:26:12 +00:00
|
|
|
if (connectedMethods.length === 1) {
|
|
|
|
|
const checkFormLogin = !(
|
|
|
|
|
"APPSMITH_FORM_LOGIN_DISABLED" in settings || disableLoginForm
|
|
|
|
|
),
|
|
|
|
|
checkGoogleAuth =
|
|
|
|
|
settings["APPSMITH_OAUTH2_GOOGLE_CLIENT_ID"] !== "" &&
|
|
|
|
|
enableGoogleOAuth,
|
|
|
|
|
checkGithubAuth =
|
|
|
|
|
settings["APPSMITH_OAUTH2_GITHUB_CLIENT_ID"] !== "" &&
|
|
|
|
|
enableGithubOAuth;
|
|
|
|
|
|
|
|
|
|
return checkFormLogin || checkGoogleAuth || checkGithubAuth;
|
2022-03-02 18:18:50 +00:00
|
|
|
} else {
|
2022-03-04 06:26:12 +00:00
|
|
|
return connectedMethods.length >= 2;
|
2022-03-02 18:18:50 +00:00
|
|
|
}
|
|
|
|
|
};
|
2022-12-01 06:30:50 +00:00
|
|
|
|
|
|
|
|
/* get default admin settings path */
|
|
|
|
|
export const getDefaultAdminSettingsPath = (
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
|
|
{ isSuperUser, tenantPermissions = [] }: Record<string, any>,
|
|
|
|
|
): string => {
|
|
|
|
|
return ADMIN_SETTINGS_CATEGORY_DEFAULT_PATH;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const showAdminSettings = (user?: User): boolean => {
|
|
|
|
|
return (user?.isSuperUser && user?.isConfigurable) || false;
|
|
|
|
|
};
|
2023-02-14 01:34:53 +00:00
|
|
|
|
|
|
|
|
export const getLoginUrl = (method: string): string => {
|
|
|
|
|
const urls: Record<string, string> = {};
|
|
|
|
|
|
|
|
|
|
return urls[method];
|
|
|
|
|
};
|