Alex Trofimov преди 10 години
родител
ревизия
b79818c8bc

+ 103 - 3
modules/boonex/groups/classes/BxGroupsAlertsResponse.php

@@ -14,17 +14,117 @@
  */
 class BxGroupsAlertsResponse extends BxDolAlertsResponse
 {
+    protected $_oModule;
+
     public function response($oAlert)
     {
+        $this->_oModule = BxDolModule::getInstance('bx_groups');
+ 
         if ('bx_groups_fans' == $oAlert->sUnit && 'connection_added' == $oAlert->sAction) {
-            BxDolService::call('bx_groups', 'add_mutual_connection', array($oAlert->aExtras['content'], $oAlert->aExtras['initiator']));
+            $this->_oModule->serviceAddMutualConnection($oAlert->aExtras['content'], $oAlert->aExtras['initiator']);
         }
 
         if ('profile' == $oAlert->sUnit && 'delete' == $oAlert->sAction) {
-            BxDolService::call('bx_groups', 'delete_profile_from_fans_and_admins', array($oAlert->iObject));
-            BxDolService::call('bx_groups', 'reassign_entities_by_author', array($oAlert->iObject));
+            $this->_oModule->serviceDeleteProfileFromFansAndAdmins($oAlert->iObject);
+            $this->_oModule->serviceReassignEntitiesByAuthor($oAlert->iObject);
+        }
+
+        if ('bx_groups' != $oAlert->sUnit)
+            return;
+
+        switch ($oAlert->sAction) {
+
+            case 'timeline_view':
+                $this->processTimelineView($oAlert, $oAlert->iObject);
+                break;
+
+            case 'timeline_comment':
+            case 'timeline_report':
+            case 'timeline_vote':
+                $this->processTimelineEventsBoolResult($oAlert, $oAlert->iObject);
+                break;
+
+            case 'timeline_post':
+                $this->processTimelineEventsCheckResult($oAlert, $oAlert->iObject);
+                break;
+
+            case 'timeline_delete':
+                $this->processTimelineEventsCheckResult($oAlert, $oAlert->iObject, 'checkAllowedEdit');
+                break;
+
+            case 'timeline_share':
+                $this->processTimelineShare($oAlert, $oAlert->iObject);
+                break;
+        }
+
+    }
+
+    protected function processTimelineView ($oAlert, $iGroupProfileId)
+    {
+        $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
+        if (!$oGroupProfile) 
+            return;
+
+        $aContentInfo = $this->_oModule->serviceGetContentInfoById($oGroupProfile->getContentId());
+        if (CHECK_ACTION_RESULT_ALLOWED !== $this->_oModule->checkAllowedView($aContentInfo)) {
+            $oAlert->aExtras['override_content'] = MsgBox(_t('_sys_access_denied_to_private_content'));
+        }
+
+        foreach ($oAlert->aExtras['menu'] as $i => $r) {
+            if ('timeline-view-owner' == $r['id'] || 'timeline-view-other'  == $r['id'])
+                unset($oAlert->aExtras['menu'][$i]);
         }
+    }
+
+    protected function processTimelineEventsCheckResult ($oAlert, $iGroupProfileId, $sFunc = 'checkAllowedPost')
+    {
+        if ($oAlert->aExtras['check_result'][CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
+            return;
+
+        $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
+        if (!$oGroupProfile) 
+            return;
+
+        $aContentInfo = $this->_oModule->serviceGetContentInfoById($oGroupProfile->getContentId());
+        if (CHECK_ACTION_RESULT_ALLOWED === ($s = $this->_oModule->$sFunc($aContentInfo))) {
+            $oAlert->aExtras['check_result'][CHECK_ACTION_RESULT] = CHECK_ACTION_RESULT_ALLOWED;
+        } 
+        else {
+            $oAlert->aExtras['check_result'][CHECK_ACTION_RESULT] = CHECK_ACTION_MESSAGE_NOT_ALLOWED;
+            $oAlert->aExtras['check_result'][CHECK_ACTION_MESSAGE] = $s;
+        }
+    }
+
+    protected function processTimelineEventsBoolResult ($oAlert, $iGroupProfileId, $sFunc = 'checkAllowedPost')
+    {
+        if (!$oAlert->aExtras['result'])
+            return;
 
+        $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
+        if (!$oGroupProfile) 
+            return;
+
+        $aContentInfo = $this->_oModule->serviceGetContentInfoById($oGroupProfile->getContentId());
+        $oAlert->aExtras['result'] = (CHECK_ACTION_RESULT_ALLOWED === $this->_oModule->$sFunc($aContentInfo)) ? true : false;
+    }
+
+    protected function processTimelineShare ($oAlert, $iGroupProfileId)
+    {
+        if ($oAlert->aExtras['check_result'][CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
+            break;
+
+        $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
+        if (!$oGroupProfile) 
+            break;
+
+        $aContentInfo = $this->_oModule->serviceGetContentInfoById($oGroupProfile->getContentId());
+        if (BX_DOL_PG_ALL == $aContentInfo[$this->_oModule->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']] || 'c' == $aContentInfo[$this->_oModule->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']]) {
+            $oAlert->aExtras['check_result'][CHECK_ACTION_RESULT] = CHECK_ACTION_RESULT_ALLOWED;
+        }
+        else {
+            $oAlert->aExtras['check_result'][CHECK_ACTION_RESULT] = CHECK_ACTION_MESSAGE_NOT_ALLOWED;
+            $oAlert->aExtras['check_result'][CHECK_ACTION_MESSAGE] = _t('_sys_access_denied_to_private_content');
+        }
     }
 }
 

+ 32 - 3
modules/boonex/groups/classes/BxGroupsModule.php

@@ -208,13 +208,23 @@ class BxGroupsModule extends BxBaseModProfileModule
         return $this->_serviceBrowse ('joined_entries', array('joined_profile' => $iProfileId), BX_DB_PADDING_DEF, $bDisplayEmptyMsg);
     }
 
+    /**
+     * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
+     */
+    public function checkAllowedPost ($aDataEntry, $isPerformAction = false)
+    {
+        if ($this->isFan($aDataEntry[$this->_oConfig->CNF['FIELD_ID']]))
+            return CHECK_ACTION_RESULT_ALLOWED;
+
+        return _t('_sys_txt_access_denied');
+    }
+
     /**
      * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
      */
     public function checkAllowedView ($aDataEntry, $isPerformAction = false)
     {
-        $oGroupProfile = BxDolProfile::getInstanceByContentAndType($aDataEntry[$this->_oConfig->CNF['FIELD_ID']], $this->getName());
-        if ($oGroupProfile && ($oConnection = BxDolConnection::getObjectInstance($this->_oConfig->CNF['OBJECT_CONNECTIONS'])) && $oConnection->isConnected(bx_get_logged_profile_id(), $oGroupProfile->id(), true))
+        if ($this->isFan($aDataEntry[$this->_oConfig->CNF['FIELD_ID']]))
             return CHECK_ACTION_RESULT_ALLOWED;
 
         return parent::checkAllowedView ($aDataEntry, $isPerformAction);
@@ -225,6 +235,9 @@ class BxGroupsModule extends BxBaseModProfileModule
      */
     public function checkAllowedFanAdd (&$aDataEntry, $isPerformAction = false)
     {
+        if (!$this->isFan($aDataEntry[$this->_oConfig->CNF['FIELD_ID']]) && isLogged())
+            return CHECK_ACTION_RESULT_ALLOWED;
+
         return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, $this->_oConfig->CNF['OBJECT_CONNECTIONS'], true, false);
     }
 
@@ -275,14 +288,30 @@ class BxGroupsModule extends BxBaseModProfileModule
         return parent::checkAllowedDelete ($aDataEntry, $isPerformAction);
     }
 
+    public function checkAllowedSubscribeAdd (&$aDataEntry, $isPerformAction = false)
+    {
+        if (!$this->isFan($aDataEntry[$this->_oConfig->CNF['FIELD_ID']]))
+            return _t('_sys_txt_access_denied');
+
+        return parent::checkAllowedSubscribeAdd ($aDataEntry, $isPerformAction);
+    }
+
     protected function _checkAllowedConnect (&$aDataEntry, $isPerformAction, $sObjConnection, $isMutual, $isInvertResult, $isSwap = false)
     {
         $sResult = $this->checkAllowedView($aDataEntry);
-        if (CHECK_ACTION_RESULT_ALLOWED !== $sResult)
+
+        if (CHECK_ACTION_RESULT_ALLOWED !== $sResult && 'c' != $aDataEntry[$this->_oConfig->CNF['FIELD_ALLOW_VIEW_TO']])
             return $sResult;
 
         return parent::_checkAllowedConnect ($aDataEntry, $isPerformAction, $sObjConnection, $isMutual, $isInvertResult, $isSwap);
     }
+
+    public function isFan ($iContentId, $iProfileId = false) 
+    {
+        $oGroupProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->getName());
+
+        return $oGroupProfile && ($oConnection = BxDolConnection::getObjectInstance($this->_oConfig->CNF['OBJECT_CONNECTIONS'])) && $oConnection->isConnected($iProfileId ? $iProfileId : bx_get_logged_profile_id(), $oGroupProfile->id(), true);
+    }
 }
 
 /** @} */

+ 3 - 2
modules/boonex/groups/classes/BxGroupsPageEntry.php

@@ -22,11 +22,12 @@ class BxGroupsPageEntry extends BxBaseModProfilePageEntry
 
     protected function _processPermissionsCheck ()
     {
-        if ('c' != $this->_aContentInfo['allow_view_to'] && CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->_oModule->checkAllowedView($this->_aContentInfo))) {
+        $mixedAllowView = $this->_oModule->checkAllowedView($this->_aContentInfo);
+        if ('c' != $this->_aContentInfo['allow_view_to'] && CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $mixedAllowView)) {
             $this->_oTemplate->displayAccessDenied($sMsg);
             exit;
         }
-        elseif ('c' == $this->_aContentInfo['allow_view_to'] && 'bx_groups_view_profile' == $this->_sObject) {
+        elseif ('c' == $this->_aContentInfo['allow_view_to'] && 'bx_groups_view_profile' == $this->_sObject && CHECK_ACTION_RESULT_ALLOWED !== $mixedAllowView) {
             // replace current page with different set of blocks
             $aObject = BxDolPageQuery::getPageObject('bx_groups_view_profile_closed');
             $this->_sObject = $aObject['object'];

+ 8 - 1
modules/boonex/groups/install/sql/enable.sql

@@ -364,7 +364,14 @@ SET @iHandler := LAST_INSERT_ID();
 
 INSERT INTO `sys_alerts` (`unit`, `action`, `handler_id`) VALUES
 ('bx_groups_fans', 'connection_added', @iHandler),
-('profile', 'delete', @iHandler);
+('profile', 'delete', @iHandler),
+('bx_groups', 'timeline_view', @iHandler),
+('bx_groups', 'timeline_post', @iHandler),
+('bx_groups', 'timeline_delete', @iHandler),
+('bx_groups', 'timeline_comment', @iHandler),
+('bx_groups', 'timeline_vote', @iHandler),
+('bx_groups', 'timeline_report', @iHandler),
+('bx_groups', 'timeline_share', @iHandler);
 
 -- PRIVACY 
 

+ 38 - 13
modules/boonex/timeline/classes/BxTimelineModule.php

@@ -557,10 +557,16 @@ class BxTimelineModule extends BxBaseModNotificationsModule
             array('id' => 'timeline-get-rss', 'name' => 'timeline-get-rss', 'class' => '', 'link' => BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'rss/' . $iProfileId . '/', 'target' => '_blank', 'title' => _t('_bx_timeline_menu_item_get_rss')),
         );
 
+        $sContent = '';
+        $oProfileOwner = BxDolProfile::getInstance($this->_iOwnerId);
+        bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_view', $this->_iOwnerId, $this->getUserId(), array('override_content' => &$sContent, 'params' => &$aParams, 'menu' => &$aMenu));
+
         $oMenu = new BxTemplMenuInteractive(array('template' => 'menu_interactive_vertical.html', 'menu_id'=> 'timeline-view-all', 'menu_items' => $aMenu));
         $oMenu->setSelected('', 'timeline-view-all');
 
-        $sContent = $this->_oTemplate->getViewBlock($aParams);
+        if (!$sContent)
+            $sContent = $this->_oTemplate->getViewBlock($aParams);
+
         return array('content' => $sContent, 'menu' => $oMenu);
     }
     public function deleteEvent($aEvent)
@@ -742,6 +748,7 @@ class BxTimelineModule extends BxBaseModNotificationsModule
     }
 
     //--- Check permissions methods ---//
+
     public function isAllowedPost($bPerform = false)
     {
         if(isAdmin())
@@ -752,7 +759,11 @@ class BxTimelineModule extends BxBaseModNotificationsModule
             return true;
 
         $aCheckResult = checkActionModule($iUserId, 'post', $this->getName(), $bPerform);
-        return $aCheckResult[CHECK_ACTION_RESULT] != CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
+
+        if ($oProfileOwner = BxDolProfile::getInstance($this->_iOwnerId))
+            bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_post', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
+
+        return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
     }
 
     public function isAllowedDelete($aEvent, $bPerform = false)
@@ -765,7 +776,11 @@ class BxTimelineModule extends BxBaseModNotificationsModule
            return true;
 
         $aCheckResult = checkActionModule($iUserId, 'delete', $this->getName(), $bPerform);
-        return $aCheckResult[CHECK_ACTION_RESULT] != CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
+
+        if ($oProfileOwner = BxDolProfile::getInstance((int)$aEvent['owner_id']))
+            bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_delete', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
+
+        return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
     }
 
     public function isAllowedComment($aEvent, $bPerform = false)
@@ -778,10 +793,12 @@ class BxTimelineModule extends BxBaseModNotificationsModule
         $oCmts = $this->getCmtsObject($sSystem, $iObjectId);
         $oCmts->addCssJs();
 
-        if(isAdmin())
-            return true;
+        $bResult = isAdmin() ? true : false;
 
-        return true;
+        if ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']))
+            bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_comment', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
+
+        return $bResult;
     }
 
     public function isAllowedVote($aEvent, $bPerform = false)
@@ -794,10 +811,12 @@ class BxTimelineModule extends BxBaseModNotificationsModule
         $oVote = $this->getVoteObject($sSystem, $iObjectId);
         $oVote->addCssJs();
 
-        if(isAdmin())
-            return true;
+        $bResult = isAdmin() ? true : false;
 
-        return true;
+        if ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']))
+            bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_vote', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
+
+        return $bResult;
     }
 
     public function isAllowedReport($aEvent, $bPerform = false)
@@ -810,10 +829,12 @@ class BxTimelineModule extends BxBaseModNotificationsModule
         $oReport = $this->getReportObject($sSystem, $iObjectId);
         $oReport->addCssJs();
 
-        if(isAdmin())
-            return true;
+        $bResult = isAdmin() ? true : false;
 
-        return true;
+        if ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']))
+            bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_report', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
+
+        return $bResult;
     }
 
     public function isAllowedShare($aEvent, $bPerform = false)
@@ -826,7 +847,11 @@ class BxTimelineModule extends BxBaseModNotificationsModule
             return false;
 
         $aCheckResult = checkActionModule($iUserId, 'share', $this->getName(), $bPerform);
-        return $aCheckResult[CHECK_ACTION_RESULT] != CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
+
+        if ($oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']))
+            bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_share', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
+
+        return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
     }
 
     public function isAllowedMore($aEvent, $bPerform = false)