summaryrefslogtreecommitdiffstats
path: root/lib/Dashboard
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2022-10-28 09:22:56 +0200
committerJoas Schilling <coding@schilljs.com>2022-10-31 11:33:45 +0100
commit9006e988c46b65527765f1653177edb2f934375b (patch)
treee7626e5c7d89417b4ebc9e498b2a6171e9459960 /lib/Dashboard
parentb4ec580da7a79f39ea893660a8cbc979ec8f8fe0 (diff)
Disable the dashboard widget with proper API
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/Dashboard')
-rw-r--r--lib/Dashboard/TalkWidget.php23
1 files changed, 14 insertions, 9 deletions
diff --git a/lib/Dashboard/TalkWidget.php b/lib/Dashboard/TalkWidget.php
index 951329195..3ca280fc9 100644
--- a/lib/Dashboard/TalkWidget.php
+++ b/lib/Dashboard/TalkWidget.php
@@ -27,7 +27,6 @@ namespace OCA\Talk\Dashboard;
use OCA\Talk\Chat\MessageParser;
use OCA\Talk\Config;
-use OCA\Talk\Exceptions\NotAllowedToUseTalkException;
use OCA\Talk\Manager;
use OCA\Talk\Participant;
use OCA\Talk\Room;
@@ -35,6 +34,7 @@ use OCA\Talk\Service\ParticipantService;
use OCP\Comments\IComment;
use OCP\Dashboard\IAPIWidget;
use OCP\Dashboard\IButtonWidget;
+use OCP\Dashboard\IConditionalWidget;
use OCP\Dashboard\IIconWidget;
use OCP\Dashboard\IOptionWidget;
use OCP\Dashboard\Model\WidgetButton;
@@ -46,7 +46,9 @@ use OCP\IUser;
use OCP\IUserSession;
use OCP\Util;
-class TalkWidget implements IAPIWidget, IIconWidget, IButtonWidget, IOptionWidget {
+class TalkWidget implements IAPIWidget, IIconWidget, IButtonWidget, IOptionWidget, IConditionalWidget {
+ protected IUserSession $userSession;
+ protected Config $talkConfig;
protected IURLGenerator $url;
protected IL10N $l10n;
protected Manager $manager;
@@ -62,13 +64,8 @@ class TalkWidget implements IAPIWidget, IIconWidget, IButtonWidget, IOptionWidge
ParticipantService $participantService,
MessageParser $messageParser
) {
- $user = $userSession->getUser();
- if ($user instanceof IUser && $talkConfig->isDisabledForUser($user)) {
- // This is dirty and will log everytime a user opens the dashboard or requests the api,
- // so we should look for a different solution in the server.
- throw new NotAllowedToUseTalkException();
- }
-
+ $this->userSession = $userSession;
+ $this->talkConfig = $talkConfig;
$this->url = $url;
$this->l10n = $l10n;
$this->manager = $manager;
@@ -104,6 +101,14 @@ class TalkWidget implements IAPIWidget, IIconWidget, IButtonWidget, IOptionWidge
return 'dashboard-talk-icon';
}
+ /**
+ * @inheritDoc
+ */
+ public function isEnabled(): bool {
+ $user = $this->userSession->getUser();
+ return !($user instanceof IUser && $this->talkConfig->isDisabledForUser($user));
+ }
+
public function getWidgetOptions(): WidgetOptions {
return new WidgetOptions(true);
}