Browse Source

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>
tags/v29.0.0beta1
Ferdinand Thiessen 2 months ago
parent
commit
26728846b4
No account linked to committer's email address

+ 4
- 2
apps/updatenotification/lib/BackgroundJob/AppUpdatedNotifications.php View File

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


+ 6
- 0
apps/updatenotification/lib/Listener/AppUpdateEventListener.php View File

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

+ 6
- 0
apps/updatenotification/lib/Listener/BeforeTemplateRenderedEventListener.php View File

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