Browse Source

#724 Privacy enhancements: privacy checking, show following groups/events

Alex Trofimov 8 years ago
parent
commit
fab3d6c841

+ 3 - 1
inc/classes/BxDol.php

@@ -221,9 +221,11 @@ interface iBxDolProfileService
 
     /**
      * Get profiles, current profile have relation with, like friends, joined groups and events
+     * @param $iProfileId profile to get relations for
+     * @param $aConnectionObject look for relations in these connection objects
      * @return array
      */
-    public function serviceGetParticipatingProfiles($iProfileId);
+    public function serviceGetParticipatingProfiles($iProfileId, $aConnectionObject = false);
 
     /**
      * Get space title

+ 9 - 0
inc/classes/BxDolConnection.php

@@ -152,6 +152,15 @@ class BxDolConnection extends BxDolFactory implements iBxDolFactoryObject
         return ($GLOBALS['bxDolClasses']['BxDolConnection!'.$sObject] = $o);
     }
 
+    /**
+     * Get connection type.
+     * return BX_CONNECTIONS_TYPE_ONE_WAY or BX_CONNECTIONS_TYPE_MUTUAL
+     */ 
+    public function getType()
+    {
+        return $this->_sType;
+    }
+
     /**
      * Check whether connection between Initiator and Content can be established.
      */

+ 11 - 3
modules/base/general/classes/BxBaseModGeneralModule.php

@@ -821,21 +821,29 @@ class BxBaseModGeneralModule extends BxDolModule
      */
     public function checkAllowedView ($aDataEntry, $isPerformAction = false)
     {
+        return $this->serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction);
+    }
+
+    public function serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction = false, $iProfileId = false)
+    {
+        if (!$iProfileId)
+            $iProfileId = $this->_iProfileId;
+
         $CNF = &$this->_oConfig->CNF;
 
         // moderator and owner always have access
-        if (!empty($this->_iProfileId) && ((int)$aDataEntry[$CNF['FIELD_AUTHOR']] == (int)$this->_iProfileId || $this->_isModerator($isPerformAction)))
+        if (!empty($iProfileId) && ((int)$aDataEntry[$CNF['FIELD_AUTHOR']] == (int)$iProfileId || $this->_isModerator($isPerformAction)))
             return CHECK_ACTION_RESULT_ALLOWED;
 
         // check ACL
-        $aCheck = checkActionModule($this->_iProfileId, 'view entry', $this->getName(), $isPerformAction);
+        $aCheck = checkActionModule($iProfileId, 'view entry', $this->getName(), $isPerformAction);
         if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
             return $aCheck[CHECK_ACTION_MESSAGE];
 
         // check privacy
         if (!empty($CNF['OBJECT_PRIVACY_VIEW'])) {
             $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
-            if ($oPrivacy && !$oPrivacy->check($aDataEntry[$CNF['FIELD_ID']]))
+            if ($oPrivacy && !$oPrivacy->check($aDataEntry[$CNF['FIELD_ID']], $iProfileId))
                 return _t('_sys_access_denied_to_private_content');
         }
 

+ 10 - 6
modules/base/groups/classes/BxBaseModGroupsModule.php

@@ -51,10 +51,10 @@ class BxBaseModGroupsModule extends BxBaseModProfileModule
     /**
      * @see iBxDolProfileService::serviceGetParticipatingProfiles
      */ 
-    public function serviceGetParticipatingProfiles($iProfileId, $sConnectionObject = '')
+    public function serviceGetParticipatingProfiles($iProfileId, $aConnectionObjects = false)
     {
-        $sConnectionObject = $this->_oConfig->CNF['OBJECT_CONNECTIONS'];
-        return parent::serviceGetParticipatingProfiles($iProfileId, $sConnectionObject);
+        $aConnectionObjects = array($this->_oConfig->CNF['OBJECT_CONNECTIONS'], 'sys_profiles_subscriptions');
+        return parent::serviceGetParticipatingProfiles($iProfileId, $aConnectionObjects);
     }
     
     /**
@@ -477,10 +477,14 @@ class BxBaseModGroupsModule extends BxBaseModProfileModule
      */
     public function checkAllowedView ($aDataEntry, $isPerformAction = false)
     {
-        if ($this->isFan($aDataEntry[$this->_oConfig->CNF['FIELD_ID']]))
-            return CHECK_ACTION_RESULT_ALLOWED;
+        return $this->serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction);
+    }
 
-        return parent::checkAllowedView ($aDataEntry, $isPerformAction);
+    public function serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction = false, $iProfileId = false)
+    {
+        if ($this->isFan($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $iProfileId))
+            return CHECK_ACTION_RESULT_ALLOWED;
+        return parent::serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction, $iProfileId);
     }
 
     /**

+ 41 - 8
modules/base/profile/classes/BxBaseModProfileModule.php

@@ -300,12 +300,35 @@ class BxBaseModProfileModule extends BxBaseModGeneralModule implements iBxDolCon
     /**
      * @see iBxDolProfileService::serviceGetParticipatingProfiles
      */ 
-    public function serviceGetParticipatingProfiles($iProfileId, $sConnectionObject = 'sys_profiles_friends')
+    public function serviceGetParticipatingProfiles($iProfileId, $aConnectionObjects = false)
     {
-        if (!($o = BxDolConnection::getObjectInstance($sConnectionObject)))
-            return array();
+        if (false === $aConnectionObjects)
+            $aConnectionObjects = array('sys_profiles_friends');
+
+        $a = array();
+        foreach ($aConnectionObjects as $sConnectionObject) {
+            if (!($o = BxDolConnection::getObjectInstance($sConnectionObject)))
+                continue;
+
+            if (BX_CONNECTIONS_TYPE_MUTUAL == $o->getType())
+                $a = array_merge($a, $o->getConnectedContent($iProfileId, true));
+            else
+                $a = array_merge($a, $o->getConnectedContent($iProfileId));
+        }
+
+        $a = array_unique($a);
+        $aRet = array();
+        foreach ($a as $iConnectedProfileId) {
+            if (!($oConnectedProfile = BxDolProfile::getInstance($iConnectedProfileId)))
+                continue;
+            if ($oConnectedProfile->getModule() != $this->getName())
+                continue;
 
-        return $o->getConnectedContent($iProfileId, true);
+            if (CHECK_ACTION_RESULT_ALLOWED === bx_srv($oConnectedProfile->getModule(), 'check_allowed_post_in_profile', array($oConnectedProfile->getContentId(), $iProfileId)))
+                $aRet[] = $iConnectedProfileId;
+        }
+
+        return $aRet;
     }
     
     /**
@@ -327,9 +350,12 @@ class BxBaseModProfileModule extends BxBaseModGeneralModule implements iBxDolCon
     /**
      * @see iBxDolProfileService::serviceCheckAllowedPostInProfile
      */ 
-    public function serviceCheckAllowedPostInProfile($iContentId)
+    public function serviceCheckAllowedPostInProfile($iContentId, $iProfileIdPoster = false)
     {
-        return $this->serviceCheckAllowedProfileView($iContentId);
+        if (!$iContentId || !($aContentInfo = $this->_oDb->getContentInfoById($iContentId)))
+            return _t('_sys_request_page_not_found_cpt');
+        
+        return $this->serviceCheckAllowedViewForProfile($aContentInfo, false, $iProfileIdPoster);
     }
 
     /**
@@ -748,10 +774,17 @@ class BxBaseModProfileModule extends BxBaseModGeneralModule implements iBxDolCon
      */
     public function checkAllowedView ($aDataEntry, $isPerformAction = false)
     {
+        return $this->serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction);
+    }
+
+    public function serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction = false, $iProfileId = false)
+    {
+        if (!$iProfileId)
+            $iProfileId = $this->_iProfileId;
         $oProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->getName());
-        if ($oProfile && $oProfile->id() == $this->_iProfileId)
+        if ($oProfile && $oProfile->id() == $iProfileId)
             return CHECK_ACTION_RESULT_ALLOWED;
-        return parent::checkAllowedView ($aDataEntry, $isPerformAction);
+        return parent::serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction, $iProfileId);
     }
     
     /**

+ 10 - 3
modules/boonex/convos/classes/BxCnvModule.php

@@ -369,12 +369,19 @@ class BxCnvModule extends BxBaseModTextModule
      */
     public function checkAllowedView ($aDataEntry, $isPerformAction = false)
     {
-        if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = parent::checkAllowedView ($aDataEntry, $isPerformAction)))
+        return $this->serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction);
+    }
+
+    public function serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction = false, $iProfileId = false)
+    {
+        if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = parent::serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction, $iProfileId)))
             return $sMsg;
 
-        return $this->isCollaborator($aDataEntry, bx_get_logged_profile_id()) ? CHECK_ACTION_RESULT_ALLOWED : _t('_sys_txt_access_denied');
-    }
+        if (!$iProfileId)
+            $iProfileId = bx_get_logged_profile_id();
 
+        return $this->isCollaborator($aDataEntry, $iProfileId) ? CHECK_ACTION_RESULT_ALLOWED : _t('_sys_txt_access_denied');
+    }
 
     protected function isCollaborator($aDataEntry, $iProfileId)
     {

+ 4 - 2
modules/boonex/organizations/classes/BxOrgsModule.php

@@ -51,9 +51,11 @@ class BxOrgsModule extends BxBaseModGroupsModule
     /**
      * @see iBxDolProfileService::serviceGetParticipatingProfiles
      */ 
-    public function serviceGetParticipatingProfiles($iProfileId, $sConnectionObject = 'sys_profiles_friends')
+    public function serviceGetParticipatingProfiles($iProfileId, $aConnectionObjects = false)
     {
-        return BxBaseModProfileModule::serviceGetParticipatingProfiles($iProfileId, $sConnectionObject);
+        if (false === $aConnectionObjects)
+            $aConnectionObjects = array('sys_profiles_friends');
+        return BxBaseModProfileModule::serviceGetParticipatingProfiles($iProfileId, $aConnectionObjects);
     }
     
     public function servicePrepareFields ($aFieldsProfile)

+ 1 - 1
template/scripts/BxBaseServices.php

@@ -89,7 +89,7 @@ class BxBaseServices extends BxDol implements iBxDolProfileService
     /**
      * @see iBxDolProfileService::serviceGetParticipatingProfiles
      */ 
-    public function serviceGetParticipatingProfiles($iProfileId)
+    public function serviceGetParticipatingProfiles($iProfileId, $aConnectionObject = false)
     {
         return array();
     }