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
52 changes: 52 additions & 0 deletions .github/workflows/lint-php-cs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# This workflow is provided via the organization template repository
#
# https://github.com/nextcloud/.github
# https://docs.github.com/en/actions/learn-github-actions/sharing-workflows-with-your-organization
#
# SPDX-FileCopyrightText: 2021-2024 Nextcloud GmbH and Nextcloud contributors
# SPDX-License-Identifier: MIT

name: Lint php-cs

on: pull_request

permissions:
contents: read

concurrency:
group: lint-php-cs-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
lint:
runs-on: ubuntu-latest

name: php-cs

steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
persist-credentials: false

- name: Get php version
id: versions
uses: icewind1991/nextcloud-version-matrix@58becf3b4bb6dc6cef677b15e2fd8e7d48c0908f # v1.3.1

- name: Set up php${{ steps.versions.outputs.php-min }}
uses: shivammathur/setup-php@0f7f1d08e3e32076e51cae65eb0b0c871405b16e # v2.34.1
with:
php-version: ${{ steps.versions.outputs.php-min }}
extensions: bz2, ctype, curl, dom, fileinfo, gd, iconv, intl, json, libxml, mbstring, openssl, pcntl, posix, session, simplexml, xmlreader, xmlwriter, zip, zlib, sqlite, pdo_sqlite
coverage: none
ini-file: development
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Install dependencies
run: |
composer remove nextcloud/ocp --dev --no-scripts
composer i

- name: Lint
run: composer run cs:check || ( echo 'Please run `composer run cs:fix` to format your code' && exit 1 )
22 changes: 22 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
require_once './vendor-bin/cs-fixer/vendor/autoload.php';

use Nextcloud\CodingStandard\Config;

$config = new Config();
$config
->getFinder()
->ignoreVCSIgnored(true)
->notPath('build')
->notPath('tests/stubs')
->notPath('l10n')
->notPath('src')
->notPath('vendor')
->in(__DIR__);
return $config;
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ This product includes GeoLite2 data created by MaxMind, available from [maxmind.
<screenshot>https://github.com/nextcloud/terms_of_service/raw/master/docs/notification-and-settings.png</screenshot>

<dependencies>
<nextcloud min-version="28" max-version="33" />
<nextcloud min-version="30" max-version="33" />
</dependencies>

<commands>
Expand Down
1 change: 1 addition & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
Expand Down
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"autoloader-suffix": "TermsOfService",
"optimize-autoloader": true,
"platform": {
"php": "8.0.2"
"php": "8.1"
},
"sort-packages": true
},
Expand All @@ -27,7 +27,10 @@
"scripts": {
"bin": "echo 'bin not installed'",
"lint": "find . -name \\*.php -not -path './vendor/*' -print0 | xargs -0 -n1 php -l",
"cs:check": "php-cs-fixer fix --dry-run --diff",
"cs:fix": "php-cs-fixer fix",
"openapi": "generate-spec --verbose",
"rector": "rector && composer cs:fix",
"post-install-cmd": [
"@composer bin all install --ansi",
"composer dump-autoload"
Expand Down
23 changes: 10 additions & 13 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
Expand All @@ -8,24 +9,23 @@

use Exception;
use OC\Files\Filesystem;
use OC\Files\Storage\Wrapper\Wrapper;
use OCA\Registration\Events\PassedFormEvent;
use OCA\Registration\Events\ShowFormEvent;
use OCA\Registration\Events\ValidateFormEvent;
use OCA\TermsOfService\PublicCapabilities;
use OCA\TermsOfService\Checker;
use OCA\TermsOfService\Dav\CheckPlugin;
use OCA\TermsOfService\Filesystem\StorageWrapper;
use OCA\TermsOfService\Listener\RegistrationIntegration;
use OCA\TermsOfService\Listener\UserDeletedListener;
use OCA\TermsOfService\Notifications\Notifier;
use OCA\TermsOfService\PublicCapabilities;
use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\AppFramework\Services\IAppConfig;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Storage\IStorage;
use OCP\IConfig;
use OCP\IRequest;
use OCP\IUser;
use OCP\IUserSession;
Expand All @@ -34,8 +34,8 @@
use OCP\User\Events\UserDeletedEvent;
use OCP\User\Events\UserFirstTimeLoggedInEvent;
use OCP\Util;
use Psr\Log\LoggerInterface;
use Psr\Container\ContainerExceptionInterface;
use Psr\Log\LoggerInterface;

include_once __DIR__ . '/../../vendor/autoload.php';

Expand All @@ -46,7 +46,7 @@ class Application extends App implements IBootstrap {


public function __construct() {
parent::__construct('terms_of_service');
parent::__construct(self::APPNAME);
}

public function register(IRegistrationContext $context): void {
Expand All @@ -61,7 +61,7 @@ public function boot(IBootContext $context): void {
Util::connectHook('OC_Filesystem', 'preSetup', $this, 'addStorageWrapper');

$eventDispatcher = $context->getServerContainer()->get(IEventDispatcher::class);
$eventDispatcher->addListener('OCA\DAV\Connector\Sabre::addPlugin', function (SabrePluginEvent $event) use ($context) {
$eventDispatcher->addListener('OCA\DAV\Connector\Sabre::addPlugin', function (SabrePluginEvent $event) use ($context): void {
$eventServer = $event->getServer();

if ($eventServer !== null) {
Expand All @@ -78,7 +78,7 @@ public function boot(IBootContext $context): void {
$context->injectFn([$this, 'registerFrontend']);
}

public function registerFrontend(IRequest $request, IConfig $config, IUserSession $userSession): void {
public function registerFrontend(IRequest $request, IAppConfig $appConfig, IUserSession $userSession): void {
// Ignore CLI
/** @psalm-suppress UndefinedClass */
if (\OC::$CLI) {
Expand All @@ -105,14 +105,14 @@ public function registerFrontend(IRequest $request, IConfig $config, IUserSessio
// registration
'#^/apps/registration(?:$|/)#',
];
if (array_filter($skipPatterns, fn($pattern) => preg_match($pattern, $request->getPathInfo()))) {
if (array_filter($skipPatterns, fn (string $pattern): int|false => preg_match($pattern, $request->getPathInfo()))) {
return;
}

if ($userSession->getUser() instanceof IUser) {
// Logged-in user
Util::addScript('terms_of_service', 'terms_of_service-user');
} else if ($config->getAppValue(self::APPNAME, 'tos_on_public_shares', '0') === '1') {
} elseif ($appConfig->getAppValueBool('tos_on_public_shares') === true) {
// Guests on public pages
Util::addScript('terms_of_service', 'terms_of_service-public');
}
Expand All @@ -126,9 +126,6 @@ public function addStorageWrapper(): void {
}

/**
* @param string $mountPoint
* @param IStorage $storage
*
* @return StorageWrapper|IStorage
* @throws Exception
*/
Expand Down Expand Up @@ -160,7 +157,7 @@ public function registerNotifier(IManager $notificationManager): void {
}

public function createNotificationOnFirstLogin(IManager $notificationManager, IEventDispatcher $dispatcher): void {
$dispatcher->addListener(UserFirstTimeLoggedInEvent::class, function(UserFirstTimeLoggedInEvent $event) use ($notificationManager) {
$dispatcher->addListener(UserFirstTimeLoggedInEvent::class, function (UserFirstTimeLoggedInEvent $event) use ($notificationManager): void {
$user = $event->getUser();
$notification = $notificationManager->createNotification();
$notification->setApp('terms_of_service')
Expand Down
10 changes: 5 additions & 5 deletions lib/BackgroundJobs/CreateNotifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@

namespace OCA\TermsOfService\BackgroundJobs;

use OCA\TermsOfService\AppInfo\Application;
use OCA\TermsOfService\Db\Mapper\SignatoryMapper;
use OCA\TermsOfService\Db\Mapper\TermsMapper;
use OCP\AppFramework\Services\IAppConfig;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\QueuedJob;
use OCP\IConfig;
use OCP\IUser;
use OCP\IUserManager;
use OCP\Notification\IManager;
Expand All @@ -30,15 +29,15 @@ public function __construct(
protected IManager $notificationsManager,
protected TermsMapper $termsMapper,
protected SignatoryMapper $signatoryMapper,
protected IConfig $config,
protected IAppConfig $appConfig,
protected LoggerInterface $logger,
ITimeFactory $time,
) {
parent::__construct($time);
}

protected function run($argument): void {
if ($this->config->getAppValue(Application::APPNAME, 'sent_notifications', 'no') === 'yes') {
if ($this->appConfig->getAppValueBool('sent_notifications')) {
$this->logger->debug('ToS Notifications have already been sent');
return;
}
Expand All @@ -49,7 +48,7 @@ protected function run($argument): void {
return;
}

$this->config->setAppValue(Application::APPNAME, 'sent_notifications', 'yes');
$this->appConfig->setAppValueBool('sent_notifications', true);

$this->notification = $this->notificationsManager->createNotification();
$this->notification->setApp('terms_of_service')
Expand All @@ -74,6 +73,7 @@ public function callForSeenUsers(IUser $user): void {
$this->logger->debug('User ' . $user->getUID() . ' already signed ToS');
return;
}
assert($this->notification !== null);

$this->notification->setUser($user->getUID());
$this->notificationsManager->notify($this->notification);
Expand Down
Loading
Loading