From e1ed37c7135caf3e916bcbd9d56e182bdb44ab4d Mon Sep 17 00:00:00 2001
From: Sheen Capadngan
Date: Thu, 27 Jun 2024 01:07:28 +0800
Subject: [PATCH] misc: adjusted OrgSettingsPage and PersonalSettingsPage to
include toggle
---
.../components/OrgAuthTab/OrgAuthTab.tsx | 26 +++++++++++++++----
.../OrgAuthTab/OrgGeneralAuthSection.tsx | 2 +-
.../components/OrgAuthTab/OrgLDAPSection.tsx | 2 +-
.../components/OrgAuthTab/OrgOIDCSection.tsx | 2 +-
.../components/OrgAuthTab/OrgSSOSection.tsx | 3 ++-
.../AuthMethodSection/AuthMethodSection.tsx | 23 +++++++++++-----
6 files changed, 42 insertions(+), 16 deletions(-)
diff --git a/frontend/src/views/Settings/OrgSettingsPage/components/OrgAuthTab/OrgAuthTab.tsx b/frontend/src/views/Settings/OrgSettingsPage/components/OrgAuthTab/OrgAuthTab.tsx
index 31d6987bd8..b1a079922f 100644
--- a/frontend/src/views/Settings/OrgSettingsPage/components/OrgAuthTab/OrgAuthTab.tsx
+++ b/frontend/src/views/Settings/OrgSettingsPage/components/OrgAuthTab/OrgAuthTab.tsx
@@ -1,5 +1,8 @@
-import { OrgPermissionActions, OrgPermissionSubjects } from "@app/context";
+import { useCallback } from "react";
+
+import { OrgPermissionActions, OrgPermissionSubjects, useServerConfig } from "@app/context";
import { withPermission } from "@app/hoc";
+import { LoginMethod } from "@app/hooks/api/admin/types";
import { OrgGeneralAuthSection } from "./OrgGeneralAuthSection";
import { OrgLDAPSection } from "./OrgLDAPSection";
@@ -9,12 +12,25 @@ import { OrgSSOSection } from "./OrgSSOSection";
export const OrgAuthTab = withPermission(
() => {
+ const {
+ config: { enabledLoginMethods }
+ } = useServerConfig();
+
+ const shouldDisplaySection = useCallback(
+ (method: LoginMethod) => !enabledLoginMethods || enabledLoginMethods.includes(method),
+ [enabledLoginMethods]
+ );
+
return (
-
-
-
-
+ {shouldDisplaySection(LoginMethod.SAML) && (
+ <>
+
+
+ >
+ )}
+ {shouldDisplaySection(LoginMethod.OIDC) && }
+ {shouldDisplaySection(LoginMethod.LDAP) && }
);
diff --git a/frontend/src/views/Settings/OrgSettingsPage/components/OrgAuthTab/OrgGeneralAuthSection.tsx b/frontend/src/views/Settings/OrgSettingsPage/components/OrgAuthTab/OrgGeneralAuthSection.tsx
index 7c3af9493f..6e4eca456b 100644
--- a/frontend/src/views/Settings/OrgSettingsPage/components/OrgAuthTab/OrgGeneralAuthSection.tsx
+++ b/frontend/src/views/Settings/OrgSettingsPage/components/OrgAuthTab/OrgGeneralAuthSection.tsx
@@ -11,7 +11,6 @@ import { useLogoutUser, useUpdateOrg } from "@app/hooks/api";
import { usePopUp } from "@app/hooks/usePopUp";
export const OrgGeneralAuthSection = () => {
-
const { currentOrg } = useOrganization();
const { subscription } = useSubscription();
const { popUp, handlePopUpOpen, handlePopUpToggle } = usePopUp(["upgradePlan"] as const);
@@ -88,6 +87,7 @@ export const OrgGeneralAuthSection = () => {
Enforce members to authenticate via SAML to access this organization
+
handlePopUpToggle("upgradePlan", isOpen)}
diff --git a/frontend/src/views/Settings/OrgSettingsPage/components/OrgAuthTab/OrgLDAPSection.tsx b/frontend/src/views/Settings/OrgSettingsPage/components/OrgAuthTab/OrgLDAPSection.tsx
index 87d0f28aff..0d34fcefc0 100644
--- a/frontend/src/views/Settings/OrgSettingsPage/components/OrgAuthTab/OrgLDAPSection.tsx
+++ b/frontend/src/views/Settings/OrgSettingsPage/components/OrgAuthTab/OrgLDAPSection.tsx
@@ -94,7 +94,6 @@ export const OrgLDAPSection = (): JSX.Element => {
return (
<>
-
LDAP
@@ -151,6 +150,7 @@ export const OrgLDAPSection = (): JSX.Element => {
)}
+
{
return (
<>
-
OIDC
@@ -103,6 +102,7 @@ export const OrgOIDCSection = (): JSX.Element => {
)}
+
{
const { currentOrg } = useOrganization();
const { subscription } = useSubscription();
-
+
const { data, isLoading } = useGetSSOConfig(currentOrg?.id ?? "");
const { mutateAsync } = useUpdateSSOConfig();
const { popUp, handlePopUpOpen, handlePopUpClose, handlePopUpToggle } = usePopUp([
@@ -115,6 +115,7 @@ export const OrgSSOSection = (): JSX.Element => {
Allow members to authenticate into Infisical with SAML
+
;
export const AuthMethodSection = () => {
-
const { user } = useUser();
+ const { config } = useServerConfig();
const { mutateAsync } = useUpdateUserAuthMethods();
const { reset, setValue, watch } = useForm({
@@ -102,6 +103,14 @@ export const AuthMethodSection = () => {
{user &&
authMethodOpts.map((authMethodOpt) => {
+ // only filter when enabledLoginMethods is explicitly configured by admin
+ if (
+ config.enabledLoginMethods &&
+ !config.enabledLoginMethods.includes(authMethodOpt.loginMethod)
+ ) {
+ return null;
+ }
+
return (