Quellcode durchsuchen

#288 Persons & Orgs: privacy

Alex Trofimov vor 10 Jahren
Ursprung
Commit
6ea0bc7555

+ 135 - 0
modules/base/profile/classes/BxBaseModProfileAlertsResponse.php

@@ -0,0 +1,135 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
+ * CC-BY License - http://creativecommons.org/licenses/by/3.0/
+ *
+ * @defgroup    BaseProfile Base classes for profile modules
+ * @ingroup     TridentModules
+ *
+ * @{
+ */
+
+class BxBaseModProfileAlertsResponse extends BxDolAlertsResponse
+{
+    protected $MODULE;
+    protected $_oModule;
+
+    public function __construct()
+    {
+        parent::__construct();
+        $this->_oModule = BxDolModule::getInstance($this->MODULE);
+    }
+
+    public function response($oAlert)
+    {
+/*
+        $CNF = $this->_oModule->_oConfig->CNF;
+
+        // re-translate timeline alert
+        if ('bx_timeline' == $oAlert->sUnit && 'post_common' == $oAlert->sAction && ($oGroupProfile = BxDolProfile::getInstance($oAlert->aExtras['object_author_id']))) {
+            $aContentInfo = $this->_oModule->serviceGetContentInfoById($oGroupProfile->getContentId());
+            bx_alert($this->_oModule->getName(), 'timeline_post_common', $aContentInfo[$CNF['FIELD_ID']], $oGroupProfile->id(), array('content' => $aContentInfo, 'group_profile' => $oGroupProfile->id(), 'profile' => $oAlert->iSender, 'notification_subobject_id' => $oAlert->iSender, 'object_author_id' => $aContentInfo[$CNF['FIELD_AUTHOR']]));
+        }
+ */
+        if ($this->MODULE != $oAlert->sUnit)
+            return;
+
+        // timeline events to override permissions
+        switch ($oAlert->sAction) {
+        case 'timeline_view':
+            $this->processTimelineView($oAlert, $oAlert->iObject, true);
+            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, $bDisableOwnerActions = false)
+    {
+        $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'));
+        }
+
+        if ($bDisableOwnerActions) {
+            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)
+            return;
+
+        $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
+        if (!$oGroupProfile) 
+            return;
+
+        $aContentInfo = $this->_oModule->serviceGetContentInfoById($oGroupProfile->getContentId());
+        if (BX_DOL_PG_ALL == $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');
+        }
+    }
+}
+
+/** @} */

+ 10 - 0
modules/base/profile/classes/BxBaseModProfileModule.php

@@ -305,6 +305,14 @@ class BxBaseModProfileModule extends BxBaseModGeneralModule implements iBxDolPro
 
     // ====== PERMISSION METHODS
 
+    /**
+     * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
+     */
+    public function checkAllowedPost ($aDataEntry, $isPerformAction = false)
+    {
+        return $this->checkAllowedView ($aDataEntry, $isPerformAction);
+    }
+
     /**
      * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
      */
@@ -401,6 +409,8 @@ class BxBaseModProfileModule extends BxBaseModGeneralModule implements iBxDolPro
      */
     public function checkAllowedSubscribeAdd (&$aDataEntry, $isPerformAction = false)
     {
+        if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedView($aDataEntry)))
+            return $sMsg;
         return $this->_checkAllowedConnect ($aDataEntry, $isPerformAction, 'sys_profiles_subscriptions', false, false);
     }
 

+ 14 - 8
modules/base/profile/classes/BxBaseModProfilePageEntry.php

@@ -88,17 +88,23 @@ class BxBaseModProfilePageEntry extends BxBaseModGeneralPageEntry
         bx_import('BxDolPrivacy');
 
         $mixedAllowView = $this->_oModule->checkAllowedView($this->_aContentInfo);
-        if ((BX_DOL_PG_HIDDEN == $this->_aContentInfo['allow_view_to'] || BX_DOL_PG_MEONLY == $this->_aContentInfo['allow_view_to']) && CHECK_ACTION_RESULT_ALLOWED !== $mixedAllowView) {
+        if ($CNF['OBJECT_PAGE_VIEW_ENTRY'] == $this->_sObject) {
+            if ((BX_DOL_PG_HIDDEN == $this->_aContentInfo['allow_view_to'] || BX_DOL_PG_MEONLY == $this->_aContentInfo['allow_view_to']) && CHECK_ACTION_RESULT_ALLOWED !== $mixedAllowView) {
+                $this->_oTemplate->displayAccessDenied($mixedAllowView);
+                exit;
+            }
+            elseif (CHECK_ACTION_RESULT_ALLOWED !== $mixedAllowView) {
+                // replace current page with different set of blocks
+                $aObject = BxDolPageQuery::getPageObject($CNF['OBJECT_PAGE_VIEW_ENTRY_CLOSED']);
+                $this->_sObject = $aObject['object'];
+                $this->_aObject = $aObject;
+                $this->_oQuery = new BxDolPageQuery($this->_aObject);
+            }
+        } 
+        elseif (CHECK_ACTION_RESULT_ALLOWED !== $mixedAllowView) {
             $this->_oTemplate->displayAccessDenied($mixedAllowView);
             exit;
         }
-        elseif ($CNF['OBJECT_PAGE_VIEW_ENTRY'] == $this->_sObject && CHECK_ACTION_RESULT_ALLOWED !== $mixedAllowView) {
-            // replace current page with different set of blocks
-            $aObject = BxDolPageQuery::getPageObject($CNF['OBJECT_PAGE_VIEW_ENTRY_CLOSED']);
-            $this->_sObject = $aObject['object'];
-            $this->_aObject = $aObject;
-            $this->_oQuery = new BxDolPageQuery($this->_aObject);
-        }
 
         $this->_oModule->checkAllowedView($this->_aContentInfo, true);
     }    

+ 1 - 1
modules/base/profile/classes/BxBaseModProfilePrivacy.php

@@ -14,7 +14,7 @@ class BxBaseModProfilePrivacy extends BxTemplPrivacy
 	protected $MODULE;
 	protected $_oModule;
 
-    function __construct($aOptions, $oTemplate = false)
+    public function __construct($aOptions, $oTemplate = false)
     {
         parent::__construct($aOptions, $oTemplate);
 

+ 10 - 83
modules/boonex/groups/classes/BxGroupsAlertsResponse.php

@@ -9,16 +9,18 @@
  * @{
  */
 
-/**
- * alerts handler
- */
-class BxGroupsAlertsResponse extends BxDolAlertsResponse
+class BxGroupsAlertsResponse extends BxBaseModProfileAlertsResponse
 {
-    protected $_oModule;
-
+    public function __construct()
+    {
+    	$this->MODULE = 'bx_groups';
+        parent::__construct();
+    }
+    
     public function response($oAlert)
     {
-        $this->_oModule = BxDolModule::getInstance('bx_groups');
+        parent::response($oAlert);
+
         $CNF = $this->_oModule->_oConfig->CNF;
 
         // re-translate timeline alert
@@ -56,32 +58,6 @@ class BxGroupsAlertsResponse extends BxDolAlertsResponse
             $this->sendMailJoinRequestAccepted($oAlert, $oAlert->aExtras['profile'], bx_get_logged_profile_id());
             break;
         }
-
-        // timeline events to override permissions
-        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 sendMailInvitation ($oAlert, $iProfileId, $iSender = 0)
@@ -114,55 +90,6 @@ class BxGroupsAlertsResponse extends BxDolAlertsResponse
             'EntryTitle' => $oAlert->aExtras['entry_title'],
         ), BX_EMAIL_NOTIFY);
     }
-    
-    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)
     {
@@ -170,7 +97,7 @@ class BxGroupsAlertsResponse extends BxDolAlertsResponse
             return;
 
         $oGroupProfile = BxDolProfile::getInstance($iGroupProfileId);
-        if (!$oGroupProfile) 
+        if (!$oGroupProfile)
             return;
 
         $aContentInfo = $this->_oModule->serviceGetContentInfoById($oGroupProfile->getContentId());

+ 1 - 1
modules/boonex/groups/classes/BxGroupsPrivacy.php

@@ -11,7 +11,7 @@
 
 class BxGroupsPrivacy extends BxBaseModProfilePrivacy
 {
-    function __construct($aOptions, $oTemplate = false)
+    public function __construct($aOptions, $oTemplate = false)
     {
     	$this->MODULE = 'bx_groups';
         parent::__construct($aOptions, $oTemplate);

+ 21 - 0
modules/boonex/organizations/classes/BxOrgsAlertsResponse.php

@@ -0,0 +1,21 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
+ * CC-BY License - http://creativecommons.org/licenses/by/3.0/
+ *
+ * @defgroup    Organizations Organizations
+ * @ingroup     TridentModules
+ *
+ * @{
+ */
+
+class BxOrgsAlertsResponse extends BxBaseModProfileAlertsResponse
+{
+    public function __construct()
+    {
+    	$this->MODULE = 'bx_organizations';
+        parent::__construct();
+    }
+}
+
+/** @} */

+ 1 - 0
modules/boonex/organizations/classes/BxOrgsConfig.php

@@ -26,6 +26,7 @@ class BxOrgsConfig extends BxBaseModProfileConfig
             'profile-subscribe-remove' => 'checkAllowedSubscribeRemove',
             'profile-actions-more' => 'checkAllowedViewMoreMenu',
             'profile-set-acl-level' => 'checkAllowedSetMembership',
+            'convos-compose' => 'checkAllowedSubscribeAdd',
         );
 
         $this->CNF = array (

+ 5 - 0
modules/boonex/organizations/install/sql/disable.sql

@@ -39,6 +39,11 @@ DELETE FROM `sys_objects_grid` WHERE `object` IN ('bx_organizations_administrati
 DELETE FROM `sys_grid_fields` WHERE `object` IN ('bx_organizations_administration', 'bx_organizations_moderation', 'bx_organizations_common');
 DELETE FROM `sys_grid_actions` WHERE `object` IN ('bx_organizations_administration', 'bx_organizations_moderation', 'bx_organizations_common');
 
+-- ALERTS
+SET @iHandler := (SELECT `id` FROM `sys_alerts_handlers` WHERE `name` = 'bx_organizations' LIMIT 1);
+DELETE FROM `sys_alerts` WHERE `handler_id` = @iHandler;
+DELETE FROM `sys_alerts_handlers` WHERE `id` = @iHandler;
+
 -- PRIVACY 
 DELETE FROM `sys_objects_privacy` WHERE `object` IN('bx_organizations_allow_view_to');
 

+ 16 - 0
modules/boonex/organizations/install/sql/enable.sql

@@ -350,6 +350,22 @@ INSERT INTO `sys_grid_actions` (`object`, `type`, `name`, `title`, `icon`, `icon
 ('bx_organizations_common', 'bulk', 'delete_with_content', '_bx_orgs_grid_action_title_adm_delete_with_content', '', 0, 1, 2),
 ('bx_organizations_common', 'single', 'settings', '_bx_orgs_grid_action_title_adm_more_actions', 'cog', 1, 0, 1);
 
+-- ALERTS
+
+INSERT INTO `sys_alerts_handlers` (`name`, `class`, `file`, `service_call`) VALUES 
+('bx_organizations', 'BxOrgsAlertsResponse', 'modules/boonex/organizations/classes/BxOrgsAlertsResponse.php', '');
+SET @iHandler := LAST_INSERT_ID();
+
+INSERT INTO `sys_alerts` (`unit`, `action`, `handler_id`) VALUES
+-- ('bx_timeline', 'post_common', @iHandler),
+('bx_organizations', 'timeline_view', @iHandler),
+('bx_organizations', 'timeline_post', @iHandler),
+('bx_organizations', 'timeline_delete', @iHandler),
+('bx_organizations', 'timeline_comment', @iHandler),
+('bx_organizations', 'timeline_vote', @iHandler),
+('bx_organizations', 'timeline_report', @iHandler),
+('bx_organizations', 'timeline_share', @iHandler);
+
 -- PRIVACY 
 
 INSERT INTO `sys_objects_privacy` (`object`, `module`, `action`, `title`, `default_group`, `table`, `table_field_id`, `table_field_author`, `override_class_name`, `override_class_file`) VALUES

+ 21 - 0
modules/boonex/persons/classes/BxPersonsAlertsResponse.php

@@ -0,0 +1,21 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
+ * CC-BY License - http://creativecommons.org/licenses/by/3.0/
+ *
+ * @defgroup    Persons Persons
+ * @ingroup     TridentModules
+ *
+ * @{
+ */
+
+class BxPersonsAlertsResponse extends BxBaseModProfileAlertsResponse
+{
+    public function __construct()
+    {
+    	$this->MODULE = 'bx_persons';
+        parent::__construct();
+    }
+}
+
+/** @} */

+ 1 - 0
modules/boonex/persons/classes/BxPersonsConfig.php

@@ -26,6 +26,7 @@ class BxPersonsConfig extends BxBaseModProfileConfig
             'profile-subscribe-remove' => 'checkAllowedSubscribeRemove',
             'profile-actions-more' => 'checkAllowedViewMoreMenu',
             'profile-set-acl-level' => 'checkAllowedSetMembership',
+            'convos-compose' => 'checkAllowedSubscribeAdd',
         );
 
         $this->CNF = array (

+ 5 - 0
modules/boonex/persons/install/sql/disable.sql

@@ -36,6 +36,11 @@ DELETE FROM `sys_objects_grid` WHERE `object` IN ('bx_persons_administration', '
 DELETE FROM `sys_grid_fields` WHERE `object` IN ('bx_persons_administration', 'bx_persons_common');
 DELETE FROM `sys_grid_actions` WHERE `object` IN ('bx_persons_administration', 'bx_persons_common');
 
+-- ALERTS
+SET @iHandler := (SELECT `id` FROM `sys_alerts_handlers` WHERE `name` = 'bx_persons' LIMIT 1);
+DELETE FROM `sys_alerts` WHERE `handler_id` = @iHandler;
+DELETE FROM `sys_alerts_handlers` WHERE `id` = @iHandler;
+
 -- PRIVACY 
 DELETE FROM `sys_objects_privacy` WHERE `object` IN('bx_persons_allow_view_to');
 

+ 16 - 0
modules/boonex/persons/install/sql/enable.sql

@@ -341,6 +341,22 @@ INSERT INTO `sys_grid_actions` (`object`, `type`, `name`, `title`, `icon`, `icon
 ('bx_persons_common', 'bulk', 'delete_with_content', '_bx_persons_grid_action_title_adm_delete_with_content', '', 0, 1, 2),
 ('bx_persons_common', 'single', 'settings', '_bx_persons_grid_action_title_adm_more_actions', 'cog', 1, 0, 1);
 
+-- ALERTS
+
+INSERT INTO `sys_alerts_handlers` (`name`, `class`, `file`, `service_call`) VALUES 
+('bx_persons', 'BxPersonsAlertsResponse', 'modules/boonex/persons/classes/BxPersonsAlertsResponse.php', '');
+SET @iHandler := LAST_INSERT_ID();
+
+INSERT INTO `sys_alerts` (`unit`, `action`, `handler_id`) VALUES
+-- ('bx_timeline', 'post_common', @iHandler),
+('bx_persons', 'timeline_view', @iHandler),
+('bx_persons', 'timeline_post', @iHandler),
+('bx_persons', 'timeline_delete', @iHandler),
+('bx_persons', 'timeline_comment', @iHandler),
+('bx_persons', 'timeline_vote', @iHandler),
+('bx_persons', 'timeline_report', @iHandler),
+('bx_persons', 'timeline_share', @iHandler);
+
 -- PRIVACY 
 
 INSERT INTO `sys_objects_privacy` (`object`, `module`, `action`, `title`, `default_group`, `table`, `table_field_id`, `table_field_author`, `override_class_name`, `override_class_file`) VALUES