21
21
{{ t('user_ldap', 'LDAP/AD Email Address') }}
22
22
</NcCheckboxRadioSwitch >
23
23
24
- <NcSelect v-model =" ldapConfig.ldapLoginFilterAttributes"
24
+ <NcSelect :value =" selectedLoginFilterAttributes"
25
+ :close-on-select =" false"
25
26
:disabled =" ldapConfig.ldapLoginFilterMode === '1'"
26
- :options =" ['TODO'] "
27
+ :options =" filteredLoginFilterOptions "
27
28
:input-label =" t('user_ldap', 'Other Attributes:')"
28
- :multiple =" true" />
29
+ :multiple =" true"
30
+ @input =" updateLoginFilterAttributes" />
29
31
</div >
30
32
31
33
<div class =" ldap-wizard__login__line ldap-wizard__login__user-login-filter" >
60
62
</template >
61
63
62
64
<script lang="ts" setup>
63
- import { ref } from ' vue'
65
+ import { computed , ref } from ' vue'
64
66
import { storeToRefs } from ' pinia'
65
67
66
68
import { t } from ' @nextcloud/l10n'
67
69
import { NcButton , NcTextField , NcTextArea , NcCheckboxRadioSwitch , NcSelect } from ' @nextcloud/vue'
68
70
import { getCapabilities } from ' @nextcloud/capabilities'
71
+ import { showError , showSuccess } from ' @nextcloud/dialogs'
69
72
70
73
import { useLDAPConfigsStore } from ' ../../store/configs'
71
74
import { useWizardStore } from ' ../../store/wizard'
72
- import { showError , showSuccess } from ' @nextcloud/dialogs'
73
75
import { showEnableAutomaticFilterInfo } from ' ../../services/ldapConfigService'
74
76
75
77
const ldapConfigsStore = useLDAPConfigsStore ()
@@ -81,16 +83,48 @@ const instanceName = (getCapabilities() as { theming: { name:string } }).theming
81
83
const testUsername = ref (' ' )
82
84
const enableVerifyButton = ref (false )
83
85
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
+
84
92
/**
85
93
*
94
+ * @param value
86
95
*/
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
+ }
89
99
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
+ }
94
128
}
95
129
}
96
130
0 commit comments