Skip to content

Commit 8fb5991

Browse files
Merge pull request #54719 from nextcloud/backport/51727/stable30
[stable30] fix(files_versions): retrieve all display names with one request
2 parents 8d6f6e6 + 06e6b04 commit 8fb5991

File tree

4 files changed

+31
-28
lines changed

4 files changed

+31
-28
lines changed

apps/files_versions/src/components/Version.vue

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,9 @@ import { Permission, formatFileSize } from '@nextcloud/files'
125125
import { loadState } from '@nextcloud/initial-state'
126126
import { t } from '@nextcloud/l10n'
127127
import { joinPaths } from '@nextcloud/paths'
128-
import { getRootUrl, generateUrl } from '@nextcloud/router'
128+
import { getRootUrl } from '@nextcloud/router'
129129
import { defineComponent } from 'vue'
130130
131-
import axios from '@nextcloud/axios'
132-
import logger from '../utils/logger'
133-
134131
import BackupRestore from 'vue-material-design-icons/BackupRestore.vue'
135132
import Delete from 'vue-material-design-icons/Delete.vue'
136133
import Download from 'vue-material-design-icons/Download.vue'
@@ -206,7 +203,6 @@ export default defineComponent({
206203
previewLoaded: false,
207204
previewErrored: false,
208205
capabilities: loadState('core', 'capabilities', { files: { version_labeling: false, version_deletion: false } }),
209-
versionAuthor: '' as string|null,
210206
}
211207
},
212208
@@ -233,6 +229,16 @@ export default defineComponent({
233229
return label
234230
},
235231
232+
versionAuthor() {
233+
if (!this.version.author || !this.version.authorName) {
234+
return ''
235+
}
236+
if (this.version.author === getCurrentUser()?.uid) {
237+
return t('files_versions', 'You')
238+
}
239+
return this.version.authorName ?? this.version.author
240+
},
241+
236242
downloadURL(): string {
237243
if (this.isCurrent) {
238244
return getRootUrl() + joinPaths('/remote.php/webdav', this.fileInfo.path, this.fileInfo.name)
@@ -297,24 +303,6 @@ export default defineComponent({
297303
this.$emit('delete', this.version)
298304
},
299305
300-
async fetchDisplayName() {
301-
this.versionAuthor = null
302-
if (!this.version.author) {
303-
return
304-
}
305-
306-
if (this.version.author === getCurrentUser()?.uid) {
307-
this.versionAuthor = t('files_versions', 'You')
308-
} else {
309-
try {
310-
const { data } = await axios.post(generateUrl('/displaynames'), { users: [this.version.author] })
311-
this.versionAuthor = data.users[this.version.author]
312-
} catch (error) {
313-
logger.warn('Could not load user display name', { error })
314-
}
315-
}
316-
},
317-
318306
click() {
319307
if (!this.canView) {
320308
window.location.href = this.downloadURL

apps/files_versions/src/utils/versions.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { generateRemoteUrl, generateUrl } from '@nextcloud/router'
1111
import { getCurrentUser } from '@nextcloud/auth'
1212
import { joinPaths, encodePath } from '@nextcloud/paths'
1313
import moment from '@nextcloud/moment'
14+
import axios from '@nextcloud/axios'
1415

1516
import client from '../utils/davClient.js'
1617
import davRequest from '../utils/davRequest.js'
@@ -20,6 +21,7 @@ export interface Version {
2021
fileId: string, // The id of the file associated to the version.
2122
label: string, // 'Current version' or ''
2223
author: string|null, // UID for the author of the version
24+
authorName: string|null, // Display name of the author
2325
filename: string, // File name relative to the version DAV endpoint
2426
basename: string, // A base name generated from the mtime
2527
mime: string, // Empty for the current version, else the actual mime type of the version
@@ -30,7 +32,7 @@ export interface Version {
3032
permissions: string, // Only readable: 'R'
3133
previewUrl: string, // Preview URL of the version
3234
url: string, // Download URL of the version
33-
source: string, // The WebDAV endpoint of the ressource
35+
source: string, // The WebDAV endpoint of the resource
3436
fileVersion: string|null, // The version id, null for the current version
3537
}
3638

@@ -43,10 +45,22 @@ export async function fetchVersions(fileInfo: any): Promise<Version[]> {
4345
details: true,
4446
}) as ResponseDataDetailed<FileStat[]>
4547

46-
return response.data
48+
const versions = response.data
4749
// Filter out root
4850
.filter(({ mime }) => mime !== '')
4951
.map(version => formatVersion(version, fileInfo))
52+
53+
const authorIds = new Set(versions.map(version => version.author))
54+
const authors = await axios.post(generateUrl('/displaynames'), { users: [...authorIds] })
55+
56+
for (const version of versions) {
57+
const author = authors.data.users[version.author]
58+
if (author) {
59+
version.authorName = author
60+
}
61+
}
62+
63+
return versions
5064
} catch (exception) {
5165
logger.error('Could not fetch version', { exception })
5266
throw exception
@@ -93,6 +107,7 @@ function formatVersion(version: any, fileInfo: any): Version {
93107
// If version-label is defined make sure it is a string (prevent issue if the label is a number an PHP returns a number then)
94108
label: version.props['version-label'] && String(version.props['version-label']),
95109
author: version.props['version-author'] ?? null,
110+
authorName: null,
96111
filename: version.filename,
97112
basename: moment(mtime).format('LLL'),
98113
mime: version.mime,

dist/files_versions-files_versions.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/files_versions-files_versions.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)