Skip to content

Commit 228a537

Browse files
committed
Fix sidebar opening for different dav root and non-dav files
Signed-off-by: John Molakvoæ <[email protected]>
1 parent 8da3b48 commit 228a537

File tree

7 files changed

+41
-15
lines changed

7 files changed

+41
-15
lines changed

cypress/e2e/non-dav-files.cy.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,11 @@ describe('Open non-dav files in viewer', function() {
7373
cy.get('body > .viewer button.prev').should('not.be.visible')
7474
cy.get('body > .viewer button.next').should('not.be.visible')
7575
})
76+
77+
it('Does not see the sidebar button', function() {
78+
// open the menu
79+
cy.get('body > .viewer .modal-header button.action-item__menutoggle').click()
80+
cy.get('.action-button__icon.icon-menu-sidebar').should('not.be.visible')
81+
})
82+
7683
})

src/components/Images.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export default {
110110
return this.src
111111
}
112112
113-
// If there is no preview and we have a drirect source
113+
// If there is no preview and we have a direct source
114114
// load it instead
115115
if (this.source && !this.hasPreview) {
116116
return this.source

src/mixins/Mime.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ export default {
5050
// file path relative to user folder
5151
hasPreview: {
5252
type: Boolean,
53-
required: true,
53+
default: false,
5454
},
5555
// unique file id
5656
fileid: {
5757
type: [Number, String],
58-
required: true,
58+
required: false,
5959
},
6060
// list of all the visible files
6161
fileList: {

src/mixins/PreviewUrl.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*
2222
*/
2323
import { generateUrl } from '@nextcloud/router'
24-
import { getToken, isPublic } from '../utils/davUtils.js'
24+
import { getToken, getUserRoot, isPublic } from '../utils/davUtils.js'
2525
import { encodeFilePath, getDavPath } from '../utils/fileUtils.js'
2626

2727
export default {

src/utils/davUtils.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,23 @@
2323
import { generateRemoteUrl } from '@nextcloud/router'
2424
import { getCurrentUser } from '@nextcloud/auth'
2525

26-
const getRootPath = function() {
26+
export const getRootPath = function() {
2727
if (getCurrentUser()) {
28-
return generateRemoteUrl(`dav/files/${getCurrentUser().uid}`)
28+
return generateRemoteUrl(`dav${getUserRoot()}`)
2929
} else {
3030
return generateRemoteUrl('webdav').replace('/remote.php', '/public.php')
3131
}
3232
}
3333

34-
const isPublic = function() {
34+
export const getUserRoot = function() {
35+
return '/files/' + getCurrentUser().uid
36+
}
37+
38+
export const isPublic = function() {
3539
return !getCurrentUser()
3640
}
3741

38-
const getToken = function() {
42+
export const getToken = function() {
3943
return document.getElementById('sharingToken') && document.getElementById('sharingToken').value
4044
}
4145

42-
export { getRootPath, getToken, isPublic }

src/utils/fileUtils.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
*/
2222
import { dirname } from '@nextcloud/paths'
2323
import { generateUrl } from '@nextcloud/router'
24-
2524
import camelcase from 'camelcase'
26-
import { getRootPath, getToken, isPublic } from './davUtils.js'
25+
26+
import { getRootPath, getToken, getUserRoot, isPublic } from './davUtils.js'
2727
import { isNumber } from './numberUtil.js'
2828

2929
/**
@@ -129,9 +129,22 @@ const genFileInfo = function(obj) {
129129
* @param {object} fileInfo The fileInfo
130130
* @param {string} fileInfo.filename the file full path
131131
* @param {string} fileInfo.basename the file name
132+
* @param {string} fileInfo.source the file source if any
132133
* @return {string}
133134
*/
134-
const getDavPath = function({ filename, basename }) {
135+
const getDavPath = function({ filename, basename, source = '' }) {
136+
const prefixUser = getUserRoot()
137+
138+
// If we have a source but we're not a dav resource, return null
139+
if (source && !source.includes(prefixUser)) {
140+
return null
141+
}
142+
143+
// Workaround for files with different root like /remote.php/dav
144+
if (filename.startsWith(prefixUser)) {
145+
filename = filename.slice(prefixUser.length)
146+
}
147+
135148
// TODO: allow proper dav access without the need of basic auth
136149
// https://github.com/nextcloud/server/issues/19700
137150
if (isPublic()) {

src/views/Viewer.vue

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
{{ t('viewer', 'Edit') }}
7979
</NcActionButton>
8080
<!-- Menu items -->
81-
<NcActionButton v-if="Sidebar && !isSidebarShown"
81+
<NcActionButton v-if="Sidebar && sidebarOpenFilePath && !isSidebarShown"
8282
:close-after-click="true"
8383
icon="icon-menu-sidebar"
8484
@click="showSidebar">
@@ -167,7 +167,7 @@ import isFullscreen from '@nextcloud/vue/dist/Mixins/isFullscreen.js'
167167
import isMobile from '@nextcloud/vue/dist/Mixins/isMobile'
168168
169169
import { extractFilePaths, sortCompare } from '../utils/fileUtils.js'
170-
import { getRootPath } from '../utils/davUtils.js'
170+
import { getRootPath, getUserRoot } from '../utils/davUtils.js'
171171
import canDownload from '../utils/canDownload.js'
172172
import cancelableRequest from '../utils/CancelableRequest.js'
173173
import Error from '../components/Error.vue'
@@ -290,6 +290,9 @@ export default {
290290
sidebarFile() {
291291
return this.Sidebar && this.Sidebar.file
292292
},
293+
sidebarOpenFilePath() {
294+
return this.currentFile?.davPath?.split(getUserRoot())[1]
295+
},
293296
294297
/**
295298
* Is the current user allowed to delete the file?
@@ -906,7 +909,7 @@ export default {
906909
// TODO: also hide figure, needs a proper method for it in server Sidebar
907910
908911
if (OCA?.Files?.Sidebar) {
909-
await OCA.Files.Sidebar.open(this.currentFile.filename)
912+
await OCA.Files.Sidebar.open(this.sidebarOpenFilePath)
910913
}
911914
},
912915

0 commit comments

Comments
 (0)