Skip to content

Commit

Permalink
refactor: move to office.vue component
Browse files Browse the repository at this point in the history
Signed-off-by: Elizabeth Danzberger <[email protected]>
  • Loading branch information
elzody committed Apr 18, 2024
1 parent 695f4a5 commit 3e06cf0
Show file tree
Hide file tree
Showing 31 changed files with 199 additions and 58 deletions.
1 change: 1 addition & 0 deletions cypress/e2e/direct.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ describe('Direct editing (legacy)', function() {
cy.nextcloudTestingAppConfigSet('richdocuments', 'uiDefaults-UIMode', 'classic')
cy.logout()
cy.visit(token)
cy.screenshot('direct')
cy.waitForCollabora(false)
cy.screenshot('direct')
})
Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/open.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ describe('Open existing office files', function() {

// Share action
cy.get('@loleafletframe').within(() => {
cy.get('#main-menu #menu-file > a').click()
cy.get('#main-menu #menu-shareas > a').click()
cy.get('#main-menu li#menu-file > a').click()
cy.get('#main-menu li#menu-shareas > a').click()
})

cy.get('#app-sidebar-vue')
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/settings.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import { User } from '@nextcloud/cypress'

const usesHttps = Cypress.env('baseUrl').substr(0, 5) === 'https'
const collaboraUrl = Cypress.env('collaboraUrl')
const collaboraUrl = Cypress.config('collaboraUrl')
const defaultFonts = ['AmaticSC-Regular.ttf']

describe('Office admin settings', function() {
Expand Down
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(true)
cy.waitForCollabora()
cy.get('@loleafletframe').within(() => {
cy.get('#closebutton').click()
})
Expand Down
4 changes: 2 additions & 2 deletions lib/AppConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function __construct(
) {
}

public function getAppNamespace($key) {
public function getAppNamespace(string $key) {
if (str_starts_with($key, 'watermark_')) {
return self::WATERMARK_APP_NAMESPACE;
}
Expand All @@ -85,7 +85,7 @@ public function getAppValue($key, $defaultValue = null) {
* @param $key
* @return list<string>|string
*/
public function getAppValueArray($key) {
public function getAppValueArray(string $key) {
$value = $this->config->getAppValue($this->getAppNamespace($key), $key, []);
if (array_key_exists($key, self::APP_SETTING_TYPES) && self::APP_SETTING_TYPES[$key] === 'array') {
$value = $value !== '' ? explode(',', $value) : [];
Expand Down
2 changes: 2 additions & 0 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use OCA\Richdocuments\Listener\BeforeFetchPreviewListener;
use OCA\Richdocuments\Listener\BeforeTemplateRenderedListener;
use OCA\Richdocuments\Listener\FileCreatedFromTemplateListener;
use OCA\Richdocuments\Listener\LoadPublicViewerListener;
use OCA\Richdocuments\Listener\LoadViewerListener;
use OCA\Richdocuments\Listener\ReferenceListener;
use OCA\Richdocuments\Listener\ShareLinkListener;
Expand Down Expand Up @@ -81,6 +82,7 @@ public function register(IRegistrationContext $context): void {
$context->registerEventListener(FileCreatedFromTemplateEvent::class, FileCreatedFromTemplateListener::class);
$context->registerEventListener(AddContentSecurityPolicyEvent::class, AddContentSecurityPolicyListener::class);
$context->registerEventListener(AddFeaturePolicyEvent::class, AddFeaturePolicyListener::class);
$context->registerEventListener(BeforeTemplateRenderedEvent::class, LoadPublicViewerListener::class);
$context->registerEventListener(LoadViewer::class, LoadViewerListener::class);
$context->registerEventListener(ShareLinkAccessedEvent::class, ShareLinkListener::class);
$context->registerEventListener(BeforePreviewFetchedEvent::class, BeforeFetchPreviewListener::class);
Expand Down
5 changes: 4 additions & 1 deletion lib/Controller/DirectViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,10 @@ public function showPublicShare(Direct $direct) {
return new TemplateResponse('core', '403', [], 'guest');
}

private function renderErrorPage($message) {
/**
* @psalm-param 'Failed to open the requested file.' $message
*/
private function renderErrorPage(string $message) {
$params = [
'errors' => [['error' => $message]]
];
Expand Down
2 changes: 1 addition & 1 deletion lib/Controller/OCSController.php
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ public function createFromTemplate($path, $template) {
}
}

private function mb_pathinfo($filepath) {
private function mb_pathinfo(string $filepath) {
$result = [];
preg_match('%^(.*?)[\\\\/]*(([^/\\\\]*?)(\.([^\.\\\\/]+?)|))[\\\\/\.]*$%im', ltrim('/' . $filepath), $matches);
if ($matches[1]) {
Expand Down
8 changes: 6 additions & 2 deletions lib/Controller/TemplatesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ public function __construct($appName,

/**
* @NoAdminRequired
*
* @NoCSRFRequired
*
* @PublicPage
*
* Get preview for a specific template
Expand All @@ -93,15 +95,17 @@ public function __construct($appName,
* @param bool $a
* @param bool $forceIcon
* @param string $mode
* @return DataResponse
*
* @throws NotFoundResponse
*
* @psalm-return DataResponse<400|404, array<never, never>, array<never, never>>|DataResponse<int, array|null|object|scalar, array<string, mixed>>|FileDisplayResponse<int, array<string, mixed>>
*/
public function getPreview($fileId,
$x = 150,
$y = 150,
$a = false,
$forceIcon = true,
$mode = 'fill') {
$mode = 'fill'): DataResponse|FileDisplayResponse {
if ($fileId === '' || $x === 0 || $y === 0) {
return new DataResponse([], Http::STATUS_BAD_REQUEST);
}
Expand Down
5 changes: 3 additions & 2 deletions lib/Db/AssetMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ public function __construct(IDBConnection $db, ISecureRandom $random, ITimeFacto
}

/**
* @param $uid
* @param null|string $uid
* @param $fileid
*
* @return Asset
*/
public function newAsset($uid, $fileid) {
public function newAsset(string|null $uid, int $fileid) {
$asset = new Asset();
$asset->setUid($uid);
$asset->setFileid($fileid);
Expand Down
6 changes: 5 additions & 1 deletion lib/Db/DirectMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,13 @@ public function __construct(IDBConnection $db,
* @param string|null $uid
* @param int $fileid
* @param int $destination
* @param null|string $share
* @param null|string $initiatorHost
* @param null|string $initiatorToken
*
* @return Direct
*/
public function newDirect($uid, $fileid, $destination = null, $share = null, $initiatorHost = null, $initiatorToken = null) {
public function newDirect($uid, $fileid, $destination = null, string|null $share = null, string|null $initiatorHost = null, string|null $initiatorToken = null) {
$direct = new Direct();
$direct->setUid($uid);
$direct->setFileid($fileid);
Expand Down
2 changes: 1 addition & 1 deletion lib/Db/WopiMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function generateFileToken($fileId, $owner, $editor, $version, $updatable
return $wopi;
}

public function generateInitiatorToken($uid, $remoteServer) {
public function generateInitiatorToken(string $uid, string $remoteServer) {
$token = $this->random->generate(32, ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_DIGITS);

$wopi = Wopi::fromParams([
Expand Down
50 changes: 50 additions & 0 deletions lib/Listener/LoadPublicViewerListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2024 Elizabeth Danzberger <[email protected]>
*
* @author Elizabeth Danzberger <[email protected]>
*
* @license GNU AGPL version 3 or any later version
*
* 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/>.
*
*/



namespace OCA\Richdocuments\Listener;

use OCA\Richdocuments\AppInfo\Application;
use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\Util;

class LoadPublicViewerListener implements IEventListener {

Check failure on line 38 in lib/Listener/LoadPublicViewerListener.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

MissingTemplateParam

lib/Listener/LoadPublicViewerListener.php:38:43: MissingTemplateParam: OCA\Richdocuments\Listener\LoadPublicViewerListener has missing template params when extending OCP\EventDispatcher\IEventListener, expecting 1 (see https://psalm.dev/182)
public function handle(Event $event): void {
if (!$event instanceof BeforeTemplateRenderedEvent) {
return;
}

if ($event->getResponse()->getRenderAs() !== TemplateResponse::RENDER_AS_PUBLIC) {
return;
}

Util::addScript(Application::APPNAME, 'richdocuments-public');
}
}
3 changes: 1 addition & 2 deletions lib/Preview/Office.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
use OCA\Richdocuments\Capabilities;
use OCP\Files\File;
use OCP\Http\Client\IClientService;
use OCP\IImage;
use OCP\Image;
use OCP\Preview\IProviderV2;
use Psr\Log\LoggerInterface;
Expand All @@ -47,7 +46,7 @@ public function isAvailable(\OCP\Files\FileInfo $file): bool {
/**
* {@inheritDoc}
*/
public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage {
public function getThumbnail(File $file, int $maxX, int $maxY): Image|null {

Check failure on line 49 in lib/Preview/Office.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

MissingDependency

lib/Preview/Office.php:49:66: MissingDependency: OCP\Image depends on class or interface oc_image that does not exist (see https://psalm.dev/157)
if ($file->getSize() === 0) {
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/CapabilitiesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public function getCapabilitiesEndpoint(): ?string {
return rtrim($remoteHost, '/') . '/hosting/capabilities';
}

public function fetchFromRemote($throw = false): void {
public function fetchFromRemote(bool $throw = false): void {
if (!$this->getCapabilitiesEndpoint()) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/DemoService.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function __construct(ICache $cache, IClientService $clientService) {
$this->clientService = $clientService;
}

public function fetchDemoServers($refresh = false) {
public function fetchDemoServers(bool $refresh = false) {
$servers = $this->cache->get('richdocuments-demo');
if (!$refresh) {
return json_decode($servers, true);
Expand Down
4 changes: 2 additions & 2 deletions lib/Service/FederationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function getTrustedServers(): array {
* @return string
* @throws \Exception
*/
public function getRemoteCollaboraURL($remote) {
public function getRemoteCollaboraURL(string $remote) {
// If no protocol is provided we default to https
if (strpos($remote, 'http://') !== 0 && strpos($remote, 'https://') !== 0) {
$remote = 'https://' . $remote;
Expand All @@ -122,7 +122,7 @@ public function getRemoteCollaboraURL($remote) {
return '';
}

public function isTrustedRemote($domainWithPort) {
public function isTrustedRemote(string $domainWithPort) {
if (strpos($domainWithPort, 'http://') === 0 || strpos($domainWithPort, 'https://') === 0) {
$port = parse_url($domainWithPort, PHP_URL_PORT);
$domainWithPort = parse_url($domainWithPort, PHP_URL_HOST) . ($port ? ':' . $port : '');
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/FileTargetService.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function getFileTargets(File $file): array {
return $categories;
}

public function getTargetPreview($file, $target) {
public function getTargetPreview(File $file, string $target) {
return $this->remoteService->fetchTargetThumbnail($file, $target);
}

Expand Down
4 changes: 3 additions & 1 deletion lib/Service/FontService.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,10 @@ static function (ISimpleFile $f) use ($url) {

/**
* @param string $fileName
* @param $newFileResource
* @param resource $newFileResource
*
* @return array
*
* @throws \OCP\Files\NotPermittedException
*/
public function uploadFontFile(string $fileName, $newFileResource): array {
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/RemoteService.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function __construct(
) {
}

public function fetchTargets($file): array {
public function fetchTargets(File $file): array {
$client = $this->clientService->newClient();
try {
$response = $client->put(
Expand Down
5 changes: 5 additions & 0 deletions lib/Template/CollaboraTemplateProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ public function getTemplateType(): string {
return CollaboraTemplateProvider::class;
}

/**
* @return Template[]
*
* @psalm-return array<Template>

Check failure on line 58 in lib/Template/CollaboraTemplateProvider.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

ImplementedReturnTypeMismatch

lib/Template/CollaboraTemplateProvider.php:58:19: ImplementedReturnTypeMismatch: The inherited return type 'array<array-key, OCP\Files\File>' for OCP\Files\Template\ICustomTemplateProvider::getCustomTemplates is different to the implemented return type for OCA\Richdocuments\Template\CollaboraTemplateProvider::getcustomtemplates 'array<array-key, OCP\Files\Template\Template>' (see https://psalm.dev/123)
*/
public function getCustomTemplates(string $mimetype): array {
if (in_array($mimetype, TemplateManager::MIMES_DOCUMENTS)) {
$type = 'document';
Expand Down
Loading

0 comments on commit 3e06cf0

Please sign in to comment.