瀏覽代碼

Ticket #5478 - ACL: Add possibility to associate a level with a profile type.

AntonLV 5 月之前
父節點
當前提交
9c2b059cb0

+ 4 - 0
inc/classes/BxDolAclQuery.php

@@ -90,6 +90,9 @@ class BxDolAclQuery extends BxDolDb implements iBxDolSingleton
                     MEMBERSHIP_ID_SUSPENDED
                     
                 )) . ")";
+
+                if(($sAvailableTo = $aParams['available_to'] ?? false))
+                    $sWhereClause .= " AND `tal`.`UnavailableTo` NOT LIKE " . $this->escape('%|' . $aParams['available_to'] . '|%');
                 break;
 
             case 'all_pair':
@@ -122,6 +125,7 @@ class BxDolAclQuery extends BxDolDb implements iBxDolSingleton
                 `tal`.`Active` AS `active`,
                 `tal`.`Purchasable` AS `purchasable`,
                 `tal`.`Removable` AS `removable`,
+                `tal`.`UnavailableTo` AS `unavailable_to`,
                 `tal`.`QuotaSize` AS `quota_size`,
                 `tal`.`QuotaNumber` AS `quota_number`,
                 `tal`.`QuotaMaxFileSize` AS `quota_max_file_size`,

+ 1 - 0
install/sql/system.sql

@@ -1391,6 +1391,7 @@ CREATE TABLE `sys_acl_levels` (
   `Active` enum('yes','no') NOT NULL default 'no',
   `Purchasable` enum('yes','no') NOT NULL default 'yes',
   `Removable` enum('yes','no') NOT NULL default 'yes',
+  `UnavailableTo` varchar(255) NOT NULL default '',
   `QuotaSize` bigint(20) NOT NULL,
   `QuotaNumber` int(11) NOT NULL,
   `QuotaMaxFileSize` bigint(20) NOT NULL,

+ 8 - 0
modules/boonex/acl/classes/BxAclGridView.php

@@ -231,6 +231,14 @@ class BxAclGridView extends BxAclGridLevels
     	return parent::_getActionDefault($sType, $sKey, $a, false, $isDisabled, $aRow);
     }
 
+    protected function _getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage)
+    {
+        if($this->_iLogged && ($oLogged = BxDolProfile::getInstance($this->_iLogged)) !== false)
+            $this->_aOptions['source'] .= "AND `tl`.`UnavailableTo` NOT LIKE " . $this->_oModule->_oDb->escape('%|' . $oLogged->getModule() . '|%') . " ";
+
+        return parent::_getDataSql($sFilter, $sOrderField, $sOrderDir, $iStart, $iPerPage);;
+    }
+
     protected function _isLifetime($aRow)
     {
         return empty($aRow['period']) && empty($aRow['period_unit']);

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

@@ -1427,6 +1427,7 @@
 	<string name="_adm_prm_dsc_actions_avail"><![CDATA[Leave it blank if the action is always available]]></string>
 	<string name="_adm_prm_dsc_actions_number"><![CDATA[Leave it blank for unlimited actions]]></string>
 	<string name="_adm_prm_dsc_actions_reset"><![CDATA[In hours. Leave it blank if you don't want to reset counter]]></string>
+        <string name="_adm_prm_dsc_level_unavailable_to"><![CDATA[Select nothing if a level should be available to all profile types.]]></string>
 	<string name="_adm_prm_dsc_level_description"><![CDATA[Brief overview of terms and advantages of this level.]]></string>
 	<string name="_adm_prm_dsc_level_icon"><![CDATA[You may use font icon here]]></string>
 	<string name="_adm_prm_dsc_level_icon_image"><![CDATA[or upload an image.]]></string>
@@ -1467,6 +1468,7 @@
 	<string name="_adm_prm_txt_level_account"><![CDATA[Account]]></string>
 	<string name="_adm_prm_txt_level_actions_copy"><![CDATA[Copy actions from]]></string>
 	<string name="_adm_prm_txt_level_administrator"><![CDATA[Administrator]]></string>
+        <string name="_adm_prm_txt_level_unavailable_to"><![CDATA[Unavailable for]]></string>
 	<string name="_adm_prm_txt_level_create_popup"><![CDATA[Add New Level]]></string>
 	<string name="_adm_prm_txt_level_description"><![CDATA[Description]]></string>
 	<string name="_adm_prm_txt_level_edit_popup"><![CDATA[Edit "{0}" Level]]></string>

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

@@ -1409,6 +1409,7 @@
 	<string name="_adm_prm_dsc_actions_avail"><![CDATA[Оставьте пустым, если действие всегда доступно]]></string>
 	<string name="_adm_prm_dsc_actions_number"><![CDATA[Оставьте пустым для бесконечных действий]]></string>
 	<string name="_adm_prm_dsc_actions_reset"><![CDATA[В часах. Оставьте пустым, если не хотите сбрасывать счётчик]]></string>
+        <string name="_adm_prm_dsc_level_unavailable_to"><![CDATA[Не выбирайте ничего, если уровень должен быть доступен для всех типов профилей.]]></string>
 	<string name="_adm_prm_dsc_level_description"><![CDATA[Краткое описание достоинств и правил данного членства.]]></string>
 	<string name="_adm_prm_dsc_level_icon"><![CDATA[Здесь можно использовать иконку шрифта]]></string>
 	<string name="_adm_prm_dsc_level_icon_image"><![CDATA[или загрузить изображение.]]></string>
@@ -1445,6 +1446,7 @@
 	<string name="_adm_prm_txt_level_account"><![CDATA[Аккаунт]]></string>
 	<string name="_adm_prm_txt_level_actions_copy"><![CDATA[Скопировать действия из]]></string>
 	<string name="_adm_prm_txt_level_administrator"><![CDATA[Администратор]]></string>
+        <string name="_adm_prm_txt_level_unavailable_to"><![CDATA[Недоступно для]]></string>
 	<string name="_adm_prm_txt_level_create_popup"><![CDATA[Добавить новый уровень]]></string>
 	<string name="_adm_prm_txt_level_description"><![CDATA[Описание]]></string>
 	<string name="_adm_prm_txt_level_edit_popup"><![CDATA[Редактировать "{0}" уровень]]></string>

+ 38 - 17
studio/template/scripts/BxBaseStudioPermissionsLevels.php

@@ -37,6 +37,9 @@ class BxBaseStudioPermissionsLevels extends BxDolStudioPermissionsLevels
                 return;
             }
 
+            if(($aUnavailableTo = $oForm->getCleanValue('UnavailableTo')) && is_array($aUnavailableTo))
+            BxDolForm::setSubmittedValue('UnavailableTo', implode(',', $aUnavailableTo), $oForm->aFormAttrs['method']);
+
             $mixedIcon = '';
             if(!empty($_FILES['Icon_image']['tmp_name'])) {
                 $oStorage = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES);
@@ -71,16 +74,16 @@ class BxBaseStudioPermissionsLevels extends BxDolStudioPermissionsLevels
 
             	$iActionsFrom = (int)$oForm->getCleanValue('Actions');
             	if($iActionsFrom > 0) {
-            		$aActions = array();
-            		$this->oDb->getActions(array('type' => 'by_level_id', 'value' => $iActionsFrom), $aActions, false);
-            		foreach($aActions as $aAction)
-            			$this->oDb->switchAction($iId, $aAction['id'], true, array(
-            				'AllowedCount' => $aAction['allowed_count'],
-            				'AllowedPeriodLen' => $aAction['allowed_period_len'],
-            				'AllowedPeriodStart' => $aAction['allowed_period_start'],
-            				'AllowedPeriodEnd' => $aAction['allowed_period_end'],
-            				'AdditionalParamValue' => $aAction['additional_param_value']
-            			));
+                    $aActions = array();
+                    $this->oDb->getActions(array('type' => 'by_level_id', 'value' => $iActionsFrom), $aActions, false);
+                    foreach($aActions as $aAction)
+                        $this->oDb->switchAction($iId, $aAction['id'], true, array(
+                            'AllowedCount' => $aAction['allowed_count'],
+                            'AllowedPeriodLen' => $aAction['allowed_period_len'],
+                            'AllowedPeriodStart' => $aAction['allowed_period_start'],
+                            'AllowedPeriodEnd' => $aAction['allowed_period_end'],
+                            'AdditionalParamValue' => $aAction['additional_param_value']
+                        ));
             	}
 
                 // create system event
@@ -133,6 +136,9 @@ class BxBaseStudioPermissionsLevels extends BxDolStudioPermissionsLevels
         $oForm->initChecker();
 
         if($oForm->isSubmittedAndValid()) {
+            if(($aUnavailableTo = $oForm->getCleanValue('UnavailableTo')) && is_array($aUnavailableTo))
+                BxDolForm::setSubmittedValue('UnavailableTo', implode(',', $aUnavailableTo), $oForm->aFormAttrs['method']);
+
             $bIconImageCur = is_numeric($aLevel['icon']) && (int)$aLevel['icon'] != 0;
             $bIconImageNew = !empty($_FILES['Icon_image']['tmp_name']);
 
@@ -321,7 +327,7 @@ class BxBaseStudioPermissionsLevels extends BxDolStudioPermissionsLevels
 
     protected function _getFormObject($sAction, $aLevel = array())
     {
-    	bx_import('BxTemplStudioFormView');
+        bx_import('BxTemplStudioFormView');
 
         $aForm = array(
             'form_attrs' => array(
@@ -394,11 +400,21 @@ class BxBaseStudioPermissionsLevels extends BxDolStudioPermissionsLevels
                     'caption' => _t('_adm_prm_txt_level_description'),
                     'info' => _t('_adm_prm_dsc_level_description'),
                     'value' => isset($aLevel['description']) ? $aLevel['description'] : '_adm_prm_txt_level',
-                	'code' => 1,
+                    'code' => 1,
                     'db' => array (
                         'pass' => 'XssHtml',
                     )
                 ),
+                'UnavailableTo' => array(
+                    'type' => 'checkbox_set',
+                    'name' => 'UnavailableTo',
+                    'caption' => _t('_adm_prm_txt_level_unavailable_to'),
+                    'info' => _t('_adm_prm_dsc_level_unavailable_to'),
+                    'value' => isset($aLevel['unavailable_to']) ? explode(',', $aLevel['unavailable_to']) : [],
+                    'db' => array (
+                        'pass' => 'Xss',
+                    )
+                ),
                 'QuotaSize' => array(
                     'type' => 'text',
                     'name' => 'QuotaSize',
@@ -486,7 +502,7 @@ class BxBaseStudioPermissionsLevels extends BxDolStudioPermissionsLevels
                     'info' => _t('_adm_prm_dsc_level_icon'),
                     'value' => '',
                     'required' => '0',
-					'code' => 1,
+                    'code' => 1,
                     'db' => array (
                         'pass' => 'Xss',
                     ),
@@ -495,7 +511,7 @@ class BxBaseStudioPermissionsLevels extends BxDolStudioPermissionsLevels
                         'params' => array(),
                         'error' => _t('_adm_prm_err_level_icon'),
                     ),
-					'attrs' => array('class' => 'bx-form-input-textarea-small'),
+                    'attrs' => array('class' => 'bx-form-input-textarea-small'),
                 ),
                 'Icon_image' => array(
                     'type' => 'file',
@@ -520,8 +536,8 @@ class BxBaseStudioPermissionsLevels extends BxDolStudioPermissionsLevels
                     'name' => 'Actions',
                     'caption' => _t('_adm_prm_txt_level_actions_copy'),
                     'values' => array(
-                		array('key' => 0, 'value' => _t('_sys_txt_empty'))
-                	),
+                        array('key' => 0, 'value' => _t('_sys_txt_empty'))
+                    ),
                 ),
                 'controls' => array(
                     'name' => 'controls',
@@ -547,7 +563,12 @@ class BxBaseStudioPermissionsLevels extends BxDolStudioPermissionsLevels
         $aLevels = array(); 
         $this->oDb->getLevels(array('type' => 'all_pair'), $aLevels, false);
         foreach($aLevels as $iId => $sName)
-        	$aForm['inputs']['Actions']['values'][] = array('key' => $iId, 'value' => _t($sName));
+            $aForm['inputs']['Actions']['values'][] = array('key' => $iId, 'value' => _t($sName));
+        
+        $aModules = bx_srv('system', 'GetModulesByType', ['profile']);
+        foreach($aModules as $aModule)
+            $aForm['inputs']['UnavailableTo']['values'][] = array('key' => '|' . $aModule['name'] . '|', 'value' => BxDolStudioUtils::getModuleTitle($aModule['name']));
+        
 
         switch($sAction) {
             case 'add':

+ 5 - 2
template/scripts/BxBaseMenuSetAclLevel.php

@@ -66,11 +66,14 @@ class BxBaseMenuSetAclLevel extends BxTemplMenu
                     'o' => 'sys_set_acl_level', 
                 ]);
 
-                $oForm->aInputs['profile_id']['value'] = $mixedProfileId;
+                $oProfile = BxDolProfile::getInstance($mixedProfileId);
+                $bProfile = $oProfile !== false;
+
+                $oForm->aInputs['profile_id']['value'] = $bProfile ? $oProfile->id() : $mixedProfileId;
                 $oForm->aInputs['card']['value'] = 0;
 
                 $oAcl = BxDolAcl::getInstance();
-                $aAclLevels = $oAcl->getMembershipsBy(array('type' => 'all_active_not_automatic_pair'));
+                $aAclLevels = $oAcl->getMembershipsBy(['type' => 'all_active_not_automatic_pair', 'available_to' => $bProfile ? $oProfile->getModule() : '']);
 		foreach ($aAclLevels as $k => $s)
                     $oForm->aInputs['level_id']['values'][] = ['key' => $k, 'value' => _t($s)];