]> source.dussan.org Git - nextcloud-server.git/commitdiff
WIP9 artonge/chore/ldap_wizard_rewrite 48065/head
authorLouis Chemineau <louis@chmn.me>
Mon, 23 Sep 2024 12:46:13 +0000 (14:46 +0200)
committerLouis Chemineau <louis@chmn.me>
Thu, 3 Oct 2024 13:45:22 +0000 (15:45 +0200)
Signed-off-by: Louis Chemineau <louis@chmn.me>
apps/user_ldap/src/components/SettingsTabs/LoginTab.vue
apps/user_ldap/src/services/ldapConfigService.ts
apps/user_ldap/src/views/Settings.vue

index b62b7e87761848a663ffc22c0b4d2b87ab66d09a..7c0a7ca2f1407c0a8a21a2032d08489a27b106b3 100644 (file)
                                {{ t('user_ldap', 'LDAP/AD Email Address') }}
                        </NcCheckboxRadioSwitch>
 
-                       <NcSelect v-model="ldapConfig.ldapLoginFilterAttributes"
+                       <NcSelect :value="selectedLoginFilterAttributes"
+                               :close-on-select="false"
                                :disabled="ldapConfig.ldapLoginFilterMode === '1'"
-                               :options="['TODO']"
+                               :options="filteredLoginFilterOptions"
                                :input-label="t('user_ldap', 'Other Attributes:')"
-                               :multiple="true" />
+                               :multiple="true"
+                               @input="updateLoginFilterAttributes" />
                </div>
 
                <div class="ldap-wizard__login__line ldap-wizard__login__user-login-filter">
 </template>
 
 <script lang="ts" setup>
-import { ref } from 'vue'
+import { computed, ref } from 'vue'
 import { storeToRefs } from 'pinia'
 
 import { t } from '@nextcloud/l10n'
 import { NcButton, NcTextField, NcTextArea, NcCheckboxRadioSwitch, NcSelect } from '@nextcloud/vue'
 import { getCapabilities } from '@nextcloud/capabilities'
+import { showError, showSuccess } from '@nextcloud/dialogs'
 
 import { useLDAPConfigsStore } from '../../store/configs'
 import { useWizardStore } from '../../store/wizard'
-import { showError, showSuccess } from '@nextcloud/dialogs'
 import { showEnableAutomaticFilterInfo } from '../../services/ldapConfigService'
 
 const ldapConfigsStore = useLDAPConfigsStore()
@@ -81,16 +83,48 @@ const instanceName = (getCapabilities() as { theming: { name:string } }).theming
 const testUsername = ref('')
 const enableVerifyButton = ref(false)
 
+const loginFilterOptions = ref<string[]>([])
+const selectedLoginFilterAttributes = computed(() => ldapConfig.value.ldapLoginFilterAttributes.split(';'))
+const filteredLoginFilterOptions = computed(() => loginFilterOptions.value.filter((option) => !selectedLoginFilterAttributes.value.includes(option)))
+wizardStore.callWizardAction('determineAttributes')
+       .then(({ options }) => { loginFilterOptions.value = options.ldap_loginfilter_attributes })
+
 /**
  *
+ * @param value
  */
-async function verifyLoginName() {
-       const { changes: { ldap_test_loginname: testLoginName, ldap_test_effective_filter: testEffectiveFilter } } = await wizardStore.callWizardAction('testLoginName', { ldap_test_loginname: testUsername.value })
+function updateLoginFilterAttributes(value) {
+       ldapConfig.value.ldapLoginFilterAttributes = value.join(';')
+}
 
-       if (testLoginName === 1) {
-               showSuccess(t('user_ldap', 'User found and settings verified.'))
-       } else {
-               showError(t('user_ldap', 'User not found. Please check your login attributes and username. Effective filter (to copy-and-paste for command-line validation): {filter}', { filter: testEffectiveFilter }))
+/**
+ *
+ */
+async function verifyLoginName() {
+       try {
+               const { changes: { ldap_test_loginname: testLoginName, ldap_test_effective_filter: testEffectiveFilter } } = await wizardStore.callWizardAction('testLoginName', { ldap_test_loginname: testUsername.value })
+
+               if (testLoginName < 1) {
+                       showSuccess(t('user_ldap', 'User not found. Please check your login attributes and username. Effective filter (to copy-and-paste for command-line validation): {filter}', { filter: testEffectiveFilter }))
+               } else if (testLoginName === 1) {
+                       showSuccess(t('user_ldap', 'User found and settings verified.'))
+               } else if (testLoginName > 1) {
+                       showSuccess(t('user_ldap', 'Consider narrowing your search, as it encompassed many users, only the first one of whom will be able to log in.'))
+               }
+       } catch (error) {
+               const message = error ?? t('user_ldap', 'An unspecified error occurred. Please check log and settings.')
+
+               switch (message) {
+               case 'Bad search filter':
+                       showError(t('user_ldap', 'The search filter is invalid, probably due to syntax issues like uneven number of opened and closed brackets. Please revise.'))
+                       break
+               case 'connection error':
+                       showError(t('user_ldap', 'A connection error to LDAP/AD occurred. Please check host, port and credentials.'))
+                       break
+               case 'missing placeholder':
+                       showError(t('user_ldap', 'The "%uid" placeholder is missing. It will be replaced with the login name when querying LDAP/AD.'))
+                       break
+               }
        }
 }
 
index 06ea614390878cd033a081a5880ead9cbcc2b137..a7ac3eae9f53320418fb5861db5b160d81776644 100644 (file)
@@ -146,7 +146,7 @@ export async function callWizard(action: WizardAction, configId: string, extraPa
 
        if (response.data.status === 'error') {
                showError(response.data.message)
-               throw new Error(t('user_ldap', 'Error when calling wizard.php'))
+               throw new Error(response.data.message)
        }
 
        return response.data
index f062b77830718dbb3106d59b833b13397cc8e72f..915b53c52e7082a69aed3baa9f0f818ccf748023 100644 (file)
@@ -9,8 +9,7 @@
                <div class="ldap-wizard__config-selection">
                        <NcSelect v-model="selectedConfigId"
                                :options="Object.keys(ldapConfigs)"
-                               :input-label="t('user_ldap', 'Select LDAP Config')"
-                               @input="selectedConfigId = $event">
+                               :input-label="t('user_ldap', 'Select LDAP Config')">
                                <template #option="{label: configId}">
                                        {{ `${configId}: ${ldapConfigs[configId].ldapHost}` }}
                                </template>