aboutsummaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorFerdinand Thiessen <opensource@fthiessen.de>2024-03-06 11:25:36 +0100
committerJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2024-03-07 22:40:30 +0100
commit26728846b40bb1819ad4de507f397b944d15877b (patch)
tree28eea14d3151fbff6a7f845096e99780fe0370e7 /apps
parent40ae1295e6bd2414cf2716b79e2d4a74cb4bd2d5 (diff)
downloadnextcloud-server-26728846b40bb1819ad4de507f397b944d15877b.tar.gz
nextcloud-server-26728846b40bb1819ad4de507f397b944d15877b.zip
feat(updatenotification): Allow to disable the app updated notifications and allow to en/disable guest users notification
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
Diffstat (limited to 'apps')
-rw-r--r--apps/updatenotification/lib/BackgroundJob/AppUpdatedNotifications.php6
-rw-r--r--apps/updatenotification/lib/Listener/AppUpdateEventListener.php6
-rw-r--r--apps/updatenotification/lib/Listener/BeforeTemplateRenderedEventListener.php6
3 files changed, 16 insertions, 2 deletions
diff --git a/apps/updatenotification/lib/BackgroundJob/AppUpdatedNotifications.php b/apps/updatenotification/lib/BackgroundJob/AppUpdatedNotifications.php
index caeb5a8dfa9..11d6577e81b 100644
--- a/apps/updatenotification/lib/BackgroundJob/AppUpdatedNotifications.php
+++ b/apps/updatenotification/lib/BackgroundJob/AppUpdatedNotifications.php
@@ -28,6 +28,7 @@ namespace OCA\UpdateNotification\BackgroundJob;
use OCA\UpdateNotification\AppInfo\Application;
use OCA\UpdateNotification\Manager;
use OCP\App\IAppManager;
+use OCP\AppFramework\Services\IAppConfig;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\QueuedJob;
use OCP\IConfig;
@@ -41,6 +42,7 @@ class AppUpdatedNotifications extends QueuedJob {
public function __construct(
ITimeFactory $time,
private IConfig $config,
+ private IAppConfig $appConfig,
private IManager $notificationManager,
private IUserManager $userManager,
private IAppManager $appManager,
@@ -98,13 +100,13 @@ class AppUpdatedNotifications extends QueuedJob {
* Notify all users for which the updated app is enabled
*/
private function notifyUsers(string $appId, INotification $notification): void {
- $guestsEnabled = class_exists('\OCA\Guests\UserBackend');
+ $guestsEnabled = $this->appConfig->getAppValueBool('app_updated.notify_guests', false) && class_exists('\OCA\Guests\UserBackend');
$isDefer = $this->notificationManager->defer();
// Notify all seen users about the app update
$this->userManager->callForSeenUsers(function (IUser $user) use ($guestsEnabled, $appId, $notification) {
- if ($guestsEnabled && ($user->getBackend() instanceof ('\OCA\Guests\UserBackend'))) {
+ if (!$guestsEnabled && ($user->getBackendClassName() === '\OCA\Guests\UserBackend')) {
return;
}
diff --git a/apps/updatenotification/lib/Listener/AppUpdateEventListener.php b/apps/updatenotification/lib/Listener/AppUpdateEventListener.php
index 15b7223e0d4..5ca801cc39a 100644
--- a/apps/updatenotification/lib/Listener/AppUpdateEventListener.php
+++ b/apps/updatenotification/lib/Listener/AppUpdateEventListener.php
@@ -31,6 +31,7 @@ use OCP\App\Events\AppUpdateEvent;
use OCP\BackgroundJob\IJobList;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
+use OCP\IAppConfig;
use Psr\Log\LoggerInterface;
/** @template-implements IEventListener<AppUpdateEvent> */
@@ -39,6 +40,7 @@ class AppUpdateEventListener implements IEventListener {
public function __construct(
private IJobList $jobList,
private LoggerInterface $logger,
+ private IAppConfig $appConfig,
) {
}
@@ -50,6 +52,10 @@ class AppUpdateEventListener implements IEventListener {
return;
}
+ if (!$this->appConfig->getValueBool(Application::APP_NAME, 'app_updated.enabled', true)) {
+ return;
+ }
+
foreach ($this->jobList->getJobsIterator(AppUpdatedNotifications::class, null, 0) as $job) {
// Remove waiting notification jobs for this app
if ($job->getArgument()['appId'] === $event->getAppId()) {
diff --git a/apps/updatenotification/lib/Listener/BeforeTemplateRenderedEventListener.php b/apps/updatenotification/lib/Listener/BeforeTemplateRenderedEventListener.php
index 0f86337e969..0691719040f 100644
--- a/apps/updatenotification/lib/Listener/BeforeTemplateRenderedEventListener.php
+++ b/apps/updatenotification/lib/Listener/BeforeTemplateRenderedEventListener.php
@@ -30,6 +30,7 @@ use OCP\App\IAppManager;
use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
+use OCP\IAppConfig;
use Psr\Log\LoggerInterface;
/** @template-implements IEventListener<BeforeTemplateRenderedEvent> */
@@ -38,6 +39,7 @@ class BeforeTemplateRenderedEventListener implements IEventListener {
public function __construct(
private IAppManager $appManager,
private LoggerInterface $logger,
+ private IAppConfig $appConfig,
) {
}
@@ -49,6 +51,10 @@ class BeforeTemplateRenderedEventListener implements IEventListener {
return;
}
+ if (!$this->appConfig->getValueBool(Application::APP_NAME, 'app_updated.enabled', true)) {
+ return;
+ }
+
// Only handle logged in users
if (!$event->isLoggedIn()) {
return;