Skip to content

Commit

Permalink
Merge pull request #3172 from nextcloud/backport/3152/stable27
Browse files Browse the repository at this point in the history
  • Loading branch information
juliusknorr authored Sep 13, 2023
2 parents 666a176 + 2f5e3dd commit 471dd22
Show file tree
Hide file tree
Showing 34 changed files with 1,059 additions and 765 deletions.
8 changes: 7 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ module.exports = {
'plugin:cypress/recommended',
],
env: {
'cypress/globals': true
'cypress/globals': true,
},
rules: {
'import/no-named-as-default-member': 'off',
'jsdoc/check-values': 'off',
'jsdoc/valid-types': 'off',
'jsdoc/no-undefined-types': 'off',
}
}
2 changes: 1 addition & 1 deletion .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ jobs:
run: cd tests && bash run-integration.sh features/${{ matrix.scenarios }}.feature

oci:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04

strategy:
# do not stop on another job's failure
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/phpunit-oci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ concurrency:

jobs:
phpunit-oci:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04

strategy:
matrix:
Expand Down
1 change: 1 addition & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
['name' => 'document#remote', 'url' => 'remote', 'verb' => 'GET'],
['name' => 'document#createFromTemplate', 'url' => 'indexTemplate', 'verb' => 'GET'],
['name' => 'document#publicPage', 'url' => '/public', 'verb' => 'GET'],
['name' => 'document#token', 'url' => '/token', 'verb' => 'POST'],

['name' => 'document#editOnline', 'url' => 'editonline', 'verb' => 'GET'],
['name' => 'document#editOnlineTarget', 'url' => 'editonline/{fileId}/{target}', 'verb' => 'GET'],
Expand Down
136 changes: 136 additions & 0 deletions cypress/e2e/integration.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/**
* SPDX-FileLicenseText: 2023 Julius Härtl <jus@bitgrid.net>
* SPDX-License-Identifier: AGPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

describe('Nextcloud integration', function() {
let randUser

before(function() {
cy.nextcloudTestingAppConfigSet('richdocuments', 'uiDefaults-UIMode', 'notebookbar')
cy.createRandomUser().then(user => {
randUser = user
cy.login(user)
cy.uploadFile(randUser, 'image.png', 'image/png', '/image.png')
cy.uploadFile(user, 'document.odt', 'application/vnd.oasis.opendocument.text', '/document.odt')
})
})

const filename = 'document.odt'

beforeEach(function() {
cy.login(randUser)
cy.visit('/apps/files', {
onBeforeLoad(win) {
cy.spy(win, 'postMessage').as('postMessage')
},
})
cy.openFile(filename)
cy.waitForViewer()
cy.waitForCollabora()
})

it('Sharing sidebar', function() {
cy.get('@loleafletframe').within(() => {
cy.get('#File-tab-label').click()
cy.get('#ShareAs').click()
})

cy.get('#app-sidebar-vue')
.should('be.visible')
cy.get('.app-sidebar-header__maintitle')
.should('be.visible')
.should('contain.text', filename)

cy.get('#tab-sharing').should('be.visible')
})

it('Versions sidebar', function() {
cy.get('@loleafletframe').within(() => {
cy.get('#File-tab-label').click()
cy.get('#Rev-History').click()
})

cy.get('#app-sidebar-vue')
.should('be.visible')
cy.get('.app-sidebar-header__maintitle')
.should('be.visible')
.should('contain.text', filename)

cy.get('#tab-version_vue').should('be.visible')

cy.get('#tab-version_vue .line-one__title').contains('Current version')
})

it('Save as', function() {
cy.get('@loleafletframe').within(() => {
cy.get('#File-tab-label').click()
cy.get('#saveas').click()
cy.get('#w2ui-overlay-download-as-menu .menu-text').eq(1).click()
})

cy.get('.oc-dialog').should('be.visible')
cy.get('.oc-dialog input[type=text]')
.should('be.visible')
.should('have.value', 'document.rtf')

cy.get('.oc-dialog button.primary').click()

cy.get('@loleafletframe').within(() => {
cy.get('#closebutton').click()
})
cy.get('#viewer', { timeout: 5000 }).should('not.exist')

// FIXME: We should not need to reload
cy.get('.breadcrumb .crumbhome').eq(0).click()

cy.openFile('document.rtf')
})

it('Open locally', function() {
cy.get('@loleafletframe').within(() => {
cy.get('#Open_Local_Editor').click()
})

cy.get('.oc-dialog').should('be.visible')
cy.get('.oc-dialog .oc-dialog-title')
.should('contain', 'Open file locally ')

cy.on('url:changed', (newUrl) => {
expect(newUrl).to.contain('nc://')
})
cy.get('.oc-dialog button.primary').click()

})

it('Insert image', function() {
cy.get('@loleafletframe').within(() => {
cy.get('#Insert-tab-label').click()
cy.get('#insert-insert-graphic').click()
cy.get('#w2ui-overlay-insert-graphic-menu .menu-text').eq(1).click()
})
cy.get('.modal-container').should('be.visible')
})

it('Smart picker', function() {
cy.get('@loleafletframe').within(() => {
cy.get('#Insert-tab-label').click()
cy.get('#insert-insert-remote-link').click()
})
cy.get('.reference-picker-modal--content').should('be.visible')
})
})
2 changes: 1 addition & 1 deletion cypress/e2e/share-link.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('Public sharing of office documents', function() {
cy.spy(win, 'postMessage').as('postMessage')
},
})
cy.waitForCollabora()
cy.waitForCollabora(true)
cy.get('@loleafletframe').within(() => {
cy.get('#closebutton').click()
})
Expand Down
Binary file added cypress/fixtures/image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ Cypress.Commands.add('waitForViewer', () => {
.and('have.class', 'modal-mask')
.and('not.have.class', 'icon-loading')
})
Cypress.Commands.add('waitForCollabora', (wrapped = true) => {
Cypress.Commands.add('waitForCollabora', (wrapped = false) => {
if (wrapped) {
cy.get('[data-cy="documentframe"]', { timeout: 30000 })
.its('0.contentDocument')
Expand Down
12 changes: 12 additions & 0 deletions cypress/support/e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,15 @@ Cypress.Screenshot.defaults({
overwrite: true,
capture: 'viewport',
})

Cypress.on('uncaught:exception', (err) => {
if (err.message.includes('ResizeObserver')) {
return false
}

if (err.message.includes('fetchpriority')) {
return false
}

return true
})
69 changes: 18 additions & 51 deletions lib/Controller/DirectViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,57 +46,20 @@
class DirectViewController extends Controller {
use DocumentTrait;

/** @var IRootFolder */
private $rootFolder;

/** @var TokenManager */
private $tokenManager;

/** @var DirectMapper */
private $directMapper;

/** @var IConfig */
private $config;

/** @var AppConfig */
private $appConfig;

/** @var TemplateManager */
private $templateManager;

/** @var FederationService */
private $federationService;

/** @var ILogger */
private $logger;

/** @var InitialStateService */
private $initialState;

public function __construct(
$appName,
string $appName,
IRequest $request,
IRootFolder $rootFolder,
TokenManager $tokenManager,
DirectMapper $directMapper,
InitialStateService $initialState,
IConfig $config,
AppConfig $appConfig,
TemplateManager $templateManager,
FederationService $federationService,
ILogger $logger
private IRootFolder $rootFolder,
private TokenManager $tokenManager,
private DirectMapper $directMapper,
private InitialStateService $initialState,
private IConfig $config,
private AppConfig $appConfig,
private TemplateManager $templateManager,
private FederationService $federationService,
private ILogger $logger
) {
parent::__construct($appName, $request);

$this->rootFolder = $rootFolder;
$this->tokenManager = $tokenManager;
$this->directMapper = $directMapper;
$this->initialState = $initialState;
$this->config = $config;
$this->appConfig = $appConfig;
$this->templateManager = $templateManager;
$this->federationService = $federationService;
$this->logger = $logger;
}

/**
Expand Down Expand Up @@ -134,7 +97,9 @@ public function show($token) {
}

try {
list($urlSrc, $wopi) = $this->tokenManager->getTokenForTemplate($item, $direct->getUid(), $direct->getTemplateDestination(), true);
$urlSrc = $this->tokenManager->getUrlSrc($item);

$wopi = $this->tokenManager->generateWopiTokenForTemplate($item, $direct->getUid(), $direct->getTemplateDestination(), true);

$targetFile = $folder->getById($direct->getTemplateDestination())[0];
$relativePath = $folder->getRelativePath($targetFile->getPath());
Expand All @@ -157,7 +122,8 @@ public function show($token) {
return $response;
}

list($urlSrc, $token, $wopi) = $this->tokenManager->getToken($item->getId(), null, $direct->getUid(), true);
$urlSrc = $this->tokenManager->getUrlSrc($item);
$wopi = $this->tokenManager->generateWopiToken($item->getId(), null, $direct->getUid(), true);
} catch (\Exception $e) {
$this->logger->error('Failed to generate token for existing file on direct editing', ['exception' => $e]);
return $this->renderErrorPage('Failed to open the requested file.');
Expand Down Expand Up @@ -218,11 +184,12 @@ public function showPublicShare(Direct $direct) {
'directGuest' => empty($direct->getUid()),
];

list($urlSrc, $token, $wopi) = $this->tokenManager->getToken($node->getId(), $direct->getShare(), $direct->getUid(), true);
$urlSrc = $this->tokenManager->getUrlSrc($node);
$wopi = $this->tokenManager->generateWopiToken($node->getId(), $direct->getShare(), $direct->getUid(), true);
if (!empty($direct->getInitiatorHost())) {
$this->tokenManager->upgradeFromDirectInitiator($direct, $wopi);
}
$params['token'] = $token;
$params['token'] = $wopi->getToken();
$params['token_ttl'] = $wopi->getExpiry();
$params['urlsrc'] = $urlSrc;

Expand Down
Loading

0 comments on commit 471dd22

Please sign in to comment.