Przeglądaj źródła

Merge branch 'master' of https://github.com/unaio/una

AntonLV 6 lat temu
rodzic
commit
ffbace7b03

+ 2 - 2
modules/boonex/oauth2/classes/BxOAuthAPI.php

@@ -234,10 +234,10 @@ class BxOAuthAPI extends BxDol
         if (!BxDolRequest::serviceExists($sModule, $sMethod, $sClass))
             return false;
 
-        if (!BxDolRequest::serviceExists($sModule, $sCheckMethod, $sClass))
+        if (!BxDolRequest::serviceExists($sModule, $sCheckMethod, 'system' == $sModule ? 'TemplServices' : $sClass))
             return false;
 
-        return BxDolService::call($sModule, $sCheckMethod, array($sMethod));
+        return BxDolService::call($sModule, $sCheckMethod, array($sMethod), 'system' == $sModule ? 'TemplServices' : $sClass);
     }
     
 

+ 2 - 2
modules/boonex/oauth2/classes/BxOAuthModule.php

@@ -238,13 +238,13 @@ class BxOAuthModule extends BxDolModule
             $this->_oAPI = new BxOAuthAPI($this);
         }
 
-        $bPublic = $this->_oAPI->isPublicAPI(bx_get('module') ? bx_get('module') : 'bx_api', $sMethod);
+        $bPublic = $this->_oAPI->isPublicAPI(bx_get('module') ? bx_get('module') : 'bx_api', $sMethod, bx_get('class') ? bx_get('class') : false);
         if ($bPublic) {
             $this->checkAllowedOrigins();
             $this->_oAPI->com($sMethod, array(), $bPublic);
         }
         else {
-            if (!$this->_oAPI->isSafeAPI(bx_get('module') ? bx_get('module') : 'bx_api', $sMethod)) {
+            if (!$this->_oAPI->isSafeAPI(bx_get('module') ? bx_get('module') : 'bx_api', $sMethod, bx_get('class') ? bx_get('class') : false)) {
                 $this->_oAPI->errorOutput(403, 'access_denied', 'Only "public" and "safe" services can be called, or method doesn\'t exist');
                 return;
             }

+ 12 - 21
template/scripts/BxBasePageAccount.php

@@ -53,38 +53,29 @@ class BxBasePageAccount extends BxTemplPage
 
         // switch profile context
         if ($iSwitchToProfileId = (int)bx_get('switch_to_profile')) {
+            $sInformerMsg = '';
             $oProfile = BxDolProfile::getInstance($iSwitchToProfileId);
-            $sInformerMsg = '';            
 
             if ($oProfile && BxDolService::call($oProfile->getModule(), 'act_as_profile')) {
-                $iViewerAccountId = getLoggedId();
-                $iSwitchToAccountId = $oProfile->getAccountId();
-                
-                $iViewerProfileId = bx_get_logged_profile_id();
-                $aCheck = checkActionModule($iViewerProfileId, 'switch to any profile', 'system', false);
-                $bAllowSwitchToAnyProfile = $aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED;
-                
-                $bCanSwitch = ($iSwitchToAccountId == $iViewerAccountId || $bAllowSwitchToAnyProfile);
-                bx_alert('account', 'check_switch_context', $iSwitchToAccountId, $iViewerProfileId, array('switch_to_profile' => $iSwitchToProfileId, 'viewer_account' => $iViewerAccountId, 'override_result' => &$bCanSwitch));
 
-                if ($bCanSwitch) {
-                    $oAccount = BxDolAccount::getInstance();
-                    if ($oAccount->updateProfileContext($iSwitchToProfileId)) {
-                        checkActionModule($iViewerProfileId, 'switch to any profile', 'system', true);
-                        $sInformerMsg = _t('_sys_txt_account_profile_context_changed_success', $oProfile->getDisplayName());
-                        if ((int)bx_get('redirect_back') && isset($_SERVER['HTTP_REFERER']) && 0 === mb_stripos($_SERVER['HTTP_REFERER'], BX_DOL_URL_ROOT)) {
-                            header("Location:" . $_SERVER['HTTP_REFERER']);
-                            exit;
-                        }
+                $mixedRes = bx_srv('system','switch_profile',[$oProfile->id()], 'TemplServiceAccount');
+                if (true === $mixedRes) {
+                    $sInformerMsg = _t('_sys_txt_account_profile_context_changed_success', $oProfile->getDisplayName());
+                    if ((int)bx_get('redirect_back') && isset($_SERVER['HTTP_REFERER']) && 0 === mb_stripos($_SERVER['HTTP_REFERER'], BX_DOL_URL_ROOT)) {
+                        header("Location:" . $_SERVER['HTTP_REFERER']);
+                        exit;
                     }
                 }
+                else {
+                    $sInformerMsg = $mixedRes;
+                }
 
                 $oInformer = BxDolInformer::getInstance($this->_oTemplate);
                 if ($oInformer)
-                    $oInformer->add('sys-account-profile-context-change-result', $sInformerMsg ? $sInformerMsg : _t('_error occured'), $sInformerMsg ? BX_INFORMER_INFO : BX_INFORMER_ERROR);
+                    $oInformer->add('sys-account-profile-context-change-result', $sInformerMsg ? $sInformerMsg : _t('_error occured'), true === $mixedRes ? BX_INFORMER_INFO : BX_INFORMER_ERROR);
+
             }
         }
-
     }
 
     protected function _isVisiblePage ($a)

+ 53 - 0
template/scripts/BxBaseServiceAccount.php

@@ -445,6 +445,59 @@ class BxBaseServiceAccount extends BxDol
         return '<div class="bx-def-padding-sec-bottom">' . $sResultMsg . '</div>' . $sForm . ($bShowErrorEmptyBoth ? '<div class="bx-form-warn">' . _t("_sys_form_forgot_password_phone_and_email_empty_error") . '</div>' : '');
     }
 
+    /**
+     * @page service Service Calls
+     * @section bx_system_general System Services 
+     * @subsection bx_system_general-account Account
+     * @subsubsection bx_system_general-switch_profile switch_profile
+     * 
+     * @code bx_srv('system', 'switch_profile', [123], 'TemplServiceAccount'); @endcode
+     * @code {{~system:switch_profile:TemplServiceAccount:[123]~}} @endcode
+     * 
+     * Switch current user profile. 
+     * User can switch between profiles if multiple profiles are created.
+     * Also it's possible to switch to Organization profile if user is admin of Organization, 
+     * or other module which can `actAsProfile`.
+     * Admin can switch to any prifile by default
+     *
+     * @param $iSwitchToProfileId profile ID to switch to
+     * @return true on success or error message otherwise, so make sue to make strict (===) comparision
+     * 
+     * @see BxBaseServiceAccount::serviceSwitchProfile
+     */
+    /** 
+     * @ref bx_system_general-switch_profile "switch_profile"
+     */
+    public function serviceSwitchProfile($iSwitchToProfileId)
+    {
+        $oProfile = BxDolProfile::getInstance($iSwitchToProfileId);
+        if (!$oProfile) {
+            return _t('_sys_txt_error_occured');
+        }
+
+        $iViewerAccountId = getLoggedId();
+        $iSwitchToAccountId = $oProfile->getAccountId();
+        
+        $iViewerProfileId = bx_get_logged_profile_id();
+        $aCheck = checkActionModule($iViewerProfileId, 'switch to any profile', 'system', false);
+        $bAllowSwitchToAnyProfile = $aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED;
+
+        $bCanSwitch = ($iSwitchToAccountId == $iViewerAccountId || $bAllowSwitchToAnyProfile);
+        bx_alert('account', 'check_switch_context', $iSwitchToAccountId, $iViewerProfileId, array('switch_to_profile' => $iSwitchToProfileId, 'viewer_account' => $iViewerAccountId, 'override_result' => &$bCanSwitch));
+
+        if (!$bCanSwitch) {
+            return isset($aCheck[CHECK_ACTION_MESSAGE]) ? $aCheck[CHECK_ACTION_MESSAGE] : _t('_sys_txt_error_occured'); 
+        } 
+
+        $oAccount = BxDolAccount::getInstance();
+        if (!$oAccount->updateProfileContext($iSwitchToProfileId)) {
+            return _t('_sys_txt_error_occured');
+        }
+
+        checkActionModule($iViewerProfileId, 'switch to any profile', 'system', true);
+        return true;
+    }
+
     /**
      * Reset password procedure
      */

+ 1 - 0
template/scripts/BxBaseServices.php

@@ -33,6 +33,7 @@ class BxBaseServices extends BxDol implements iBxDolProfileService
 
             'CreateAccountForm' => 'BxBaseServiceAccount',
             'ForgotPassword' => 'BxBaseServiceAccount',
+            'SwitchProfile' => 'BxBaseServiceAccount',
 
             'CategoriesList' => 'BxBaseServiceCategory',