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>
pull/43967/head
Ferdinand Thiessen 3 months ago committed by John Molakvoæ (skjnldsv)
parent 40ae1295e6
commit 26728846b4
No known key found for this signature in database
GPG Key ID: 60C25B8C072916CF

@ -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;
}

@ -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()) {

@ -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;

Loading…
Cancel
Save