mirror of
https://github.com/nextcloud/server.git
synced 2026-04-23 15:21:00 -04:00
fix(user_ldap): Improve typing
Signed-off-by: Louis Chmn <louis@chmn.me>
This commit is contained in:
parent
85721eef99
commit
3d847cd801
5 changed files with 28 additions and 19 deletions
|
|
@ -96,10 +96,10 @@ const ldapGroupFilterGroups = computed({
|
|||
*/
|
||||
async function init() {
|
||||
const response1 = await callWizard('determineGroupObjectClasses', props.configId)
|
||||
groupObjectClasses.value = response1.options!.ldap_groupfilter_objectclass
|
||||
groupObjectClasses.value = response1.options?.ldap_groupfilter_objectclass ?? []
|
||||
|
||||
const response2 = await callWizard('determineGroupsForGroups', props.configId)
|
||||
groupGroups.value = response2.options!.ldap_groupfilter_groups
|
||||
groupGroups.value = response2.options?.ldap_groupfilter_groups ?? []
|
||||
}
|
||||
|
||||
init()
|
||||
|
|
@ -110,7 +110,7 @@ init()
|
|||
async function getGroupFilter() {
|
||||
const response = await callWizard('getGroupFilter', props.configId)
|
||||
// Not using ldapConfig to avoid triggering the save logic.
|
||||
ldapConfigs.value[props.configId].ldapGroupFilter = response.changes!.ldap_group_filter as string
|
||||
ldapConfigs.value[props.configId]!.ldapGroupFilter = (response.changes?.ldap_group_filter as string | undefined) ?? ''
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ const filteredLoginFilterOptions = computed(() => loginFilterOptions.value.filte
|
|||
*/
|
||||
async function init() {
|
||||
const response = await callWizard('determineAttributes', props.configId)
|
||||
loginFilterOptions.value = response.options!.ldap_loginfilter_attributes
|
||||
loginFilterOptions.value = response.options?.ldap_loginfilter_attributes ?? []
|
||||
}
|
||||
|
||||
init()
|
||||
|
|
@ -102,7 +102,7 @@ async function getUserLoginFilter() {
|
|||
if (ldapConfigProxy.value.ldapLoginFilterMode === '0') {
|
||||
const response = await callWizard('getUserLoginFilter', props.configId)
|
||||
// Not using ldapConfig to avoid triggering the save logic.
|
||||
ldapConfigs.value[props.configId].ldapLoginFilter = response.changes!.ldap_login_filter as string
|
||||
ldapConfigs.value[props.configId]!.ldapLoginFilter = (response.changes?.ldap_login_filter as string | undefined) ?? ''
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -97,14 +97,14 @@ const ldapUserFilterGroups = computed({
|
|||
*/
|
||||
async function init() {
|
||||
const response1 = await callWizard('determineUserObjectClasses', props.configId)
|
||||
userObjectClasses.value = response1.options!.ldap_userfilter_objectclass
|
||||
userObjectClasses.value = response1.options?.ldap_userfilter_objectclass ?? []
|
||||
// Not using ldapConfig to avoid triggering the save logic.
|
||||
ldapConfigs.value[props.configId].ldapUserFilterObjectclass = response1.changes!.ldap_userfilter_objectclass?.join(';') ?? ''
|
||||
ldapConfigs.value[props.configId]!.ldapUserFilterObjectclass = (response1.changes?.ldap_userfilter_objectclass as string[] | undefined)?.join(';') ?? ''
|
||||
|
||||
const response2 = await callWizard('determineGroupsForUsers', props.configId)
|
||||
userGroups.value = response2.options!.ldap_userfilter_groups
|
||||
userGroups.value = response2.options?.ldap_userfilter_groups ?? []
|
||||
// Not using ldapConfig to avoid triggering the save logic.
|
||||
ldapConfigs.value[props.configId].ldapUserFilterGroups = response2.changes!.ldap_userfilter_groups?.join(';') ?? ''
|
||||
ldapConfigs.value[props.configId]!.ldapUserFilterGroups = (response2.changes?.ldap_userfilter_groups as string[] | undefined)?.join(';') ?? ''
|
||||
}
|
||||
|
||||
init()
|
||||
|
|
@ -116,11 +116,11 @@ async function reloadFilters() {
|
|||
if (ldapConfigProxy.value.ldapUserFilterMode === '0') {
|
||||
const response1 = await callWizard('getUserListFilter', props.configId)
|
||||
// Not using ldapConfig to avoid triggering the save logic.
|
||||
ldapConfigs.value[props.configId].ldapUserFilter = response1.changes!.ldap_userlist_filter as string
|
||||
ldapConfigs.value[props.configId]!.ldapUserFilter = (response1.changes?.ldap_userlist_filter as string | undefined) ?? ''
|
||||
|
||||
const response2 = await callWizard('getUserLoginFilter', props.configId)
|
||||
// Not using ldapConfig to avoid triggering the save logic.
|
||||
ldapConfigs.value[props.configId].ldapLoginFilter = response2.changes!.ldap_userlogin_filter as string
|
||||
ldapConfigs.value[props.configId]!.ldapLoginFilter = (response2.changes?.ldap_userlogin_filter as string | undefined) ?? ''
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ export async function getConfig(configId: string): Promise<LDAPConfig> {
|
|||
* @param configId
|
||||
* @param config
|
||||
*/
|
||||
export async function updateConfig(configId: string, config: LDAPConfig): Promise<LDAPConfig> {
|
||||
export async function updateConfig(configId: string, config: Partial<LDAPConfig>): Promise<LDAPConfig> {
|
||||
const response = await axios.put(
|
||||
generateOcsUrl('apps/user_ldap/api/v1/config/{configId}', { configId }),
|
||||
{ configData: config },
|
||||
|
|
@ -142,7 +142,7 @@ export async function clearMapping(subject: 'user' | 'group') {
|
|||
{ subject },
|
||||
) as AxiosResponse<OCSResponse>
|
||||
|
||||
logger.debug('Cleared mapping', { subject, params, response })
|
||||
logger.debug('Cleared mapping', { subject, response })
|
||||
showSuccess(t('user_ldap', 'Mapping cleared'))
|
||||
return true
|
||||
} catch (error) {
|
||||
|
|
|
|||
|
|
@ -7,13 +7,13 @@ import type { LDAPConfig } from '../models/index.ts'
|
|||
|
||||
import { loadState } from '@nextcloud/initial-state'
|
||||
import { defineStore } from 'pinia'
|
||||
import Vue, { computed, ref } from 'vue'
|
||||
import { computed, ref } from 'vue'
|
||||
import { copyConfig, createConfig, deleteConfig, getConfig, updateConfig } from '../services/ldapConfigService.ts'
|
||||
|
||||
export const useLDAPConfigsStore = defineStore('ldap-configs', () => {
|
||||
const ldapConfigs = ref(loadState('user_ldap', 'ldapConfigs') as Record<string, LDAPConfig>)
|
||||
const selectedConfigId = ref<string>(Object.keys(ldapConfigs.value)[0])
|
||||
const selectedConfig = computed(() => ldapConfigs.value[selectedConfigId.value])
|
||||
const selectedConfigId = ref<string | undefined>(Object.keys(ldapConfigs.value)[0])
|
||||
const selectedConfig = computed(() => selectedConfigId.value === undefined ? undefined : ldapConfigs.value[selectedConfigId.value])
|
||||
const updatingConfig = ref(0)
|
||||
|
||||
/**
|
||||
|
|
@ -22,6 +22,10 @@ export const useLDAPConfigsStore = defineStore('ldap-configs', () => {
|
|||
* @param postSetHooks
|
||||
*/
|
||||
function getConfigProxy<J>(configId: string, postSetHooks: Partial<Record<keyof LDAPConfig, (value: J) => void>> = {}) {
|
||||
if (ldapConfigs.value[configId] === undefined) {
|
||||
throw new Error(`Config with id ${configId} does not exist`)
|
||||
}
|
||||
|
||||
return new Proxy(ldapConfigs.value[configId], {
|
||||
get(target, property) {
|
||||
return target[property]
|
||||
|
|
@ -49,7 +53,7 @@ export const useLDAPConfigsStore = defineStore('ldap-configs', () => {
|
|||
*/
|
||||
async function create() {
|
||||
const configId = await createConfig()
|
||||
Vue.set(ldapConfigs.value, configId, await getConfig(configId))
|
||||
ldapConfigs.value[configId] = await getConfig(configId)
|
||||
selectedConfigId.value = configId
|
||||
return configId
|
||||
}
|
||||
|
|
@ -59,8 +63,13 @@ export const useLDAPConfigsStore = defineStore('ldap-configs', () => {
|
|||
* @param fromConfigId
|
||||
*/
|
||||
async function _copyConfig(fromConfigId: string) {
|
||||
if (ldapConfigs.value[fromConfigId] === undefined) {
|
||||
throw new Error(`Config with id ${fromConfigId} does not exist`)
|
||||
}
|
||||
|
||||
const configId = await copyConfig(fromConfigId)
|
||||
Vue.set(ldapConfigs.value, configId, { ...ldapConfigs.value[fromConfigId] })
|
||||
|
||||
ldapConfigs.value[configId] = { ...ldapConfigs.value[fromConfigId] }
|
||||
selectedConfigId.value = configId
|
||||
return configId
|
||||
}
|
||||
|
|
@ -72,7 +81,7 @@ export const useLDAPConfigsStore = defineStore('ldap-configs', () => {
|
|||
async function removeConfig(configId: string) {
|
||||
const result = await deleteConfig(configId)
|
||||
if (result === true) {
|
||||
Vue.delete(ldapConfigs.value, configId)
|
||||
delete ldapConfigs.value[configId]
|
||||
}
|
||||
|
||||
selectedConfigId.value = Object.keys(ldapConfigs.value)[0] ?? await create()
|
||||
|
|
|
|||
Loading…
Reference in a new issue