Skip to content

Commit

Permalink
fix: prevent mutating sessions array
Browse files Browse the repository at this point in the history
  • Loading branch information
albanm committed Dec 17, 2024
1 parent 85056c9 commit 5be29c7
Showing 1 changed file with 1 addition and 24 deletions.
25 changes: 1 addition & 24 deletions ui/src/pages/me.vue
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@

<v-list>
<v-list-item
v-for="session of userDetailsFetch.data.value?.sessions?.reverse() ?? []"
v-for="session of userDetailsFetch.data.value?.sessions?.slice().reverse() ?? []"
:key="session.id"
>
<v-list-item-title>{{ session.deviceName }}</v-list-item-title>
Expand Down Expand Up @@ -288,17 +288,13 @@
import { FetchError } from 'ofetch'
import type { VForm } from 'vuetify/components'
console.log('setup 1')
const { user, keepalive } = useSession()
const { dayjs, duration } = useLocaleDayjs()
const { t } = useI18n()
const { userDetailsFetch, authProvidersFetch } = useStore()
if (!user.value) throw new Error('auth required')
console.log('setup 2')
userDetailsFetch.refresh()
authProvidersFetch.refresh()
const userOrgsFetch = useFetch<{ count: number }>($apiPath + '/organizations', { query: { creator: user.value?.id, size: 0 } })
Expand All @@ -312,51 +308,40 @@ const newPatch = () => ({
defaultDep: userDetailsFetch.data.value?.defaultDep || ''
})
const patch = ref(newPatch())
console.log('setup 3')
watch(userDetailsFetch.data, () => {
console.log('computed userDetailsFetch')
patch.value = newPatch()
})
const birthdayMenu = ref(false)
const maxBirthday = dayjs().subtract(13, 'years').toISOString()
const activeBirthDayPicker = ref()
const setBirthDay = (birthday: Date) => {
console.log('setBirthDay')
patch.value.birthday = birthday.toISOString().slice(0, 10)
birthdayMenu.value = false
save()
}
console.log('setup 4')
const readonly = computed(() => $uiConfig.readonly || !!user.value?.os || !!user.value?.idp)
const nbCreatedOrgs = computed(() => userOrgsFetch.data.value?.count)
const maxCreatedOrgs = computed(() => {
console.log('computed maxCreatedOrgs')
if (!userDetailsFetch.data.value) return 0
return userDetailsFetch.data.value.maxCreatedOrgs !== undefined && userDetailsFetch.data.value.maxCreatedOrgs !== null ? userDetailsFetch.data.value.maxCreatedOrgs : $uiConfig.quotas.defaultMaxCreatedOrgs
})
const showMaxCreatedOrgs = computed(() => {
console.log('computed showMaxCreatedOrgs')
if (!userDetailsFetch.data.value) return false
if ($uiConfig.quotas.defaultMaxCreatedOrgs === -1) return false
if ($uiConfig.quotas.defaultMaxCreatedOrgs === 0 && !userDetailsFetch.data.value.maxCreatedOrgs) return false
return maxCreatedOrgs.value === -1 ? 'illimité' : ('' + maxCreatedOrgs.value)
})
console.log('setup 5')
const defaultOrgItems = computed<{ value: string, title: string }[]>(() => {
console.log('computed defaultOrgItems')
return (patch.value.ignorePersonalAccount ? [] : [{ value: '', title: t('common.userAccount') }])
.concat((userDetailsFetch.data.value?.organizations ?? []).map(o => ({
value: o.id + (o.department ? (':' + o.department) : ''),
title: o.name + (o.department ? (':' + (o.departmentName ?? o.department)) : '')
})))
})
const showIgnorePersonalAccount = computed(() => {
console.log('computed showIgnorePersonalAccount')
// invitation mode only (means user should always be in an orga)
// ignorePersonalAccount should already be true in this case
if ($uiConfig.onlyCreateInvited && userDetailsFetch.data.value?.ignorePersonalAccount) return false
Expand All @@ -366,15 +351,11 @@ const showIgnorePersonalAccount = computed(() => {
return true
})
console.log('setup 6')
const defaultOrg = computed<string>({
get () {
console.log('computed defaultOrg')
return patch.value.defaultOrg + (patch.value.defaultDep ? (':' + patch.value.defaultDep) : '')
},
set (value) {
console.log('setDefaultOrg')
if (value) {
const [org, dep] = value.split(':')
patch.value.defaultOrg = org
Expand All @@ -386,18 +367,14 @@ const defaultOrg = computed<string>({
})
const userIdentities = computed(() => {
console.log('computed userIdentities')
if (!authProvidersFetch.data.value || !userDetailsFetch.data.value) return []
return authProvidersFetch.data.value.map(p => ({
...p,
user: (userDetailsFetch.data.value as any)?.[p.type]?.[p.id]
})).filter(p => !!p.user).map(p => ({ ...p, name: p.user.login || p.user.name }))
})
console.log('setup 7')
watch(birthdayMenu, (val) => {
console.log('watch birthdayMenu')
if (val) setTimeout(() => { activeBirthDayPicker.value = 'YEAR' })
})
Expand Down

0 comments on commit 5be29c7

Please sign in to comment.