Sfoglia il codice sorgente

Ticket #5403 - ACL: Add possibility to downgrade membership level.

AntonLV 7 mesi fa
parent
commit
64d786bf70

+ 21 - 0
inc/js/functions.js

@@ -793,6 +793,27 @@ function bx_set_acl_level (iProfileId, iAclLevel, mixedLoadingElement) {
     }, 'json');
 }
 
+/**
+ * Reset ACL level for specified profile to Standard.
+ * @param iProfileId - profile id to reset acl level for
+ */
+function bx_reset_acl_level (iProfileId, mixedLoadingElement) {
+    var bBulk = !$.isNumeric(iProfileId);
+    var iAclCard = !bBulk && $('#sys-acl-profile-' + iProfileId).length > 0 ? 1 : 0;
+
+    var fPerform = function() {
+        var bLoading = typeof(mixedLoadingElement) != 'undefined';
+        if(bLoading)
+            bx_loading($(mixedLoadingElement), true);
+
+        $.post(sUrlRoot + 'menu.php', {o:'sys_set_acl_level', profile_id: iProfileId, level_id: 3, card: iAclCard}, function(oData) {
+            bx_on_set_acl_level(oData, mixedLoadingElement);
+        }, 'json');
+    };
+
+    bx_confirm(_t('_Are_you_sure'), fPerform);
+}
+
 function bx_on_set_acl_level(oData, oLoadingElement) {
     if(typeof(oLoadingElement) != 'undefined')
         bx_loading($(oLoadingElement), false);

+ 15 - 1
modules/boonex/acl/classes/BxAclResponse.php

@@ -38,7 +38,21 @@ class BxAclResponse extends BxDolAlertsResponse
 
     protected function _processSystemPageOutputBlockAclLevel($oAlert)
     {
-        $oAlert->aExtras['block_code'] .= $this->_oModule->serviceGetMembershipActions((int)$oAlert->aExtras['block_owner']);
+        if((int)$oAlert->aExtras['block_owner'] != $this->_oModule->getUserId())
+            return;
+
+        $oAlert->aExtras['block_tmpl_vars']['bx_if:show_actions']['content']['bx_repeat:actions'][] = [
+            'href' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink($this->_oModule->_oConfig->CNF['URL_VIEW']),
+            'bx_if:show_onclick' => [
+                'condition' => false,
+                'content' => [
+                    'onclick' => ''
+                ]
+            ],
+            'content' => _t('_bx_acl_txt_upgrade')
+        ];
+
+        $oAlert->aExtras['block_code'] = BxDolTemplate::getInstance()->parseHtmlByName($oAlert->aExtras['block_tmpl_name'], $oAlert->aExtras['block_tmpl_vars']);
     }
 
     protected function _processAclDeleted($oAlert)

+ 1 - 0
modules/boonex/english/data/langs/system/en.xml

@@ -2234,6 +2234,7 @@
 	<string name="_sys_acl_expire_never"><![CDATA[never]]></string>
     <string name="_sys_acl_state"><![CDATA[State: ]]></string>
     <string name="_sys_acl_state_trial"><![CDATA[Trial]]></string>
+    <string name="_sys_acl_downgrade"><![CDATA[Downgrade]]></string>
 
     <string name="_sys_agents_form_field_err_enter"><![CDATA[This field is essential. Please enter something here.]]></string>
     <string name="_sys_agents_form_field_err_select"><![CDATA[This field is essential. Please select something here.]]></string>

+ 1 - 0
modules/boonex/russian/data/langs/system/ru.xml

@@ -2209,6 +2209,7 @@
 	<string name="_sys_acl_expire_never"><![CDATA[никогда]]></string>
         <string name="_sys_acl_state"><![CDATA[Состояние: ]]></string>
         <string name="_sys_acl_state_trial"><![CDATA[Пробный]]></string>
+        <string name="_sys_acl_downgrade"><![CDATA[Понизить]]></string>
 
         <string name="_sys_agents_form_field_err_enter"><![CDATA[Это поле имеет важное значение. Пожалуйста, напишите что-нибудь здесь.]]></string>
         <string name="_sys_agents_form_field_err_select"><![CDATA[Это поле имеет важное значение. Пожалуйста, выберите что-нибудь здесь.]]></string>

+ 10 - 1
template/acl_membership.html

@@ -1,7 +1,16 @@
 <div id="__html_id__" class="bx-acl-membeship text-center">
     <div class="bx-acl-m-title bx-def-font-h3">__level__</div>
-    <div class="bx-acl-m-thumbnail mt-2">__thumbnail__</div>
+    <div class="bx-acl-m-thumbnail flex justify-center mt-2">__thumbnail__</div>
     <bx_if:show_private_info>
         <div class="bx-acl-m-info mt-2 bx-def-font-small"><bx_text:_sys_acl_start /> <b>__date_start__</b> <bx_text:_sys_acl_expire /> <b>__date_expire__</b><bx_if:show_state><br /><bx_text:_sys_acl_state /> <b>__state__</b></bx_if:show_state></div>
     </bx_if:show_private_info>
+    <bx_if:show_actions>
+        <div class="bx-acl-m-actions flex justify-center space-x-2 mt-4">
+            <bx_repeat:actions>
+                <div class="bx-acl-m-action">
+                    <a class="bx-btn bx-btn-small" href="__href__" <bx_if:show_onclick>onclick="__onclick__"</bx_if:show_onclick>>__content__</a>
+                </div>
+            </bx_repeat:actions>
+        </div>
+    </bx_if:show_actions>
 </div>

+ 45 - 12
template/scripts/BxBaseAcl.php

@@ -26,11 +26,15 @@ class BxBaseAcl extends BxDolAcl
 
         $oTemplate = BxDolTemplate::getInstance();
 
-        $iLoggedProfileId = bx_get_logged_profile_id();
         $aLevelInfo = $this->getMembershipInfo($aLevel['id']);
 
-        $aCheck = checkActionModule($iLoggedProfileId, 'show membership private info', 'system', false);
-        $oProfile = BxDolProfile::getInstance($iLoggedProfileId);
+        $bOwner = $bCanView = false;
+        if(($iLoggedPid = bx_get_logged_profile_id()) && ($oLogged = BxDolProfile::getInstance($iLoggedPid)) !== false) {
+            $bOwner = BxDolProfile::getInstance($iProfileId)->getAccountId() == $oLogged->getAccountId();
+
+            $aCheck = checkActionModule($iLoggedPid, 'show membership private info', 'system', false);
+            $bCanView = $aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED;
+        }
 
         if($this->_bIsApi) {
             $sIconS = $aLevelInfo['icon'];
@@ -49,8 +53,8 @@ class BxBaseAcl extends BxDolAcl
             ];
         }
 
-        $aTmplVarsPrivateInfo = array();
-        $bTmplVarsPrivateInfo = ($oProfile && (BxDolProfile::getInstance($iProfileId)->getAccountId() == $oProfile->getAccountId() || $aCheck[CHECK_ACTION_RESULT] === CHECK_ACTION_RESULT_ALLOWED) && !empty($aLevel['date_starts']));
+        $aTmplVarsPrivateInfo = [];
+        $bTmplVarsPrivateInfo = (($bOwner || $bCanView) && !empty($aLevel['date_starts']));
         if($bTmplVarsPrivateInfo)
             $aTmplVarsPrivateInfo = array(
                 'date_start' => bx_time_js($aLevel['date_starts']),
@@ -61,17 +65,44 @@ class BxBaseAcl extends BxDolAcl
                         'state' => _t('_sys_acl_state_' . $aLevel['state'])
                     )
                 )
-            );
+            );        
+
+        $aTmplVarsActions = [];
+        if($bOwner) {
+            $aDowngradable = $this->getMemberships(false, true, true, true);
+            unset($aDowngradable[MEMBERSHIP_ID_STANDARD]);
+
+            if(in_array($aLevel['id'], array_keys($aDowngradable)))
+                $aTmplVarsActions[] = [
+                    'href' => 'javascript:void(0)',
+                    'bx_if:show_onclick' => [
+                        'condition' => true,
+                        'content' => [
+                            'onclick' => 'javascript:bx_reset_acl_level(' . $iProfileId . ', this)'
+                        ]
+                    ],
+                    'content' => _t('_sys_acl_downgrade')
+                ];
+        }
 
-        $sContent = $oTemplate->parseHtmlByName('acl_membership.html', array(
+        $sTmplName = 'acl_membership.html';
+        $aTmplVars = [
             'html_id' => 'sys-acl-profile-' . $iProfileId,
             'level' => _t($aLevel['name']),
-            'thumbnail' => $oTemplate->getImage($aLevelInfo['icon'], array('class' => 'bx-acl-m-thumbnail')),
-            'bx_if:show_private_info' => array(
+            'thumbnail' => $oTemplate->getImage($aLevelInfo['icon'], ['class' => 'bx-acl-m-thumbnail']),
+            'bx_if:show_private_info' => [
                 'condition' => $bTmplVarsPrivateInfo,
                 'content' => $aTmplVarsPrivateInfo
-            )
-        ));
+            ],
+            'bx_if:show_actions' => [
+                'condition' => !empty($aTmplVarsActions),
+                'content' => [
+                    'bx_repeat:actions' => $aTmplVarsActions
+                ]
+            ]
+        ];
+
+        $sContent = $oTemplate->parseHtmlByName($sTmplName, $aTmplVars);
 
         /**
          * @hooks
@@ -87,10 +118,12 @@ class BxBaseAcl extends BxDolAcl
          */
         bx_alert('system', 'page_output_block_acl_level', 0, false, [
             'block_owner' => $iProfileId,
+            'block_tmpl_name' => $sTmplName,
+            'block_tmpl_vars' => $aTmplVars,
             'block_code' => &$sContent
         ]);
 
-        $oTemplate->addCss(array('acl.css'));
+        $oTemplate->addCss(['acl.css']);
         return $sContent;
     }
 

+ 19 - 0
template/scripts/BxBaseServiceProfiles.php

@@ -1206,6 +1206,25 @@ class BxBaseServiceProfiles extends BxDol
         return true;//$aResult;
     }
 
+    public function serviceResetMembership($mixedProfileId)
+    {
+        if(!is_array($mixedProfileId))
+            $mixedProfileId = [$mixedProfileId];
+
+        $oAcl = BxDolAcl::getInstance();
+        $iAclLevelId = MEMBERSHIP_ID_STANDARD;
+
+        $iReset = 0;
+        foreach($mixedProfileId as $iProfileId) {
+            if(!$oAcl->setMembership($iProfileId, $iAclLevelId, 0, true))
+                continue;
+
+            $iReset += 1;
+        }
+
+        return $iReset != 0;
+    }
+
     public function serviceAccountProfileSwitcher ($iAccountId = false, $iActiveProfileId = null, $sUrlProfileAction = '', $bShowAll = 0, $sButtonTitle = '', $sProfileTemplate = '')
     {
         if (!$iAccountId)

+ 1 - 0
template/scripts/BxBaseServices.php

@@ -85,6 +85,7 @@ class BxBaseServices extends BxDol implements iBxDolProfileService
             'BrowseRecommendationsSubscriptions' => 'BxBaseServiceProfiles',
             'BrowseFriends' => 'BxBaseServiceProfiles',
             'SetMembership' => 'BxBaseServiceProfiles',
+            'ResetMembership' => 'BxBaseServiceProfiles',
             'BrowseFriendRequests' => 'BxBaseServiceProfiles',
             'BrowseFriendRequested' => 'BxBaseServiceProfiles',
             'BrowseSubscribedMe' => 'BxBaseServiceProfiles',