mirror of
https://github.com/nextcloud/richdocuments.git
synced 2025-12-18 05:20:43 +01:00
chore: Apply rector fixes
Signed-off-by: Julius Knorr <jus@bitgrid.net>
This commit is contained in:
parent
dd7e2e551f
commit
62c6c0443f
38 changed files with 176 additions and 495 deletions
|
|
@ -112,7 +112,7 @@ class AppConfig {
|
|||
|
||||
$keys = $this->config->getAppKeys(self::WATERMARK_APP_NAMESPACE);
|
||||
foreach ($keys as $key) {
|
||||
if (strpos($key, 'watermark_') === 0) {
|
||||
if (str_starts_with($key, 'watermark_')) {
|
||||
$value = $this->getAppValueArray($key);
|
||||
$value = $value === 'yes' ? true : $value;
|
||||
$result[$key] = $value === 'no' ? false : $value;
|
||||
|
|
@ -209,22 +209,18 @@ class AppConfig {
|
|||
}
|
||||
|
||||
$federationService = \OCP\Server::get(FederationService::class);
|
||||
$trustedNextcloudDomains = array_filter(array_map(function ($server) use ($federationService) {
|
||||
return $federationService->isTrustedRemote($server) ? $server : null;
|
||||
}, $federationService->getTrustedServers()));
|
||||
$trustedNextcloudDomains = array_filter(array_map(fn ($server) => $federationService->isTrustedRemote($server) ? $server : null, $federationService->getTrustedServers()));
|
||||
|
||||
$trustedCollaboraDomains = array_filter(array_map(function ($server) use ($federationService) {
|
||||
try {
|
||||
return $federationService->getRemoteCollaboraURL($server);
|
||||
} catch (\Exception $e) {
|
||||
} catch (\Exception) {
|
||||
// If there is no remote collabora server we can just skip that
|
||||
return null;
|
||||
}
|
||||
}, $trustedNextcloudDomains));
|
||||
|
||||
return array_map(function ($url) {
|
||||
return $this->domainOnly($url);
|
||||
}, array_merge($trustedNextcloudDomains, $trustedCollaboraDomains));
|
||||
return array_map(fn ($url) => $this->domainOnly($url), array_merge($trustedNextcloudDomains, $trustedCollaboraDomains));
|
||||
}
|
||||
|
||||
private function getGSDomains(): array {
|
||||
|
|
|
|||
|
|
@ -13,15 +13,8 @@ use OCP\DB\QueryBuilder\IQueryBuilder;
|
|||
use OCP\IDBConnection;
|
||||
|
||||
class Cleanup extends TimedJob {
|
||||
/** @var IDBConnection */
|
||||
private $db;
|
||||
/** @var WopiMapper $wopiMapper */
|
||||
private $wopiMapper;
|
||||
|
||||
public function __construct(ITimeFactory $time, IDBConnection $db, WopiMapper $wopiMapper) {
|
||||
public function __construct(ITimeFactory $time, private IDBConnection $db, private WopiMapper $wopiMapper) {
|
||||
parent::__construct($time);
|
||||
$this->db = $db;
|
||||
$this->wopiMapper = $wopiMapper;
|
||||
|
||||
$this->setInterval(60 * 60);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,11 +13,7 @@ use Symfony\Component\Console\Input\InputInterface;
|
|||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class UpdateEmptyTemplates extends Command {
|
||||
/** @var TemplateManager */
|
||||
private $templateManager;
|
||||
|
||||
public function __construct(TemplateManager $templateManager) {
|
||||
$this->templateManager = $templateManager;
|
||||
public function __construct(private TemplateManager $templateManager) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,26 +22,14 @@ use OCP\IRequest;
|
|||
use OCP\IURLGenerator;
|
||||
|
||||
class AssetsController extends Controller {
|
||||
private AssetMapper $assetMapper;
|
||||
private IRootFolder $rootFolder;
|
||||
private ?string $userId;
|
||||
private UserScopeService $userScopeService;
|
||||
private IURLGenerator $urlGenerator;
|
||||
|
||||
public function __construct($appName,
|
||||
IRequest $request,
|
||||
AssetMapper $assetMapper,
|
||||
IRootFolder $rootFolder,
|
||||
$userId,
|
||||
UserScopeService $userScopeService,
|
||||
IURLGenerator $urlGenerator) {
|
||||
private AssetMapper $assetMapper,
|
||||
private IRootFolder $rootFolder,
|
||||
private ?string $userId,
|
||||
private UserScopeService $userScopeService,
|
||||
private IURLGenerator $urlGenerator) {
|
||||
parent::__construct($appName, $request);
|
||||
|
||||
$this->assetMapper = $assetMapper;
|
||||
$this->rootFolder = $rootFolder;
|
||||
$this->userId = $userId;
|
||||
$this->userScopeService = $userScopeService;
|
||||
$this->urlGenerator = $urlGenerator;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -56,7 +44,7 @@ class AssetsController extends Controller {
|
|||
|
||||
try {
|
||||
$node = $userFolder->get($path);
|
||||
} catch (NotFoundException $e) {
|
||||
} catch (NotFoundException) {
|
||||
return new JSONResponse([], Http::STATUS_NOT_FOUND);
|
||||
}
|
||||
|
||||
|
|
@ -80,7 +68,7 @@ class AssetsController extends Controller {
|
|||
public function get($token) {
|
||||
try {
|
||||
$asset = $this->assetMapper->getAssetByToken($token);
|
||||
} catch (DoesNotExistException $e) {
|
||||
} catch (DoesNotExistException) {
|
||||
return new DataResponse([], Http::STATUS_NOT_FOUND);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,23 +29,8 @@ use Psr\Log\LoggerInterface;
|
|||
use Throwable;
|
||||
|
||||
class DocumentAPIController extends \OCP\AppFramework\OCSController {
|
||||
private $rootFolder;
|
||||
private $shareManager;
|
||||
private $templateManager;
|
||||
private $l10n;
|
||||
private $logger;
|
||||
private $lockManager;
|
||||
private $userId;
|
||||
|
||||
public function __construct(IRequest $request, IRootFolder $rootFolder, IManager $shareManager, TemplateManager $templateManager, IL10N $l10n, LoggerInterface $logger, ILockManager $lockManager, $userId) {
|
||||
public function __construct(IRequest $request, private IRootFolder $rootFolder, private IManager $shareManager, private TemplateManager $templateManager, private IL10N $l10n, private LoggerInterface $logger, private ILockManager $lockManager, private $userId) {
|
||||
parent::__construct(Application::APPNAME, $request);
|
||||
$this->rootFolder = $rootFolder;
|
||||
$this->shareManager = $shareManager;
|
||||
$this->templateManager = $templateManager;
|
||||
$this->l10n = $l10n;
|
||||
$this->logger = $logger;
|
||||
$this->lockManager = $lockManager;
|
||||
$this->userId = $userId;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -153,9 +138,9 @@ class DocumentAPIController extends \OCP\AppFramework\OCSController {
|
|||
Application::APPNAME
|
||||
));
|
||||
return new DataResponse([]);
|
||||
} catch (NoLockProviderException|PreConditionNotMetException $e) {
|
||||
} catch (NoLockProviderException|PreConditionNotMetException) {
|
||||
return new DataResponse([], Http::STATUS_BAD_REQUEST);
|
||||
} catch (\Exception $e) {
|
||||
} catch (\Exception) {
|
||||
return new DataResponse([], Http::STATUS_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -169,7 +169,7 @@ class DocumentController extends Controller {
|
|||
$userFolder = $this->rootFolder->getUserFolder($this->userId);
|
||||
try {
|
||||
$folder = $userFolder->get($dir);
|
||||
} catch (NotFoundException $e) {
|
||||
} catch (NotFoundException) {
|
||||
return new TemplateResponse('core', '403', [], 'guest');
|
||||
}
|
||||
|
||||
|
|
@ -286,7 +286,7 @@ class DocumentController extends Controller {
|
|||
$response->addHeader('X-Frame-Options', 'ALLOW');
|
||||
return $response;
|
||||
}
|
||||
} catch (ShareNotFound $e) {
|
||||
} catch (ShareNotFound) {
|
||||
return new TemplateResponse('core', '404', [], 'guest');
|
||||
} catch (Exception $e) {
|
||||
$this->logger->error($e->getMessage(), ['exception' => $e]);
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ trait DocumentTrait {
|
|||
private function domainOnly(string $url): string {
|
||||
$parsed_url = parse_url($url);
|
||||
$scheme = isset($parsed_url['scheme']) ? $parsed_url['scheme'] . '://' : '';
|
||||
$host = isset($parsed_url['host']) ? $parsed_url['host'] : '';
|
||||
$host = $parsed_url['host'] ?? '';
|
||||
$port = isset($parsed_url['port']) ? ':' . $parsed_url['port'] : '';
|
||||
return "$scheme$host$port";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,36 +19,16 @@ use OCP\IUserManager;
|
|||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class FederationController extends OCSController {
|
||||
/** @var IConfig */
|
||||
private $config;
|
||||
|
||||
/** @var LoggerInterface */
|
||||
private $logger;
|
||||
|
||||
/** @var WopiMapper */
|
||||
private $wopiMapper;
|
||||
|
||||
/** @var IUserManager */
|
||||
private $userManager;
|
||||
|
||||
/** @var IURLGenerator */
|
||||
private $urlGenerator;
|
||||
|
||||
public function __construct(
|
||||
string $appName,
|
||||
IRequest $request,
|
||||
IConfig $config,
|
||||
LoggerInterface $logger,
|
||||
WopiMapper $wopiMapper,
|
||||
IUserManager $userManager,
|
||||
IURLGenerator $urlGenerator
|
||||
private IConfig $config,
|
||||
private LoggerInterface $logger,
|
||||
private WopiMapper $wopiMapper,
|
||||
private IUserManager $userManager,
|
||||
private IURLGenerator $urlGenerator
|
||||
) {
|
||||
parent::__construct($appName, $request);
|
||||
$this->config = $config;
|
||||
$this->logger = $logger;
|
||||
$this->wopiMapper = $wopiMapper;
|
||||
$this->userManager = $userManager;
|
||||
$this->urlGenerator = $urlGenerator;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -97,10 +77,10 @@ class FederationController extends OCSController {
|
|||
}
|
||||
$this->logger->debug('COOL-Federation-Initiator: Token ' . $token . ' returned');
|
||||
return new DataResponse($initiatorWopi);
|
||||
} catch (UnknownTokenException $e) {
|
||||
} catch (UnknownTokenException) {
|
||||
$this->logger->debug('COOL-Federation-Initiator: Token ' . $token . 'not found');
|
||||
throw new OCSNotFoundException();
|
||||
} catch (ExpiredTokenException $e) {
|
||||
} catch (ExpiredTokenException) {
|
||||
$this->logger->debug('COOL-Federation-Initiator: Token ' . $token . ' is expired');
|
||||
throw new OCSNotFoundException();
|
||||
}
|
||||
|
|
@ -132,10 +112,10 @@ class FederationController extends OCSController {
|
|||
'displayName' => $user->getDisplayName(),
|
||||
'avatar' => $this->urlGenerator->linkToRouteAbsolute('core.avatar.getAvatar', ['userId' => $wopi->getEditorUid(), 'size' => WopiController::WOPI_AVATAR_SIZE])
|
||||
]);
|
||||
} catch (UnknownTokenException $e) {
|
||||
} catch (UnknownTokenException) {
|
||||
$this->logger->debug('COOL-Federation-Initiator-User: Token ' . $token . 'not found');
|
||||
throw new OCSNotFoundException();
|
||||
} catch (ExpiredTokenException $e) {
|
||||
} catch (ExpiredTokenException) {
|
||||
$this->logger->debug('COOL-Federation-Initiator-User: Token ' . $token . ' is expired.');
|
||||
throw new OCSNotFoundException();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,56 +30,22 @@ use OCP\Share\IManager;
|
|||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class OCSController extends \OCP\AppFramework\OCSController {
|
||||
/** @var IRootFolder */
|
||||
private $rootFolder;
|
||||
|
||||
/** @var string */
|
||||
private $userId;
|
||||
|
||||
/** @var DirectMapper */
|
||||
private $directMapper;
|
||||
|
||||
/** @var IURLGenerator */
|
||||
private $urlGenerator;
|
||||
|
||||
/** @var TemplateManager */
|
||||
private $manager;
|
||||
|
||||
/** @var TokenManager */
|
||||
private $tokenManager;
|
||||
|
||||
/** @var IManager */
|
||||
private $shareManager;
|
||||
|
||||
/** @var FederationService */
|
||||
private $federationService;
|
||||
|
||||
/** @var LoggerInterface */
|
||||
private $logger;
|
||||
|
||||
/**
|
||||
* @param string $userId
|
||||
*/
|
||||
public function __construct(string $appName,
|
||||
IRequest $request,
|
||||
IRootFolder $rootFolder,
|
||||
$userId,
|
||||
DirectMapper $directMapper,
|
||||
IURLGenerator $urlGenerator,
|
||||
TemplateManager $manager,
|
||||
TokenManager $tokenManager,
|
||||
IManager $shareManager,
|
||||
FederationService $federationService,
|
||||
LoggerInterface $logger
|
||||
private IRootFolder $rootFolder,
|
||||
private $userId,
|
||||
private DirectMapper $directMapper,
|
||||
private IURLGenerator $urlGenerator,
|
||||
private TemplateManager $manager,
|
||||
private TokenManager $tokenManager,
|
||||
private IManager $shareManager,
|
||||
private FederationService $federationService,
|
||||
private LoggerInterface $logger
|
||||
) {
|
||||
parent::__construct($appName, $request);
|
||||
|
||||
$this->rootFolder = $rootFolder;
|
||||
$this->userId = $userId;
|
||||
$this->directMapper = $directMapper;
|
||||
$this->urlGenerator = $urlGenerator;
|
||||
$this->manager = $manager;
|
||||
$this->tokenManager = $tokenManager;
|
||||
$this->shareManager = $shareManager;
|
||||
$this->federationService = $federationService;
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -111,7 +77,7 @@ class OCSController extends \OCP\AppFramework\OCSController {
|
|||
'token' => $direct->getToken()
|
||||
])
|
||||
]);
|
||||
} catch (NotFoundException $e) {
|
||||
} catch (NotFoundException) {
|
||||
throw new OCSNotFoundException();
|
||||
}
|
||||
}
|
||||
|
|
@ -174,7 +140,7 @@ class OCSController extends \OCP\AppFramework\OCSController {
|
|||
|
||||
try {
|
||||
$share = $this->shareManager->getShareByToken($shareToken);
|
||||
} catch (ShareNotFound $ex) {
|
||||
} catch (ShareNotFound) {
|
||||
$response = new DataResponse([], HTTP::STATUS_NOT_FOUND);
|
||||
$response->throttle();
|
||||
return $response;
|
||||
|
|
@ -220,7 +186,7 @@ class OCSController extends \OCP\AppFramework\OCSController {
|
|||
): DataResponse {
|
||||
try {
|
||||
$share = $this->shareManager->getShareByToken($shareToken);
|
||||
} catch (ShareNotFound $ex) {
|
||||
} catch (ShareNotFound) {
|
||||
$response = new DataResponse([], HTTP::STATUS_NOT_FOUND);
|
||||
$response->throttle();
|
||||
return $response;
|
||||
|
|
@ -261,11 +227,11 @@ class OCSController extends \OCP\AppFramework\OCSController {
|
|||
try {
|
||||
$this->tokenManager->updateGuestName($access_token, $guestName);
|
||||
return new DataResponse([], Http::STATUS_OK);
|
||||
} catch (UnknownTokenException $e) {
|
||||
} catch (UnknownTokenException) {
|
||||
$response = new DataResponse([], Http::STATUS_FORBIDDEN);
|
||||
$response->throttle();
|
||||
return $response;
|
||||
} catch (ExpiredTokenException $e) {
|
||||
} catch (ExpiredTokenException) {
|
||||
$response = new DataResponse([], Http::STATUS_UNAUTHORIZED);
|
||||
$response->throttle();
|
||||
return $response;
|
||||
|
|
@ -318,7 +284,7 @@ class OCSController extends \OCP\AppFramework\OCSController {
|
|||
'token' => $direct->getToken()
|
||||
])
|
||||
]);
|
||||
} catch (NotFoundException $e) {
|
||||
} catch (NotFoundException) {
|
||||
throw new OCSNotFoundException();
|
||||
} catch (\Exception $e) {
|
||||
$this->logger->error($e->getMessage(), ['exception' => $e]);
|
||||
|
|
|
|||
|
|
@ -242,7 +242,7 @@ class SettingsController extends Controller {
|
|||
if ($templateFolder !== null) {
|
||||
try {
|
||||
$this->config->setUserValue($this->userId, 'richdocuments', 'templateFolder', $templateFolder);
|
||||
} catch (PreConditionNotMetException $e) {
|
||||
} catch (PreConditionNotMetException) {
|
||||
$message = $this->l10n->t('Error when saving');
|
||||
$status = 'error';
|
||||
}
|
||||
|
|
@ -250,7 +250,7 @@ class SettingsController extends Controller {
|
|||
if ($zoteroAPIKeyInput !== null) {
|
||||
try {
|
||||
$this->config->setUserValue($this->userId, 'richdocuments', 'zoteroAPIKey', $zoteroAPIKeyInput);
|
||||
} catch (PreConditionNotMetException $e) {
|
||||
} catch (PreConditionNotMetException) {
|
||||
$message = $this->l10n->t('Error when saving');
|
||||
$status = 'error';
|
||||
}
|
||||
|
|
@ -295,9 +295,7 @@ class SettingsController extends Controller {
|
|||
public function getJsonFontList() {
|
||||
$files = $this->fontService->getFontFiles();
|
||||
$etags = array_map(
|
||||
static function (ISimpleFile $f) {
|
||||
return $f->getETag();
|
||||
},
|
||||
static fn (ISimpleFile $f) => $f->getETag(),
|
||||
$files
|
||||
);
|
||||
$etag = md5(implode(',', $etags));
|
||||
|
|
@ -335,7 +333,7 @@ class SettingsController extends Controller {
|
|||
Http::STATUS_OK,
|
||||
['Content-Type' => $fontFile->getMimeType(), 'Etag' => $etag]
|
||||
);
|
||||
} catch (NotFoundException $e) {
|
||||
} catch (NotFoundException) {
|
||||
return new DataDisplayResponse('', Http::STATUS_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
|
|
@ -357,7 +355,7 @@ class SettingsController extends Controller {
|
|||
Http::STATUS_OK,
|
||||
['Content-Type' => 'image/png']
|
||||
);
|
||||
} catch (NotFoundException $e) {
|
||||
} catch (NotFoundException) {
|
||||
return new DataDisplayResponse('', Http::STATUS_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ class TargetController extends \OCP\AppFramework\OCSController {
|
|||
try {
|
||||
$file = $this->getFile($path);
|
||||
return new DataResponse($this->fileTargetService->getFileTargets($file));
|
||||
} catch (NotFoundException $e) {
|
||||
} catch (NotFoundException) {
|
||||
}
|
||||
|
||||
return new DataResponse('File not found', Http::STATUS_NOT_FOUND);
|
||||
|
|
@ -54,7 +54,7 @@ class TargetController extends \OCP\AppFramework\OCSController {
|
|||
Http::STATUS_OK,
|
||||
['Content-Type' => 'image/png']
|
||||
);
|
||||
} catch (NotFoundException $e) {
|
||||
} catch (NotFoundException) {
|
||||
return new DataResponse('File not found', Http::STATUS_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
|
|
@ -71,7 +71,7 @@ class TargetController extends \OCP\AppFramework\OCSController {
|
|||
}
|
||||
|
||||
return $file;
|
||||
} catch (NotFoundException|NotPermittedException|NoUserException $e) {
|
||||
} catch (NotFoundException|NotPermittedException|NoUserException) {
|
||||
throw new NotFoundException();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ class TemplateFieldController extends OCSController {
|
|||
$fields = $this->templateFieldService->extractFields($fileId);
|
||||
|
||||
return new DataResponse($fields, Http::STATUS_OK);
|
||||
} catch (\Exception $e) {
|
||||
} catch (\Exception) {
|
||||
return new DataResponse(['Unable to extract fields from given file'], Http::STATUS_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
|
@ -54,7 +54,7 @@ class TemplateFieldController extends OCSController {
|
|||
}
|
||||
|
||||
return new DataResponse([], Http::STATUS_OK);
|
||||
} catch (\Exception $e) {
|
||||
} catch (\Exception) {
|
||||
return new DataResponse(['Unable to fill fields into the given file'], Http::STATUS_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,12 +26,6 @@ use OCP\IRequest;
|
|||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class TemplatesController extends Controller {
|
||||
private IL10N $l10n;
|
||||
private TemplateManager $manager;
|
||||
private IPreview $preview;
|
||||
private IMimeTypeDetector $mimeTypeDetector;
|
||||
private LoggerInterface $logger;
|
||||
|
||||
/** @var int Max template size */
|
||||
private $maxSize = 20 * 1024 * 1024;
|
||||
|
||||
|
|
@ -46,21 +40,16 @@ class TemplatesController extends Controller {
|
|||
*/
|
||||
public function __construct($appName,
|
||||
IRequest $request,
|
||||
IL10N $l10n,
|
||||
TemplateManager $manager,
|
||||
IPreview $preview,
|
||||
IMimeTypeDetector $mimeTypeDetector,
|
||||
LoggerInterface $logger
|
||||
private IL10N $l10n,
|
||||
private TemplateManager $manager,
|
||||
private IPreview $preview,
|
||||
private IMimeTypeDetector $mimeTypeDetector,
|
||||
private LoggerInterface $logger
|
||||
) {
|
||||
parent::__construct($appName, $request);
|
||||
|
||||
$this->appName = $appName;
|
||||
$this->request = $request;
|
||||
$this->l10n = $l10n;
|
||||
$this->manager = $manager;
|
||||
$this->preview = $preview;
|
||||
$this->mimeTypeDetector = $mimeTypeDetector;
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -91,7 +80,7 @@ class TemplatesController extends Controller {
|
|||
|
||||
try {
|
||||
$template = $this->manager->get($fileId);
|
||||
} catch (NotFoundException $e) {
|
||||
} catch (NotFoundException) {
|
||||
return new DataResponse([], Http::STATUS_NOT_FOUND);
|
||||
}
|
||||
|
||||
|
|
@ -171,7 +160,7 @@ class TemplatesController extends Controller {
|
|||
['data' => ['status' => 'success']],
|
||||
Http::STATUS_NO_CONTENT
|
||||
);
|
||||
} catch (NotFoundException $e) {
|
||||
} catch (NotFoundException) {
|
||||
return new JSONResponse(
|
||||
['data' => ['message' => $this->l10n->t('Template not found')]],
|
||||
Http::STATUS_NOT_FOUND
|
||||
|
|
@ -208,9 +197,9 @@ class TemplatesController extends Controller {
|
|||
$response->cacheFor(3600 * 24);
|
||||
|
||||
return $response;
|
||||
} catch (NotFoundException $e) {
|
||||
} catch (NotFoundException) {
|
||||
return new DataResponse([], Http::STATUS_NOT_FOUND);
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
} catch (\InvalidArgumentException) {
|
||||
return new DataResponse([], Http::STATUS_BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -109,10 +109,7 @@ class WopiController extends Controller {
|
|||
if (!($file instanceof File)) {
|
||||
throw new NotFoundException('No valid file found for ' . $fileId);
|
||||
}
|
||||
} catch (NotFoundException $e) {
|
||||
$this->logger->debug($e->getMessage(), ['exception' => $e]);
|
||||
return new JSONResponse([], Http::STATUS_FORBIDDEN);
|
||||
} catch (UnknownTokenException $e) {
|
||||
} catch (NotFoundException|UnknownTokenException $e) {
|
||||
$this->logger->debug($e->getMessage(), ['exception' => $e]);
|
||||
return new JSONResponse([], Http::STATUS_FORBIDDEN);
|
||||
} catch (ExpiredTokenException $e) {
|
||||
|
|
@ -188,9 +185,7 @@ class WopiController extends Controller {
|
|||
'email' => $email,
|
||||
];
|
||||
$watermarkTemplate = $this->appConfig->getAppValue('watermark_text');
|
||||
$response['WatermarkText'] = preg_replace_callback('/{(.+?)}/', function ($matches) use ($replacements) {
|
||||
return $replacements[$matches[1]];
|
||||
}, $watermarkTemplate);
|
||||
$response['WatermarkText'] = preg_replace_callback('/{(.+?)}/', fn ($matches) => $replacements[$matches[1]], $watermarkTemplate);
|
||||
}
|
||||
|
||||
$user = $this->userManager->get($wopi->getEditorUid());
|
||||
|
|
@ -463,9 +458,7 @@ class WopiController extends Controller {
|
|||
if ($freespace >= 0 && $contentLength > $freespace) {
|
||||
throw new \Exception('Not enough storage');
|
||||
}
|
||||
$this->wrappedFilesystemOperation($wopi, function () use ($file, $content) {
|
||||
return $file->putContent($content);
|
||||
});
|
||||
$this->wrappedFilesystemOperation($wopi, fn () => $file->putContent($content));
|
||||
} catch (LockedException $e) {
|
||||
$this->logger->error($e->getMessage(), ['exception' => $e]);
|
||||
return new JSONResponse(['message' => 'File locked'], Http::STATUS_INTERNAL_SERVER_ERROR);
|
||||
|
|
@ -566,9 +559,9 @@ class WopiController extends Controller {
|
|||
|
||||
$suggested = mb_convert_encoding($suggested, 'utf-8', 'utf-7') . '.' . $file->getExtension();
|
||||
|
||||
if (strpos($suggested, '.') === 0) {
|
||||
if (str_starts_with($suggested, '.')) {
|
||||
$path = dirname($file->getPath()) . '/New File' . $suggested;
|
||||
} elseif (strpos($suggested, '/') !== 0) {
|
||||
} elseif (!str_starts_with($suggested, '/')) {
|
||||
$path = dirname($file->getPath()) . '/' . $suggested;
|
||||
} else {
|
||||
$path = $userFolder->getPath() . $suggested;
|
||||
|
|
@ -592,7 +585,7 @@ class WopiController extends Controller {
|
|||
$this->getFileForWopiToken($wopi),
|
||||
ILock::TYPE_APP,
|
||||
Application::APPNAME
|
||||
), function () use (&$file, $path) {
|
||||
), function () use (&$file, $path): void {
|
||||
$file = $file->move($path);
|
||||
});
|
||||
} else {
|
||||
|
|
@ -632,10 +625,8 @@ class WopiController extends Controller {
|
|||
$this->userScopeService->setFilesystemScope($wopi->getEditorUid());
|
||||
|
||||
try {
|
||||
$this->wrappedFilesystemOperation($wopi, function () use ($file, $content) {
|
||||
return $file->putContent($content);
|
||||
});
|
||||
} catch (LockedException $e) {
|
||||
$this->wrappedFilesystemOperation($wopi, fn () => $file->putContent($content));
|
||||
} catch (LockedException) {
|
||||
return new JSONResponse(['message' => 'File locked'], Http::STATUS_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
|
|
@ -666,7 +657,7 @@ class WopiController extends Controller {
|
|||
Application::APPNAME
|
||||
));
|
||||
return new JSONResponse();
|
||||
} catch (NoLockProviderException|PreConditionNotMetException $e) {
|
||||
} catch (NoLockProviderException|PreConditionNotMetException) {
|
||||
return new JSONResponse([], Http::STATUS_BAD_REQUEST);
|
||||
} catch (OwnerLockedException $e) {
|
||||
// If a file is manually locked by a user we want to all this user to still perform a WOPI lock and write
|
||||
|
|
@ -675,7 +666,7 @@ class WopiController extends Controller {
|
|||
}
|
||||
|
||||
return new JSONResponse([], Http::STATUS_LOCKED);
|
||||
} catch (\Exception $e) {
|
||||
} catch (\Exception) {
|
||||
return new JSONResponse([], Http::STATUS_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
|
@ -688,14 +679,14 @@ class WopiController extends Controller {
|
|||
Application::APPNAME
|
||||
));
|
||||
return new JSONResponse();
|
||||
} catch (NoLockProviderException|PreConditionNotMetException $e) {
|
||||
} catch (NoLockProviderException|PreConditionNotMetException) {
|
||||
$locks = $this->lockManager->getLocks($wopi->getFileid());
|
||||
$canWriteThroughLock = count($locks) > 0 && $locks[0]->getType() === ILock::TYPE_USER && $locks[0]->getOwner() !== $wopi->getEditorUid() ? false : true;
|
||||
if ($canWriteThroughLock) {
|
||||
return new JSONResponse();
|
||||
}
|
||||
return new JSONResponse([], Http::STATUS_BAD_REQUEST);
|
||||
} catch (\Exception $e) {
|
||||
} catch (\Exception) {
|
||||
return new JSONResponse([], Http::STATUS_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
|
@ -708,11 +699,11 @@ class WopiController extends Controller {
|
|||
Application::APPNAME
|
||||
));
|
||||
return new JSONResponse();
|
||||
} catch (NoLockProviderException|PreConditionNotMetException $e) {
|
||||
} catch (NoLockProviderException|PreConditionNotMetException) {
|
||||
return new JSONResponse([], Http::STATUS_BAD_REQUEST);
|
||||
} catch (OwnerLockedException $e) {
|
||||
} catch (OwnerLockedException) {
|
||||
return new JSONResponse([], Http::STATUS_LOCKED);
|
||||
} catch (\Exception $e) {
|
||||
} catch (\Exception) {
|
||||
return new JSONResponse([], Http::STATUS_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
|
@ -729,7 +720,7 @@ class WopiController extends Controller {
|
|||
* @throws ShareNotFound
|
||||
*/
|
||||
protected function wrappedFilesystemOperation(Wopi $wopi, callable $filesystemOperation): void {
|
||||
$retryOperation = function () use ($filesystemOperation) {
|
||||
$retryOperation = function () use ($filesystemOperation): void {
|
||||
$this->retryOperation($filesystemOperation);
|
||||
};
|
||||
try {
|
||||
|
|
@ -738,7 +729,7 @@ class WopiController extends Controller {
|
|||
ILock::TYPE_APP,
|
||||
Application::APPNAME
|
||||
), $retryOperation);
|
||||
} catch (NoLockProviderException $e) {
|
||||
} catch (NoLockProviderException) {
|
||||
$retryOperation();
|
||||
}
|
||||
}
|
||||
|
|
@ -798,9 +789,7 @@ class WopiController extends Controller {
|
|||
|
||||
// Workaround to always open files with edit permissions if multiple occurrences of
|
||||
// the same file id are in the user home, ideally we should also track the path of the file when opening
|
||||
usort($files, function (Node $a, Node $b) {
|
||||
return ($b->getPermissions() & Constants::PERMISSION_UPDATE) <=> ($a->getPermissions() & Constants::PERMISSION_UPDATE);
|
||||
});
|
||||
usort($files, fn (Node $a, Node $b) => ($b->getPermissions() & Constants::PERMISSION_UPDATE) <=> ($a->getPermissions() & Constants::PERMISSION_UPDATE));
|
||||
|
||||
return array_shift($files);
|
||||
}
|
||||
|
|
@ -808,7 +797,7 @@ class WopiController extends Controller {
|
|||
private function getShareForWopiToken(Wopi $wopi): ?IShare {
|
||||
try {
|
||||
return $wopi->getShare() ? $this->shareManager->getShareByToken($wopi->getShare()) : null;
|
||||
} catch (ShareNotFound $e) {
|
||||
} catch (ShareNotFound) {
|
||||
}
|
||||
|
||||
return null;
|
||||
|
|
@ -857,7 +846,7 @@ class WopiController extends Controller {
|
|||
try {
|
||||
$util = \OC::$server->query(\OCA\Encryption\Util::class);
|
||||
return $util->isMasterKeyEnabled();
|
||||
} catch (QueryException $e) {
|
||||
} catch (QueryException) {
|
||||
// No encryption module enabled
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,14 +17,8 @@ class AssetMapper extends QBMapper {
|
|||
/** @var int Lifetime of a token is 10 minutes */
|
||||
public const TOKEN_TTL = 600;
|
||||
|
||||
private ISecureRandom $random;
|
||||
private ITimeFactory $time;
|
||||
|
||||
public function __construct(IDBConnection $db, ISecureRandom $random, ITimeFactory $timeFactory) {
|
||||
public function __construct(IDBConnection $db, private ISecureRandom $random, private ITimeFactory $time) {
|
||||
parent::__construct($db, 'richdocuments_assets', Asset::class);
|
||||
|
||||
$this->random = $random;
|
||||
$this->time = $timeFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -61,7 +55,7 @@ class AssetMapper extends QBMapper {
|
|||
}
|
||||
|
||||
return $asset;
|
||||
} catch (\Exception $e) {
|
||||
} catch (\Exception) {
|
||||
}
|
||||
|
||||
throw new DoesNotExistException('No asset for token found');
|
||||
|
|
|
|||
|
|
@ -17,16 +17,10 @@ class DirectMapper extends QBMapper {
|
|||
/** @var int Lifetime of a token is 10 minutes */
|
||||
public const TOKEN_TTL = 600;
|
||||
|
||||
protected ISecureRandom $random;
|
||||
protected ITimeFactory $timeFactory;
|
||||
|
||||
public function __construct(IDBConnection $db,
|
||||
ISecureRandom $random,
|
||||
ITimeFactory $timeFactory) {
|
||||
protected ISecureRandom $random,
|
||||
protected ITimeFactory $timeFactory) {
|
||||
parent::__construct($db, 'richdocuments_direct', Direct::class);
|
||||
|
||||
$this->random = $random;
|
||||
$this->timeFactory = $timeFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -66,7 +60,7 @@ class DirectMapper extends QBMapper {
|
|||
}
|
||||
|
||||
return $direct;
|
||||
} catch (\Exception $e) {
|
||||
} catch (\Exception) {
|
||||
}
|
||||
|
||||
throw new DoesNotExistException('No asset for token found');
|
||||
|
|
|
|||
|
|
@ -168,7 +168,7 @@ class Wopi extends Entity implements \JsonSerializable {
|
|||
$reflection = new \ReflectionClass($this);
|
||||
$json = [];
|
||||
foreach ($properties as $property => $value) {
|
||||
if (strpos($property, '_') !== 0 && $reflection->hasProperty($property)) {
|
||||
if (!str_starts_with($property, '_') && $reflection->hasProperty($property)) {
|
||||
$propertyReflection = $reflection->getProperty($property);
|
||||
if (!$propertyReflection->isPrivate()) {
|
||||
$json[$property] = $this->getter($property);
|
||||
|
|
|
|||
|
|
@ -17,29 +17,12 @@ use Psr\Log\LoggerInterface;
|
|||
|
||||
/** @template-extends QBMapper<Wopi> */
|
||||
class WopiMapper extends QBMapper {
|
||||
/** @var ISecureRandom */
|
||||
private $random;
|
||||
|
||||
/** @var LoggerInterface */
|
||||
private $logger;
|
||||
|
||||
/** @var ITimeFactory */
|
||||
private $timeFactory;
|
||||
|
||||
/** @var AppConfig */
|
||||
private $appConfig;
|
||||
|
||||
public function __construct(IDBConnection $db,
|
||||
ISecureRandom $random,
|
||||
LoggerInterface $logger,
|
||||
ITimeFactory $timeFactory,
|
||||
AppConfig $appConfig) {
|
||||
private ISecureRandom $random,
|
||||
private LoggerInterface $logger,
|
||||
private ITimeFactory $timeFactory,
|
||||
private AppConfig $appConfig) {
|
||||
parent::__construct($db, 'richdocuments_wopi', Wopi::class);
|
||||
|
||||
$this->random = $random;
|
||||
$this->logger = $logger;
|
||||
$this->timeFactory = $timeFactory;
|
||||
$this->appConfig = $appConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -9,20 +9,16 @@ use OCP\EventDispatcher\Event;
|
|||
use OCP\Files\Node;
|
||||
|
||||
class BeforeFederationRedirectEvent extends Event {
|
||||
/** @var Node */
|
||||
private $node;
|
||||
/** @var string */
|
||||
private $relativePath;
|
||||
/** @var string|null */
|
||||
private $redirectUrl = null;
|
||||
/** @var string */
|
||||
private $remote;
|
||||
|
||||
public function __construct($node, $relativePath, $remote) {
|
||||
/**
|
||||
* @param Node $node
|
||||
* @param string $relativePath
|
||||
* @param string $remote
|
||||
*/
|
||||
public function __construct(private $node, private $relativePath, private $remote) {
|
||||
parent::__construct();
|
||||
$this->node = $node;
|
||||
$this->relativePath = $relativePath;
|
||||
$this->remote = $remote;
|
||||
}
|
||||
|
||||
public function getRelativePath() {
|
||||
|
|
|
|||
|
|
@ -11,12 +11,7 @@ namespace OCA\Richdocuments\Events;
|
|||
use OCP\Files\Node;
|
||||
|
||||
class DocumentOpenedEvent extends \OCP\EventDispatcher\Event {
|
||||
private ?string $userId;
|
||||
private Node $node;
|
||||
|
||||
public function __construct(?string $userId, Node $node) {
|
||||
$this->userId = $userId;
|
||||
$this->node = $node;
|
||||
public function __construct(private ?string $userId, private Node $node) {
|
||||
}
|
||||
|
||||
public function getUserId(): ?string {
|
||||
|
|
|
|||
|
|
@ -10,11 +10,10 @@ use DateTimeZone;
|
|||
use OCP\Files\Folder;
|
||||
|
||||
class Helper {
|
||||
/** @var string|null */
|
||||
private $userId;
|
||||
|
||||
public function __construct($userId) {
|
||||
$this->userId = $userId;
|
||||
/**
|
||||
* @param string|null $userId
|
||||
*/
|
||||
public function __construct(private $userId) {
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -38,7 +37,7 @@ class Helper {
|
|||
throw new \Exception('$fileId has not the expected format');
|
||||
}
|
||||
|
||||
if (strpos($fileId, '-') !== false) {
|
||||
if (str_contains($fileId, '-')) {
|
||||
[$fileId, $templateId] = explode('/', $fileId);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,16 +24,7 @@ use OCP\Share\IShare;
|
|||
|
||||
/** @template-implements IEventListener<Event|BeforePreviewFetchedEvent> */
|
||||
class BeforeFetchPreviewListener implements IEventListener {
|
||||
private PermissionManager $permissionManager;
|
||||
private IUserSession $userSession;
|
||||
private IRequest $request;
|
||||
private IManager $shareManager;
|
||||
|
||||
public function __construct(PermissionManager $permissionManager, IUserSession $userSession, IRequest $request, IManager $shareManager) {
|
||||
$this->permissionManager = $permissionManager;
|
||||
$this->userSession = $userSession;
|
||||
$this->request = $request;
|
||||
$this->shareManager = $shareManager;
|
||||
public function __construct(private PermissionManager $permissionManager, private IUserSession $userSession, private IRequest $request, private IManager $shareManager) {
|
||||
}
|
||||
|
||||
public function handle(Event $event): void {
|
||||
|
|
@ -56,7 +47,7 @@ class BeforeFetchPreviewListener implements IEventListener {
|
|||
// Get different share for public previews as the share from the node is only set for mounted shares
|
||||
try {
|
||||
$share = $shareToken ? $this->shareManager->getShareByToken($shareToken) : $share;
|
||||
} catch (ShareNotFound $e) {
|
||||
} catch (ShareNotFound) {
|
||||
}
|
||||
|
||||
$userId = $this->userSession->getUser() ? $this->userSession->getUser()->getUID() : null;
|
||||
|
|
|
|||
|
|
@ -14,10 +14,7 @@ use OCP\EventDispatcher\IEventListener;
|
|||
|
||||
/** @template-implements IEventListener<BeforeTemplateRenderedEvent|Event> */
|
||||
class BeforeTemplateRenderedListener implements IEventListener {
|
||||
private CapabilitiesService $capabilitiesService;
|
||||
|
||||
public function __construct(CapabilitiesService $capabilitiesService) {
|
||||
$this->capabilitiesService = $capabilitiesService;
|
||||
public function __construct(private CapabilitiesService $capabilitiesService) {
|
||||
}
|
||||
|
||||
public function handle(Event $event): void {
|
||||
|
|
|
|||
|
|
@ -20,17 +20,7 @@ use OCP\Util;
|
|||
|
||||
/** @template-implements IEventListener<Event|LoadViewer> */
|
||||
class LoadViewerListener implements IEventListener {
|
||||
/** @var PermissionManager */
|
||||
private $permissionManager;
|
||||
/** @var InitialStateService */
|
||||
private $initialStateService;
|
||||
|
||||
private ?string $userId = null;
|
||||
|
||||
public function __construct(PermissionManager $permissionManager, InitialStateService $initialStateService, ?string $userId) {
|
||||
$this->permissionManager = $permissionManager;
|
||||
$this->initialStateService = $initialStateService;
|
||||
$this->userId = $userId;
|
||||
public function __construct(private PermissionManager $permissionManager, private InitialStateService $initialStateService, private ?string $userId) {
|
||||
}
|
||||
|
||||
public function handle(Event $event): void {
|
||||
|
|
|
|||
|
|
@ -21,14 +21,7 @@ use OCP\Util;
|
|||
|
||||
/** @template-implements IEventListener<Event|ShareLinkAccessedEvent> */
|
||||
class ShareLinkListener implements \OCP\EventDispatcher\IEventListener {
|
||||
/** @var PermissionManager */
|
||||
private $permissionManager;
|
||||
/** @var InitialStateService */
|
||||
private $initialStateService;
|
||||
|
||||
public function __construct(PermissionManager $permissionManager, InitialStateService $initialStateService) {
|
||||
$this->permissionManager = $permissionManager;
|
||||
$this->initialStateService = $initialStateService;
|
||||
public function __construct(private PermissionManager $permissionManager, private InitialStateService $initialStateService) {
|
||||
}
|
||||
|
||||
public function handle(Event $event): void {
|
||||
|
|
|
|||
|
|
@ -19,27 +19,14 @@ use OCP\Share\IShare;
|
|||
use OCP\SystemTag\ISystemTagObjectMapper;
|
||||
|
||||
class PermissionManager {
|
||||
private AppConfig $appConfig;
|
||||
private IConfig $config;
|
||||
private IGroupManager $groupManager;
|
||||
private IUserManager $userManager;
|
||||
private IUserSession $userSession;
|
||||
private ISystemTagObjectMapper $systemTagObjectMapper;
|
||||
|
||||
public function __construct(
|
||||
AppConfig $appConfig,
|
||||
IConfig $config,
|
||||
IGroupManager $groupManager,
|
||||
IUserManager $userManager,
|
||||
IUserSession $userSession,
|
||||
ISystemTagObjectMapper $systemTagObjectMapper
|
||||
private AppConfig $appConfig,
|
||||
private IConfig $config,
|
||||
private IGroupManager $groupManager,
|
||||
private IUserManager $userManager,
|
||||
private IUserSession $userSession,
|
||||
private ISystemTagObjectMapper $systemTagObjectMapper
|
||||
) {
|
||||
$this->appConfig = $appConfig;
|
||||
$this->config = $config;
|
||||
$this->groupManager = $groupManager;
|
||||
$this->userManager = $userManager;
|
||||
$this->userSession = $userSession;
|
||||
$this->systemTagObjectMapper = $systemTagObjectMapper;
|
||||
}
|
||||
|
||||
private function userMatchesGroupList(?string $userId = null, ?array $groupList = []): bool {
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ abstract class CachedRequestService {
|
|||
$appData = $this->appDataFactory->get(Application::APPNAME);
|
||||
try {
|
||||
$folder = $appData->getFolder('remoteData');
|
||||
} catch (NotFoundException $e) {
|
||||
} catch (NotFoundException) {
|
||||
$folder = $appData->newFolder('remoteData');
|
||||
}
|
||||
return $folder;
|
||||
|
|
@ -147,7 +147,7 @@ abstract class CachedRequestService {
|
|||
return true;
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
} catch (\Exception) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,18 +10,7 @@ use OCP\Http\Client\IClientService;
|
|||
use OCP\ICache;
|
||||
|
||||
class DemoService {
|
||||
/**
|
||||
* @var ICache
|
||||
*/
|
||||
private $cache;
|
||||
/**
|
||||
* @var IClientService
|
||||
*/
|
||||
private $clientService;
|
||||
|
||||
public function __construct(ICache $cache, IClientService $clientService) {
|
||||
$this->cache = $cache;
|
||||
$this->clientService = $clientService;
|
||||
public function __construct(private ICache $cache, private IClientService $clientService) {
|
||||
}
|
||||
|
||||
public function fetchDemoServers($refresh = false) {
|
||||
|
|
@ -34,7 +23,7 @@ class DemoService {
|
|||
try {
|
||||
$response = $client->get($demoServerList);
|
||||
$servers = json_decode($response->getBody(), true)['servers'] ?? [];
|
||||
} catch (\Exception $e) {
|
||||
} catch (\Exception) {
|
||||
$servers = [];
|
||||
}
|
||||
$this->cache->set('richdocuments-demo', json_encode($servers));
|
||||
|
|
|
|||
|
|
@ -32,34 +32,14 @@ use Psr\Log\LoggerInterface;
|
|||
class FederationService {
|
||||
/** @var ICache */
|
||||
private $cache;
|
||||
/** @var IClientService */
|
||||
private $clientService;
|
||||
/** @var LoggerInterface */
|
||||
private $logger;
|
||||
/** @var TrustedServers */
|
||||
private $trustedServers;
|
||||
/** @var AppConfig */
|
||||
private $appConfig;
|
||||
/** @var TokenManager */
|
||||
private $tokenManager;
|
||||
/** @var IRequest */
|
||||
private $request;
|
||||
/** @var IURLGenerator */
|
||||
private $urlGenerator;
|
||||
|
||||
public function __construct(ICacheFactory $cacheFactory, IClientService $clientService, LoggerInterface $logger, TokenManager $tokenManager, AppConfig $appConfig, IRequest $request, IURLGenerator $urlGenerator) {
|
||||
public function __construct(ICacheFactory $cacheFactory, private IClientService $clientService, private LoggerInterface $logger, private TokenManager $tokenManager, private AppConfig $appConfig, private IRequest $request, private IURLGenerator $urlGenerator) {
|
||||
$this->cache = $cacheFactory->createDistributed('richdocuments_remote/');
|
||||
$this->clientService = $clientService;
|
||||
$this->logger = $logger;
|
||||
$this->tokenManager = $tokenManager;
|
||||
$this->appConfig = $appConfig;
|
||||
$this->request = $request;
|
||||
$this->urlGenerator = $urlGenerator;
|
||||
try {
|
||||
$this->trustedServers = \OC::$server->get(\OCA\Federation\TrustedServers::class);
|
||||
} catch (NotFoundExceptionInterface $e) {
|
||||
} catch (ContainerExceptionInterface $e) {
|
||||
} catch (AutoloadNotAllowedException $e) {
|
||||
} catch (NotFoundExceptionInterface|ContainerExceptionInterface|AutoloadNotAllowedException) {
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -68,9 +48,7 @@ class FederationService {
|
|||
return [];
|
||||
}
|
||||
|
||||
return array_map(function (array $server) {
|
||||
return $server['url'];
|
||||
}, $this->trustedServers->getServers());
|
||||
return array_map(fn (array $server) => $server['url'], $this->trustedServers->getServers());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -80,7 +58,7 @@ class FederationService {
|
|||
*/
|
||||
public function getRemoteCollaboraURL($remote) {
|
||||
// If no protocol is provided we default to https
|
||||
if (strpos($remote, 'http://') !== 0 && strpos($remote, 'https://') !== 0) {
|
||||
if (!str_starts_with($remote, 'http://') && !str_starts_with($remote, 'https://')) {
|
||||
$remote = 'https://' . $remote;
|
||||
}
|
||||
|
||||
|
|
@ -106,7 +84,7 @@ class FederationService {
|
|||
}
|
||||
|
||||
public function isTrustedRemote($domainWithPort) {
|
||||
if (strpos($domainWithPort, 'http://') === 0 || strpos($domainWithPort, 'https://') === 0) {
|
||||
if (str_starts_with($domainWithPort, 'http://') || str_starts_with($domainWithPort, 'https://')) {
|
||||
$port = parse_url($domainWithPort, PHP_URL_PORT);
|
||||
$domainWithPort = parse_url($domainWithPort, PHP_URL_HOST) . ($port ? ':' . $port : '');
|
||||
}
|
||||
|
|
@ -126,9 +104,7 @@ class FederationService {
|
|||
if (!is_string($trusted)) {
|
||||
break;
|
||||
}
|
||||
$regex = '/^' . implode('[-\.a-zA-Z0-9]*', array_map(function ($v) {
|
||||
return preg_quote($v, '/');
|
||||
}, explode('*', $trusted))) . '$/i';
|
||||
$regex = '/^' . implode('[-\.a-zA-Z0-9]*', array_map(fn ($v) => preg_quote($v, '/'), explode('*', $trusted))) . '$/i';
|
||||
if (preg_match($regex, $domain) || preg_match($regex, $domainWithPort)) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,32 +18,16 @@ use OCP\IURLGenerator;
|
|||
|
||||
class FontService {
|
||||
private const INVALIDATE_FONT_LIST_CACHE_AFTER_SECONDS = 3600;
|
||||
|
||||
/**
|
||||
* @var IAppData
|
||||
*/
|
||||
private $appData;
|
||||
/**
|
||||
* @var \OCP\ICache
|
||||
*/
|
||||
private $cache;
|
||||
/**
|
||||
* @var IURLGenerator
|
||||
*/
|
||||
private $url;
|
||||
/**
|
||||
* @var IConfig
|
||||
*/
|
||||
private $config;
|
||||
|
||||
public function __construct(IAppData $appData,
|
||||
public function __construct(private IAppData $appData,
|
||||
ICacheFactory $cacheFactory,
|
||||
IURLGenerator $url,
|
||||
IConfig $config) {
|
||||
$this->appData = $appData;
|
||||
private IURLGenerator $url,
|
||||
private IConfig $config) {
|
||||
$this->cache = $cacheFactory->createDistributed(Application::APPNAME);
|
||||
$this->url = $url;
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -53,7 +37,7 @@ class FontService {
|
|||
private function getFontAppDataDir(): ISimpleFolder {
|
||||
try {
|
||||
return $this->appData->getFolder('fonts');
|
||||
} catch (NotFoundException $e) {
|
||||
} catch (NotFoundException) {
|
||||
return $this->appData->newFolder('fonts');
|
||||
}
|
||||
}
|
||||
|
|
@ -65,7 +49,7 @@ class FontService {
|
|||
private function getFontOverviewAppDataDir(): ISimpleFolder {
|
||||
try {
|
||||
return $this->appData->getFolder('font-overviews');
|
||||
} catch (NotFoundException $e) {
|
||||
} catch (NotFoundException) {
|
||||
return $this->appData->newFolder('font-overviews');
|
||||
}
|
||||
}
|
||||
|
|
@ -93,9 +77,7 @@ class FontService {
|
|||
if ($cachedNames === null) {
|
||||
$files = $this->getFontFiles();
|
||||
$cachedNames = array_map(
|
||||
static function (ISimpleFile $f) {
|
||||
return $f->getName();
|
||||
},
|
||||
static fn (ISimpleFile $f) => $f->getName(),
|
||||
$files
|
||||
);
|
||||
$this->cache->set($cacheKey, $cachedNames, self::INVALIDATE_FONT_LIST_CACHE_AFTER_SECONDS);
|
||||
|
|
@ -113,12 +95,10 @@ class FontService {
|
|||
public function getFontList(array $fontFiles): array {
|
||||
$url = $this->url;
|
||||
$list = array_map(
|
||||
static function (ISimpleFile $f) use ($url) {
|
||||
return [
|
||||
'uri' => $url->linkToRouteAbsolute(Application::APPNAME . '.settings.getFontFile', ['name' => $f->getName()]),
|
||||
'stamp' => $f->getETag(),
|
||||
];
|
||||
},
|
||||
static fn (ISimpleFile $f) => [
|
||||
'uri' => $url->linkToRouteAbsolute(Application::APPNAME . '.settings.getFontFile', ['name' => $f->getName()]),
|
||||
'stamp' => $f->getETag(),
|
||||
],
|
||||
$fontFiles
|
||||
);
|
||||
|
||||
|
|
@ -220,7 +200,7 @@ class FontService {
|
|||
imagepng($im, $imageFileResource);
|
||||
imagedestroy($im);
|
||||
}
|
||||
} catch (\Exception|\Throwable $e) {
|
||||
} catch (\Exception|\Throwable) {
|
||||
// do nothing if there was any kind of error during overview generation
|
||||
// the /apps/richdocuments/settings/fonts/FILE_NAME/overview request will fail with 404
|
||||
// in the UI and display a fallback message
|
||||
|
|
|
|||
|
|
@ -13,23 +13,12 @@ use OCP\IConfig;
|
|||
use OCP\Settings\ISettings;
|
||||
|
||||
class Personal implements ISettings {
|
||||
/** @var IConfig Config */
|
||||
private $config;
|
||||
|
||||
/** @var CapabilitiesService */
|
||||
private $capabilitiesService;
|
||||
|
||||
/** @var InitialStateService */
|
||||
private $initialState;
|
||||
|
||||
/** @var string */
|
||||
private $userId;
|
||||
|
||||
public function __construct(IConfig $config, CapabilitiesService $capabilitiesService, InitialStateService $initialStateService, $userId) {
|
||||
$this->config = $config;
|
||||
$this->capabilitiesService = $capabilitiesService;
|
||||
$this->initialState = $initialStateService;
|
||||
$this->userId = $userId;
|
||||
public function __construct(
|
||||
private IConfig $config,
|
||||
private CapabilitiesService $capabilitiesService,
|
||||
private InitialStateService $initialState,
|
||||
private ?string $userId
|
||||
) {
|
||||
}
|
||||
|
||||
/** @psalm-suppress InvalidNullableReturnType */
|
||||
|
|
|
|||
|
|
@ -12,17 +12,7 @@ use OCP\IURLGenerator;
|
|||
use OCP\Settings\IIconSection;
|
||||
|
||||
class Section implements IIconSection {
|
||||
/** @var IURLGenerator */
|
||||
private $url;
|
||||
/** @var CapabilitiesService */
|
||||
private $capabilitites;
|
||||
/** @var IL10N */
|
||||
private $l10n;
|
||||
|
||||
public function __construct(IURLGenerator $url, CapabilitiesService $capabilities, IL10N $l10n) {
|
||||
$this->url = $url;
|
||||
$this->capabilitites = $capabilities;
|
||||
$this->l10n = $l10n;
|
||||
public function __construct(private IURLGenerator $url, private CapabilitiesService $capabilitites, private IL10N $l10n) {
|
||||
}
|
||||
|
||||
public function getID() {
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ class CollaboraTemplateProvider implements ICustomTemplateProvider {
|
|||
$internalPath = $userTemplatesFolder->getInternalPath();
|
||||
$userTemplatePath = mb_strpos($internalPath, 'files/') === 0 ? mb_substr($internalPath, 5): $internalPath;
|
||||
return $this->coreTemplateManager->getTemplatePath() === $userTemplatePath;
|
||||
} catch (NotFoundException $e) {
|
||||
} catch (NotFoundException) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,27 +27,6 @@ class TemplateManager {
|
|||
/** @var string */
|
||||
protected $userId;
|
||||
|
||||
/** @var IConfig */
|
||||
private $config;
|
||||
|
||||
/** @var IURLGenerator */
|
||||
private $urlGenerator;
|
||||
|
||||
/** @var IRootFolder */
|
||||
private $rootFolder;
|
||||
|
||||
/** @var IL10N */
|
||||
private $l;
|
||||
|
||||
/** @var IDBConnection */
|
||||
private $db;
|
||||
|
||||
/** @var IAppData */
|
||||
private $appData;
|
||||
|
||||
/** @var LoggerInterface */
|
||||
private $logger;
|
||||
|
||||
/** Accepted templates mime types */
|
||||
public const MIMES_DOCUMENTS = [
|
||||
'application/vnd.oasis.opendocument.text-template',
|
||||
|
|
@ -91,22 +70,15 @@ class TemplateManager {
|
|||
|
||||
public function __construct(
|
||||
?string $userId,
|
||||
IConfig $config,
|
||||
IAppData $appData,
|
||||
IURLGenerator $urlGenerator,
|
||||
IRootFolder $rootFolder,
|
||||
IL10N $l,
|
||||
IDBConnection $connection,
|
||||
LoggerInterface $logger
|
||||
private IConfig $config,
|
||||
private IAppData $appData,
|
||||
private IURLGenerator $urlGenerator,
|
||||
private IRootFolder $rootFolder,
|
||||
private IL10N $l,
|
||||
private IDBConnection $db,
|
||||
private LoggerInterface $logger
|
||||
) {
|
||||
$this->userId = $userId;
|
||||
$this->config = $config;
|
||||
$this->rootFolder = $rootFolder;
|
||||
$this->urlGenerator = $urlGenerator;
|
||||
$this->db = $connection;
|
||||
$this->logger = $logger;
|
||||
$this->appData = $appData;
|
||||
$this->l = $l;
|
||||
}
|
||||
|
||||
private function ensureAppDataFolders() {
|
||||
|
|
@ -117,12 +89,12 @@ class TemplateManager {
|
|||
*/
|
||||
try {
|
||||
$this->appData->getFolder('templates');
|
||||
} catch (NotFoundException $e) {
|
||||
} catch (NotFoundException) {
|
||||
$this->appData->newFolder('templates');
|
||||
}
|
||||
try {
|
||||
$this->appData->getFolder('empty_templates');
|
||||
} catch (NotFoundException $e) {
|
||||
} catch (NotFoundException) {
|
||||
$this->appData->newFolder('empty_templates');
|
||||
}
|
||||
}
|
||||
|
|
@ -185,21 +157,13 @@ class TemplateManager {
|
|||
}
|
||||
|
||||
public function getTemplateTypeForExtension(string $extension): ?string {
|
||||
switch ($extension) {
|
||||
case 'odt':
|
||||
case 'docx':
|
||||
return 'document';
|
||||
case 'ods':
|
||||
case 'xlsx':
|
||||
return 'spreadsheet';
|
||||
case 'odp':
|
||||
case 'pptx':
|
||||
return 'presentation';
|
||||
case 'odg':
|
||||
return 'drawing';
|
||||
}
|
||||
|
||||
return null;
|
||||
return match ($extension) {
|
||||
'odt', 'docx' => 'document',
|
||||
'ods', 'xlsx' => 'spreadsheet',
|
||||
'odp', 'pptx' => 'presentation',
|
||||
'odg' => 'drawing',
|
||||
default => null,
|
||||
};
|
||||
}
|
||||
|
||||
public function getEmpty($type = null) {
|
||||
|
|
@ -234,7 +198,7 @@ class TemplateManager {
|
|||
try {
|
||||
$folder = $this->getEmptyTemplateDir();
|
||||
$folder->delete();
|
||||
} catch (NotFoundException $e) {
|
||||
} catch (NotFoundException) {
|
||||
}
|
||||
$this->appData->newFolder('empty_templates');
|
||||
$this->getEmpty();
|
||||
|
|
@ -262,13 +226,9 @@ class TemplateManager {
|
|||
$empty = $this->getEmpty($type);
|
||||
$system = $this->getSystem($type);
|
||||
|
||||
$emptyFormatted = array_map(function (File $file) {
|
||||
return $this->formatEmpty($file);
|
||||
}, $empty);
|
||||
$emptyFormatted = array_map(fn (File $file) => $this->formatEmpty($file), $empty);
|
||||
|
||||
$systemFormatted = array_map(function (File $file) {
|
||||
return $this->formatNodeReturn($file);
|
||||
}, $system);
|
||||
$systemFormatted = array_map(fn (File $file) => $this->formatNodeReturn($file), $system);
|
||||
|
||||
return array_merge($emptyFormatted, $systemFormatted);
|
||||
}
|
||||
|
|
@ -288,7 +248,7 @@ class TemplateManager {
|
|||
$templateFiles = $templateDir->getDirectoryListing();
|
||||
|
||||
return $this->filterTemplates($templateFiles, $type);
|
||||
} catch (NotFoundException $e) {
|
||||
} catch (NotFoundException) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
|
@ -303,9 +263,7 @@ class TemplateManager {
|
|||
|
||||
$templates = $this->getUser($type);
|
||||
|
||||
return array_map(function (File $file) {
|
||||
return $this->formatNodeReturn($file);
|
||||
}, $templates);
|
||||
return array_map(fn (File $file) => $this->formatNodeReturn($file), $templates);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -354,7 +312,7 @@ class TemplateManager {
|
|||
|
||||
try {
|
||||
$template = $folder->get($templateName);
|
||||
} catch (NotFoundException $e) {
|
||||
} catch (NotFoundException) {
|
||||
$template = $folder->newFile($templateName);
|
||||
}
|
||||
$template->putContent($templateFile);
|
||||
|
|
@ -416,7 +374,7 @@ class TemplateManager {
|
|||
// fallback to default template dir
|
||||
try {
|
||||
$templateDir = $userFolder->get('Templates');
|
||||
} catch (NotFoundException $e) {
|
||||
} catch (NotFoundException) {
|
||||
throw new NotFoundException('Template directory not found');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ class AddFeaturePolicyListenerTest extends TestCase {
|
|||
$eventDispatcher = $this->createMock(IEventDispatcher::class);
|
||||
$eventDispatcher->expects(self::once())
|
||||
->method('dispatchTyped')
|
||||
->willReturnCallback(function ($event) {
|
||||
->willReturnCallback(function ($event): void {
|
||||
$this->featurePolicyListener->handle($event);
|
||||
});
|
||||
$manager = new FeaturePolicyManager($eventDispatcher);
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ if (!defined('PHPUNIT_RUN')) {
|
|||
|
||||
require_once __DIR__.'/../../../lib/base.php';
|
||||
|
||||
if (!class_exists('\PHPUnit\Framework\TestCase')) {
|
||||
if (!class_exists(\PHPUnit\Framework\TestCase::class)) {
|
||||
require_once('PHPUnit/Autoload.php');
|
||||
}
|
||||
\OC_App::loadApp('richdocuments');
|
||||
|
|
|
|||
|
|
@ -128,7 +128,7 @@ class DirectContext implements Context {
|
|||
Assert::assertNotEmpty($initialState['document']['fileId']);
|
||||
Assert::assertNotEmpty($initialState['document']['token']);
|
||||
|
||||
$currentServer = $currentServer ?? $this->serverContext->getBaseUrl();
|
||||
$currentServer ??= $this->serverContext->getBaseUrl();
|
||||
|
||||
$this->wopiContext->setWopiParameters($currentServer, $initialState['document']['fileId'], $initialState['document']['token']);
|
||||
Assert::assertEquals(200, $response->getStatusCode());
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ class AddContentSecurityPolicyListenerTest extends TestCase {
|
|||
$eventDispatcher = $this->createMock(IEventDispatcher::class);
|
||||
$eventDispatcher->expects(self::once())
|
||||
->method('dispatchTyped')
|
||||
->willReturnCallback(function ($event) {
|
||||
->willReturnCallback(function ($event): void {
|
||||
$this->listener->handle($event);
|
||||
});
|
||||
$manager = new ContentSecurityPolicyManager($eventDispatcher);
|
||||
|
|
@ -191,7 +191,7 @@ class AddContentSecurityPolicyListenerTest extends TestCase {
|
|||
$eventDispatcher = $this->createMock(IEventDispatcher::class);
|
||||
$eventDispatcher->expects(self::once())
|
||||
->method('dispatchTyped')
|
||||
->willReturnCallback(function (AddContentSecurityPolicyEvent $event) {
|
||||
->willReturnCallback(function (AddContentSecurityPolicyEvent $event): void {
|
||||
$otherPolicy = new EmptyContentSecurityPolicy();
|
||||
$otherPolicy->addAllowedFrameDomain('external.example.com');
|
||||
$otherPolicy->addAllowedFormActionDomain('external.example.com');
|
||||
|
|
@ -203,7 +203,7 @@ class AddContentSecurityPolicyListenerTest extends TestCase {
|
|||
|
||||
$policy = $manager->getDefaultPolicy();
|
||||
|
||||
self::assertArrayUnordered(["'self'", 'external.example.com', 'http://public', 'nc:'], $policy->getAllowedFrameDomains(), 'Domains are equal', 0.0, 10, true);
|
||||
self::assertArrayUnordered(["'self'", 'external.example.com', 'http://public', 'nc:'], $policy->getAllowedFrameDomains(), 'Domains are equal');
|
||||
self::assertArrayUnordered(["'self'", 'external.example.com', 'http://public'], $policy->getAllowedFormActionDomains());
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue