Skip to content

Commit 5ebcc6d

Browse files
committed
fix(Users/Quota setting): Prevent floating point value from getting truncated in locales other than english
fixes #18468 Signed-off-by: Marcel Klehr <mklehr@gmx.net>
1 parent 89aa395 commit 5ebcc6d

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

apps/settings/src/components/Users/UserRow.vue

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ import UserRowActions from './UserRowActions.vue'
307307
308308
import UserRowMixin from '../../mixins/UserRowMixin.js'
309309
import { isObfuscated, unlimitedQuota } from '../../utils/userUtils.ts'
310+
import {formatFileSize, parseFileSize} from "@nextcloud/files";
310311
311312
export default {
312313
name: 'UserRow',
@@ -435,9 +436,9 @@ export default {
435436
436437
usedSpace() {
437438
if (this.user.quota?.used) {
438-
return t('settings', '{size} used', { size: OC.Util.humanFileSize(this.user.quota?.used) })
439+
return t('settings', '{size} used', { size: formatFileSize(this.user.quota?.used) })
439440
}
440-
return t('settings', '{size} used', { size: OC.Util.humanFileSize(0) })
441+
return t('settings', '{size} used', { size: formatFileSize(0) })
441442
},
442443
443444
canEdit() {
@@ -451,17 +452,17 @@ export default {
451452
quota = this.settings.defaultQuota
452453
if (quota !== 'none') {
453454
// convert to numeric value to match what the server would usually return
454-
quota = OC.Util.computerFileSize(quota)
455+
quota = parseFileSize(quota, true)
455456
}
456457
}
457458
458459
// when the default quota is unlimited, the server returns -3 here, map it to "none"
459460
if (quota === 'none' || quota === -3) {
460461
return t('settings', 'Unlimited')
461462
} else if (quota >= 0) {
462-
return OC.Util.humanFileSize(quota)
463+
return formatFileSize(quota)
463464
}
464-
return OC.Util.humanFileSize(0)
465+
return formatFileSize(0)
465466
},
466467
467468
userActions() {
@@ -498,7 +499,7 @@ export default {
498499
if (this.selectedQuota !== false) {
499500
return this.selectedQuota
500501
}
501-
if (this.settings.defaultQuota !== unlimitedQuota.id && OC.Util.computerFileSize(this.settings.defaultQuota) >= 0) {
502+
if (this.settings.defaultQuota !== unlimitedQuota.id && parseFileSize(this.settings.defaultQuota, true) >= 0) {
502503
// if value is valid, let's map the quotaOptions or return custom quota
503504
return { id: this.settings.defaultQuota, label: this.settings.defaultQuota }
504505
}
@@ -834,7 +835,8 @@ export default {
834835
await this.$store.dispatch('setUserData', {
835836
userid: this.user.id,
836837
key: 'quota',
837-
value: quota,
838+
// translate from locale string format to raw float format so backend can read it
839+
value: '' + parseFileSize(quota, true)
838840
})
839841
} catch (error) {
840842
console.error(error)
@@ -855,12 +857,12 @@ export default {
855857
quota = quota?.id || quota.label
856858
}
857859
// only used for new presets sent through @Tag
858-
const validQuota = OC.Util.computerFileSize(quota)
860+
const validQuota = parseFileSize(quota, true)
859861
if (validQuota === null) {
860862
return unlimitedQuota
861863
} else {
862864
// unify format output
863-
quota = OC.Util.humanFileSize(OC.Util.computerFileSize(quota))
865+
quota = formatFileSize(parseFileSize(quota, true))
864866
return { id: quota, label: quota }
865867
}
866868
},

apps/settings/src/store/users.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import axios from '@nextcloud/axios'
3232
import { generateOcsUrl } from '@nextcloud/router'
3333
import { getCapabilities } from '@nextcloud/capabilities'
3434
import logger from '../logger.js'
35+
import { parseFileSize } from "@nextcloud/files"
3536

3637
const orderGroups = function(groups, orderBy) {
3738
/* const SORT_USERCOUNT = 1;
@@ -227,7 +228,7 @@ const mutations = {
227228
},
228229
setUserData(state, { userid, key, value }) {
229230
if (key === 'quota') {
230-
const humanValue = OC.Util.computerFileSize(value)
231+
const humanValue = parseFileSize(value, true)
231232
state.users.find(user => user.id === userid)[key][key] = humanValue !== null ? humanValue : value
232233
} else {
233234
state.users.find(user => user.id === userid)[key] = value

0 commit comments

Comments
 (0)