From e5731eda6008cd3e9480bb6d2720fc9694840319 Mon Sep 17 00:00:00 2001
From: Thomas Hackl <hackl@data-quest.de>
Date: Wed, 4 May 2022 10:42:20 +0200
Subject: [PATCH] handle admin and root accounts

---
 controllers/matrix_chat.php | 4 ++++
 plugin.manifest             | 2 +-
 views/matrix_chat/index.php | 9 +++++++++
 3 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/controllers/matrix_chat.php b/controllers/matrix_chat.php
index f80088b..83836ff 100644
--- a/controllers/matrix_chat.php
+++ b/controllers/matrix_chat.php
@@ -44,6 +44,10 @@ class MatrixChatController extends AuthenticatedController
 
         $member = CourseMember::find([$this->course->id, User::findCurrent()->id]);
 
+        if (!$member || $GLOBALS['perm']->have_perm('admin')) {
+            $this->noMemberHint = true;
+        }
+
         // Chat can only be used if user is visible (Matrix has no privacy settings in chat)
         if ($member->visible == 'yes' || $member->visible == 'unknown' && Config::get()->USER_VISIBILITY_UNKNOWN) {
 
diff --git a/plugin.manifest b/plugin.manifest
index 251380b..82b8eb1 100644
--- a/plugin.manifest
+++ b/plugin.manifest
@@ -1,7 +1,7 @@
 pluginname=Matrix-Chat
 pluginclassname=MatrixPlugin
 origin=data-quest
-version=1.0
+version=1.1.q
 screenshot=assets/images/matrix_logo.png
 description=Matrix chat for Stud.IP courses
 studipMinVersion=4.5
diff --git a/views/matrix_chat/index.php b/views/matrix_chat/index.php
index c5eb6c3..f19f183 100644
--- a/views/matrix_chat/index.php
+++ b/views/matrix_chat/index.php
@@ -1,3 +1,12 @@
+<? if ($noMemberHint) : ?>
+    <div class="messagebox messagebox_warning">
+        <p>
+            <?= dgettext('matrix', 'Sie sind nicht als teilnehmende Person in dieser Veranstaltung ' .
+                'eingetragen und können daher den zu dieser Veranstaltung gehörenden Matrixraum nicht nutzen. Das ' .
+                'kann daran liegen, dass Sie eine Admin- oder Rootkennung nutzen.') ?>
+        </p>
+    </div>
+<? endif ?>
 <? if ($showAccountHint) : ?>
     <div class="messagebox messagebox_warning">
         <p>
-- 
GitLab