Skip to content
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
6 changes: 5 additions & 1 deletion cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,9 @@ module.exports = defineConfig({
experimentalSessionAndOrigin: true,
specPattern: 'cypress/e2e/**/*.{js,jsx,ts,tsx}',
},
retries: 2,
retries: {
"runMode": 2,
// do not retry in `cypress open`
"openMode": 0
},
})
63 changes: 18 additions & 45 deletions cypress/e2e/share.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,11 @@ describe('Open test.md in viewer', function() {
})

it('Shares the file as a public read only link', function() {
cy.visit('/apps/files')
cy.get('.files-fileList tr[data-file="test.md"] a.action-share')
.click({ force: true })
cy.get('#app-sidebar-vue')
.should('be.visible')
cy.get('#app-sidebar-vue a#sharing').trigger('click')
cy.get('#app-sidebar-vue button.new-share-link').trigger('click')
cy.get('#app-sidebar-vue a.sharing-entry__copy')
.should('have.attr', 'href').and('include', '/s/')
.then((href) => cy.visit(href))
cy.shareFile('/test.md')
.then((token) => {
cy.logout()
cy.visit(`/s/${token}`)
})
.then(() => {
cy.getEditor().should('be.visible')
cy.getContent()
Expand All @@ -64,20 +59,10 @@ describe('Open test.md in viewer', function() {
})

it('Shares the file as a public link with write permissions', function() {
cy.visit('/apps/files')
cy.get('.files-fileList tr[data-file="test2.md"] a.action-share')
.click({ force: true })
cy.get('#app-sidebar-vue')
.should('be.visible')
cy.get('#app-sidebar-vue a#sharing').trigger('click')
cy.get('#app-sidebar-vue button.new-share-link').trigger('click')
cy.get('#app-sidebar-vue .sharing-link-list .action-item__menutoggle').trigger('click')
const checkboxAllowEditing = '.popover.open input[type=checkbox]'
cy.get(checkboxAllowEditing).first().check({ force: true })
cy.get(checkboxAllowEditing).first().should('be.checked')
cy.get('#app-sidebar-vue a.sharing-entry__copy')
.should('have.attr', 'href').and('include', '/s/')
.then((href) => cy.visit(href))
cy.shareFile('/test2.md', { edit: true })
.then((token) => {
cy.visit(`/s/${token}`)
})
.then(() => {
cy.getEditor().should('be.visible')
cy.getContent()
Expand All @@ -92,17 +77,10 @@ describe('Open test.md in viewer', function() {
})

it('Opens the editor as guest', function() {
cy.visit('/apps/files')
cy.get('.files-fileList tr[data-file="test2.md"] a.action-share')
.click({ force: true })
cy.get('#app-sidebar-vue')
.should('be.visible')
cy.get('#app-sidebar-vue a#sharing').trigger('click')
cy.get('#app-sidebar-vue a.sharing-entry__copy')
.should('have.attr', 'href').and('include', '/s/')
.then((href) => {
return cy.logout()
.then(() => cy.visit(href))
cy.shareFile('/test2.md', { edit: true })
.then((token) => {
cy.logout()
cy.visit(`/s/${token}`)
})
.then(() => {
cy.getEditor().should('be.visible')
Expand All @@ -118,16 +96,11 @@ describe('Open test.md in viewer', function() {
})

it('Shares a folder as a public read only link', function() {
cy.visit('/apps/files')
cy.get('.files-fileList tr[data-file="folder"] a.action-share')
.click({ force: true })
cy.get('#app-sidebar-vue')
.should('be.visible')
cy.get('#app-sidebar-vue a#sharing').trigger('click')
cy.get('#app-sidebar-vue button.new-share-link').trigger('click')
cy.get('#app-sidebar-vue a.sharing-entry__copy')
.should('have.attr', 'href').and('include', '/s/')
.then((href) => cy.visit(href))
cy.shareFile('/folder')
.then((token) => {
cy.logout()
cy.visit(`/s/${token}`)
})
.then(() => {
cy.get('#rich-workspace').should('contain', 'Hello world')
cy.openFile('test.md')
Expand Down
34 changes: 34 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,40 @@ Cypress.Commands.add('shareFileToUser', (userId, password, path, targetUserId) =
})
})

Cypress.Commands.add('shareFile', (path, options = {}) => {
return cy.window().then(async window => {
try {
const headers = { requesttoken: window.OC.requestToken }
const request = await axios.post(
`${Cypress.env('baseUrl')}/ocs/v2.php/apps/files_sharing/api/v1/shares`,
{ path, shareType: window.OC.Share.SHARE_TYPE_LINK },
{ headers }
)
const token = request.data?.ocs?.data?.token
const id = request.data?.ocs?.data?.id
if (!token || !id || token.length === 0) {
throw request
}
cy.log(`Share link created: ${token}`)

if (options.edit) {
// Same permissions makeing the share editable in the UI would set
// 1 = read; 2 = write; 16 = share;
const permissions = 19
await axios.put(
`${Cypress.env('baseUrl')}/ocs/v2.php/apps/files_sharing/api/v1/shares/${id}`,
{ permissions },
{ headers }
)
cy.log(`Made share ${token} editable.`)
}
return cy.wrap(token)
} catch (error) {
console.error(error)
}
}).should('have.length', 15)
})

Cypress.Commands.add('createFolder', dirName => cy.window()
.then(win => win.OC.Files.getClient().createDirectory(dirName))
)
Expand Down
4 changes: 2 additions & 2 deletions lib/Controller/ImageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,9 @@ public function getImage(int $documentId, int $sessionId, string $sessionToken,
* @param int $documentId
* @param int $sessionId
* @param string $sessionToken
* @return string
* @return ?string
*/
private function getUserIdFromSession(int $documentId, int $sessionId, string $sessionToken): string {
private function getUserIdFromSession(int $documentId, int $sessionId, string $sessionToken): ?string {
$session = $this->sessionService->getSession($documentId, $sessionId, $sessionToken);
return $session->getUserId();
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Db/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
use OCP\AppFramework\Db\Entity;

/**
* @method string getUserId()
* @method ?string getUserId()
* @method void setUserId(?string $userId)
* @method string getToken()
* @method void setToken(string $token)
Expand Down
8 changes: 6 additions & 2 deletions lib/Service/SessionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ public function getAllSessions($documentId): array {
$sessions = $this->sessionMapper->findAll($documentId);
return array_map(function (Session $session) {
$result = $session->jsonSerialize();
$result['displayName'] = $this->userManager->getDisplayName($session->getUserId());
if ($session->getUserId() !== null) {
$result['displayName'] = $this->userManager->getDisplayName($session->getUserId());
}
return $result;
}, $sessions);
}
Expand All @@ -125,7 +127,9 @@ public function getActiveSessions($documentId): array {
$sessions = $this->sessionMapper->findAllActive($documentId);
return array_map(function (Session $session) {
$result = $session->jsonSerialize();
$result['displayName'] = $this->userManager->getDisplayName($session->getUserId());
if ($session->getUserId() !== null) {
$result['displayName'] = $this->userManager->getDisplayName($session->getUserId());
}
return $result;
}, $sessions);
}
Expand Down