]> git.mxchange.org Git - friendica.git/commitdiff
Preparations for a moderator role
authorMichael <heluecht@pirati.ca>
Thu, 10 Aug 2023 21:06:08 +0000 (21:06 +0000)
committerMichael <heluecht@pirati.ca>
Thu, 10 Aug 2023 21:06:08 +0000 (21:06 +0000)
src/Core/Session/Capability/IHandleUserSessions.php
src/Core/Session/Model/UserSession.php
src/Model/User.php
src/Module/BaseModeration.php
src/Module/Notifications/Ping.php

index 5734eafdf788d62955948ae93493d0ed4cb8cd62..3b135b52122e47438ab3a331d34578e17770177a 100644 (file)
@@ -93,6 +93,13 @@ interface IHandleUserSessions extends IHandleSessions
         */
        public function isSiteAdmin(): bool;
 
+       /**
+        * Check if current user is a moderator.
+        *
+        * @return bool true if user is a moderator
+        */
+       public function isModerator(): bool;
+
        /**
         * Returns User ID of the managed user in case it's a different identity
         *
index 8dfc3d8321386cb421cdc5c9926f6c289b4ec5bd..c1a38dffaecc7a760e974bbec252b0929f5c35d6 100644 (file)
@@ -139,6 +139,12 @@ class UserSession implements IHandleUserSessions
                return User::isSiteAdmin($this->getLocalUserId());
        }
 
+       /** {@inheritDoc} */
+       public function isModerator(): bool
+       {
+               return User::isModerator($this->getLocalUserId());
+       }
+
        /** {@inheritDoc} */
        public function setVisitorsContacts(string $my_url)
        {
index 89d75849fe9430057a65a34953c718e7b68d516f..18da3e956046c2d79968de025e8a01138981aae8 100644 (file)
@@ -880,6 +880,20 @@ class User
                ]);
        }
 
+       /**
+        * Returns if the given uid is valid and a moderator
+        *
+        * @param int $uid
+        *
+        * @return bool
+        * @throws Exception
+        */
+       public static function isModerator(int $uid): bool
+       {
+               // @todo Replace with a moderator check in the future
+               return self::isSiteAdmin($uid);
+       }
+
        /**
         * Checks if a nickname is in the list of the forbidden nicknames
         *
index 3de46b319c6a87261c34e1c2d1c091291dd781e0..a575e51f79e01abe35d25b4cc90af1abe924742d 100644 (file)
@@ -82,12 +82,12 @@ abstract class BaseModeration extends BaseModule
                        }
                }
 
-               if (!$this->app->isSiteAdmin()) {
-                       throw new HTTPException\ForbiddenException($this->t('You don\'t have access to administration pages.'));
+               if (!$this->session->isModerator()) {
+                       throw new HTTPException\ForbiddenException($this->t('You don\'t have access to moderation pages.'));
                }
 
                if ($this->session->getSubManagedUserId()) {
-                       throw new HTTPException\ForbiddenException($this->t('Submanaged account can\'t access the administration pages. Please log back in as the main account.'));
+                       throw new HTTPException\ForbiddenException($this->t('Submanaged account can\'t access the moderation pages. Please log back in as the main account.'));
                }
        }
 
index e54bd577b2d55a6ea6028c4ac45623daa41a25d1..603d6408c7bde7c008f73772441ab63d15fd76e4 100644 (file)
@@ -175,7 +175,7 @@ class Ping extends BaseModule
                        $myurl      = $this->session->getMyUrl();
                        $mail_count = $this->database->count('mail', ["`uid` = ? AND NOT `seen` AND `from-url` != ?", $this->session->getLocalUserId(), $myurl]);
 
-                       if (intval($this->config->get('config', 'register_policy')) === Register::APPROVE && $this->app->isSiteAdmin()) {
+                       if (intval($this->config->get('config', 'register_policy')) === Register::APPROVE && $this->session->isSiteAdmin()) {
                                $registrations = \Friendica\Model\Register::getPending();
                                $register_count = count($registrations);
                        }