Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a private link for the current folder to the app bar #2009

Merged
merged 3 commits into from
Sep 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions apps/files/src/components/FilesAppBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@
<file-drop :rootPath='item' :url='url' :headers="headers" @success="onFileSuccess" @error="onFileError" @progress="onFileProgress" />
<oc-grid flex gutter="small">
<div class="uk-width-expand">
<oc-breadcrumb id="files-breadcrumb" :items="breadcrumbs" v-if="showBreadcrumb" home></oc-breadcrumb>
<div class="uk-flex">
<oc-breadcrumb id="files-breadcrumb" :items="breadcrumbs" v-if="showBreadcrumb" home></oc-breadcrumb>
<span class="uk-margin-small-left" v-if="showBreadcrumb && currentFolder.privateLink">
<oc-icon name="ready" v-show="linkCopied" />
<oc-icon id="files-permalink-copy" name="link" v-clipboard="() => currentFolder.privateLink"
v-show="!linkCopied"
v-clipboard:success="clipboardSuccessHandler"
/>
</span>
</div>
<span class="uk-flex uk-flex-middle" v-if="!showBreadcrumb">
<oc-icon v-if="pageIcon" :name="pageIcon" class="uk-margin-small-right" />
<span class="uk-text-lead">{{pageTitle}}</span>
Expand Down Expand Up @@ -91,7 +100,8 @@ export default {
path: '',
searchedFiles: [],
fileFolderCreationLoading: false,
actionsKey: Math.floor(Math.random() * 20)
actionsKey: Math.floor(Math.random() * 20),
linkCopied: false
}),
computed: {
...mapGetters(['getToken', 'configuration']),
Expand Down Expand Up @@ -459,6 +469,15 @@ export default {
}
this.resetFileSelection()
this.setHighlightedFile(null)
},
clipboardSuccessHandler () {
this.linkCopied = true

// Use copy icon after some time
const self = this
setTimeout(() => {
self.linkCopied = false
}, 1000)
}
},
filters: {
Expand Down
22 changes: 22 additions & 0 deletions tests/acceptance/customCommands/getClipBoardContent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
exports.command = function (callback) {
const helperElementId = 'helperClipboardInput'
this.execute(function (elementId) {
const myInput = document.createElement('INPUT')
const inputId = document.createAttribute('id')
inputId.value = elementId
myInput.setAttributeNode(inputId)
myInput.setAttribute('style', 'position: absolute; left:0; top:0;') // make sure its visible
document.body.appendChild(myInput)
}, [helperElementId])
.setValue(`#${helperElementId}`, '') // just to focus the element
.keys([this.Keys.CONTROL, 'v']) // copy the content of the clipboard into that field
.getValue(`#${helperElementId}`, function (clipboard) {
callback(clipboard.value)
})
.execute(function (elementId) {
const el = document.getElementById(elementId)
el.parentNode.removeChild(el)
}, [helperElementId])

return this
}
18 changes: 18 additions & 0 deletions tests/acceptance/features/webUIFiles/copyPrivateLinks.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Feature: copy current path as a permanent link
As a user
I want to copy the permanent link to the current folder
So that I can share it with other users

Background:
Given user "user1" has been created with default attributes
And user "user1" has logged in using the webUI
And the user has browsed to the files page

Scenario Outline: Copy permalink to clipboard
When the user browses to the folder <folder_name> on the files page
And the user copies the permalink of the current folder using the webUI
Then the clipboard content should match permalink of resource <folder_name>
Examples:
| folder_name |
| "/" |
| "simple-folder" |
24 changes: 24 additions & 0 deletions tests/acceptance/helpers/webdavHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,27 @@ exports.createFile = function (user, fileName, contents = '') {
.then(res => httpHelper.checkStatus(res, `Could not create the file "${fileName}" for user "${user}".`))
.then(res => res.text())
}

/**
* Get file or folder properties using webDAV api.
*
* @param {string} path
* @param {string} userId
* @param {array} requestedProps
*/
exports.getProperties = function (path, userId, requestedProps) {
return new Promise((resolve) => {
const trimmedPath = path.replace(/^\/+/, '') // remove a leading slash
const relativePath = `/files/${userId}/${trimmedPath}`
exports.propfind(relativePath, userId, userSettings.getPasswordForUser(userId), requestedProps,
0)
.then(str => {
const response = JSON.parse(convert.xml2json(str, { compact: true }))['d:multistatus']['d:response']
const properties = {}
requestedProps.map(propertyName => {
properties[propertyName] = response['d:propstat']['d:prop'][propertyName]._text
})
resolve(properties)
})
})
}
8 changes: 8 additions & 0 deletions tests/acceptance/pageObjects/filesPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ module.exports = {
.isVisible(selector, (result) => {
callback(result.value)
})
},
copyPermalinkFromFilesAppBar: function () {
return this
.waitForElementVisible('@permalinkCopyButton')
.click('@permalinkCopyButton')
}
},
elements: {
Expand All @@ -174,6 +179,9 @@ module.exports = {
newFolderOkButton: {
selector: '#new-folder-ok'
},
permalinkCopyButton: {
selector: '#files-permalink-copy'
},
breadcrumb: {
selector: '#files-breadcrumb li:nth-of-type(2)'
},
Expand Down
18 changes: 18 additions & 0 deletions tests/acceptance/stepDefinitions/filesContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -474,3 +474,21 @@ Given('the user has created the following files', function (entryList) {
})
return client
})

When('the user browses to the folder {string} on the files page', (folderName) => {
const targetFolder = folderName === '/' ? '' : folderName
return client
.page.filesPage()
.navigateAndWaitTillLoaded(targetFolder)
})
When('the user copies the permalink of the current folder using the webUI', function () {
return client.page.filesPage().copyPermalinkFromFilesAppBar()
})
Then('the clipboard content should match permalink of resource {string}', function (folderName) {
return client.getClipBoardContent(function (value) {
webdav.getProperties(folderName, client.globals.currentUser, ['oc:privatelink'])
.then(folderData => {
assert.strictEqual(folderData['oc:privatelink'], value)
})
})
})