misc: addres LDAP config update and test issues

This commit is contained in:
Sheen Capadngan
2025-08-07 23:56:52 +08:00
parent 1ad02e2da6
commit 569edd2852
5 changed files with 117 additions and 78 deletions
@@ -151,10 +151,23 @@ export const useDeleteLDAPGroupMapping = () => {
export const useTestLDAPConnection = () => {
return useMutation({
mutationFn: async (ldapConfigId: string) => {
const { data } = await apiRequest.post<boolean>(
`/api/v1/ldap/config/${ldapConfigId}/test-connection`
);
mutationFn: async ({
url,
bindDN,
bindPass,
caCert
}: {
url: string;
bindDN: string;
bindPass: string;
caCert: string;
}) => {
const { data } = await apiRequest.post<boolean>("/api/v1/ldap/config/test-connection", {
url,
bindDN,
bindPass,
caCert
});
return data;
}
});
@@ -92,12 +92,7 @@ export const LDAPModal = ({ popUp, handlePopUpClose, handlePopUpToggle, hideDele
const watchUrl = watch("url");
const watchBindDN = watch("bindDN");
const watchBindPass = watch("bindPass");
const watchSearchBase = watch("searchBase");
const watchSearchFilter = watch("searchFilter");
const watchGroupSearchBase = watch("groupSearchBase");
const watchGroupSearchFilter = watch("groupSearchFilter");
const watchCaCert = watch("caCert");
const watchUniqueUserAttribute = watch("uniqueUserAttribute");
useEffect(() => {
if (data) {
@@ -147,7 +142,6 @@ export const LDAPModal = ({ popUp, handlePopUpClose, handlePopUpToggle, hideDele
} else {
await updateMutateAsync({
organizationId: currentOrg.id,
isActive: false,
url,
bindDN,
bindPass,
@@ -179,23 +173,13 @@ export const LDAPModal = ({ popUp, handlePopUpClose, handlePopUpToggle, hideDele
const handleTestLDAPConnection = async () => {
try {
await onSSOModalSubmit({
const result = await testLDAPConnection({
url: watchUrl,
bindDN: watchBindDN,
bindPass: watchBindPass,
searchBase: watchSearchBase,
searchFilter: watchSearchFilter,
groupSearchBase: watchGroupSearchBase,
groupSearchFilter: watchGroupSearchFilter,
uniqueUserAttribute: watchUniqueUserAttribute,
caCert: watchCaCert,
shouldCloseModal: false
caCert: watchCaCert ?? ""
});
if (!data) return;
const result = await testLDAPConnection(data.id);
if (!result) {
createNotification({
text: "Failed to test the LDAP connection: Bind operation was unsuccessful",