Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/user_ldap/lib/Controller/ConfigAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public function testConfiguration(string $configID) {
$this->ensureConfigIDExists($configID);
$connection = $this->connectionFactory->get($configID);
$conf = $connection->getConfiguration();
if ($conf['ldap_configuration_active'] === '0') {
if ($conf['ldap_configuration_active'] !== '1') {
//needs to be true, otherwise it will also fail with an irritating message
$conf['ldap_configuration_active'] = '1';
}
Expand Down
20 changes: 16 additions & 4 deletions apps/user_ldap/src/components/SettingsTabs/ServerTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
type="number"
autocomplete="off"
@change="(event) => ldapConfigProxy.ldapPort = event.target.value" />
<NcButton :disabled="loadingGuessPortAndTLS" @click="guessPortAndTLS">
<NcButton :disabled="loadingGuessPortAndTLS || ldapConfigProxy.ldapHost === ''" @click="guessPortAndTLS">
{{ t('user_ldap', 'Detect Port') }}
</NcButton>
</div>
Expand Down Expand Up @@ -83,7 +83,7 @@
:helper-text="t('user_ldap', 'You can specify Base DN for users and groups in the Advanced tab')"
@change="(event) => ldapConfigProxy.ldapBase = event.target.value" />

<NcButton :disabled="loadingGuessBaseDN" @click="guessBaseDN">
<NcButton :disabled="loadingGuessBaseDN || needsToSaveCredentials" @click="guessBaseDN">
{{ t('user_ldap', 'Detect Base DN') }}
</NcButton>
<NcButton :disabled="loadingCountInBaseDN || ldapConfigProxy.ldapBase === ''" @click="countInBaseDN">
Expand All @@ -98,7 +98,7 @@ import { showInfo } from '@nextcloud/dialogs'
import { n, t } from '@nextcloud/l10n'
import { NcButton, NcCheckboxRadioSwitch, NcTextArea, NcTextField } from '@nextcloud/vue'
import { storeToRefs } from 'pinia'
import { computed, ref } from 'vue'
import { computed, ref, watch } from 'vue'
import ContentCopy from 'vue-material-design-icons/ContentCopy.vue'
import Delete from 'vue-material-design-icons/Delete.vue'
import { callWizard } from '../../services/ldapConfigService.ts'
Expand All @@ -120,6 +120,18 @@ const needsToSaveCredentials = computed(() => {
return ldapConfigProxy.value.ldapAgentName !== localLdapAgentName.value || ldapConfigProxy.value.ldapAgentPassword !== localLdapAgentPassword.value
})

watch(
ldapConfigProxy,
(newVal) => {
localLdapAgentName.value = newVal.ldapAgentName
if (newVal.ldapAgentPassword === '***') {
localLdapAgentPassword.value = ''
} else {
localLdapAgentPassword.value = newVal.ldapAgentPassword
}
},
)

/**
*
*/
Expand All @@ -136,7 +148,7 @@ async function guessPortAndTLS() {
loadingGuessPortAndTLS.value = true
const { changes } = await callWizard('guessPortAndTLS', props.configId)
// Not using ldapConfigProxy to avoid triggering the save logic.
ldapConfigs.value[props.configId].ldapPort = (changes!.ldap_port as string) ?? ''
ldapConfigs.value[props.configId]!.ldapPort = (changes!.ldap_port as string) ?? ''
} finally {
loadingGuessPortAndTLS.value = false
}
Expand Down
9 changes: 7 additions & 2 deletions apps/user_ldap/src/services/ldapConfigService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,16 @@ export async function callWizard(action: WizardAction, configId: string, extraPa

return response.data.ocs.data
} catch (error) {
let message = t('user_ldap', 'An error occurred')

if (isAxiosError(error) && error.response?.data.ocs.meta.status === 'failure') {
const message = error.response.data.ocs.meta.message ?? t('user_ldap', 'An error occurred')
showError(message)
if (error.response.data.ocs.meta.message !== '' && error.response.data.ocs.meta.message !== undefined) {
message = error.response.data.ocs.meta.message
}
}

showError(message)

throw error
}
}
Expand Down
16 changes: 13 additions & 3 deletions apps/user_ldap/src/store/configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,21 @@ export const useLDAPConfigsStore = defineStore('ldap-configs', () => {
*/
async function removeConfig(configId: string) {
const result = await deleteConfig(configId)

if (result === true) {
delete ldapConfigs.value[configId]
if (Object.keys(ldapConfigs.value).length === 1) {
// Ensure at least one config exists before deleting the last one
selectedConfigId.value = await create()
// The new config id could be the same as the deleted one, so only delete if different
if (selectedConfigId.value !== configId) {
delete ldapConfigs.value[configId]
}
} else {
// Select the first config that is not the deleted one
selectedConfigId.value = Object.keys(ldapConfigs.value).filter((_configId) => configId !== _configId)[0]
delete ldapConfigs.value[configId]
}
}

selectedConfigId.value = Object.keys(ldapConfigs.value)[0] ?? await create()
}

return {
Expand Down
7 changes: 4 additions & 3 deletions apps/user_ldap/src/views/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
:options="Object.keys(ldapConfigs)"
:input-label="t('user_ldap', 'Select LDAP Config')">
<template #option="{ label: configId }">
{{ `${configId}: ${ldapConfigs[configId].ldapHost}` }}
{{ `${configId}: ${ldapConfigs[configId]?.ldapHost ?? ''}` }}
</template>
<template #selected-option="{ label: configId }">
{{ `${configId}: ${ldapConfigs[configId].ldapHost}` }}
{{ `${configId}: ${ldapConfigs[configId]?.ldapHost ?? ''}` }}
</template>
</NcSelect>
<NcButton
Expand Down Expand Up @@ -123,7 +123,8 @@ const selectedTab = ref('server')
const clearMappingLoading = ref(false)

const selectedConfigHasServerInfo = computed(() => {
return selectedConfig.value.ldapHost !== ''
return selectedConfig.value !== undefined
&& selectedConfig.value.ldapHost !== ''
&& selectedConfig.value.ldapPort !== ''
&& selectedConfig.value.ldapBase !== ''
&& selectedConfig.value.ldapAgentName !== ''
Expand Down
Loading