Skip to content

Commit ff9ea47

Browse files
committed
WIP9
Signed-off-by: Louis Chemineau <louis@chmn.me>
1 parent 1330f0d commit ff9ea47

File tree

3 files changed

+47
-14
lines changed

3 files changed

+47
-14
lines changed

apps/user_ldap/src/components/SettingsTabs/LoginTab.vue

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@
2121
{{ t('user_ldap', 'LDAP/AD Email Address') }}
2222
</NcCheckboxRadioSwitch>
2323

24-
<NcSelect v-model="ldapConfig.ldapLoginFilterAttributes"
24+
<NcSelect :value="selectedLoginFilterAttributes"
25+
:close-on-select="false"
2526
:disabled="ldapConfig.ldapLoginFilterMode === '1'"
26-
:options="['TODO']"
27+
:options="filteredLoginFilterOptions"
2728
:input-label="t('user_ldap', 'Other Attributes:')"
28-
:multiple="true" />
29+
:multiple="true"
30+
@input="updateLoginFilterAttributes" />
2931
</div>
3032

3133
<div class="ldap-wizard__login__line ldap-wizard__login__user-login-filter">
@@ -60,16 +62,16 @@
6062
</template>
6163

6264
<script lang="ts" setup>
63-
import { ref } from 'vue'
65+
import { computed, ref } from 'vue'
6466
import { storeToRefs } from 'pinia'
6567
6668
import { t } from '@nextcloud/l10n'
6769
import { NcButton, NcTextField, NcTextArea, NcCheckboxRadioSwitch, NcSelect } from '@nextcloud/vue'
6870
import { getCapabilities } from '@nextcloud/capabilities'
71+
import { showError, showSuccess } from '@nextcloud/dialogs'
6972
7073
import { useLDAPConfigsStore } from '../../store/configs'
7174
import { useWizardStore } from '../../store/wizard'
72-
import { showError, showSuccess } from '@nextcloud/dialogs'
7375
import { showEnableAutomaticFilterInfo } from '../../services/ldapConfigService'
7476
7577
const ldapConfigsStore = useLDAPConfigsStore()
@@ -81,16 +83,48 @@ const instanceName = (getCapabilities() as { theming: { name:string } }).theming
8183
const testUsername = ref('')
8284
const enableVerifyButton = ref(false)
8385
86+
const loginFilterOptions = ref<string[]>([])
87+
const selectedLoginFilterAttributes = computed(() => ldapConfig.value.ldapLoginFilterAttributes.split(';'))
88+
const filteredLoginFilterOptions = computed(() => loginFilterOptions.value.filter((option) => !selectedLoginFilterAttributes.value.includes(option)))
89+
wizardStore.callWizardAction('determineAttributes')
90+
.then(({ options }) => { loginFilterOptions.value = options.ldap_loginfilter_attributes })
91+
8492
/**
8593
*
94+
* @param value
8695
*/
87-
async function verifyLoginName() {
88-
const { changes: { ldap_test_loginname: testLoginName, ldap_test_effective_filter: testEffectiveFilter } } = await wizardStore.callWizardAction('testLoginName', { ldap_test_loginname: testUsername.value })
96+
function updateLoginFilterAttributes(value) {
97+
ldapConfig.value.ldapLoginFilterAttributes = value.join(';')
98+
}
8999
90-
if (testLoginName === 1) {
91-
showSuccess(t('user_ldap', 'User found and settings verified.'))
92-
} else {
93-
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 }))
100+
/**
101+
*
102+
*/
103+
async function verifyLoginName() {
104+
try {
105+
const { changes: { ldap_test_loginname: testLoginName, ldap_test_effective_filter: testEffectiveFilter } } = await wizardStore.callWizardAction('testLoginName', { ldap_test_loginname: testUsername.value })
106+
107+
if (testLoginName < 1) {
108+
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 }))
109+
} else if (testLoginName === 1) {
110+
showSuccess(t('user_ldap', 'User found and settings verified.'))
111+
} else if (testLoginName > 1) {
112+
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.'))
113+
}
114+
} catch (error) {
115+
const message = error ?? t('user_ldap', 'An unspecified error occurred. Please check log and settings.')
116+
117+
switch (message) {
118+
case 'Bad search filter':
119+
showError(t('user_ldap', 'The search filter is invalid, probably due to syntax issues like uneven number of opened and closed brackets. Please revise.'))
120+
break
121+
case 'connection error':
122+
showError(t('user_ldap', 'A connection error to LDAP/AD occurred. Please check host, port and credentials.'))
123+
break
124+
case 'missing placeholder':
125+
showError(t('user_ldap', 'The "%uid" placeholder is missing. It will be replaced with the login name when querying LDAP/AD.'))
126+
break
127+
}
94128
}
95129
}
96130

apps/user_ldap/src/services/ldapConfigService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ export async function callWizard(action: WizardAction, configId: string, extraPa
146146

147147
if (response.data.status === 'error') {
148148
showError(response.data.message)
149-
throw new Error(t('user_ldap', 'Error when calling wizard.php'))
149+
throw new Error(response.data.message)
150150
}
151151

152152
return response.data

apps/user_ldap/src/views/Settings.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
<div class="ldap-wizard__config-selection">
1010
<NcSelect v-model="selectedConfigId"
1111
:options="Object.keys(ldapConfigs)"
12-
:input-label="t('user_ldap', 'Select LDAP Config')"
13-
@input="selectedConfigId = $event">
12+
:input-label="t('user_ldap', 'Select LDAP Config')">
1413
<template #option="{label: configId}">
1514
{{ `${configId}: ${ldapConfigs[configId].ldapHost}` }}
1615
</template>

0 commit comments

Comments
 (0)