Skip to content

Commit

Permalink
fix(Users/Quota setting): Prevent floating point value from getting t…
Browse files Browse the repository at this point in the history
…runcated in locales other than english

fixes #18468

Signed-off-by: Marcel Klehr <[email protected]>
  • Loading branch information
marcelklehr authored and AndyScherzinger committed Dec 14, 2023
1 parent 073b868 commit 6b2f477
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
20 changes: 11 additions & 9 deletions apps/settings/src/components/Users/UserRow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ import UserRowActions from './UserRowActions.vue'

import UserRowMixin from '../../mixins/UserRowMixin.js'
import { isObfuscated, unlimitedQuota } from '../../utils/userUtils.ts'
import {formatFileSize, parseFileSize} from "@nextcloud/files";

export default {
name: 'UserRow',
Expand Down Expand Up @@ -435,9 +436,9 @@ export default {

usedSpace() {
if (this.user.quota?.used) {
return t('settings', '{size} used', { size: OC.Util.humanFileSize(this.user.quota?.used) })
return t('settings', '{size} used', { size: formatFileSize(this.user.quota?.used) })
}
return t('settings', '{size} used', { size: OC.Util.humanFileSize(0) })
return t('settings', '{size} used', { size: formatFileSize(0) })
},

canEdit() {
Expand All @@ -451,17 +452,17 @@ export default {
quota = this.settings.defaultQuota
if (quota !== 'none') {
// convert to numeric value to match what the server would usually return
quota = OC.Util.computerFileSize(quota)
quota = parseFileSize(quota, true)
}
}

// when the default quota is unlimited, the server returns -3 here, map it to "none"
if (quota === 'none' || quota === -3) {
return t('settings', 'Unlimited')
} else if (quota >= 0) {
return OC.Util.humanFileSize(quota)
return formatFileSize(quota)
}
return OC.Util.humanFileSize(0)
return formatFileSize(0)
},

userActions() {
Expand Down Expand Up @@ -498,7 +499,7 @@ export default {
if (this.selectedQuota !== false) {
return this.selectedQuota
}
if (this.settings.defaultQuota !== unlimitedQuota.id && OC.Util.computerFileSize(this.settings.defaultQuota) >= 0) {
if (this.settings.defaultQuota !== unlimitedQuota.id && parseFileSize(this.settings.defaultQuota, true) >= 0) {
// if value is valid, let's map the quotaOptions or return custom quota
return { id: this.settings.defaultQuota, label: this.settings.defaultQuota }
}
Expand Down Expand Up @@ -834,7 +835,8 @@ export default {
await this.$store.dispatch('setUserData', {
userid: this.user.id,
key: 'quota',
value: quota,
// translate from locale string format to raw float format so backend can read it
value: '' + parseFileSize(quota, true)
})
} catch (error) {
console.error(error)
Expand All @@ -855,12 +857,12 @@ export default {
quota = quota?.id || quota.label
}
// only used for new presets sent through @Tag
const validQuota = OC.Util.computerFileSize(quota)
const validQuota = parseFileSize(quota, true)
if (validQuota === null) {
return unlimitedQuota
} else {
// unify format output
quota = OC.Util.humanFileSize(OC.Util.computerFileSize(quota))
quota = formatFileSize(parseFileSize(quota, true))
return { id: quota, label: quota }
}
},
Expand Down
3 changes: 2 additions & 1 deletion apps/settings/src/store/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import axios from '@nextcloud/axios'
import { generateOcsUrl } from '@nextcloud/router'
import { getCapabilities } from '@nextcloud/capabilities'
import logger from '../logger.js'
import { parseFileSize } from "@nextcloud/files"

const orderGroups = function(groups, orderBy) {
/* const SORT_USERCOUNT = 1;
Expand Down Expand Up @@ -227,7 +228,7 @@ const mutations = {
},
setUserData(state, { userid, key, value }) {
if (key === 'quota') {
const humanValue = OC.Util.computerFileSize(value)
const humanValue = parseFileSize(value, true)
state.users.find(user => user.id === userid)[key][key] = humanValue !== null ? humanValue : value
} else {
state.users.find(user => user.id === userid)[key] = value
Expand Down

0 comments on commit 6b2f477

Please sign in to comment.