cleanup: Qualifier -> Imports (#125)

Fixes IDE warnings:

* Qualifier can be replaced with an import
* Argument matches the parameter's default value

Signed-off-by: Alexander Piskun <bigcat88@icloud.com>
This commit is contained in:
Alexander Piskun
2023-11-25 10:59:07 +03:00
committed by GitHub
parent b0e06fe4a1
commit 83333b5e0a
20 changed files with 66 additions and 48 deletions

View File

@ -19,7 +19,7 @@ class AppAPIAuthBackend implements BackendInterface {
) { ) {
} }
public function check(RequestInterface $request, ResponseInterface $response) { public function check(RequestInterface $request, ResponseInterface $response): array {
if ($this->request->getHeader('AUTHORIZATION-APP-API')) { if ($this->request->getHeader('AUTHORIZATION-APP-API')) {
$davAuthenticated = $this->session->get(Auth::DAV_AUTHENTICATED); $davAuthenticated = $this->session->get(Auth::DAV_AUTHENTICATED);
$userIdHeader = explode(':', base64_decode($this->request->getHeader('AUTHORIZATION-APP-API')), 2)[0]; $userIdHeader = explode(':', base64_decode($this->request->getHeader('AUTHORIZATION-APP-API')), 2)[0];

View File

@ -34,6 +34,7 @@ use OCP\SabrePluginEvent;
use OCP\User\Events\UserDeletedEvent; use OCP\User\Events\UserDeletedEvent;
use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface; use Psr\Container\NotFoundExceptionInterface;
use Throwable;
class Application extends App implements IBootstrap { class Application extends App implements IBootstrap {
public const APP_ID = 'app_api'; public const APP_ID = 'app_api';
@ -66,7 +67,7 @@ class Application extends App implements IBootstrap {
$profiler->add(new AppAPIDataCollector()); $profiler->add(new AppAPIDataCollector());
} }
$context->injectFn($this->registerExAppsManagementNavigation(...)); $context->injectFn($this->registerExAppsManagementNavigation(...));
} catch (NotFoundExceptionInterface|ContainerExceptionInterface|\Throwable) { } catch (NotFoundExceptionInterface|ContainerExceptionInterface|Throwable) {
} }
} }

View File

@ -64,7 +64,7 @@ class Deploy extends Command {
return 2; return 2;
} }
$defaultDaemonConfigName = $this->config->getAppValue(Application::APP_ID, 'default_daemon_config', ''); $defaultDaemonConfigName = $this->config->getAppValue(Application::APP_ID, 'default_daemon_config');
$daemonConfigName = $input->getArgument('daemon-config-name'); $daemonConfigName = $input->getArgument('daemon-config-name');
if (!isset($daemonConfigName) && $defaultDaemonConfigName !== '') { if (!isset($daemonConfigName) && $defaultDaemonConfigName !== '') {
$daemonConfigName = $defaultDaemonConfigName; $daemonConfigName = $defaultDaemonConfigName;

View File

@ -59,7 +59,7 @@ class Register extends Command {
return 2; return 2;
} }
$defaultDaemonConfigName = $this->config->getAppValue(Application::APP_ID, 'default_daemon_config', ''); $defaultDaemonConfigName = $this->config->getAppValue(Application::APP_ID, 'default_daemon_config');
$daemonConfigName = $input->getArgument('daemon-config-name'); $daemonConfigName = $input->getArgument('daemon-config-name');
if (!isset($daemonConfigName) && $defaultDaemonConfigName !== '') { if (!isset($daemonConfigName) && $defaultDaemonConfigName !== '') {
$daemonConfigName = $defaultDaemonConfigName; $daemonConfigName = $defaultDaemonConfigName;

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace OCA\AppAPI\Controller; namespace OCA\AppAPI\Controller;
use Exception;
use OC\App\AppStore\Fetcher\CategoryFetcher; use OC\App\AppStore\Fetcher\CategoryFetcher;
use OC\App\AppStore\Version\VersionParser; use OC\App\AppStore\Version\VersionParser;
use OC\App\DependencyAnalyzer; use OC\App\DependencyAnalyzer;
@ -34,6 +35,7 @@ use OCP\IL10N;
use OCP\IRequest; use OCP\IRequest;
use OCP\L10N\IFactory; use OCP\L10N\IFactory;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use SimpleXMLElement;
/** /**
* ExApps actions controller similar to default one with project-specific changes and additions * ExApps actions controller similar to default one with project-specific changes and additions
@ -96,7 +98,7 @@ class ExAppsPageController extends Controller {
*/ */
#[NoCSRFRequired] #[NoCSRFRequired]
public function viewApps(): TemplateResponse { public function viewApps(): TemplateResponse {
$defaultDaemonConfigName = $this->config->getAppValue(Application::APP_ID, 'default_daemon_config', ''); $defaultDaemonConfigName = $this->config->getAppValue(Application::APP_ID, 'default_daemon_config');
$appInitialData = [ $appInitialData = [
'appstoreEnabled' => $this->config->getSystemValueBool('appstoreenabled', true), 'appstoreEnabled' => $this->config->getSystemValueBool('appstoreenabled', true),
@ -142,7 +144,7 @@ class ExAppsPageController extends Controller {
* @param string $requestedCategory * @param string $requestedCategory
* @return array * @return array
* *
* @throws \Exception * @throws Exception
*/ */
private function getAppsForCategory(string $requestedCategory = ''): array { private function getAppsForCategory(string $requestedCategory = ''): array {
$versionParser = new VersionParser(); $versionParser = new VersionParser();
@ -498,13 +500,13 @@ class ExAppsPageController extends Controller {
} }
return new JSONResponse(['data' => ['update_required' => $updateRequired]]); return new JSONResponse(['data' => ['update_required' => $updateRequired]]);
} catch (\Exception $e) { } catch (Exception $e) {
$this->logger->error('Could not enable ExApps', ['exception' => $e]); $this->logger->error('Could not enable ExApps', ['exception' => $e]);
return new JSONResponse(['data' => ['message' => $e->getMessage()]], Http::STATUS_INTERNAL_SERVER_ERROR); return new JSONResponse(['data' => ['message' => $e->getMessage()]], Http::STATUS_INTERNAL_SERVER_ERROR);
} }
} }
private function deployExApp(string $appId, \SimpleXMLElement $infoXml, DaemonConfig $daemonConfig): bool { private function deployExApp(string $appId, SimpleXMLElement $infoXml, DaemonConfig $daemonConfig): bool {
$deployParams = $this->dockerActions->buildDeployParams($daemonConfig, $infoXml); $deployParams = $this->dockerActions->buildDeployParams($daemonConfig, $infoXml);
[$pullResult, $createResult, $startResult] = $this->dockerActions->deployExApp($daemonConfig, $deployParams); [$pullResult, $createResult, $startResult] = $this->dockerActions->deployExApp($daemonConfig, $deployParams);
@ -527,7 +529,7 @@ class ExAppsPageController extends Controller {
return true; return true;
} }
private function registerExApp(string $appId, \SimpleXMLElement $infoXml, DaemonConfig $daemonConfig): bool { private function registerExApp(string $appId, SimpleXMLElement $infoXml, DaemonConfig $daemonConfig): bool {
$exAppInfo = $this->dockerActions->loadExAppInfo($appId, $daemonConfig); $exAppInfo = $this->dockerActions->loadExAppInfo($appId, $daemonConfig);
$exApp = $this->service->registerExApp($appId, [ $exApp = $this->service->registerExApp($appId, [
@ -603,7 +605,7 @@ class ExAppsPageController extends Controller {
} }
} }
return new JSONResponse([]); return new JSONResponse([]);
} catch (\Exception $e) { } catch (Exception $e) {
$this->logger->error('Could not disable ExApp', ['exception' => $e]); $this->logger->error('Could not disable ExApp', ['exception' => $e]);
return new JSONResponse(['data' => ['message' => $e->getMessage()]], Http::STATUS_INTERNAL_SERVER_ERROR); return new JSONResponse(['data' => ['message' => $e->getMessage()]], Http::STATUS_INTERNAL_SERVER_ERROR);
} }
@ -695,11 +697,11 @@ class ExAppsPageController extends Controller {
/** /**
* @param ExApp $exApp * @param ExApp $exApp
* @param \SimpleXMLElement $infoXml * @param SimpleXMLElement $infoXml
* *
* @return void * @return void
*/ */
private function upgradeExAppScopes(ExApp $exApp, \SimpleXMLElement $infoXml): void { private function upgradeExAppScopes(ExApp $exApp, SimpleXMLElement $infoXml): void {
$newExAppScopes = $this->service->getExAppRequestedScopes($exApp, $infoXml); $newExAppScopes = $this->service->getExAppRequestedScopes($exApp, $infoXml);
$newExAppScopes = array_merge( $newExAppScopes = array_merge(

View File

@ -16,6 +16,7 @@ use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCS\OCSBadRequestException; use OCP\AppFramework\OCS\OCSBadRequestException;
use OCP\AppFramework\OCSController; use OCP\AppFramework\OCSController;
use OCP\IRequest; use OCP\IRequest;
use Psr\Log\InvalidArgumentException;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
class OCSApiController extends OCSController { class OCSApiController extends OCSController {
@ -63,7 +64,7 @@ class OCSApiController extends OCSController {
'app' => $appId, 'app' => $appId,
]); ]);
return new DataResponse(); return new DataResponse();
} catch (\Psr\Log\InvalidArgumentException) { } catch (InvalidArgumentException) {
$this->logger->error('Invalid log level'); $this->logger->error('Invalid log level');
throw new OCSBadRequestException('Invalid log level'); throw new OCSBadRequestException('Invalid log level');
} }

View File

@ -37,7 +37,7 @@ class AIODockerActions {
* @return DaemonConfig|null * @return DaemonConfig|null
*/ */
public function registerAIODaemonConfig(): ?DaemonConfig { public function registerAIODaemonConfig(): ?DaemonConfig {
$defaultDaemonConfig = $this->config->getAppValue(Application::APP_ID, 'default_daemon_config', ''); $defaultDaemonConfig = $this->config->getAppValue(Application::APP_ID, 'default_daemon_config');
if ($defaultDaemonConfig !== '') { if ($defaultDaemonConfig !== '') {
$daemonConfig = $this->daemonConfigService->getDaemonConfigByName(self::AIO_DAEMON_CONFIG_NAME); $daemonConfig = $this->daemonConfigService->getDaemonConfigByName(self::AIO_DAEMON_CONFIG_NAME);
if ($daemonConfig !== null) { if ($daemonConfig !== null) {

View File

@ -18,6 +18,7 @@ use OCP\IConfig;
use OCP\IURLGenerator; use OCP\IURLGenerator;
use OCP\Security\ISecureRandom; use OCP\Security\ISecureRandom;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use SimpleXMLElement;
class DockerActions implements IDeployActions { class DockerActions implements IDeployActions {
public const DOCKER_API_VERSION = 'v1.41'; public const DOCKER_API_VERSION = 'v1.41';
@ -327,7 +328,7 @@ class DockerActions implements IDeployActions {
return [$stopResult, $removeResult]; return [$stopResult, $removeResult];
} }
public function buildDeployParams(DaemonConfig $daemonConfig, \SimpleXMLElement $infoXml, array $params = []): array { public function buildDeployParams(DaemonConfig $daemonConfig, SimpleXMLElement $infoXml, array $params = []): array {
$appId = (string) $infoXml->id; $appId = (string) $infoXml->id;
$deployConfig = $daemonConfig->getDeployConfig(); $deployConfig = $daemonConfig->getDeployConfig();

View File

@ -4,12 +4,13 @@ declare(strict_types=1);
namespace OCA\AppAPI\Exceptions; namespace OCA\AppAPI\Exceptions;
use Exception;
use OCP\AppFramework\Http; use OCP\AppFramework\Http;
/** /**
* @package OCA\AppAPI\Exceptions * @package OCA\AppAPI\Exceptions
*/ */
class AppAPIAuthNotValidException extends \Exception { class AppAPIAuthNotValidException extends Exception {
public function __construct($message = 'AppAPIAuth failed', $code = Http::STATUS_UNAUTHORIZED) { public function __construct($message = 'AppAPIAuth failed', $code = Http::STATUS_UNAUTHORIZED) {
parent::__construct($message, $code); parent::__construct($message, $code);
} }

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace OCA\AppAPI\Fetcher; namespace OCA\AppAPI\Fetcher;
use Exception;
use GuzzleHttp\Exception\ConnectException; use GuzzleHttp\Exception\ConnectException;
use OC\Files\AppData\Factory; use OC\Files\AppData\Factory;
use OCA\AppAPI\AppInfo\Application; use OCA\AppAPI\AppInfo\Application;
@ -45,7 +46,7 @@ abstract class AppAPIFetcher {
* @param string $ETag * @param string $ETag
* @param string $content * @param string $content
* *
* @throws \Exception * @throws Exception
* @return array * @return array
*/ */
protected function fetch(string $ETag, string $content): array { protected function fetch(string $ETag, string $content): array {
@ -160,7 +161,7 @@ abstract class AppAPIFetcher {
} catch (ConnectException $e) { } catch (ConnectException $e) {
$this->logger->warning('Could not connect to appstore: ' . $e->getMessage(), ['app' => 'appstoreFetcher']); $this->logger->warning('Could not connect to appstore: ' . $e->getMessage(), ['app' => 'appstoreFetcher']);
return []; return [];
} catch (\Exception $e) { } catch (Exception $e) {
$this->logger->warning($e->getMessage(), [ $this->logger->warning($e->getMessage(), [
'exception' => $e, 'exception' => $e,
'app' => 'appstoreFetcher', 'app' => 'appstoreFetcher',

View File

@ -4,10 +4,12 @@ declare(strict_types=1);
namespace OCA\AppAPI\Fetcher; namespace OCA\AppAPI\Fetcher;
use Exception;
use OC\Archive\TAR; use OC\Archive\TAR;
use OCP\Http\Client\IClientService; use OCP\Http\Client\IClientService;
use OCP\ITempManager; use OCP\ITempManager;
use phpseclib\File\X509; use phpseclib\File\X509;
use SimpleXMLElement;
/** /**
* ExApps release archive fetcher with the same logic as for default (signature check). * ExApps release archive fetcher with the same logic as for default (signature check).
@ -26,9 +28,9 @@ class ExAppArchiveFetcher {
* *
* @param array $exAppAppstoreData * @param array $exAppAppstoreData
* *
* @return \SimpleXMLElement|null * @return SimpleXMLElement|null
*/ */
public function downloadInfoXml(array $exAppAppstoreData): ?\SimpleXMLElement { public function downloadInfoXml(array $exAppAppstoreData): ?SimpleXMLElement {
// 1. Signature check // 1. Signature check
if (!$this->checkExAppSignature($exAppAppstoreData)) { if (!$this->checkExAppSignature($exAppAppstoreData)) {
return null; return null;
@ -99,12 +101,12 @@ class ExAppArchiveFetcher {
} }
$crl->loadCRL(file_get_contents(\OC::$SERVERROOT . '/resources/codesigning/root.crl')); $crl->loadCRL(file_get_contents(\OC::$SERVERROOT . '/resources/codesigning/root.crl'));
if ($crl->validateSignature() !== true) { if ($crl->validateSignature() !== true) {
throw new \Exception('Could not validate CRL signature'); throw new Exception('Could not validate CRL signature');
} }
$csn = $loadedCertificate['tbsCertificate']['serialNumber']->toString(); $csn = $loadedCertificate['tbsCertificate']['serialNumber']->toString();
$revoked = $crl->getRevoked($csn); $revoked = $crl->getRevoked($csn);
if ($revoked !== false) { if ($revoked !== false) {
throw new \Exception( throw new Exception(
sprintf( sprintf(
'Certificate "%s" has been revoked', 'Certificate "%s" has been revoked',
$csn $csn
@ -114,7 +116,7 @@ class ExAppArchiveFetcher {
// Verify if the certificate has been issued by the Nextcloud Code Authority CA // Verify if the certificate has been issued by the Nextcloud Code Authority CA
if ($certificate->validateSignature() !== true) { if ($certificate->validateSignature() !== true) {
throw new \Exception( throw new Exception(
sprintf( sprintf(
'App with id %s has a certificate not issued by a trusted Code Signing Authority', 'App with id %s has a certificate not issued by a trusted Code Signing Authority',
$appId $appId
@ -125,7 +127,7 @@ class ExAppArchiveFetcher {
// Verify if the certificate is issued for the requested app id // Verify if the certificate is issued for the requested app id
$certInfo = openssl_x509_parse($exAppAppstoreData['certificate']); $certInfo = openssl_x509_parse($exAppAppstoreData['certificate']);
if (!isset($certInfo['subject']['CN'])) { if (!isset($certInfo['subject']['CN'])) {
throw new \Exception( throw new Exception(
sprintf( sprintf(
'App with id %s has a cert with no CN', 'App with id %s has a cert with no CN',
$appId $appId
@ -133,7 +135,7 @@ class ExAppArchiveFetcher {
); );
} }
if ($certInfo['subject']['CN'] !== $appId) { if ($certInfo['subject']['CN'] !== $appId) {
throw new \Exception( throw new Exception(
sprintf( sprintf(
'App with id %s has a cert issued to %s', 'App with id %s has a cert issued to %s',
$appId, $appId,

View File

@ -4,6 +4,8 @@ declare(strict_types=1);
namespace OCA\AppAPI\Fetcher; namespace OCA\AppAPI\Fetcher;
use Exception;
use InvalidArgumentException;
use OC\App\AppStore\Version\VersionParser; use OC\App\AppStore\Version\VersionParser;
use OC\App\CompareVersion; use OC\App\CompareVersion;
use OC\Files\AppData\Factory; use OC\Files\AppData\Factory;
@ -49,7 +51,7 @@ class ExAppFetcher extends AppAPIFetcher {
* @param string $content * @param string $content
* @param bool $allowUnstable [$allowUnstable] Allow unstable releases * @param bool $allowUnstable [$allowUnstable] Allow unstable releases
* *
* @throws \Exception * @throws Exception
* @return array * @return array
*/ */
protected function fetch(string $ETag, string $content, bool $allowUnstable = false): array { protected function fetch(string $ETag, string $content, bool $allowUnstable = false): array {
@ -102,7 +104,7 @@ class ExAppFetcher extends AppAPIFetcher {
if ($minFulfilled && ($this->ignoreMaxVersion || $maxFulfilled) && $isPhpCompatible) { if ($minFulfilled && ($this->ignoreMaxVersion || $maxFulfilled) && $isPhpCompatible) {
$releases[] = $release; $releases[] = $release;
} }
} catch (\InvalidArgumentException $e) { } catch (InvalidArgumentException $e) {
$this->logger->warning($e->getMessage(), [ $this->logger->warning($e->getMessage(), [
'exception' => $e, 'exception' => $e,
]); ]);

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace OCA\AppAPI\Listener; namespace OCA\AppAPI\Listener;
use Exception;
use OCA\AppAPI\Service\ExAppUsersService; use OCA\AppAPI\Service\ExAppUsersService;
use OCP\EventDispatcher\Event; use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener; use OCP\EventDispatcher\IEventListener;
@ -30,7 +31,7 @@ class UserDeletedListener implements IEventListener {
// Delete ExApp user record on user deletion // Delete ExApp user record on user deletion
try { try {
$this->exAppUsersService->removeDeletedUser($event->getUser()->getUID()); $this->exAppUsersService->removeDeletedUser($event->getUser()->getUID());
} catch (\Exception $e) { } catch (Exception $e) {
// Ignore exceptions // Ignore exceptions
$this->logger->info('Could not delete ExApp user ' . $event->getUser()->getUID(), [ $this->logger->info('Could not delete ExApp user ' . $event->getUser()->getUID(), [
'exception' => $e, 'exception' => $e,

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace OCA\AppAPI\Middleware; namespace OCA\AppAPI\Middleware;
use Exception;
use OCA\AppAPI\Attribute\AppAPIAuth; use OCA\AppAPI\Attribute\AppAPIAuth;
use OCA\AppAPI\Exceptions\AppAPIAuthNotValidException; use OCA\AppAPI\Exceptions\AppAPIAuthNotValidException;
use OCA\AppAPI\Service\AppAPIService; use OCA\AppAPI\Service\AppAPIService;
@ -46,11 +47,11 @@ class AppAPIAuthMiddleware extends Middleware {
* @param Controller $controller the controller that is being called * @param Controller $controller the controller that is being called
* @param string $methodName the name of the method that will be called on * @param string $methodName the name of the method that will be called on
* the controller * the controller
* @param \Exception $exception the thrown exception * @param Exception $exception the thrown exception
* @return Response a Response object or null in case that the exception could not be handled * @return Response a Response object or null in case that the exception could not be handled
* @throws \Exception the passed in exception if it can't handle it * @throws Exception the passed in exception if it can't handle it
*/ */
public function afterException($controller, $methodName, \Exception $exception): Response { public function afterException($controller, $methodName, Exception $exception): Response {
if ($exception instanceof AppAPIAuth) { if ($exception instanceof AppAPIAuth) {
$response = new JSONResponse([ $response = new JSONResponse([
'message' => $exception->getMessage(), 'message' => $exception->getMessage(),

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace OCA\AppAPI\Notifications; namespace OCA\AppAPI\Notifications;
use InvalidArgumentException;
use OCA\AppAPI\AppInfo\Application; use OCA\AppAPI\AppInfo\Application;
use OCA\AppAPI\Service\AppAPIService; use OCA\AppAPI\Service\AppAPIService;
use OCP\IURLGenerator; use OCP\IURLGenerator;
@ -33,10 +34,10 @@ class ExAppAdminNotifier implements INotifier {
// TODO: Think about another possible admin ExApp notifications, make them unified // TODO: Think about another possible admin ExApp notifications, make them unified
// TODO: Think about ExApp rich objects // TODO: Think about ExApp rich objects
if ($exApp === null || $notification->getSubject() !== 'ex_app_version_update') { if ($exApp === null || $notification->getSubject() !== 'ex_app_version_update') {
throw new \InvalidArgumentException(); throw new InvalidArgumentException();
} }
if ($exApp->getEnabled()) { if ($exApp->getEnabled()) {
throw new \InvalidArgumentException('ExApp is probably already re-enabled'); throw new InvalidArgumentException('ExApp is probably already re-enabled');
} }
$parameters = $notification->getSubjectParameters(); $parameters = $notification->getSubjectParameters();

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace OCA\AppAPI\Notifications; namespace OCA\AppAPI\Notifications;
use InvalidArgumentException;
use OCA\AppAPI\AppInfo\Application; use OCA\AppAPI\AppInfo\Application;
use OCA\AppAPI\Service\AppAPIService; use OCA\AppAPI\Service\AppAPIService;
use OCP\IURLGenerator; use OCP\IURLGenerator;
@ -31,12 +32,12 @@ class ExAppNotifier implements INotifier {
public function prepare(INotification $notification, string $languageCode): INotification { public function prepare(INotification $notification, string $languageCode): INotification {
$exApp = $this->service->getExApp($notification->getApp()); $exApp = $this->service->getExApp($notification->getApp());
if ($exApp === null) { if ($exApp === null) {
throw new \InvalidArgumentException(); throw new InvalidArgumentException();
} }
if ($notification->getSubject() === 'ex_app_version_update' && $exApp->getEnabled()) { if ($notification->getSubject() === 'ex_app_version_update' && $exApp->getEnabled()) {
throw new \InvalidArgumentException('ExApp is probably already re-enabled'); throw new InvalidArgumentException('ExApp is probably already re-enabled');
} elseif (!$exApp->getEnabled()) { // Only enabled ExApps can render notifications } elseif (!$exApp->getEnabled()) { // Only enabled ExApps can render notifications
throw new \InvalidArgumentException('ExApp is disabled'); throw new InvalidArgumentException('ExApp is disabled');
} }
$parameters = $notification->getSubjectParameters(); $parameters = $notification->getSubjectParameters();

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace OCA\AppAPI\Notifications; namespace OCA\AppAPI\Notifications;
use DateTime;
use OCP\IGroupManager; use OCP\IGroupManager;
use OCP\Notification\IManager; use OCP\Notification\IManager;
use OCP\Notification\INotification; use OCP\Notification\INotification;
@ -29,7 +30,7 @@ class ExNotificationsManager {
$notification $notification
->setApp($appId) ->setApp($appId)
->setUser($userId) ->setUser($userId)
->setDateTime(new \DateTime()) ->setDateTime(new DateTime())
->setObject($params['object'], $params['object_id']) ->setObject($params['object'], $params['object_id'])
->setSubject($params['subject_type'], $params['subject_params']); ->setSubject($params['subject_type'], $params['subject_params']);
$this->notificationManager->notify($notification); $this->notificationManager->notify($notification);
@ -44,7 +45,7 @@ class ExNotificationsManager {
$notification $notification
->setApp($appId) ->setApp($appId)
->setUser($adminUser->getUID()) ->setUser($adminUser->getUID())
->setDateTime(new \DateTime()) ->setDateTime(new DateTime())
->setObject($params['object'], $params['object_id']) ->setObject($params['object'], $params['object_id'])
->setSubject($params['subject_type'], $params['subject_params']); ->setSubject($params['subject_type'], $params['subject_params']);
$this->notificationManager->notify($notification); $this->notificationManager->notify($notification);

View File

@ -10,6 +10,7 @@ use OCA\AppAPI\AppInfo\Application;
use OCP\AppFramework\Http\Response; use OCP\AppFramework\Http\Response;
use OCP\DataCollector\AbstractDataCollector; use OCP\DataCollector\AbstractDataCollector;
use Throwable;
/** /**
* @psalm-suppress UndefinedClass * @psalm-suppress UndefinedClass
@ -19,7 +20,7 @@ class AppAPIDataCollector extends AbstractDataCollector {
return Application::APP_ID; return Application::APP_ID;
} }
public function collect(Request $request, Response $response, \Throwable $exception = null): void { public function collect(Request $request, Response $response, Throwable $exception = null): void {
$headers = []; $headers = [];
$aeHeadersList = [ $aeHeadersList = [
'AA-VERSION', 'AA-VERSION',

View File

@ -30,6 +30,7 @@ use OCP\Log\ILogFactory;
use OCP\Security\Bruteforce\IThrottler; use OCP\Security\Bruteforce\IThrottler;
use OCP\Security\ISecureRandom; use OCP\Security\ISecureRandom;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use SimpleXMLElement;
class AppAPIService { class AppAPIService {
public const BASIC_API_SCOPE = 1; public const BASIC_API_SCOPE = 1;
@ -392,7 +393,7 @@ class AppAPIService {
} }
} }
public function getExAppRequestedScopes(ExApp $exApp, ?\SimpleXMLElement $infoXml = null, array $jsonInfo = []): ?array { public function getExAppRequestedScopes(ExApp $exApp, ?SimpleXMLElement $infoXml = null, array $jsonInfo = []): ?array {
if (isset($jsonInfo['scopes'])) { if (isset($jsonInfo['scopes'])) {
return $jsonInfo['scopes']; return $jsonInfo['scopes'];
} }
@ -429,9 +430,9 @@ class AppAPIService {
* *
* @param ExApp $exApp * @param ExApp $exApp
* *
* @return \SimpleXMLElement|null * @return SimpleXMLElement|null
*/ */
public function getExAppInfoFromAppstore(ExApp $exApp): ?\SimpleXMLElement { public function getExAppInfoFromAppstore(ExApp $exApp): ?SimpleXMLElement {
$exApps = $this->exAppFetcher->get(); $exApps = $this->exAppFetcher->get();
$exAppAppstoreData = array_filter($exApps, function (array $exAppItem) use ($exApp) { $exAppAppstoreData = array_filter($exApps, function (array $exAppItem) use ($exApp) {
return $exAppItem['id'] === $exApp->getAppid() && count(array_filter($exAppItem['releases'], function (array $release) use ($exApp) { return $exAppItem['id'] === $exApp->getAppid() && count(array_filter($exAppItem['releases'], function (array $release) use ($exApp) {
@ -449,9 +450,9 @@ class AppAPIService {
* *
* @param string $appId * @param string $appId
* *
* @return \SimpleXMLElement|null * @return SimpleXMLElement|null
*/ */
public function getLatestExAppInfoFromAppstore(string $appId): ?\SimpleXMLElement { public function getLatestExAppInfoFromAppstore(string $appId): ?SimpleXMLElement {
$exApps = $this->exAppFetcher->get(); $exApps = $this->exAppFetcher->get();
$exAppAppstoreData = array_filter($exApps, function (array $exAppItem) use ($appId) { $exAppAppstoreData = array_filter($exApps, function (array $exAppItem) use ($appId) {
return $exAppItem['id'] === $appId && count($exAppItem['releases']) > 0; return $exAppItem['id'] === $appId && count($exAppItem['releases']) > 0;
@ -790,7 +791,7 @@ class AppAPIService {
return true; return true;
} }
public function updateExAppLastCheckTime(ExApp &$exApp): void { public function updateExAppLastCheckTime(ExApp $exApp): void {
$exApp->setLastCheckTime(time()); $exApp->setLastCheckTime(time());
try { try {
$this->exAppMapper->updateLastCheckTime($exApp); $this->exAppMapper->updateLastCheckTime($exApp);
@ -831,7 +832,7 @@ class AppAPIService {
* *
* @return bool * @return bool
*/ */
public function handleExAppVersionChange(IRequest $request, ExApp &$exApp): bool { public function handleExAppVersionChange(IRequest $request, ExApp $exApp): bool {
$requestExAppVersion = $request->getHeader('EX-APP-VERSION'); $requestExAppVersion = $request->getHeader('EX-APP-VERSION');
$versionValid = $exApp->getVersion() === $requestExAppVersion; $versionValid = $exApp->getVersion() === $requestExAppVersion;
if (!$versionValid) { if (!$versionValid) {

View File

@ -51,11 +51,11 @@ class Admin implements ISettings {
}, $this->daemonConfigService->getRegisteredDaemonConfigs()); }, $this->daemonConfigService->getRegisteredDaemonConfigs());
$adminInitialData = [ $adminInitialData = [
'daemons' => $daemons, 'daemons' => $daemons,
'default_daemon_config' => $this->config->getAppValue(Application::APP_ID, 'default_daemon_config', ''), 'default_daemon_config' => $this->config->getAppValue(Application::APP_ID, 'default_daemon_config'),
'updates_count' => count($this->getExAppsWithUpdates()), 'updates_count' => count($this->getExAppsWithUpdates()),
]; ];
$defaultDaemonConfigName = $this->config->getAppValue(Application::APP_ID, 'default_daemon_config', ''); $defaultDaemonConfigName = $this->config->getAppValue(Application::APP_ID, 'default_daemon_config');
if ($defaultDaemonConfigName !== '') { if ($defaultDaemonConfigName !== '') {
$daemonConfig = $this->daemonConfigService->getDaemonConfigByName($defaultDaemonConfigName); $daemonConfig = $this->daemonConfigService->getDaemonConfigByName($defaultDaemonConfigName);
if ($daemonConfig !== null) { if ($daemonConfig !== null) {