diff --git a/apps/files/src/components/FileLink.vue b/apps/files/src/components/FileLink.vue index e80844591c7..bb277b52785 100644 --- a/apps/files/src/components/FileLink.vue +++ b/apps/files/src/components/FileLink.vue @@ -17,11 +17,11 @@ {{ link.token }} | {{ link.description }}
- - - + +
@@ -107,9 +107,17 @@ export default { enforced: expireDate.enforced === '1' } }, - $_tooltipTextLink () { return `title: ${this.$gettext('Click to open the link')}; pos: bottom` + }, + $_deleteButtonLabel () { + return this.$gettext('Delete public link') + }, + $_editButtonLabel () { + return this.$gettext('Edit public link') + }, + $_copyButtonLabel () { + return this.$gettext('Copy link url') } }, methods: { diff --git a/tests/acceptance/features/webUISharingPublic/shareByPublicLink.feature b/tests/acceptance/features/webUISharingPublic/shareByPublicLink.feature index df3ed655fe6..15ffc69bd12 100644 --- a/tests/acceptance/features/webUISharingPublic/shareByPublicLink.feature +++ b/tests/acceptance/features/webUISharingPublic/shareByPublicLink.feature @@ -68,7 +68,7 @@ Feature: Share by public link Scenario: public link share shows up on shared-with-others page Given user "user1" has logged in using the webUI - And user "user1" has created a new public link for resource "simple-folder" + And user "user1" has shared folder "simple-folder" with link with "read" permissions When the user browses to the shared-with-others page using the webUI Then folder "simple-folder" should be listed on the webUI But file "data.zip" should not be listed on the webUI @@ -289,20 +289,17 @@ Feature: Share by public link When the public uses the webUI to access the last public link created by user "user1" with password "pass123" Then file "lorem.txt" should be listed on the webUI - @skip @yetToImplement Scenario: public should not be able to access a public link with wrong password - When the user creates a new public link for folder "simple-folder" using the webUI with - | password | pass123 | - And the public tries to access the last created public link with wrong password "pass12" using the webUI + Given user "user1" has shared folder "simple-folder" with link with "read" permissions and password "pass123" + When the public uses the webUI to access the last public link created by user "user1" with password "pass12" Then the public should not get access to the publicly shared file - @skip @yetToImplement Scenario: user shares a public link with folder longer than 64 chars and shorter link name - Given user "user1" has moved folder "simple-folder" to "aquickbrownfoxjumpsoveraverylazydogaquickbrownfoxjumpsoveralazydog" - And the user has reloaded the current page of the webUI + Given user "user1" has renamed folder "simple-folder" to "aquickbrownfoxjumpsoveraverylazydogaquickbrownfoxjumpsoveralazydog" + And user "user1" has logged in using the webUI When the user creates a new public link for folder "aquickbrownfoxjumpsoveraverylazydogaquickbrownfoxjumpsoveralazydog" using the webUI with | name | short_linkname | - And the public accesses the last created public link using the webUI + And the public uses the webUI to access the last public link created by user "user1" Then file "lorem.txt" should be listed on the webUI Scenario: user tries to create a public link with Viewer role without entering share password while enforce password on read only public share is enforced @@ -349,17 +346,22 @@ Feature: Share by public link | path | /simple-folder | | name | Public link | - @skip @yetToImplement + @yetToImplement Scenario: public should be able to access the shared file through public link - When the user creates a new public link for file 'lorem.txt' using the webUI - And the public accesses the last created public link using the webUI - Then the text preview of the public link should contain "Lorem ipsum dolor sit amet, consectetur" - And the content of the file shared by the last public link should be the same as "lorem.txt" + Given user "user1" has logged in using the webUI + And user "user1" has created a public link with following settings + | path | lorem.txt | + | name | Public link | + When the public uses the webUI to access the last public link created by user "user1" + Then file "lorem.txt" should be listed on the webUI +# Then the text preview of the public link should contain "Lorem ipsum dolor sit amet, consectetur" +# And the content of the file shared by the last public link should be the same as "lorem.txt" @skip @yetToImplement Scenario: user shares a public link via email - Given parameter "shareapi_allow_public_notification" of app "core" has been set to "yes" - And the user has reloaded the current page of the webUI + Given the setting "shareapi_allow_public_notification" of app "core" has been set to "yes" + And user "user1" has logged in using the webUI + And the user reloads the current page of the webUI When the user creates a new public link for folder "simple-folder" using the webUI with | email | foo@bar.co | Then the email address "foo@bar.co" should have received an email with the body containing @@ -370,8 +372,8 @@ Feature: Share by public link @skip @yetToImplement Scenario: user shares a public link via email and sends a copy to self - Given parameter "shareapi_allow_public_notification" of app "core" has been set to "yes" - And the user has reloaded the current page of the webUI + Given the setting "shareapi_allow_public_notification" of app "core" has been set to "yes" + And the user reloads the current page of the webUI When the user creates a new public link for folder "simple-folder" using the webUI with | email | foo@bar.co | | emailToSelf | true | @@ -388,8 +390,8 @@ Feature: Share by public link @skip @yetToImplement Scenario: user shares a public link via email with multiple addresses - Given parameter "shareapi_allow_public_notification" of app "core" has been set to "yes" - And the user has reloaded the current page of the webUI + Given the setting "shareapi_allow_public_notification" of app "core" has been set to "yes" + And the user reloads the current page of the webUI When the user creates a new public link for folder "simple-folder" using the webUI with | email | foo@bar.co, foo@barr.co | Then the email address "foo@bar.co" should have received an email with the body containing @@ -405,8 +407,8 @@ Feature: Share by public link @skip @yetToImplement Scenario: user shares a public link via email with a personal message - Given parameter "shareapi_allow_public_notification" of app "core" has been set to "yes" - And the user has reloaded the current page of the webUI + Given the setting "shareapi_allow_public_notification" of app "core" has been set to "yes" + And the user reloads the current page of the webUI When the user creates a new public link for folder "simple-folder" using the webUI with | email | foo@bar.co | | personalMessage | lorem ipsum | @@ -422,8 +424,8 @@ Feature: Share by public link @skip @yetToImplement Scenario: user shares a public link via email adding few addresses before and then removing some addresses afterwards - Given parameter "shareapi_allow_public_notification" of app "core" has been set to "yes" - And the user has reloaded the current page of the webUI + Given the setting "shareapi_allow_public_notification" of app "core" has been set to "yes" + And the user reloads the current page of the webUI When the user opens the share dialog for folder "simple-folder" using the webUI And the user opens the public link share tab And the user opens the create public link share popup @@ -451,17 +453,18 @@ Feature: Share by public link But the email address "foo1234@bar.co" should not have received an email And the email address "foo5678@barr.co" should not have received an email - @skip @yetToImplement + @yetToImplement Scenario: user edits a public link and does not save the changes - Given parameter "shareapi_allow_public_notification" of app "core" has been set to "yes" - And the user has reloaded the current page of the webUI - And the user has created a new public link for folder "simple-folder" using the webUI with - | email | foo1234@bar.co | - | password | pass123 | - When the user opens the edit public link share popup for the link named "Public link" - And the user enters the password "qwertyui" on the edit public link share popup for the link - And the user does not save any changes in the edit public link share popup - And the public tries to access the last created public link with wrong password "qwertyui" using the webUI + Given the setting "shareapi_allow_public_notification" of app "core" has been set to "yes" + And user "user1" has logged in using the webUI + And user "user1" has created a public link with following settings + | path | simple-folder | + | name | test_public_link | + | password | pass123 | +# | email | foo1234@bar.co | + When the user edits the public link named "test_public_link" of folder "simple-folder" changing following but not saving + | password | qwertyui | + And the public uses the webUI to access the last public link created by user "user1" with password "qwertyui" Then the public should not get access to the publicly shared file @skip @yetToImplement @@ -481,53 +484,52 @@ Feature: Share by public link """ And the email address "foo@bar.co" should have received an email containing the last shared public link - @skip @yetToImplement Scenario: user edits a name of an already existing public link - Given the user has created a new public link for folder "simple-folder" using the webUI - And the user has opened the public link share tab - When the user renames the public link name from "Public link" to "simple-folder Share" - And the public accesses the last created public link using the webUI + Given user "user1" has logged in using the webUI + And user "user1" has shared folder "simple-folder" with link with "read" permissions and password "pass123" + When the user edits the public link named "{}" of folder "simple-folder" changing following + | name | simple-folder Share | + And the public uses the webUI to access the last public link created by user "user1" with password "pass123" Then file "lorem.txt" should be listed on the webUI - @skip @yetToImplement - Scenario: user shares a file through public link and then it appears in a Shared by link page - Given parameter "shareapi_allow_public_notification" of app "core" has been set to "yes" - And the user has reloaded the current page of the webUI - And the user has created a new public link for folder "simple-folder" using the webUI - When the user browses to the shared-by-link page + Scenario: user shares a file through public link and then it appears in a shared-with-others page + Given the setting "shareapi_allow_public_notification" of app "core" has been set to "yes" + And user "user1" has shared folder "simple-folder" with link with "read, change, create, delete" permissions + And user "user1" has logged in using the webUI + When the user browses to the shared-with-others page Then folder "simple-folder" should be listed on the webUI - @skip @yetToImplement Scenario: user edits the password of an already existing public link - Given the user has created a new public link for folder "simple-folder" using the webUI with - | password | pass123 | - When the user changes the password of the public link named "Public link" to "pass1234" - And the public accesses the last created public link with password "pass1234" using the webUI + Given user "user1" has shared folder "simple-folder" with link with "read, change, create, delete" permissions and password "pass123" + And user "user1" has logged in using the webUI + When the user edits the public link named "{}" of folder "simple-folder" changing following + | password | qwertyui | + And the public uses the webUI to access the last public link created by user "user1" with password "qwertyui" Then file "lorem.txt" should be listed on the webUI - @skip @yetToImplement Scenario: user edits the password of an already existing public link and tries to access with old password - Given the user has created a new public link for folder "simple-folder" using the webUI with - | password | pass123 | - When the user changes the password of the public link named "Public link" to "pass1234" - And the public tries to access the last created public link with wrong password "pass123" using the webUI + Given user "user1" has shared folder "simple-folder" with link with "read, change, create, delete" permissions and password "pass123" + And user "user1" has logged in using the webUI + And the user edits the public link named "{}" of folder "simple-folder" changing following + | password | qwertyui | + When the public uses the webUI to access the last public link created by user "user1" with password "pass123" Then the public should not get access to the publicly shared file - @skip @yetToImplement Scenario: user edits the permission of an already existing public link from read-write to read - Given the user has created a new public link for folder "simple-folder" using the webUI with - | permission | read-write | - When the user changes the permission of the public link named "Public link" to "read" - And the public accesses the last created public link using the webUI + Given user "user1" has shared folder "simple-folder" with link with "read, change, create, delete" permissions + And user "user1" has logged in using the webUI + When the user edits the public link named "{}" of folder "simple-folder" changing following + | role | Viewer | + And the public uses the webUI to access the last public link created by user "user1" Then file "lorem.txt" should be listed on the webUI And it should not be possible to delete file "lorem.txt" using the webUI - @skip @yetToImplement Scenario: user edits the permission of an already existing public link from read to read-write - Given the user has created a new public link for folder "simple-folder" using the webUI with - | permission | read | - When the user changes the permission of the public link named "Public link" to "read-write" - And the public accesses the last created public link using the webUI + Given user "user1" has shared folder "simple-folder" with link with "read" permissions + And user "user1" has logged in using the webUI + When the user edits the public link named "{}" of folder "simple-folder" changing following + | role | Editor | + And the public uses the webUI to access the last public link created by user "user1" And the user deletes the following elements using the webUI | name | | simple-empty-folder | @@ -535,30 +537,26 @@ Feature: Share by public link Then the deleted elements should not be listed on the webUI And the deleted elements should not be listed on the webUI after a page reload - @skip @yetToImplement Scenario: user changes the expiration date of an already existing public link using webUI - Given user "user1" has created a share with settings - | path | lorem.txt | - | name | Public link | - | expireDate | 14-10-2038 | - | shareType | 3 | - When the user changes the expiration of the public link named "Public link" of file "lorem.txt" to "21-07-2038" - And the user gets the info of the last share using the sharing API - Then the fields of the last response should include - | expiration | 21-07-2038 | + Given user "user1" has created a public link with following settings + | path | lorem.txt | + | name | Public link | + | expireDate | 2038-10-14 | + And user "user1" has logged in using the webUI + When the user edits the public link named "Public link" of file "lorem.txt" changing following + | expireDate | 2038-July-21 | + Then the fields of the last public link share response of user "user1" should include + | expireDate | 2038-07-21 | - @skip @yetToImplement Scenario: user tries to change the expiration date of the public link to past date using webUI - Given user "user1" has created a share with settings - | path | lorem.txt | - | name | Public link | - | expireDate | 14-10-2038 | - | shareType | 3 | - When the user changes the expiration of the public link named "Public link" of file "lorem.txt" to "14-09-2017" - And the user gets the info of the last share using the sharing API - Then the user should see an error message on the public link share dialog saying "Expiration date is in the past" - And the fields of the last response should include - | expiration | 14-10-2038 | + Given user "user1" has created a public link with following settings + | path | lorem.txt | + | name | Public link | + | expireDate | 2038-10-14 | + And user "user1" has logged in using the webUI + When the user tries to edit expiration of the public link named "Public link" of file "lorem.txt" to past date "2019-Oct-10" + Then the fields of the last public link share response of user "user1" should include + | expireDate | 2038-10-14 | @skip @yetToImplement Scenario: share two file with same name but different paths by public link @@ -570,11 +568,11 @@ Feature: Share by public link Then file "lorem.txt" with path "" should be listed in the shared with others page on the webUI And file "lorem.txt" with path "/simple-folder" should be listed in the shared with others page on the webUI - @skip @yetToImplement - Scenario: user removes the public link of a file - Given the user has created a new public link for file "lorem.txt" using the webUI - When the user removes the public link of file "lorem.txt" using the webUI - Then the public should see an error message "File not found" while accessing last created public link using the webUI + Scenario: user removes the public link of a file using webUI + Given user "user1" has logged in using the webUI + And user "user1" has shared file "lorem.txt" with link with "read" permissions + When the user "user1" removes the public link named "{}" of file "lorem.txt" using the webUI + Then user "user1" should not have any public link @skip @yetToImplement Scenario: user cancel removes operation for the public link of a file @@ -583,41 +581,53 @@ Feature: Share by public link And the public accesses the last created public link using the webUI Then the content of the file shared by the last public link should be the same as "lorem.txt" - @skip @yetToImplement Scenario: user creates a multiple public link of a file and delete the first link - Given the user has created a new public link for file "lorem.txt" using the webUI with - | name | first-link | - And the user has created a new public link for file "lorem.txt" using the webUI with - | name | second-link | - And the user has created a new public link for file "lorem.txt" using the webUI with - | name | third-link | - When the user removes the public link at position 1 of file "lorem.txt" using the webUI - Then the public link with name "first-link" should not be in the public links list - And the number of public links should be 2 + Given user "user1" has created a public link with following settings + | path | lorem.txt | + | name | first-name | + And user "user1" has created a public link with following settings + | path | lorem.txt | + | name | second-name | + And user "user1" has created a public link with following settings + | path | lorem.txt | + | name | third-name | + And user "user1" has logged in using the webUI + When the user "user1" removes the public link named "first-name" of file "lorem.txt" using the webUI + Then public link named "first-name" should not be listed on the public links list on the webUI + And a link named "second-name" should be listed with role "Viewer" in the public link list of file "lorem.txt" on the webUI + And a link named "third-name" should be listed with role "Viewer" in the public link list of folder "lorem.txt" on the webUI - @skip @yetToImplement Scenario: user creates a multiple public link of a file and delete the second link - Given the user has created a new public link for file "lorem.txt" using the webUI with - | name | first-link | - And the user has created a new public link for file "lorem.txt" using the webUI with - | name | second-link | - And the user has created a new public link for file "lorem.txt" using the webUI with - | name | third-link | - When the user removes the public link at position 2 of file "lorem.txt" using the webUI - Then the public link with name "second-link" should not be in the public links list - And the number of public links should be 2 + Given user "user1" has created a public link with following settings + | path | lorem.txt | + | name | first-name | + And user "user1" has created a public link with following settings + | path | lorem.txt | + | name | second-name | + And user "user1" has created a public link with following settings + | path | lorem.txt | + | name | third-name | + And user "user1" has logged in using the webUI + When the user "user1" removes the public link named "second-name" of file "lorem.txt" using the webUI + Then public link named "second-name" should not be listed on the public links list on the webUI + And a link named "first-name" should be listed with role "Viewer" in the public link list of file "lorem.txt" on the webUI + And a link named "third-name" should be listed with role "Viewer" in the public link list of folder "lorem.txt" on the webUI - @skip @yetToImplement Scenario: user creates a multiple public link of a file and delete the third link - Given the user has created a new public link for file "lorem.txt" using the webUI with - | name | first-link | - And the user has created a new public link for file "lorem.txt" using the webUI with - | name | second-link | - And the user has created a new public link for file "lorem.txt" using the webUI with - | name | third-link | - When the user removes the public link at position 3 of file "lorem.txt" using the webUI - Then the public link with name "third-link" should not be in the public links list - And the number of public links should be 2 + Given user "user1" has created a public link with following settings + | path | lorem.txt | + | name | first-name | + And user "user1" has created a public link with following settings + | path | lorem.txt | + | name | second-name | + And user "user1" has created a public link with following settings + | path | lorem.txt | + | name | third-name | + And user "user1" has logged in using the webUI + When the user "user1" removes the public link named "third-name" of file "lorem.txt" using the webUI + Then public link named "third-name" should not be listed on the public links list on the webUI + And a link named "first-name" should be listed with role "Viewer" in the public link list of file "lorem.txt" on the webUI + And a link named "second-name" should be listed with role "Viewer" in the public link list of folder "lorem.txt" on the webUI @skip @yetToImplement Scenario: user creates public link with view and upload feature diff --git a/tests/acceptance/helpers/sharingHelper.js b/tests/acceptance/helpers/sharingHelper.js index 2f4be6e0a6f..4450083e93e 100644 --- a/tests/acceptance/helpers/sharingHelper.js +++ b/tests/acceptance/helpers/sharingHelper.js @@ -67,73 +67,84 @@ module.exports = { return fetch(apiURL, { method: 'GET', headers: headers }) .then(res => res.json()) .then(function (sharesResult) { - if (sharesResult.ocs.meta.statuscode === 200) { - const shares = sharesResult.ocs.data - let found - for (var shareI = 0; shareI < shares.length; shareI++) { - const share = shares[shareI] - found = true - for (var expectedDetailsI = 0; expectedDetailsI < expectedDetailsTable.hashes().length; expectedDetailsI++) { - const expectedDetail = expectedDetailsTable.hashes()[expectedDetailsI] - if (expectedDetail.field === 'permissions') { - expectedDetail.value = sharingHelper.humanReadablePermissionsToBitmask(expectedDetail.value).toString() - } else if (expectedDetail.field === 'share_type') { - expectedDetail.value = sharingHelper.humanReadableShareTypeToNumber(expectedDetail.value).toString() - } - if (!(expectedDetail.field in share) || share[expectedDetail.field].toString() !== expectedDetail.value) { - found = false - break - } + httpHelper.checkOCSStatus(sharesResult, 'Could not get shares. Message: ' + sharesResult.ocs.meta.message) + const shares = sharesResult.ocs.data + let found + for (const share of shares) { + found = true + for (const expectedDetail of expectedDetailsTable.hashes()) { + if (expectedDetail.field === 'permissions') { + expectedDetail.value = sharingHelper.humanReadablePermissionsToBitmask(expectedDetail.value).toString() + } else if (expectedDetail.field === 'share_type') { + expectedDetail.value = sharingHelper.humanReadableShareTypeToNumber(expectedDetail.value).toString() } - if (found === true) { + if (!(expectedDetail.field in share) || share[expectedDetail.field].toString() !== expectedDetail.value) { + found = false break } } - assert.strictEqual( - found, true, 'could not find expected share in "' + JSON.stringify(sharesResult, null, 2) + '"' - ) - return this - } else { - throw Error('Could not get shares. Message: ' + sharesResult.ocs.meta.message) + if (found) { + break + } } + assert.strictEqual( + found, true, 'could not find expected share in "' + JSON.stringify(sharesResult, null, 2) + '"' + ) + return this }) }, - /** * Asynchronously fetches the last public link created by the given link creator * * @async - * @param {string[]} linkCreator link creator + * @param {string} linkCreator link creator * @return {Promise} last share token */ fetchLastPublicLinkShare: async function (linkCreator) { const self = this const headers = httpHelper.createAuthHeader(linkCreator) const apiURL = client.globals.backend_url + '/ocs/v2.php/apps/files_sharing/api/v1/shares?format=json' + let lastShareToken let lastShare await fetch(apiURL, { method: 'GET', headers: headers }) .then(res => res.json()) .then(function (sharesResult) { - if (sharesResult.ocs.meta.statuscode === 200) { - const shares = sharesResult.ocs.data - let lastFoundShareId = 0 - for (var shareI = 0; shareI < shares.length; shareI++) { - const share = shares[shareI] - if (share.share_type === self.SHARE_TYPES.public_link && share.id >= lastFoundShareId) { - lastFoundShareId = share.id - lastShare = share - } + httpHelper.checkOCSStatus(sharesResult, 'Could not get shares. Message: ' + sharesResult.ocs.meta.message) + const shares = sharesResult.ocs.data + let lastFoundShareId = 0 + for (const share of shares) { + if (share.share_type === self.SHARE_TYPES.public_link && share.id >= lastFoundShareId) { + lastFoundShareId = share.id + lastShareToken = share.token + lastShare = share } - if (lastShare === null) { - throw Error('Could not find public shares. All shares: ' + JSON.stringify(shares, null, 2)) - } - } else { - throw Error('Could not get shares. Message: ' + sharesResult.ocs.meta.message) + } + if (lastShareToken === null) { + throw Error('Could not find public shares. All shares: ' + JSON.stringify(shares, null, 2)) } }) - return lastShare }, + /** + * get a list of all public link shares shared by provided sharer + * + * @param sharer user whose all public links are to be fetched + * @returns {Object<[]>} + */ + getAllPublicLinkShares: async function (sharer) { + const headers = httpHelper.createAuthHeader(sharer) + const data = [] + const apiURL = client.globals.backend_url + '/ocs/v2.php/apps/files_sharing/api/v1/shares?&format=json' + const response = await fetch(apiURL, { method: 'GET', headers: headers }) + const jsonResponse = await response.json() + httpHelper.checkOCSStatus(jsonResponse, 'Could not get shares. Message: ' + jsonResponse.ocs.meta.message) + for (const share of jsonResponse.ocs.data) { + if (share.share_type === this.SHARE_TYPES.public_link) { + data.push(share) + } + } + return data + }, /** * * @param {string} user @@ -185,5 +196,32 @@ module.exports = { }) } } + }, + /** + * asserts expectedDetails with the last public link share of a user + * + * @param {string} linkCreator - owner of public link share + * @param {Object} expectedDetails - provided expected details of last public link share for assertion + * @param {string} expectedDetails.token - token of the public link share + * @param {string} expectedDetails.expireDate - expire date for public link share in format 'YYYY-MM-DD' + * @returns {Promise} + */ + assertUserLastPublicShareDetails: async function (linkCreator, expectedDetails) { + const lastShare = await this.fetchLastPublicLinkShare(linkCreator) + if (lastShare.share_type === this.SHARE_TYPES.public_link) { + const regDate = lastShare.expiration.split(' ')[0] + if (expectedDetails.token) { + assert.strictEqual( + lastShare.token, expectedDetails.token, 'Token Missmatch' + lastShare + ) + } + if (expectedDetails.expireDate) { + assert.strictEqual( + regDate, expectedDetails.expireDate, 'Expiry Date Missmatch: ' + lastShare + ) + } + } else { + throw new Error('Invalid Share Type' + lastShare) + } } } diff --git a/tests/acceptance/pageObjects/FilesPageElement/filesList.js b/tests/acceptance/pageObjects/FilesPageElement/filesList.js index f23bd6cb593..af471ff8542 100644 --- a/tests/acceptance/pageObjects/FilesPageElement/filesList.js +++ b/tests/acceptance/pageObjects/FilesPageElement/filesList.js @@ -208,8 +208,8 @@ module.exports = { * * @param {string} fileName */ - openPublicLinkDialog: function (fileName) { - this.waitForFileVisible(fileName) + openPublicLinkDialog: async function (fileName) { + await this.waitForFileVisible(fileName) .useXpath() .performFileAction(fileName, 'share') .waitForElementVisible('@linkToPublicLinksTag') @@ -514,7 +514,6 @@ module.exports = { }) }) }, - copyPrivateLink: function () { return this .waitForElementVisible('@sidebar') diff --git a/tests/acceptance/pageObjects/FilesPageElement/publicLinksDialog.js b/tests/acceptance/pageObjects/FilesPageElement/publicLinksDialog.js index f52e60ab99e..2993f629cda 100644 --- a/tests/acceptance/pageObjects/FilesPageElement/publicLinksDialog.js +++ b/tests/acceptance/pageObjects/FilesPageElement/publicLinksDialog.js @@ -1,25 +1,350 @@ +const assert = require('assert') +const util = require('util') + module.exports = { commands: { + /** + * clicks the edit button of public link + * + * @param linkName Name of the public link + * @returns {Promise} + */ + clickLinkEditBtn: function (linkName) { + const linkRowEditButtonSelector = util.format(this.elements.publicLinkEditButton.selector, linkName) + const linkRowEditButton = { + locateStrategy: this.elements.publicLinkEditButton.locateStrategy, + selector: linkRowEditButtonSelector + } + return this + .initAjaxCounters() + .waitForElementVisible(linkRowEditButton) + .click(linkRowEditButton) + .waitForOutstandingAjaxCalls() + }, + /** + * sets up the xpath for year in expiry date of public link + * + * @param year + * @returns {{locateStrategy: string, selector: *}} + */ + setExpiryDateYearSelectorXpath: function (year) { + const yearSelectorXpath = util.format(this.elements.dateTimeYearPicker.selector, year) + return { + selector: yearSelectorXpath, + locateStrategy: this.elements.dateTimeYearPicker.locateStrategy + } + }, + /** + * sets up the xpath for month in expiry date of public link + * + * @param month + * @returns {{locateStrategy: string, selector: *}} + */ + setExpiryDateMonthSelectorXpath: function (month) { + const monthSelectorXpath = util.format(this.elements.dateTimeMonthPicker.selector, month) + return { + selector: monthSelectorXpath, + locateStrategy: this.elements.dateTimeMonthPicker.locateStrategy + } + }, + /** + * sets up the xpath for year in expiry date of public link + * + * @param day + * @returns {{locateStrategy: string, selector: *}} + */ + setExpiryDateDaySelectorXpath: function (day) { + const daySelectorXpath = util.format(this.elements.dateTimeDayPicker.selector, day) + return { + selector: daySelectorXpath, + locateStrategy: this.elements.dateTimeDayPicker.locateStrategy + } + }, + /** + * sets provided year in expiry date field on webUI + * + * @param {string} year + * @returns {Promise} + */ + setExpiryDateYear: function (year) { + const yearSelector = this.setExpiryDateYearSelectorXpath(year) + return this + .waitForElementVisible('@dateTimePopupYear') + .waitForAnimationToFinish() + .waitForElementEnabled( + this.elements.dateTimePopupYear.selector + ) + .click('@dateTimePopupYear') + .waitForElementVisible(yearSelector) + .click(yearSelector) + .click('@dateTimeOkButton') + .waitForElementNotPresent(yearSelector) + }, + /** + * sets provided month in expiry date field on webUI + * + * @param {string} month + * @returns {Promise} + */ + setExpiryDateMonth: function (month) { + const monthSelector = this.setExpiryDateMonthSelectorXpath(month) + return this + .waitForElementVisible('@dateTimePopupDate') + .click('@dateTimePopupDate') + .waitForElementVisible(monthSelector) + .click(monthSelector) + .click('@dateTimeOkButton') + .waitForElementNotPresent(monthSelector) + }, + /** + * sets provided day in expiry date field on webUI + * + * @param {string} day + * @returns {Promise} + */ + setExpiryDateDay: function (day) { + const daySelector = this.setExpiryDateDaySelectorXpath(day) + return this + .waitForElementVisible(daySelector) + .click(daySelector) + .click('@dateTimeOkButton') + .waitForElementNotPresent(daySelector) + }, + /** + * sets role or permissions for public link on webUI + * + * @param {string} role - e.g. Viewer, Contributor, Editor, Uploader + * @returns {Promise} + */ + setPublicLinkRole: function (role) { + const roleSelectorXpath = util.format(this.elements.roleButton.selector, role) + const roleSelector = { + locateStrategy: this.elements.roleButton.locateStrategy, + selector: roleSelectorXpath + } + return this + .waitForElementVisible(roleSelector) + .click(roleSelector) + }, + /** + * sets name of the public link share on webUI + * + * @param {string} linkName Name of the public link share + * + */ + setPublicLinkName: function (linkName) { + return this + .waitForElementVisible('@publicLinkNameInputField') + .clearValue('@publicLinkNameInputField') + .setValue('@publicLinkNameInputField', linkName) + }, + /** + * sets password of the public link share + * + * @param {string} linkPassword + * @returns {Promise} + */ + setPublicLinkPassword: function (linkPassword) { + return this + .waitForElementVisible('@publicLinkPasswordField') + .clearValue('@publicLinkPasswordField') + .setValue('@publicLinkPasswordField', linkPassword) + }, + /** + * sets expire date of the public link share using webUI + * + * @param {string} value - provided date in format YYYY-MM-DD + * @returns {Promise} + */ + setPublicLinkExpiryDate: function (value) { + const [year, month, day] = value.split('-') + return this + .initAjaxCounters() + .waitForElementVisible('@linkExpirationDateField') + .click('@linkExpirationDateField') + .setExpiryDateYear(year) + .setExpiryDateMonth(month) + .setExpiryDateDay(day) + }, + /** + * function sets different fields for public link + * + * @param key fields like name, password, expireDate, role + * @param value values for the different fields to be set + * @returns {*|Promise|exports} + */ + setPublicLinkForm: function (key, value) { + if (key === 'role') { + return this.setPublicLinkRole(value) + } else if (key === 'name') { + return this.setPublicLinkName(value) + } else if (key === 'password') { + return this.setPublicLinkPassword(value) + } else if (key === 'expireDate') { + return this.setPublicLinkExpiryDate(value) + } + return this + }, + /** + * checks if the provided expiryDate is selectors are disabled or not + * + * @param linkName name of the public link + * @param pastDate provided past date for inspection + * pastDate should be in form 2000-August-7 | 2000-Aug-7 + * leading zeros before day are removed + * @returns {Promise} + */ + assertDisabledExpiryDate: async function (linkName, pastDate) { + await this.clickLinkEditBtn(linkName) + const [year, month, day] = pastDate.split(/-/) + let disabled = false + const iDay = parseInt(day) + const yearSelector = this.setExpiryDateYearSelectorXpath(year) + const monthSelector = this.setExpiryDateMonthSelectorXpath(month) + const daySelector = this.setExpiryDateDaySelectorXpath(iDay) + await this + .initAjaxCounters() + .waitForElementVisible('@linkExpirationDateField') + .click('@linkExpirationDateField') + .waitForElementVisible('@dateTimePopupYear') + .waitForAnimationToFinish() + .waitForElementEnabled( + this.elements.dateTimePopupYear.selector + ) + .angryClick('@dateTimePopupYear') + .waitForElementVisible(yearSelector) + .getAttribute(yearSelector, 'class', (result) => { + if (result.value.includes('--disabled') === true) { + disabled = true + } + }) + if (disabled) { return } + await this + .click(yearSelector) + .click('@dateTimeOkButton') + .waitForElementVisible('@dateTimePopupDate') + .click('@dateTimePopupDate') + .waitForElementVisible(monthSelector) + .getAttribute(monthSelector, 'class', (result) => { + if (result.value.includes('--disabled') === true) { + disabled = true + } + }) + if (disabled) { return } + await this + .click(monthSelector) + .click('@dateTimeOkButton') + .waitForElementVisible(daySelector) + .getAttribute(daySelector, 'class', (result) => { + if (result.value.includes('--disabled') === true) { + disabled = true + } + }) + assert.strictEqual( + disabled, true, 'Provided date is not disabled' + ) + }, + /** + * sets up public link share edit form + * + * @param {string} linkName + * @param {object} editData - key: value pair of public link edit data + * @param {string} editData.role - Role of the viewer of the public link + * @param {string} editData.name - Name of the public link share + * @param {string} editData.password - Password for a public link share + * @param {string} editData.expireDate - Expire date for a public link share + * @returns {exports} + */ + editPublicLink: function (linkName, editData) { + this.clickLinkEditBtn(linkName) + for (const [key, value] of Object.entries(editData)) { + this.setPublicLinkForm(key, value) + } + return this + }, + /** + * clicks save button of public link form + * + * @returns {exports} + */ + savePublicLink: function () { + return this + .initAjaxCounters() + .waitForElementVisible('@publicLinkSaveButton') + .click('@publicLinkSaveButton') + .waitForElementNotPresent('@publicLinkSaveButton') + .waitForOutstandingAjaxCalls() + }, + /** + * deletes existing public link share + * + * @param {string} linkName Name of the public link share of a resource to be deleted + * @returns {exports} + */ + removePublicLink: function (linkName) { + const linkRowDeleteButtonSelector = util.format(this.elements.publicLinkDeleteButton.selector, linkName) + const linkRowDeleteButton = { + locateStrategy: this.elements.publicLinkDeleteButton.locateStrategy, + selector: linkRowDeleteButtonSelector + } + return this + .initAjaxCounters() + .waitForElementVisible(linkRowDeleteButton) + .click(linkRowDeleteButton) + .waitForOutstandingAjaxCalls() + }, + /** + * checks if public link share with provided name is present + * + * @param {string} linkName - Name of the public link share to be asserted + * @returns {*} + */ + assertPublicLinkNotPresent: function (linkName) { + const fileNameSelectorXpath = this.elements.publicLinkContainer.selector + this.elements.publicLinkName.selector + return this + .waitForElementNotPresent({ + selector: util.format(fileNameSelectorXpath, linkName), + locateStrategy: this.elements.publicLinkName.locateStrategy + }) + }, /** * creates a new public link + * + * @param {Object} settings - Parameters to be set up for a new public link share + * @param {string} settings.role - Role of the viewer of the public link + * @param {string} settings.name - Name of the public link share + * @param {string} settings.password - Password for a public link share + * @param {string} settings.expireDate - Expire date for a public link share * @returns {*} */ - addNewLink: async function (role = null) { - const addLinkButtonXpath = this.elements.publicLinkContainer.selector + this.elements.addLinkButton.selector - const createLinkButtonXpath = this.elements.publicLinkContainer.selector + this.elements.createLinkButton.selector - this - .click({ locateStrategy: 'xpath', selector: addLinkButtonXpath }) - .waitForElementVisible({ locateStrategy: 'xpath', selector: createLinkButtonXpath }) - - if (role !== null) { - const util = require('util') - const roleSelectorXpath = util.format(this.elements.roleButton.selector, role) - await this.click({ locateStrategy: 'xpath', selector: roleSelectorXpath }) + addNewLink: async function (settings = null) { + const addLinkButtonXpath = this.elements.publicLinkContainer.selector + + this.elements.addLinkButton.selector + const createLinkButtonXpath = this.elements.publicLinkContainer.selector + + this.elements.createLinkButton.selector + const addLinkButton = { + locateStrategy: this.elements.addLinkButton.locateStrategy, + selector: addLinkButtonXpath } - - return this.click({ locateStrategy: 'xpath', selector: createLinkButtonXpath }) + const createLinkButton = { + locateStrategy: this.elements.createLinkButton.locateStrategy, + selector: createLinkButtonXpath + } + await this + .waitForElementVisible(addLinkButton) + .click(addLinkButton) + .waitForElementVisible(createLinkButton) + if (settings !== null) { + for (const [key, value] of Object.entries(settings)) { + await this.setPublicLinkForm(key, value) + } + } + return this + .initAjaxCounters() + .waitForElementVisible(createLinkButton) + .click(createLinkButton) + .waitForElementNotPresent(createLinkButton) .waitForOutstandingAjaxCalls() - .waitForElementNotPresent({ locateStrategy: 'xpath', selector: createLinkButtonXpath, abortOnFailure: false }) }, /** * gets the text of all public links of the currently open public link tab @@ -51,7 +376,7 @@ module.exports = { getErrorMessage: async function () { let message const errorMessageXpath = this.elements.publicLinkContainer.selector + - this.elements.errorMessageInsidePublicLinkContainer.selector + this.elements.errorMessageInsidePublicLinkContainer.selector await this.getText('xpath', errorMessageXpath, function (result) { message = result.value }) @@ -67,6 +392,10 @@ module.exports = { selector: '//li', locateStrategy: 'xpath' }, + publicLinkName: { + selector: '//li//span[.="%s"]', + locateStrategy: 'xpath' + }, addLinkButton: { selector: '//button[contains(.,"Add Link")]', locateStrategy: 'xpath' @@ -76,11 +405,64 @@ module.exports = { locateStrategy: 'xpath' }, roleButton: { - selector: '//*[contains(@class,"oc-files-file-link-form")]//*[.="%s"]' + selector: '//*[contains(@class,"oc-files-file-link-form")]//*[.="%s"]', + locateStrategy: 'xpath' }, errorMessageInsidePublicLinkContainer: { selector: '//div[contains(@class, "uk-alert-danger")]', locateStrategy: 'xpath' + }, + publicLinkNameInputField: { + selector: '//input[@id="oc-files-file-link-name"]', + locateStrategy: 'xpath' + }, + publicLinkEditButton: { + selector: '//span[.="%s"]/../..//button[@aria-label="Edit public link"]', + locateStrategy: 'xpath' + }, + publicLinkDeleteButton: { + selector: '//span[.="%s"]/../..//button[@aria-label="Delete public link"]', + locateStrategy: 'xpath' + }, + publicLinkPasswordField: { + selector: '//input[@type="password"]', + locateStrategy: 'xpath' + }, + publicLinkSaveButton: { + selector: '//button/span[.="Save"]', + locateStrategy: 'xpath' + }, + linkExpirationDateField: { + selector: '.vdatetime-input' + }, + dateTimePopup: { + selector: '.vdatetime-popup' + }, + dateTimePopupYear: { + selector: '.vdatetime-popup__year' + }, + dateTimePopupDate: { + selector: '.vdatetime-popup__date' + }, + dateTimeMonthPicker: { + selector: '//div[@class="vdatetime-month-picker"]//div[contains(text(),"%s")]', + locateStrategy: 'xpath' + }, + dateTimeYearPicker: { + selector: '//div[@class="vdatetime-year-picker"]//div[normalize-space(.)="%s"]', + locateStrategy: 'xpath' + }, + dateTimeDayPicker: { + selector: '//div[@class="vdatetime-calendar"]//span/span[normalize-space(.)="%s"]/../..', + locateStrategy: 'xpath' + }, + dateTimeOkButton: { + selector: '//div[@class="vdatetime-popup__actions"]/div[.="Ok"]', + locateStrategy: 'xpath' + }, + dateTimeCancelButton: { + selector: '//div[@class="vdatetime-popup__actions"]/div[.="Cancel"]', + locateStrategy: 'xpath' } } } diff --git a/tests/acceptance/pageObjects/publicLinkPasswordPage.js b/tests/acceptance/pageObjects/publicLinkPasswordPage.js index b82eaf11c06..ff0a792cc6b 100644 --- a/tests/acceptance/pageObjects/publicLinkPasswordPage.js +++ b/tests/acceptance/pageObjects/publicLinkPasswordPage.js @@ -9,6 +9,14 @@ module.exports = { }, passwordSubmitButton: { selector: '.oc-login-authorize-button' + }, + resourceProtectedText: { + selector: '//h2[@class="oc-login-card-title"]/span', + locateStrategy: 'xpath' + }, + loadingPublicLink: { + selector: "//div[@class='oc-login-card uk-position-center']//span[.='Loading public linkā€¦']", + locateStrategy: 'xpath' } }, commands: [ @@ -27,6 +35,22 @@ module.exports = { .page.FilesPageElement.filesList() .waitForElementPresent({ selector: '@filesListProgressBar', abortOnFailure: false }) // don't fail if we are too late .waitForElementNotPresent('@filesListProgressBar') + }, + assertResourceAccessDenied: function () { + return this + .waitForElementPresent('@passwordSubmitButton') + .click('@passwordSubmitButton') + .waitForElementVisible('@loadingPublicLink') + .waitForElementPresent('@passwordInput') + .getText( + this.elements.resourceProtectedText.locateStrategy, + this.elements.resourceProtectedText.selector, + (result) => { + if (result.value !== 'This resource is password-protected.') { + throw new Error('Resource Protected Message Invalid', result) + } + } + ) } } ] diff --git a/tests/acceptance/stepDefinitions/publicLinkContext.js b/tests/acceptance/stepDefinitions/publicLinkContext.js index fff143a4665..aaeb3bf7526 100644 --- a/tests/acceptance/stepDefinitions/publicLinkContext.js +++ b/tests/acceptance/stepDefinitions/publicLinkContext.js @@ -3,27 +3,30 @@ const { When, Then } = require('cucumber') require('url-search-params-polyfill') const sharingHelper = require('../helpers/sharingHelper') const assert = require('assert') +const { SHARE_TYPES } = require('../helpers/sharingHelper') +const path = require('path') When( - 'the user creates a new public link for file/folder/resource {string} using the webUI', - function (resource) { - return client.page.FilesPageElement + 'the user (tries to )create/creates a new public link for file/folder/resource {string} using the webUI', + async function (resource) { + await client.page.FilesPageElement .filesList() .closeSidebar(100) .openPublicLinkDialog(resource) + return client.page.FilesPageElement.publicLinksDialog() .addNewLink() } ) When( - 'the user creates a new public link for file/folder/resource {string} using the webUI with', - function (resource, settingsTable) { + 'the user (tries to )create/creates a new public link for file/folder/resource {string} using the webUI with', + async function (resource, settingsTable) { const settings = settingsTable.rowsHash() - return client.page.FilesPageElement + await client.page.FilesPageElement .filesList() .closeSidebar(100) .openPublicLinkDialog(resource) - .addNewLink(settings.role) + return client.page.FilesPageElement.publicLinksDialog().addNewLink(settings) } ) @@ -56,19 +59,106 @@ When('the public uses the webUI to access the last public link created by user { return client.page.publicLinkPasswordPage().submitPublicLinkPassword(password) }) +Then('user {string} should not have any public link', + async function (sharer) { + const resp = await sharingHelper.getAllPublicLinkShares(sharer) + assert.strictEqual( + resp.length, 0, 'User has shares. Response: ' + resp) + }) + +Then('the fields of the last public link share response of user {string} should include', + function (linkCreator, dataTable) { + const fieldsData = dataTable.rowsHash() + return sharingHelper.assertUserLastPublicShareDetails(linkCreator, fieldsData) + }) + +Then('as user {string} the folder {string} should not have any public link', async function (sharer, resource) { + const publicLinkShares = await sharingHelper.getAllPublicLinkShares(sharer) + resource = path.join('/', resource) + for (const share of publicLinkShares) { + if (share.path === resource && share.share_type === SHARE_TYPES.public_link) { + assert.fail( + 'Expected share with user ' + sharer + + ' and resource ' + resource + ' is present!\n' + JSON.stringify(publicLinkShares) + ) + } + } + return this +}) + +Then('the public should not get access to the publicly shared file', function () { + return client + .page + .publicLinkPasswordPage() + .assertResourceAccessDenied() +}) + +When('the user edits the public link named {string} of file/folder/resource {string} changing following but not saving', + async function (linkName, resource, dataTable) { + const editData = dataTable.rowsHash() + await client.page.FilesPageElement + .filesList() + .closeSidebar(100) + .openPublicLinkDialog(resource) + return client.page.FilesPageElement + .publicLinksDialog() + .editPublicLink(linkName, editData) + }) + +When('the user edits the public link named {string} of file/folder/resource {string} changing following', + async function (linkName, resource, dataTable) { + const editData = dataTable.rowsHash() + await client.page.FilesPageElement + .filesList() + .closeSidebar(100) + .openPublicLinkDialog(resource) + return client.page.FilesPageElement + .publicLinksDialog() + .editPublicLink(linkName, editData) + .savePublicLink() + }) + +When('the user tries to edit expiration of the public link named {string} of file {string} to past date {string}', + async function (linkName, resource, pastDate) { + await client.page.FilesPageElement + .filesList() + .closeSidebar(100) + .openPublicLinkDialog(resource) + return client.page.FilesPageElement.publicLinksDialog() + .assertDisabledExpiryDate(linkName, pastDate) + }) + +When('the user {string} removes the public link named {string} of file/folder/resource {string} using the webUI', + async function (sharer, linkName, resource) { + await client.page + .FilesPageElement + .filesList() + .closeSidebar(100) + .openPublicLinkDialog(resource) + return client.page.FilesPageElement.publicLinksDialog() + .removePublicLink(linkName) + }) + +Then('public link named {string} should not be listed on the public links list on the webUI', function (linkName) { + return client.page.FilesPageElement.publicLinksDialog() + .assertPublicLinkNotPresent(linkName) +}) + Then( 'a link named {string} should be listed with role {string} in the public link list of file/folder/resource {string} on the webUI', - function (name, role, resource) { - return client.page.FilesPageElement + async function (name, role, resource) { + await client.page.FilesPageElement .filesList() .closeSidebar(100) .openPublicLinkDialog(resource) + return client.page.FilesPageElement + .publicLinksDialog() .getPublicLinkList() .then(links => { const searchregex = new RegExp(name + '\n.*' + role) let found = false for (const link of links) { - if (searchregex.test(link) === true) { + if (searchregex.test(link)) { found = true break } @@ -84,6 +174,11 @@ Then('the user should see an error message on the public link share dialog sayin const actualMessage = await client.page.FilesPageElement .publicLinksDialog() .getErrorMessage() - return client.assert.strictEqual(actualMessage, expectedMessage) }) + +When('the user closes the public link details sidebar', function () { + return client.page.FilesPageElement + .filesList() + .closeSidebar(100) +}) diff --git a/tests/acceptance/stepDefinitions/sharingContext.js b/tests/acceptance/stepDefinitions/sharingContext.js index 192ca89d1bc..84a6b65badc 100644 --- a/tests/acceptance/stepDefinitions/sharingContext.js +++ b/tests/acceptance/stepDefinitions/sharingContext.js @@ -10,6 +10,7 @@ const sharingHelper = require('../helpers/sharingHelper') const { SHARE_TYPES } = require('../helpers/sharingHelper') const { runOcc } = require('../helpers/occHelper') const _ = require('lodash') +const path = require('path') /** * @@ -47,26 +48,39 @@ const userSharesFileOrFolderWithUser = function (file, sharee, role) { const userSharesFileOrFolderWithGroup = function (file, sharee, role) { return userSharesFileOrFolderWithUserOrGroup(file, sharee, true, role) } - /** + * creates a new share * * @param {string} elementToShare path of file/folder being shared * @param {string} sharer username of the sharer - * @param {string} receiver username of the receiver - * @param {number} shareType Type of share 0 = user, 1 = group, 3 = public (link), 6 = federated (cloud share). - * @param {string} permissions permissions of the share for valid permissions see sharingHelper.PERMISSION_TYPES + * @param receiver username of the receiver + * @param shareType Type of share 0 = user, 1 = group, 3 = public (link), 6 = federated (cloud share). + * @param {string} permissionString permissions of the share for valid permissions see sharingHelper.PERMISSION_TYPES + * @param {string} name name of the link (for public links), default = "New Share" + * @param {object} extraParams Extra parameters allowed on the share + * @param {string} extraParams.password Password of the share (public links) + * @param {string} extraParams.expireDate Expiry date of the share */ -const shareFileFolder = function (elementToShare, sharer, receiver, shareType = SHARE_TYPES.user, permissionString = 'all', password = null) { - const permissions = sharingHelper.humanReadablePermissionsToBitmask(permissionString) +const shareFileFolder = function ( + elementToShare, sharer, receiver = null, shareType = SHARE_TYPES.user, + permissionString = 'all', name = null, extraParams = {} +) { const params = new URLSearchParams() - params.append('shareType', shareType) + elementToShare = path.join('/', elementToShare) + const permissions = sharingHelper.humanReadablePermissionsToBitmask(permissionString) + params.append('path', elementToShare) if (receiver) { params.append('shareWith', receiver) } - params.append('path', elementToShare) + params.append('shareType', shareType) params.append('permissions', permissions) - if (password) { - params.append('password', password) + if (name) { + params.append('name', name) + } + for (const key in extraParams) { + if (extraParams[key]) { + params.append(key, extraParams[key]) + } } return fetch( client.globals.backend_url + '/ocs/v2.php/apps/files_sharing/api/v1/shares?format=json', @@ -74,14 +88,37 @@ const shareFileFolder = function (elementToShare, sharer, receiver, shareType = ) .then(res => res.json()) .then(function (json) { - if (json.ocs.meta.statuscode === 200) { - return json - } else { - throw Error('Could not create share. Message: ' + json.ocs.meta.message) - } + httpHelper.checkOCSStatus(json, 'Could not create share. Message: ' + json.ocs.meta.message) }) } - +/** + * sets up data into a standard format for creating new public link share + * + * @param {string} sharer user creating share + * @param {object} data fields table with required share properties + * @param {string} data.name Name of the new share(public links) + * @param {string} data.shareType Type of share + * @param {string} data.shareWith Receiver of the share + * @param {string} data.path Path of file/folder/resource to be shared + * @param {string} data.password Password of the share + * @param {string} data.permissions Allowed permissions on the share + * @param {string} data.expireDate Expiry date of the share + */ +const createPublicLink = function (sharer, data) { + const { path, permissions = 'read', name, password, expireDate } = data + return shareFileFolder( + path, + sharer, + null, + SHARE_TYPES.public_link, + permissions, + name, + { + password, + expireDate + } + ) +} /** * * @param {string} type user|group @@ -293,7 +330,15 @@ Given( Given( 'user {string} has shared file/folder {string} with link with {string} permissions and password {string}', function (sharer, elementToShare, permissions, password) { - return shareFileFolder(elementToShare, sharer, null, SHARE_TYPES.public_link, permissions, password) + return shareFileFolder( + elementToShare, + sharer, + null, + SHARE_TYPES.public_link, + permissions, + null, + { password: password } + ) } ) @@ -333,6 +378,11 @@ Given('the administrator has set the minimum characters for sharing autocomplete ) }) +Given('user {string} has created a public link with following settings', + function (sharer, dataTable) { + return createPublicLink(sharer, dataTable.rowsHash()) + }) + Given('the administrator has excluded group {string} from receiving shares', async function (group) { const configList = await runOcc([ 'config:list' @@ -590,14 +640,14 @@ Then('user {string} should have received a share with these details:', function return sharingHelper.assertUserHasShareWithDetails(user, expectedDetailsTable, true) }) -Then('user {string} should have a share with these details:', function (user, expectedDetailsTable) { - return sharingHelper.assertUserHasShareWithDetails(user, expectedDetailsTable) -}) - Given('user {string} has created a new public link for resource {string}', function (user, resource) { return shareFileFolder(resource, user, '', SHARE_TYPES.public_link) }) +Then('user {string} should have a share with these details:', function (user, expectedDetailsTable) { + return sharingHelper.assertUserHasShareWithDetails(user, expectedDetailsTable) +}) + Then('the user should not be able to share file/folder/resource {string} using the webUI', function (resource) { return client.page .FilesPageElement