summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/composer/composer/autoload_classmap.php1
-rw-r--r--lib/composer/composer/autoload_static.php1
-rw-r--r--lib/private/AppFramework/Bootstrap/Coordinator.php2
-rw-r--r--lib/private/AppFramework/Bootstrap/RegistrationContext.php4
-rw-r--r--lib/private/Comments/Comment.php16
-rw-r--r--lib/private/Comments/Manager.php21
-rw-r--r--lib/private/Dashboard/Manager.php35
-rw-r--r--lib/private/Http/Client/LocalAddressChecker.php6
-rw-r--r--lib/public/Comments/IComment.php17
-rw-r--r--lib/public/Comments/ICommentsManager.php11
-rw-r--r--lib/public/Dashboard/IManager.php2
11 files changed, 97 insertions, 19 deletions
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php
index 1edc39c52f2..eae31d41449 100644
--- a/lib/composer/composer/autoload_classmap.php
+++ b/lib/composer/composer/autoload_classmap.php
@@ -1036,6 +1036,7 @@ return array(
'OC\\Core\\Migrations\\Version24000Date20220404230027' => $baseDir . '/core/Migrations/Version24000Date20220404230027.php',
'OC\\Core\\Migrations\\Version24000Date20220425072957' => $baseDir . '/core/Migrations/Version24000Date20220425072957.php',
'OC\\Core\\Migrations\\Version25000Date20220515204012' => $baseDir . '/core/Migrations/Version25000Date20220515204012.php',
+ 'OC\\Core\\Migrations\\Version25000Date20220602190540' => $baseDir . '/core/Migrations/Version25000Date20220602190540.php',
'OC\\Core\\Notification\\CoreNotifier' => $baseDir . '/core/Notification/CoreNotifier.php',
'OC\\Core\\Service\\LoginFlowV2Service' => $baseDir . '/core/Service/LoginFlowV2Service.php',
'OC\\DB\\Adapter' => $baseDir . '/lib/private/DB/Adapter.php',
diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php
index 2efd6effc91..8a2a72713ec 100644
--- a/lib/composer/composer/autoload_static.php
+++ b/lib/composer/composer/autoload_static.php
@@ -1069,6 +1069,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OC\\Core\\Migrations\\Version24000Date20220404230027' => __DIR__ . '/../../..' . '/core/Migrations/Version24000Date20220404230027.php',
'OC\\Core\\Migrations\\Version24000Date20220425072957' => __DIR__ . '/../../..' . '/core/Migrations/Version24000Date20220425072957.php',
'OC\\Core\\Migrations\\Version25000Date20220515204012' => __DIR__ . '/../../..' . '/core/Migrations/Version25000Date20220515204012.php',
+ 'OC\\Core\\Migrations\\Version25000Date20220602190540' => __DIR__ . '/../../..' . '/core/Migrations/Version25000Date20220602190540.php',
'OC\\Core\\Notification\\CoreNotifier' => __DIR__ . '/../../..' . '/core/Notification/CoreNotifier.php',
'OC\\Core\\Service\\LoginFlowV2Service' => __DIR__ . '/../../..' . '/core/Service/LoginFlowV2Service.php',
'OC\\DB\\Adapter' => __DIR__ . '/../../..' . '/lib/private/DB/Adapter.php',
diff --git a/lib/private/AppFramework/Bootstrap/Coordinator.php b/lib/private/AppFramework/Bootstrap/Coordinator.php
index b6378830732..3ab6ac4c8b0 100644
--- a/lib/private/AppFramework/Bootstrap/Coordinator.php
+++ b/lib/private/AppFramework/Bootstrap/Coordinator.php
@@ -151,7 +151,7 @@ class Coordinator {
*/
$this->registrationContext->delegateCapabilityRegistrations($apps);
$this->registrationContext->delegateCrashReporterRegistrations($apps, $this->registry);
- $this->registrationContext->delegateDashboardPanelRegistrations($apps, $this->dashboardManager);
+ $this->registrationContext->delegateDashboardPanelRegistrations($this->dashboardManager);
$this->registrationContext->delegateEventListenerRegistrations($this->eventDispatcher);
$this->registrationContext->delegateContainerRegistrations($apps);
$this->registrationContext->delegateMiddlewareRegistrations($apps);
diff --git a/lib/private/AppFramework/Bootstrap/RegistrationContext.php b/lib/private/AppFramework/Bootstrap/RegistrationContext.php
index 7b4d24036e8..8f6aff228e1 100644
--- a/lib/private/AppFramework/Bootstrap/RegistrationContext.php
+++ b/lib/private/AppFramework/Bootstrap/RegistrationContext.php
@@ -475,10 +475,10 @@ class RegistrationContext {
/**
* @param App[] $apps
*/
- public function delegateDashboardPanelRegistrations(array $apps, IManager $dashboardManager): void {
+ public function delegateDashboardPanelRegistrations(IManager $dashboardManager): void {
while (($panel = array_shift($this->dashboardPanels)) !== null) {
try {
- $dashboardManager->lazyRegisterWidget($panel->getService());
+ $dashboardManager->lazyRegisterWidget($panel->getService(), $panel->getAppId());
} catch (Throwable $e) {
$appId = $panel->getAppId();
$this->logger->error("Error during dashboard registration of $appId: " . $e->getMessage(), [
diff --git a/lib/private/Comments/Comment.php b/lib/private/Comments/Comment.php
index 2b338efc75f..0128dc8defd 100644
--- a/lib/private/Comments/Comment.php
+++ b/lib/private/Comments/Comment.php
@@ -45,6 +45,7 @@ class Comment implements IComment {
'creationDT' => null,
'latestChildDT' => null,
'reactions' => null,
+ 'expire_date' => null,
];
/**
@@ -447,6 +448,21 @@ class Comment implements IComment {
}
/**
+ * @inheritDoc
+ */
+ public function setExpireDate(?\DateTime $dateTime): IComment {
+ $this->data['expire_date'] = $dateTime;
+ return $this;
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function getExpireDate(): ?\DateTime {
+ return $this->data['expire_date'];
+ }
+
+ /**
* sets the comment data based on an array with keys as taken from the
* database.
*
diff --git a/lib/private/Comments/Manager.php b/lib/private/Comments/Manager.php
index b7532222c33..f21f9ec76b2 100644
--- a/lib/private/Comments/Manager.php
+++ b/lib/private/Comments/Manager.php
@@ -107,6 +107,9 @@ class Manager implements ICommentsManager {
if (!is_null($data['latest_child_timestamp'])) {
$data['latest_child_timestamp'] = new \DateTime($data['latest_child_timestamp']);
}
+ if (!is_null($data['expire_date'])) {
+ $data['expire_date'] = new \DateTime($data['expire_date']);
+ }
$data['children_count'] = (int)$data['children_count'];
$data['reference_id'] = $data['reference_id'] ?? null;
if ($this->supportReactions()) {
@@ -1203,6 +1206,7 @@ class Manager implements ICommentsManager {
'latest_child_timestamp' => $qb->createNamedParameter($comment->getLatestChildDateTime(), 'datetime'),
'object_type' => $qb->createNamedParameter($comment->getObjectType()),
'object_id' => $qb->createNamedParameter($comment->getObjectId()),
+ 'expire_date' => $qb->createNamedParameter($comment->getExpireDate(), 'datetime'),
];
if ($tryWritingReferenceId) {
@@ -1642,4 +1646,21 @@ class Manager implements ICommentsManager {
$this->initialStateService->provideInitialState('comments', 'max-message-length', IComment::MAX_MESSAGE_LENGTH);
Util::addScript('comments', 'comments-app');
}
+
+ /**
+ * @inheritDoc
+ */
+ public function deleteMessageExpiredAtObject(string $objectType, string $objectId): bool {
+ $qb = $this->dbConn->getQueryBuilder();
+ $affectedRows = $qb->delete('comments')
+ ->where($qb->expr()->lt('expire_date',
+ $qb->createNamedParameter($this->timeFactory->getDateTime(), IQueryBuilder::PARAM_DATE)))
+ ->andWhere($qb->expr()->eq('object_type', $qb->createNamedParameter($objectType)))
+ ->andWhere($qb->expr()->eq('object_id', $qb->createNamedParameter($objectId)))
+ ->executeStatement();
+
+ $this->commentsCache = [];
+
+ return $affectedRows > 0;
+ }
}
diff --git a/lib/private/Dashboard/Manager.php b/lib/private/Dashboard/Manager.php
index 09525693b4f..2aeedf3174e 100644
--- a/lib/private/Dashboard/Manager.php
+++ b/lib/private/Dashboard/Manager.php
@@ -27,10 +27,11 @@ declare(strict_types=1);
namespace OC\Dashboard;
use InvalidArgumentException;
-use OCP\AppFramework\QueryException;
+use OCP\App\IAppManager;
use OCP\Dashboard\IManager;
use OCP\Dashboard\IWidget;
-use OCP\IServerContainer;
+use Psr\Container\ContainerExceptionInterface;
+use Psr\Container\ContainerInterface;
use Throwable;
use Psr\Log\LoggerInterface;
@@ -42,10 +43,10 @@ class Manager implements IManager {
/** @var IWidget[] */
private $widgets = [];
- /** @var IServerContainer */
- private $serverContainer;
+ private ContainerInterface $serverContainer;
+ private ?IAppManager $appManager = null;
- public function __construct(IServerContainer $serverContainer) {
+ public function __construct(ContainerInterface $serverContainer) {
$this->serverContainer = $serverContainer;
}
@@ -57,17 +58,25 @@ class Manager implements IManager {
$this->widgets[$widget->getId()] = $widget;
}
- public function lazyRegisterWidget(string $widgetClass): void {
- $this->lazyWidgets[] = $widgetClass;
+ public function lazyRegisterWidget(string $widgetClass, string $appId): void {
+ $this->lazyWidgets[] = ['class' => $widgetClass, 'appId' => $appId];
}
public function loadLazyPanels(): void {
- $classes = $this->lazyWidgets;
- foreach ($classes as $class) {
+ if ($this->appManager === null) {
+ $this->appManager = $this->serverContainer->get(IAppManager::class);
+ }
+ $services = $this->lazyWidgets;
+ foreach ($services as $service) {
+ /** @psalm-suppress InvalidCatch */
try {
+ if (!$this->appManager->isEnabledForUser($service['appId'])) {
+ // all apps are registered, but some may not be enabled for the user
+ continue;
+ }
/** @var IWidget $widget */
- $widget = $this->serverContainer->query($class);
- } catch (QueryException $e) {
+ $widget = $this->serverContainer->get($service['class']);
+ } catch (ContainerExceptionInterface $e) {
/*
* There is a circular dependency between the logger and the registry, so
* we can not inject it. Thus the static call.
@@ -90,7 +99,7 @@ class Manager implements IManager {
*/
\OC::$server->get(LoggerInterface::class)->critical(
'Could not register lazy dashboard widget: ' . $e->getMessage(),
- ['excepiton' => $e]
+ ['exception' => $e]
);
}
@@ -111,7 +120,7 @@ class Manager implements IManager {
} catch (Throwable $e) {
\OC::$server->get(LoggerInterface::class)->critical(
'Error during dashboard widget loading: ' . $e->getMessage(),
- ['excepiton' => $e]
+ ['exception' => $e]
);
}
}
diff --git a/lib/private/Http/Client/LocalAddressChecker.php b/lib/private/Http/Client/LocalAddressChecker.php
index 2789b1b5935..c69d1007a16 100644
--- a/lib/private/Http/Client/LocalAddressChecker.php
+++ b/lib/private/Http/Client/LocalAddressChecker.php
@@ -66,8 +66,10 @@ class LocalAddressChecker {
$host = substr($host, 1, -1);
}
- // Disallow localhost and local network
- if ($host === 'localhost' || substr($host, -6) === '.local' || substr($host, -10) === '.localhost') {
+ // Disallow local network top-level domains from RFC 6762
+ $localTopLevelDomains = ['local','localhost','intranet','internal','private','corp','home','lan'];
+ $topLevelDomain = substr((strrchr($host, '.') ?: ''), 1);
+ if (in_array($topLevelDomain, $localTopLevelDomains)) {
$this->logger->warning("Host $host was not connected to because it violates local access rules");
throw new LocalServerException('Host violates local access rules');
}
diff --git a/lib/public/Comments/IComment.php b/lib/public/Comments/IComment.php
index 8465eaf49f4..44d294bb07c 100644
--- a/lib/public/Comments/IComment.php
+++ b/lib/public/Comments/IComment.php
@@ -299,4 +299,21 @@ interface IComment {
* @since 24.0.0
*/
public function setReactions(?array $reactions): IComment;
+
+ /**
+ * Set message expire date
+ *
+ * @param \DateTime|null $dateTime
+ * @return IComment
+ * @since 25.0.0
+ */
+ public function setExpireDate(?\DateTime $dateTime): IComment;
+
+ /**
+ * Get message expire date
+ *
+ * @return ?\DateTime
+ * @since 25.0.0
+ */
+ public function getExpireDate(): ?\DateTime;
}
diff --git a/lib/public/Comments/ICommentsManager.php b/lib/public/Comments/ICommentsManager.php
index c34bd4718cc..814ca3e8f9c 100644
--- a/lib/public/Comments/ICommentsManager.php
+++ b/lib/public/Comments/ICommentsManager.php
@@ -482,4 +482,15 @@ interface ICommentsManager {
* @since 21.0.0
*/
public function load(): void;
+
+ /**
+ * Delete comments with field expire_date less than current date
+ * Only will delete the message related with the object.
+ *
+ * @param string $objectType the object type (e.g. 'files')
+ * @param string $objectId e.g. the file id
+ * @return boolean true if at least one row was deleted
+ * @since 25.0.0
+ */
+ public function deleteMessageExpiredAtObject(string $objectType, string $objectId): bool;
}
diff --git a/lib/public/Dashboard/IManager.php b/lib/public/Dashboard/IManager.php
index 396624876ef..d9e73c89eb9 100644
--- a/lib/public/Dashboard/IManager.php
+++ b/lib/public/Dashboard/IManager.php
@@ -36,7 +36,7 @@ interface IManager {
* @param string $widgetClass
* @since 20.0.0
*/
- public function lazyRegisterWidget(string $widgetClass): void;
+ public function lazyRegisterWidget(string $widgetClass, string $appId): void;
/**
* @since 20.0.0