diff --git a/client/src/components/dynamic-groups/rule-editor.tsx b/client/src/components/dynamic-groups/rule-editor.tsx index 165a373..9b8ed1b 100644 --- a/client/src/components/dynamic-groups/rule-editor.tsx +++ b/client/src/components/dynamic-groups/rule-editor.tsx @@ -381,12 +381,16 @@ export const RuleEditor: React.FC = ({ rule, onSave, onCancel }
{ - const variableText = `{${variable}}`; + // Direct insertion of variable or prefixed OU segment const currentValue = formData.targetOU || ''; - const newValue = currentValue + variableText; + // Check if this is a variable or a direct DC value + const newValue = variable.startsWith("DC=") || variable.startsWith("OU=") + ? (currentValue && !currentValue.endsWith(",") ? currentValue + "," : currentValue) + variable + : currentValue + variable; setFormData({ ...formData, targetOU: newValue }); }} connections={formData.connections} + isForOU={true} />
diff --git a/client/src/components/dynamic-groups/variable-selector.tsx b/client/src/components/dynamic-groups/variable-selector.tsx index c279b9b..580a043 100644 --- a/client/src/components/dynamic-groups/variable-selector.tsx +++ b/client/src/components/dynamic-groups/variable-selector.tsx @@ -51,14 +51,45 @@ const COMMON_ATTRIBUTES = [ { value: 'ipPhone', label: 'ipPhone', description: 'IP phone' }, ]; -const VariableSelector: React.FC = ({ onSelectVariable, connections }) => { +const VariableSelector: React.FC = ({ onSelectVariable, connections, isForOU = false }) => { const [isOpen, setIsOpen] = useState(false); const [customAttribute, setCustomAttribute] = useState(''); const { toast } = useToast(); const inputRef = useRef(null); + // Get LDAP connection details to determine domain name for rootDSE + const { data: ldapConnections = [] } = useQuery({ + queryKey: ['/api/ldap-connections'], + staleTime: 60000, + }); + + // Find the first selected connection to get domain info + const selectedConnection = ldapConnections.find(conn => connections.includes(conn.id)); + + // Generate rootDSE string based on selected connection's domain + const getRootDSE = () => { + if (!selectedConnection || !selectedConnection.domain) { + return "DC=example,DC=com"; + } + + const domainParts = selectedConnection.domain.split('.'); + return domainParts.map(part => `DC=${part}`).join(','); + }; + + const addRootDSE = () => { + const rootDSE = getRootDSE(); + onSelectVariable(rootDSE); + setIsOpen(false); + }; + const handleSelect = (attribute: string) => { - onSelectVariable(attribute); + if (isForOU) { + // Format OU path with proper prefixes + const formattedVar = `OU={${attribute}}`; + onSelectVariable(formattedVar); + } else { + onSelectVariable(attribute); + } setIsOpen(false); }; @@ -72,7 +103,13 @@ const VariableSelector: React.FC = ({ onSelectVariable, c return; } - onSelectVariable(customAttribute.trim()); + if (isForOU) { + // Format custom attribute as OU path segment + const formattedVar = `OU={${customAttribute.trim()}}`; + onSelectVariable(formattedVar); + } else { + onSelectVariable(customAttribute.trim()); + } setCustomAttribute(''); setIsOpen(false); }; @@ -97,6 +134,26 @@ const VariableSelector: React.FC = ({ onSelectVariable, c No attributes found + {isForOU && ( + + + +
+

Add RootDSE

+

+ {selectedConnection?.domain ? + `Adds ${getRootDSE()} from ${selectedConnection.name}` : + 'Adds DC=example,DC=com (no connection selected)'} +

+
+
+
+ )} +