瀏覽代碼

Ticket #3794 - Add [+] menu or button in contexts.

AntonLV 1 年之前
父節點
當前提交
add6bf6e68

+ 25 - 6
inc/classes/BxDolPrivacy.php

@@ -397,6 +397,25 @@ class BxDolPrivacy extends BxDolFactory implements iBxDolFactoryObject
         return $this->_oDb->getGroupCustom($aParams);
     }
 
+    /**
+     * Checks if this privacy object allows to add content in specified context.
+     * 
+     * @param type $sContext - context module name
+     * @return boolean
+     */
+    public function isAllowedAddInContext($sContext)
+    {
+        $bSpaces = !empty($this->_aObject['spaces']);
+
+        if($bSpaces && $this->_aObject['spaces'] == 'all') 
+            return true;
+
+        if($bSpaces && in_array($sContext, explode(',', $this->_aObject['spaces'])))
+            return true;
+
+        return false;
+    }
+
     /**
      * Note. Is used when privacy group is processing after the main form submit.
      */
@@ -587,7 +606,7 @@ class BxDolPrivacy extends BxDolFactory implements iBxDolFactoryObject
         
         return $aValues;
     }
-    
+
     /**
      * Get database field name for action.
      *
@@ -597,12 +616,12 @@ class BxDolPrivacy extends BxDolFactory implements iBxDolFactoryObject
      */
     public static function getFieldName($sObject, $sAction = '')
     {
-    	$oPrivacy = BxDolPrivacy::getObjectInstance($sObject);
+        $oPrivacy = BxDolPrivacy::getObjectInstance($sObject);
         if(empty($oPrivacy))
             return '';
 
-		if(empty($sAction))
-			$sAction = $oPrivacy->_aObject['action'];
+        if(empty($sAction))
+            $sAction = $oPrivacy->_aObject['action'];
 
         return $oPrivacy->convertActionToField($sAction);
     }
@@ -842,9 +861,9 @@ class BxDolPrivacy extends BxDolFactory implements iBxDolFactoryObject
         return $this->_oDb->getObjectInfo($sAction, $iObjectId);
     }
 
-	protected function getPrivacyGroupsForContentPublic($iProfileIdOwner = 0, $aCustomGroups = array())
+    protected function getPrivacyGroupsForContentPublic($iProfileIdOwner = 0, $aCustomGroups = array())
     {
-    	$aGroups = array(BX_DOL_PG_ALL);
+        $aGroups = array(BX_DOL_PG_ALL);
         if(isLogged()) {
             $iProfileIdLogged = bx_get_logged_profile_id();
             if($iProfileIdLogged == $iProfileIdOwner)

+ 10 - 0
modules/base/general/classes/BxBaseModGeneralModule.php

@@ -3457,6 +3457,16 @@ class BxBaseModGeneralModule extends BxDolModule
         return CHECK_ACTION_RESULT_ALLOWED;
     }
 
+    public function serviceCheckAllowedAddInContext($sContextModule)
+    {
+        $CNF = &$this->_oConfig->CNF;
+
+        if(($sKey = 'OBJECT_PRIVACY_VIEW') && !empty($CNF[$sKey]) && ($oPrivacy = BxDolPrivacy::getObjectInstance($CNF[$sKey])) !== false && !$oPrivacy->isAllowedAddInContext($sContextModule))
+            return _t('_sys_txt_access_denied');
+
+        return CHECK_ACTION_RESULT_ALLOWED;   
+    }
+
     /**
      * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
      */

+ 77 - 0
modules/base/groups/classes/BxBaseModGroupsAddContent.php

@@ -0,0 +1,77 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    BaseGroups Base classes for groups modules
+ * @ingroup     UnaModules
+ *
+ * @{
+ */
+
+class BxBaseModGroupsAddContent extends BxBaseMenu
+{
+    protected $_sModule;
+    protected $_oModule;
+
+    protected $_iContentId;
+    protected $_aContentInfo;
+    protected $_oContentProfile;
+
+    public function __construct($aObject, $oTemplate = false)
+    {
+        parent::__construct($aObject, $oTemplate);
+        
+        $this->_oModule = BxDolModule::getInstance($this->_sModule);
+
+        $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
+        if(empty($iContentId) && bx_get('profile_id') !== false)
+            $iContentId = BxDolProfile::getInstance(bx_process_input(bx_get('profile_id'), BX_DATA_INT))->getContentId();
+
+        if(!empty($iContentId))
+            $this->setContentId($iContentId);
+    }
+
+    public function setContentId($iContentId)
+    {
+        $this->_iContentId = $iContentId;
+        $this->_aContentInfo = $this->_oModule->_oDb->getContentInfoById($this->_iContentId);
+        if(empty($this->_aContentInfo) || !is_array($this->_aContentInfo))
+            return;
+
+        $this->_oContentProfile = BxDolProfile::getInstanceByContentAndType($this->_iContentId, $this->_sModule);
+        if(!$this->_oContentProfile) 
+            return;
+
+        $this->addMarkers(array(
+            'profile_id' => $this->_oContentProfile->id()
+        ));
+    }
+
+    protected function getMenuItemsRaw ()
+    {
+        $aMenuItems = parent::getMenuItemsRaw();       
+
+        $iContextPid = $this->_oContentProfile->id();
+
+        $aResult = [];
+    	foreach($aMenuItems as $iKey => $aMenuItem) {
+            if((int)$aMenuItem['active'] == 0)
+                continue;
+
+            if(bx_srv($aMenuItem['module'], 'check_allowed_add_in_context', [$this->_sModule]) !== CHECK_ACTION_RESULT_ALLOWED)
+                continue;
+
+            if(bx_srv($this->_sModule, 'check_allowed_post_in_profile', [$this->_iContentId, $aMenuItem['module']]) !== CHECK_ACTION_RESULT_ALLOWED)
+                continue;
+
+            $aResult[$iKey] = array_merge($aMenuItem, [
+                'link' => bx_append_url_params($aMenuItem['link'], ['context_pid' => $iContextPid])
+            ]);
+    	}
+
+        return $aResult;
+    }
+}
+
+/** @} */

+ 19 - 0
modules/base/groups/classes/BxBaseModGroupsModule.php

@@ -2263,6 +2263,25 @@ class BxBaseModGroupsModule extends BxBaseModProfileModule
 
         return $mixedResult;
     }
+    
+    public function checkAllowedAddContent(&$aDataEntry, $isPerformAction = false)
+    {
+        $CNF = &$this->_oConfig->CNF;
+
+        $sErrAccessDenied = _t('_sys_txt_access_denied');
+
+        $sModule = $this->getName();
+        $iProfileId = bx_get_logged_profile_id();
+
+        $aContexts = BxDolService::call($sModule, 'get_participating_profiles', [$iProfileId]);
+        if(!in_array($aDataEntry['profile_id'], $aContexts))
+            return $sErrAccessDenied;
+
+        if(bx_srv($sModule, 'check_allowed_post_in_profile', [$aDataEntry[$CNF['FIELD_ID']]]) !== CHECK_ACTION_RESULT_ALLOWED)
+            return $sErrAccessDenied;
+
+        return CHECK_ACTION_RESULT_ALLOWED;
+    }
 
     /**
      * Note. Is mainly needed for internal usage. Access level is 'public' to allow outer calls from alerts.

+ 5 - 0
modules/base/notifications/classes/BxBaseModNotificationsModule.php

@@ -162,6 +162,11 @@ class BxBaseModNotificationsModule extends BxBaseModGeneralModule
         return $aResults;
     }
 
+    public function serviceCheckAllowedAddInContext($sContextModule)
+    {
+        return _t('_sys_txt_access_denied');
+    }
+
     public function isAllowedView($aEvent, $bPerform = false)
     {
         return true;