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

fix: 28 deprecation compatiblity #490

Merged
merged 3 commits into from
Dec 19, 2023
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
63 changes: 48 additions & 15 deletions .github/workflows/lint-eslint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,6 @@ name: Lint eslint

on:
pull_request:
paths:
- '.github/workflows/**'
- 'src/**'
- 'appinfo/info.xml'
- 'package.json'
- 'package-lock.json'
- 'tsconfig.json'
- '.eslintrc.*'
- '.eslintignore'
- '**.js'
- '**.ts'
- '**.vue'

permissions:
contents: read
Expand All @@ -31,14 +19,42 @@ concurrency:
cancel-in-progress: true

jobs:
changes:
runs-on: ubuntu-latest

outputs:
src: ${{ steps.changes.outputs.src}}

steps:
- uses: dorny/paths-filter@4512585405083f25c027a35db413c2b3b9006d50 # v2.11.1
id: changes
continue-on-error: true
with:
filters: |
src:
- '.github/workflows/**'
- 'src/**'
- 'appinfo/info.xml'
- 'package.json'
- 'package-lock.json'
- 'tsconfig.json'
- '.eslintrc.*'
- '.eslintignore'
- '**.js'
- '**.ts'
- '**.vue'

lint:
runs-on: ubuntu-latest

name: eslint
needs: changes
if: needs.changes.outputs.src != 'false'

name: NPM lint

steps:
- name: Checkout
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0

- name: Read package.json node and npm engines version
uses: skjnldsv/read-package-engines-version-actions@8205673bab74a63eb9b8093402fd9e0e018663a1 # v2.2
Expand All @@ -48,15 +64,32 @@ jobs:
fallbackNpm: '^9'

- name: Set up node ${{ steps.versions.outputs.nodeVersion }}
uses: actions/setup-node@e33196f7422957bea03ed53f6fbb155025ffc7b8 # v3
uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3
with:
node-version: ${{ steps.versions.outputs.nodeVersion }}

- name: Set up npm ${{ steps.versions.outputs.npmVersion }}
run: npm i -g npm@"${{ steps.versions.outputs.npmVersion }}"

- name: Install dependencies
env:
CYPRESS_INSTALL_BINARY: 0
run: npm ci

- name: Lint
run: npm run lint

summary:
permissions:
contents: none
runs-on: ubuntu-latest
needs: [changes, lint]

if: always()

# This is the summary, we just avoid to rename it so that branch protection rules still match
name: eslint

steps:
- name: Summary status
run: if ${{ needs.changes.outputs.src != 'false' && needs.lint.result != 'success' }}; then exit 1; fi
59 changes: 46 additions & 13 deletions .github/workflows/node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,6 @@ name: Node

on:
pull_request:
paths:
- '.github/workflows/**'
- 'src/**'
- 'appinfo/info.xml'
- 'package.json'
- 'package-lock.json'
- 'tsconfig.json'
- '**.js'
- '**.ts'
- '**.vue'
push:
branches:
- main
Expand All @@ -31,13 +21,39 @@ concurrency:
cancel-in-progress: true

jobs:
changes:
runs-on: ubuntu-latest

outputs:
src: ${{ steps.changes.outputs.src}}

steps:
- uses: dorny/paths-filter@4512585405083f25c027a35db413c2b3b9006d50 # v2.11.1
id: changes
continue-on-error: true
with:
filters: |
src:
- '.github/workflows/**'
- 'src/**'
- 'appinfo/info.xml'
- 'package.json'
- 'package-lock.json'
- 'tsconfig.json'
- '**.js'
- '**.ts'
- '**.vue'

build:
runs-on: ubuntu-latest

name: node
needs: changes
if: needs.changes.outputs.src != 'false'

name: NPM build
steps:
- name: Checkout
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0

- name: Read package.json node and npm engines version
uses: skjnldsv/read-package-engines-version-actions@8205673bab74a63eb9b8093402fd9e0e018663a1 # v2.2
Expand All @@ -47,14 +63,16 @@ jobs:
fallbackNpm: '^9'

- name: Set up node ${{ steps.versions.outputs.nodeVersion }}
uses: actions/setup-node@e33196f7422957bea03ed53f6fbb155025ffc7b8 # v3
uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3
with:
node-version: ${{ steps.versions.outputs.nodeVersion }}

- name: Set up npm ${{ steps.versions.outputs.npmVersion }}
run: npm i -g npm@"${{ steps.versions.outputs.npmVersion }}"

- name: Install dependencies & build
env:
CYPRESS_INSTALL_BINARY: 0
run: |
npm ci
npm run build --if-present
Expand All @@ -69,3 +87,18 @@ jobs:
git status
git --no-pager diff
exit 1 # make it red to grab attention

summary:
permissions:
contents: none
runs-on: ubuntu-latest
needs: [changes, build]

if: always()

# This is the summary, we just avoid to rename it so that branch protection rules still match
name: node

steps:
- name: Summary status
run: if ${{ needs.changes.outputs.src != 'false' && needs.build.result != 'success' }}; then exit 1; fi
52 changes: 0 additions & 52 deletions appinfo/app.php

This file was deleted.

75 changes: 48 additions & 27 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,14 @@
use OC\Files\Type\Detection;
use OC\Security\CSP\ContentSecurityPolicy;
use OCA\Federation\TrustedServers;
use OCA\Files\Event\LoadAdditionalScriptsEvent;
use OCA\Files_Sharing\Listener\LoadAdditionalListener;
use OCA\Officeonline\Capabilities;
use OCA\Officeonline\Hooks\WopiLockHooks;
use OCA\Officeonline\Listener\FilesScriptListener;
use OCA\Officeonline\Listener\LoadViewerListener;
use OCA\Officeonline\Middleware\WOPIMiddleware;
use OCA\Officeonline\PermissionManager;
use OCA\Officeonline\Preview\MSExcel;
use OCA\Officeonline\Preview\MSWord;
use OCA\Officeonline\Preview\OOXML;
Expand All @@ -38,44 +43,46 @@
use OCA\Officeonline\Service\FederationService;
use OCA\Viewer\Event\LoadViewer;
use OCP\AppFramework\App;
use OCP\AppFramework\QueryException;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\IPreview;
use Psr\Log\LoggerInterface;

class Application extends App {
class Application extends App implements IBootstrap {
public const APP_ID = 'officeonline';

/**
* Strips the path and query parameters from the URL.
*
* @param string $url
* @return string
*/
private function domainOnly(string $url): string {
$parsed_url = parse_url(trim($url));
$scheme = isset($parsed_url['scheme']) ? $parsed_url['scheme'] . '://' : '';
$host = isset($parsed_url['host']) ? $parsed_url['host'] : '';
$port = isset($parsed_url['port']) ? ':' . $parsed_url['port'] : '';
return "$scheme$host$port";
}

public function __construct(array $urlParams = []) {
parent::__construct(self::APP_ID, $urlParams);
}

try {
/** @var IEventDispatcher $eventDispatcher */
$eventDispatcher = $this->getContainer()->getServer()->query(IEventDispatcher::class);
if (class_exists(LoadViewer::class)) {
$eventDispatcher->addListener(LoadViewer::class, function () {
\OCP\Util::addScript('officeonline', 'viewer');
});
public function register(IRegistrationContext $context): void {
$context->registerCapability(Capabilities::class);
$context->registerMiddleWare(WOPIMiddleware::class);
$context->registerEventListener(LoadAdditionalScriptsEvent::class, FilesScriptListener::class);
$context->registerEventListener(LoadAdditionalListener::class, FilesScriptListener::class);
$context->registerEventListener(LoadViewer::class, LoadViewerListener::class);
}

public function boot(IBootContext $context): void {
if (!$this->isEnabled()) {
return;
}
$this->registerProvider();
$this->updateCSP();
}

public function isEnabled(): bool {
$currentUser = \OC::$server->getUserSession()->getUser();
if ($currentUser !== null) {
/** @var PermissionManager $permissionManager */
$permissionManager = \OCP\Server::get(PermissionManager::class);
if (!$permissionManager->isEnabledForUser($currentUser)) {
return false;
}
} catch (QueryException $e) {
}

$this->getContainer()->registerCapability(Capabilities::class);
$this->getContainer()->registerMiddleWare(WOPIMiddleware::class);
return true;
}

public function registerProvider() {
Expand Down Expand Up @@ -159,4 +166,18 @@ public function updateCSP() {

$cspManager->addDefaultPolicy($policy);
}

/**
* Strips the path and query parameters from the URL.
*
* @param string $url
* @return string
*/
private function domainOnly(string $url): string {
$parsed_url = parse_url(trim($url));
$scheme = isset($parsed_url['scheme']) ? $parsed_url['scheme'] . '://' : '';
$host = isset($parsed_url['host']) ? $parsed_url['host'] : '';
$port = isset($parsed_url['port']) ? ':' . $parsed_url['port'] : '';
return "$scheme$host$port";
}
}
1 change: 0 additions & 1 deletion lib/Controller/DocumentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,6 @@ public function index($fileId, $path = null) {
$response = new TemplateResponse('officeonline', 'documents', $params, 'base');
$policy = new ContentSecurityPolicy();
$policy->addAllowedFrameDomain($this->domainOnly($this->appConfig->getAppValue('public_wopi_url')));
$policy->allowInlineScript(true);
$response->setContentSecurityPolicy($policy);
$response->addHeader('Cache-Control', 'no-cache, no-store');
$response->addHeader('Expires', '-1');
Expand Down
12 changes: 12 additions & 0 deletions lib/Listener/FilesScriptListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace OCA\Officeonline\Listener;

use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;

class FilesScriptListener implements IEventListener {
public function handle(Event $event): void {
\OCP\Util::addScript('officeonline', 'files', 'viewer');
}
}
15 changes: 15 additions & 0 deletions lib/Listener/LoadViewerListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace OCA\Officeonline\Listener;

use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\Util;

class LoadViewerListener implements IEventListener {
public function handle(Event $event): void {
Util::addScript('officeonline', 'viewer');
}
}
Loading