Skip to content

Commit

Permalink
WIP9
Browse files Browse the repository at this point in the history
Signed-off-by: Louis Chemineau <[email protected]>
  • Loading branch information
artonge committed Sep 23, 2024
1 parent 3a9269a commit 33cec4b
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 14 deletions.
56 changes: 45 additions & 11 deletions apps/user_ldap/src/components/SettingsTabs/LoginTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@
{{ 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">
Expand Down Expand Up @@ -60,16 +62,16 @@
</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()
Expand All @@ -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
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion apps/user_ldap/src/services/ldapConfigService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions apps/user_ldap/src/views/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit 33cec4b

Please sign in to comment.