refactor(editor): Migrate ldap to @n8n/rest-api-client (no-changelog) (#16144)

This commit is contained in:
Alex Grozav
2025-06-10 11:01:09 +02:00
committed by GitHub
parent d68a776e5c
commit 9d12b741ff
6 changed files with 87 additions and 92 deletions

View File

@@ -3,6 +3,7 @@ export * from './communityNodes';
export * from './ctas';
export * from './eventbus.ee';
export * from './events';
export * from './ldap';
export * from './mfa';
export * from './nodeTypes';
export * from './npsSurvey';

View File

@@ -0,0 +1,77 @@
import type { IRestApiContext } from '../types';
import { makeRestApiRequest } from '../utils';
import type { IDataObject } from 'n8n-workflow';
export interface LdapSyncData {
id: number;
startedAt: string;
endedAt: string;
created: number;
updated: number;
disabled: number;
scanned: number;
status: string;
error: string;
runMode: string;
}
export interface LdapSyncTable {
status: string;
endedAt: string;
runTime: string;
runMode: string;
details: string;
}
export interface LdapConfig {
loginEnabled: boolean;
loginLabel: string;
connectionUrl: string;
allowUnauthorizedCerts: boolean;
connectionSecurity: string;
connectionPort: number;
baseDn: string;
bindingAdminDn: string;
bindingAdminPassword: string;
firstNameAttribute: string;
lastNameAttribute: string;
emailAttribute: string;
loginIdAttribute: string;
ldapIdAttribute: string;
userFilter: string;
synchronizationEnabled: boolean;
synchronizationInterval: number; // minutes
searchPageSize: number;
searchTimeout: number;
}
export async function getLdapConfig(context: IRestApiContext): Promise<LdapConfig> {
return await makeRestApiRequest(context, 'GET', '/ldap/config');
}
export async function testLdapConnection(context: IRestApiContext): Promise<{}> {
return await makeRestApiRequest(context, 'POST', '/ldap/test-connection');
}
export async function updateLdapConfig(
context: IRestApiContext,
adConfig: LdapConfig,
): Promise<LdapConfig> {
return await makeRestApiRequest(
context,
'PUT',
'/ldap/config',
adConfig as unknown as IDataObject,
);
}
export async function runLdapSync(context: IRestApiContext, data: IDataObject): Promise<{}> {
return await makeRestApiRequest(context, 'POST', '/ldap/sync', data as unknown as IDataObject);
}
export async function getLdapSynchronizations(
context: IRestApiContext,
pagination: { page: number },
): Promise<LdapSyncData[]> {
return await makeRestApiRequest(context, 'GET', '/ldap/sync', pagination);
}

View File

@@ -1232,49 +1232,6 @@ export type SchemaType =
| 'null'
| 'undefined';
export interface ILdapSyncData {
id: number;
startedAt: string;
endedAt: string;
created: number;
updated: number;
disabled: number;
scanned: number;
status: string;
error: string;
runMode: string;
}
export interface ILdapSyncTable {
status: string;
endedAt: string;
runTime: string;
runMode: string;
details: string;
}
export interface ILdapConfig {
loginEnabled: boolean;
loginLabel: string;
connectionUrl: string;
allowUnauthorizedCerts: boolean;
connectionSecurity: string;
connectionPort: number;
baseDn: string;
bindingAdminDn: string;
bindingAdminPassword: string;
firstNameAttribute: string;
lastNameAttribute: string;
emailAttribute: string;
loginIdAttribute: string;
ldapIdAttribute: string;
userFilter: string;
synchronizationEnabled: boolean;
synchronizationInterval: number; // minutes
searchPageSize: number;
searchTimeout: number;
}
export type Schema = { type: SchemaType; key?: string; value: string | Schema[]; path: string };
export type UsageState = {

View File

@@ -1,35 +0,0 @@
import type { ILdapConfig, ILdapSyncData } from '@/Interface';
import type { IRestApiContext } from '@n8n/rest-api-client';
import { makeRestApiRequest } from '@n8n/rest-api-client';
import type { IDataObject } from 'n8n-workflow';
export async function getLdapConfig(context: IRestApiContext): Promise<ILdapConfig> {
return await makeRestApiRequest(context, 'GET', '/ldap/config');
}
export async function testLdapConnection(context: IRestApiContext): Promise<{}> {
return await makeRestApiRequest(context, 'POST', '/ldap/test-connection');
}
export async function updateLdapConfig(
context: IRestApiContext,
adConfig: ILdapConfig,
): Promise<ILdapConfig> {
return await makeRestApiRequest(
context,
'PUT',
'/ldap/config',
adConfig as unknown as IDataObject,
);
}
export async function runLdapSync(context: IRestApiContext, data: IDataObject): Promise<{}> {
return await makeRestApiRequest(context, 'POST', '/ldap/sync', data as unknown as IDataObject);
}
export async function getLdapSynchronizations(
context: IRestApiContext,
pagination: { page: number },
): Promise<ILdapSyncData[]> {
return await makeRestApiRequest(context, 'GET', '/ldap/sync', pagination);
}

View File

@@ -3,10 +3,10 @@ import Bowser from 'bowser';
import type { IUserManagementSettings, FrontendSettings } from '@n8n/api-types';
import * as eventsApi from '@n8n/rest-api-client/api/events';
import * as ldapApi from '@/api/ldap';
import * as ldapApi from '@n8n/rest-api-client/api/ldap';
import * as settingsApi from '@/api/settings';
import { testHealthEndpoint } from '@/api/templates';
import type { ILdapConfig } from '@/Interface';
import type { LdapConfig } from '@n8n/rest-api-client/api/ldap';
import {
INSECURE_CONNECTION_WARNING,
LOCAL_STORAGE_EXPERIMENTAL_MIN_ZOOM_NODE_SETTINGS_IN_CANVAS,
@@ -363,7 +363,7 @@ export const useSettingsStore = defineStore(STORES.SETTINGS, () => {
return await ldapApi.testLdapConnection(rootStore.restApiContext);
};
const updateLdapConfig = async (ldapConfig: ILdapConfig) => {
const updateLdapConfig = async (ldapConfig: LdapConfig) => {
const rootStore = useRootStore();
return await ldapApi.updateLdapConfig(rootStore.restApiContext, ldapConfig);
};

View File

@@ -6,13 +6,8 @@ import { convertToDisplayDate } from '@/utils/typesUtils';
import { useToast } from '@/composables/useToast';
import { useMessage } from '@/composables/useMessage';
import { useDocumentTitle } from '@/composables/useDocumentTitle';
import type {
ILdapConfig,
ILdapSyncData,
ILdapSyncTable,
IFormInput,
IFormInputs,
} from '@/Interface';
import type { IFormInput, IFormInputs } from '@/Interface';
import type { LdapConfig, LdapSyncData, LdapSyncTable } from '@n8n/rest-api-client/api/ldap';
import { MODAL_CONFIRM } from '@/constants';
import humanizeDuration from 'humanize-duration';
@@ -71,9 +66,9 @@ const pageRedirectionHelper = usePageRedirectionHelper();
const settingsStore = useSettingsStore();
const dataTable = ref<ILdapSyncTable[]>([]);
const dataTable = ref<LdapSyncTable[]>([]);
const tableKey = ref(0);
const adConfig = ref<ILdapConfig>();
const adConfig = ref<LdapConfig>();
const loadingTestConnection = ref(false);
const loadingDryRun = ref(false);
const loadingLiveRun = ref(false);
@@ -123,7 +118,7 @@ const onReadyToSubmit = (ready: boolean) => {
readyToSubmit.value = ready;
};
const syncDataMapper = (sync: ILdapSyncData): ILdapSyncTable => {
const syncDataMapper = (sync: LdapSyncData): LdapSyncTable => {
const startedAt = new Date(sync.startedAt);
const endedAt = new Date(sync.endedAt);
const runTimeInMinutes = endedAt.getTime() - startedAt.getTime();
@@ -149,7 +144,7 @@ const onSubmit = async () => {
const formValues = ldapConfigFormRef.value.getValues();
const newConfiguration: ILdapConfig = {
const newConfiguration: LdapConfig = {
loginEnabled: formValues.loginEnabled,
loginLabel: formValues.loginLabel,
connectionUrl: formValues.serverAddress,