]> git.mxchange.org Git - friendica.git/commitdiff
Move "submanage" Session value into own methods
authorPhilipp <admin@philipp.info>
Fri, 21 Oct 2022 17:33:28 +0000 (19:33 +0200)
committerPhilipp <admin@philipp.info>
Fri, 21 Oct 2022 17:35:34 +0000 (19:35 +0200)
mod/removeme.php
mod/settings.php
src/Content/Nav.php
src/Core/Session/Capability/IHandleUserSessions.php
src/Core/Session/Model/UserSession.php
src/Module/BaseAdmin.php
src/Module/Delegation.php
src/Module/Settings/Delegation.php

index da946485d3bc0d60641f84d17032a5c742563b00..9ef372fede6d95fe3106826e8b9c6f9fc98945d5 100644 (file)
@@ -32,7 +32,7 @@ function removeme_post(App $a)
                return;
        }
 
-       if (!empty($_SESSION['submanage'])) {
+       if (DI::userSession()->getSubManagedUserId()) {
                return;
        }
 
index 1de3f5dcf7de57d339975ba68d62c68d8fa74a2a..45f5f96c54ed3967793c879a01c6d896faaeca69 100644 (file)
@@ -51,7 +51,7 @@ function settings_post(App $a)
                return;
        }
 
-       if (!empty($_SESSION['submanage'])) {
+       if (DI::userSession()->getSubManagedUserId()) {
                return;
        }
 
@@ -152,7 +152,7 @@ function settings_content(App $a)
                return Login::form();
        }
 
-       if (!empty($_SESSION['submanage'])) {
+       if (DI::userSession()->getSubManagedUserId()) {
                DI::sysmsg()->addNotice(DI::l10n()->t('Permission denied.'));
                return '';
        }
index b80fb2d450e49712b9cf710b46e0686e14469b7e..23f5dcf0721cade709cf16b33803fc0c05251d40 100644 (file)
@@ -287,7 +287,7 @@ class Nav
                        $nav['messages']['outbox'] = ['message/sent', DI::l10n()->t('Outbox'), '', DI::l10n()->t('Outbox')];
                        $nav['messages']['new'] = ['message/new', DI::l10n()->t('New Message'), '', DI::l10n()->t('New Message')];
 
-                       if (User::hasIdentities(DI::session()->get('submanage') ?: DI::userSession()->getLocalUserId())) {
+                       if (User::hasIdentities(DI::userSession()->getSubManagedUserId() ?: DI::userSession()->getLocalUserId())) {
                                $nav['delegation'] = ['delegation', DI::l10n()->t('Accounts'), '', DI::l10n()->t('Manage other pages')];
                        }
 
index 9cd8de345528cee86922dbfc04e737101e2b222e..e5d1b4230dca129622c1e731a2b6942907678316 100644 (file)
@@ -72,6 +72,20 @@ interface IHandleUserSessions
         */
        public function isAuthenticated(): bool;
 
+       /**
+        * Returns User ID of the managed user in case it's a different identity
+        *
+        * @return int|bool uid of the manager or false
+        */
+       public function getSubManagedUserId();
+
+       /**
+        * Sets the User ID of the managed user in case it's a different identity
+        *
+        * @param int $managed_uid The user id of the managing user
+        */
+       public function setSubManagedUserId(int $managed_uid): void;
+
        /**
         * Set the session variable that contains the contact IDs for the visitor's contact URL
         *
index 1b0d14121603b32d21162564a87d0c12679d2d94..9d7d5c091e9ec5b65f6a504affcd1a93aa4105eb 100644 (file)
@@ -118,4 +118,16 @@ class UserSession implements IHandleUserSessions
        {
                $this->session->set('remote', Contact::getVisitorByUrl($this->session->get('my_url')));
        }
+
+       /** {@inheritDoc} */
+       public function getSubManagedUserId()
+       {
+               return $this->session->get('submanage') ?? false;
+       }
+
+       /** {@inheritDoc} */
+       public function setSubManagedUserId(int $managed_uid): void
+       {
+               $this->session->set('submanage', $managed_uid);
+       }
 }
index 7088bd7d6f610e4f06260cafbf1affee7408cc14..1c9fc0f2446ab41759eaa85cfe58ab567a7c3206 100644 (file)
@@ -63,7 +63,7 @@ abstract class BaseAdmin extends BaseModule
                        throw new HTTPException\ForbiddenException(DI::l10n()->t('You don\'t have access to administration pages.'));
                }
 
-               if (!empty($_SESSION['submanage'])) {
+               if (DI::userSession()->getSubManagedUserId()) {
                        throw new HTTPException\ForbiddenException(DI::l10n()->t('Submanaged account can\'t access the administration pages. Please log back in as the main account.'));
                }
        }
index c8b5c9d902b21fc6569f074be7e47c2605f24591..772651875e60c6b5fccb3e46ef96e66ae799ad1d 100644 (file)
@@ -45,8 +45,8 @@ class Delegation extends BaseModule
                $uid = DI::userSession()->getLocalUserId();
                $orig_record = User::getById(DI::app()->getLoggedInUserId());
 
-               if (DI::session()->get('submanage')) {
-                       $user = User::getById(DI::session()->get('submanage'));
+               if (DI::userSession()->getSubManagedUserId()) {
+                       $user = User::getById(DI::userSession()->getSubManagedUserId());
                        if (DBA::isResult($user)) {
                                $uid = intval($user['uid']);
                                $orig_record = $user;
@@ -101,7 +101,7 @@ class Delegation extends BaseModule
                DI::auth()->setForUser(DI::app(), $user, true, true);
 
                if ($limited_id) {
-                       DI::session()->set('submanage', $original_id);
+                       DI::userSession()->setSubManagedUserId($original_id);
                }
 
                $ret = [];
@@ -118,7 +118,7 @@ class Delegation extends BaseModule
                        throw new ForbiddenException(DI::l10n()->t('Permission denied.'));
                }
 
-               $identities = User::identities(DI::session()->get('submanage', DI::userSession()->getLocalUserId()));
+               $identities = User::identities(DI::userSession()->getSubManagedUserId() ?: DI::userSession()->getLocalUserId());
 
                //getting additinal information for each identity
                foreach ($identities as $key => $identity) {
index a7046d40c71e6535d350889813df51400a096daf..846e19769fc42199105eda166707c75362cc6cb5 100644 (file)
@@ -76,7 +76,7 @@ class Delegation extends BaseSettings
                $user_id = $args->get(3);
 
                if ($action === 'add' && $user_id) {
-                       if (DI::session()->get('submanage')) {
+                       if (DI::userSession()->getSubManagedUserId()) {
                                DI::sysmsg()->addNotice(DI::l10n()->t('Delegated administrators can view but not change delegation permissions.'));
                                DI::baseUrl()->redirect('settings/delegation');
                        }
@@ -98,7 +98,7 @@ class Delegation extends BaseSettings
                }
 
                if ($action === 'remove' && $user_id) {
-                       if (DI::session()->get('submanage')) {
+                       if (DI::userSession()->getSubManagedUserId()) {
                                DI::sysmsg()->addNotice(DI::l10n()->t('Delegated administrators can view but not change delegation permissions.'));
                                DI::baseUrl()->redirect('settings/delegation');
                        }