Browse Source

Ticket #258 - Market module: Privacy.

AntonLV 10 years ago
parent
commit
81d817fd20

+ 17 - 0
modules/boonex/market/classes/BxMarketCmts.php

@@ -11,12 +11,29 @@
 
 class BxMarketCmts extends BxTemplCmts
 {
+	protected $MODULE;
+	protected $_oModule;
+
     function __construct($sSystem, $iId, $iInit = 1)
     {
+    	$this->MODULE = 'bx_market';
+    	$this->_oModule = BxDolModule::getInstance($this->MODULE);
+
         parent::__construct($sSystem, $iId, $iInit);
 
         $this->_aT['block_comments_title'] = '_bx_market_page_block_title_entry_comments_n';
     }
+
+    public function isPostReplyAllowed ($isPerformAction = false)
+    {
+    	$CNF = &$this->_oModule->_oConfig->CNF;
+
+    	$oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_COMMENT']);
+		if($oPrivacy && !$oPrivacy->check($this->_iId))
+			return false;
+
+		return parent::isPostReplyAllowed($isPerformAction);
+    }
 }
 
 /** @} */

+ 6 - 0
modules/boonex/market/classes/BxMarketConfig.php

@@ -42,6 +42,9 @@ class BxMarketConfig extends BxBaseModTextConfig
             'FIELD_TEXT_ID' => 'product-text',
         	'FIELD_PRICE' => 'price',
             'FIELD_ALLOW_VIEW_TO' => 'allow_view_to',
+			'FIELD_ALLOW_PURCHASE_TO' => 'allow_purchase_to',
+			'FIELD_ALLOW_COMMENT_TO' => 'allow_comment_to',
+			'FIELD_ALLOW_VOTE_TO' => 'allow_vote_to',
             'FIELD_PHOTO' => 'pictures',
             'FIELD_THUMB' => 'thumb',
         	'FIELD_FILE' => 'files',
@@ -81,6 +84,9 @@ class BxMarketConfig extends BxBaseModTextConfig
             'OBJECT_METATAGS' => 'bx_market',
             'OBJECT_COMMENTS' => 'bx_market',
             'OBJECT_PRIVACY_VIEW' => 'bx_market_allow_view_to',
+			'OBJECT_PRIVACY_PURCHASE' => 'bx_market_allow_purchase_to',
+			'OBJECT_PRIVACY_COMMENT' => 'bx_market_allow_comment_to',
+			'OBJECT_PRIVACY_VOTE' => 'bx_market_allow_vote_to',
             'OBJECT_FORM_ENTRY' => 'bx_market',
             'OBJECT_FORM_ENTRY_DISPLAY_VIEW' => 'bx_market_entry_view',
             'OBJECT_FORM_ENTRY_DISPLAY_ADD' => 'bx_market_entry_add',

+ 19 - 0
modules/boonex/market/classes/BxMarketFormEntry.php

@@ -30,6 +30,25 @@ class BxMarketFormEntry extends BxBaseModTextFormEntry
             $this->aInputs[$CNF['FIELD_FILE']]['content_id'] = 0;
             $this->aInputs[$CNF['FIELD_FILE']]['ghost_template'] = '';
         }
+
+		if (isset($this->aInputs[$CNF['FIELD_ALLOW_PURCHASE_TO']]))
+			$this->aInputs[$CNF['FIELD_ALLOW_PURCHASE_TO']] = BxDolPrivacy::getGroupChooser($CNF['OBJECT_PRIVACY_PURCHASE']);
+
+		$iOwnerId = bx_get_logged_profile_id();
+		$aDynamicGroups = array(
+			array ('key' => '', 'value' => '----'),
+			array ('key' => 'c', 'value' => _t('_bx_market_privacy_group_customers'))
+		);
+
+		if(isset($this->aInputs[$CNF['FIELD_ALLOW_COMMENT_TO']])) {
+			$this->aInputs[$CNF['FIELD_ALLOW_COMMENT_TO']] = BxDolPrivacy::getGroupChooser($CNF['OBJECT_PRIVACY_COMMENT'], $iOwnerId, array('dynamic_groups' => $aDynamicGroups));
+			$this->aInputs[$CNF['FIELD_ALLOW_COMMENT_TO']]['db']['pass'] = 'Xss';
+		}
+
+		if(isset($this->aInputs[$CNF['FIELD_ALLOW_VOTE_TO']])) {
+			$this->aInputs[$CNF['FIELD_ALLOW_VOTE_TO']] = BxDolPrivacy::getGroupChooser($CNF['OBJECT_PRIVACY_VOTE'], $iOwnerId, array('dynamic_groups' => $aDynamicGroups));
+			$this->aInputs[$CNF['FIELD_ALLOW_VOTE_TO']]['db']['pass'] = 'Xss';
+		}
     }
 
 	function initChecker ($aValues = array (), $aSpecificValues = array())

+ 18 - 8
modules/boonex/market/classes/BxMarketModule.php

@@ -72,14 +72,9 @@ class BxMarketModule extends BxBaseModTextModule
     {
     	$CNF = &$this->_oConfig->CNF;
 
-    	if (!$iContentId)
-            $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
-        if (!$iContentId)
-            return false;
-
-        $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
-        if (!$aContentInfo)
-            return false;
+    	$aContentInfo = $this->_getContentInfo($iContentId);
+    	if($aContentInfo === false)
+    		return false;
 
 		$oProfile = BxDolProfile::getInstance($aContentInfo[$CNF['FIELD_AUTHOR']]);
         if (!$oProfile)
@@ -191,6 +186,21 @@ class BxMarketModule extends BxBaseModTextModule
 			'file_version_attr' => $bFileInfoVersion ? bx_html_attribute($aFileInfo['version']) : '',
 		);
     }
+
+    protected function _getContentInfo($iContentId = 0)
+    {
+    	if(!$iContentId)
+            $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
+
+        if(!$iContentId)
+            return false;
+
+        $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
+        if(!$aContentInfo)
+            return false;
+
+		return $aContentInfo;
+    }
 }
 
 /** @} */

+ 45 - 0
modules/boonex/market/classes/BxMarketPrivacy.php

@@ -0,0 +1,45 @@
+<?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    Market Market
+ * @ingroup     TridentModules
+ *
+ * @{
+ */
+
+class BxMarketPrivacy extends BxTemplPrivacy
+{
+	protected $MODULE;
+	protected $_oModule;
+
+    function __construct($aOptions, $oTemplate = false)
+    {
+    	$this->MODULE = 'bx_market';
+
+    	$this->_oModule = BxDolModule::getInstance($this->MODULE);
+    	if(!$oTemplate)
+			$oTemplate = $this->_oModule->_oTemplate;
+
+        parent::__construct($aOptions, $oTemplate);
+    }
+
+	/**
+     * Check whethere viewer is a member of dynamic group.
+     *
+     * @param  mixed   $mixedGroupId   dynamic group ID.
+     * @param  integer $iObjectOwnerId object owner ID.
+     * @param  integer $iViewerId      viewer ID.
+     * @return boolean result of operation.
+     */
+    function isDynamicGroupMember($mixedGroupId, $iObjectOwnerId, $iViewerId, $iObjectId)
+    {
+        if($mixedGroupId != 'c')
+        	return false; 
+
+        return $this->_oModule->_oDb->isCustomer($iViewerId, $iObjectId);
+    }
+}
+
+/** @} */

+ 1 - 0
modules/boonex/market/classes/BxMarketTemplate.php

@@ -22,6 +22,7 @@ class BxMarketTemplate extends BxBaseModTextTemplate
     function __construct(&$oConfig, &$oDb)
     {
         $this->MODULE = 'bx_market';
+
         parent::__construct($oConfig, $oDb);
 
         $this->_aCurrency = $this->_oConfig->getCurrency();

+ 18 - 1
modules/boonex/market/classes/BxMarketVote.php

@@ -11,9 +11,26 @@
 
 class BxMarketVote extends BxTemplVote
 {
+	protected $MODULE;
+	protected $_oModule;
+
     function __construct($sSystem, $iId, $iInit = 1)
     {
-        parent::__construct($sSystem, $iId, $iInit);
+    	$this->MODULE = 'bx_market';
+    	$this->_oModule = BxDolModule::getInstance($this->MODULE);
+
+        parent::__construct($sSystem, $iId, $iInit);        
+    }
+
+    public function isAllowedVote($isPerformAction = false)
+    {
+    	$CNF = &$this->_oModule->_oConfig->CNF;
+
+    	$oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VOTE']);
+		if($oPrivacy && !$oPrivacy->check($this->_iId))
+			return false;
+
+    	return parent::isAllowedVote($isPerformAction);
     }
 
 	protected function _getLabelCounter($iCount)

+ 10 - 2
modules/boonex/market/install/langs/en.xml

@@ -42,8 +42,14 @@
 	<string name="_bx_market_form_entry_input_files_use_as_main"><![CDATA[Use as Main]]></string>
 	<string name="_bx_market_form_entry_input_files_name"><![CDATA[Name:]]></string>
 	<string name="_bx_market_form_entry_input_files_version"><![CDATA[Version:]]></string>
-    <string name="_bx_market_form_entry_input_sys_allow_view_to"><![CDATA[Visibility]]></string>
-    <string name="_bx_market_form_entry_input_allow_view_to"><![CDATA[Visibility]]></string>
+    <string name="_bx_market_form_entry_input_sys_allow_view_to"><![CDATA[Who can view]]></string>
+    <string name="_bx_market_form_entry_input_allow_view_to"><![CDATA[Who can view]]></string>
+    <string name="_bx_market_form_entry_input_sys_allow_purchase_to"><![CDATA[Who can purchase]]></string>
+    <string name="_bx_market_form_entry_input_allow_purchase_to"><![CDATA[Who can purchase]]></string>
+    <string name="_bx_market_form_entry_input_sys_allow_comment_to"><![CDATA[Who can review]]></string>
+    <string name="_bx_market_form_entry_input_allow_comment_to"><![CDATA[Who can review]]></string>
+    <string name="_bx_market_form_entry_input_sys_allow_vote_to"><![CDATA[Who can vote]]></string>
+    <string name="_bx_market_form_entry_input_allow_vote_to"><![CDATA[Who can vote]]></string>
 
 	<string name="_bx_market_acl_action_create_entry"><![CDATA[Create Product]]></string>
 	<string name="_bx_market_acl_action_delete_entry"><![CDATA[Delete Product]]></string>
@@ -52,6 +58,8 @@
 	<string name="_bx_market_acl_action_set_thumb"><![CDATA[Set Product Thumbnail]]></string>
 	<string name="_bx_market_acl_action_edit_any_entry"><![CDATA[Edit Any Product]]></string>
 
+	<string name="_bx_market_privacy_group_customers"><![CDATA[Customers]]></string>
+
 	<string name="_bx_market_page_title_sys_create_entry"><![CDATA[New Product]]></string>
 	<string name="_bx_market_page_title_create_entry"><![CDATA[New Product]]></string>
 	<string name="_bx_market_page_block_title_create_entry"><![CDATA[New Product]]></string>

+ 1 - 1
modules/boonex/market/install/sql/disable.sql

@@ -16,7 +16,7 @@ DELETE FROM `sys_menu_sets` WHERE `module` = 'bx_market';
 DELETE FROM `sys_menu_items` WHERE `module` = 'bx_market' OR `set_name` IN('bx_market_view', 'bx_market_submenu', 'bx_market_view_submenu', 'bx_market_my');
 
 -- PRIVACY 
-DELETE FROM `sys_objects_privacy` WHERE `object` = 'bx_market_allow_view_to';
+DELETE FROM `sys_objects_privacy` WHERE `object` IN ('bx_market_allow_view_to', 'bx_market_allow_purchase_to', 'bx_market_allow_comment_to', 'bx_market_allow_vote_to');
 
 -- ACL
 DELETE `sys_acl_actions`, `sys_acl_matrix` FROM `sys_acl_actions`, `sys_acl_matrix` WHERE `sys_acl_matrix`.`IDAction` = `sys_acl_actions`.`ID` AND `sys_acl_actions`.`Module` = 'bx_market';

+ 5 - 1
modules/boonex/market/install/sql/enable.sql

@@ -239,7 +239,11 @@ INSERT INTO `sys_menu_items`(`set_name`, `module`, `name`, `title_system`, `titl
 
 -- 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
-('bx_market_allow_view_to', 'bx_market', 'view', '_bx_market_form_entry_input_allow_view_to', '3', 'bx_market_products', 'id', 'author', '', '');
+('bx_market_allow_view_to', 'bx_market', 'view', '_bx_market_form_entry_input_allow_view_to', '3', 'bx_market_products', 'id', 'author', '', ''),
+('bx_market_allow_purchase_to', 'bx_market', 'purchase', '_bx_market_form_entry_input_allow_purchase_to', '3', 'bx_market_products', 'id', 'author', '', ''),
+('bx_market_allow_comment_to', 'bx_market', 'comment', '_bx_market_form_entry_input_allow_comment_to', 'c', 'bx_market_products', 'id', 'author', 'BxMarketPrivacy', 'modules/boonex/market/classes/BxMarketPrivacy.php'),
+('bx_market_allow_vote_to', 'bx_market', 'vote', '_bx_market_form_entry_input_allow_vote_to', 'c', 'bx_market_products', 'id', 'author', 'BxMarketPrivacy', 'modules/boonex/market/classes/BxMarketPrivacy.php');
+
 
 
 -- ACL

+ 25 - 7
modules/boonex/market/install/sql/install.sql

@@ -16,7 +16,10 @@ CREATE TABLE IF NOT EXISTS `bx_market_products` (
   `votes` int(11) NOT NULL default '0',
   `comments` int(11) NOT NULL default '0',
   `reports` int(11) NOT NULL default '0',
-  `allow_view_to` int(11) NOT NULL DEFAULT '3',
+  `allow_view_to` varchar(32) NOT NULL DEFAULT '3',
+  `allow_purchase_to` varchar(32) NOT NULL DEFAULT '3',
+  `allow_comment_to` varchar(32) NOT NULL DEFAULT 'c',
+  `allow_vote_to` varchar(32) NOT NULL DEFAULT 'c',
   `status` enum('active','hidden') NOT NULL DEFAULT 'active',
   PRIMARY KEY (`id`),
   FULLTEXT KEY `title_text` (`title`,`text`)
@@ -220,6 +223,9 @@ INSERT INTO `sys_form_displays`(`object`, `display_name`, `module`, `view_mode`,
 
 INSERT INTO `sys_form_inputs`(`object`, `module`, `name`, `value`, `values`, `checked`, `type`, `caption_system`, `caption`, `info`, `required`, `collapsed`, `html`, `attrs`, `attrs_tr`, `attrs_wrapper`, `checker_func`, `checker_params`, `checker_error`, `db_pass`, `db_params`, `editable`, `deletable`) VALUES 
 ('bx_market', 'bx_market', 'allow_view_to', '', '', 0, 'custom', '_bx_market_form_entry_input_sys_allow_view_to', '_bx_market_form_entry_input_allow_view_to', '', 1, 0, 0, '', '', '', '', '', '', '', '', 0, 0),
+('bx_market', 'bx_market', 'allow_purchase_to', '', '', 0, 'custom', '_bx_market_form_entry_input_sys_allow_purchase_to', '_bx_market_form_entry_input_allow_purchase_to', '', 1, 0, 0, '', '', '', '', '', '', '', '', 0, 0),
+('bx_market', 'bx_market', 'allow_comment_to', '', '', 0, 'custom', '_bx_market_form_entry_input_sys_allow_comment_to', '_bx_market_form_entry_input_allow_comment_to', '', 1, 0, 0, '', '', '', '', '', '', '', '', 0, 0),
+('bx_market', 'bx_market', 'allow_vote_to', '', '', 0, 'custom', '_bx_market_form_entry_input_sys_allow_vote_to', '_bx_market_form_entry_input_allow_vote_to', '', 1, 0, 0, '', '', '', '', '', '', '', '', 0, 0),
 ('bx_market', 'bx_market', 'delete_confirm', 1, '', 0, 'checkbox', '_bx_market_form_entry_input_sys_delete_confirm', '_bx_market_form_entry_input_delete_confirm', '_bx_market_form_entry_input_delete_confirm_info', 1, 0, 0, '', '', '', 'Avail', '', '_bx_market_form_entry_input_delete_confirm_error', '', '', 1, 0),
 ('bx_market', 'bx_market', 'do_publish', '_bx_market_form_entry_input_do_publish', '', 0, 'submit', '_bx_market_form_entry_input_sys_do_publish', '', '', 0, 0, 0, '', '', '', '', '', '', '', '', 1, 0),
 ('bx_market', 'bx_market', 'do_submit', '_bx_market_form_entry_input_do_submit', '', 0, 'submit', '_bx_market_form_entry_input_sys_do_submit', '', '', 0, 0, 0, '', '', '', '', '', '', '', '', 1, 0),
@@ -240,9 +246,12 @@ INSERT INTO `sys_form_display_inputs`(`display_name`, `input_name`, `visible_for
 ('bx_market_entry_add', 'files', 2147483647, 1, 6),
 ('bx_market_entry_add', 'price', 2147483647, 1, 7),
 ('bx_market_entry_add', 'allow_view_to', 2147483647, 1, 8),
-('bx_market_entry_add', 'location', 2147483647, 1, 9),
-('bx_market_entry_add', 'do_submit', 2147483647, 0, 10),
-('bx_market_entry_add', 'do_publish', 2147483647, 1, 11),
+('bx_market_entry_add', 'allow_purchase_to', 2147483647, 1, 9),
+('bx_market_entry_add', 'allow_comment_to', 2147483647, 1, 10),
+('bx_market_entry_add', 'allow_vote_to', 2147483647, 1, 11),
+('bx_market_entry_add', 'location', 2147483647, 1, 12),
+('bx_market_entry_add', 'do_submit', 2147483647, 0, 13),
+('bx_market_entry_add', 'do_publish', 2147483647, 1, 14),
 ('bx_market_entry_delete', 'location', 2147483647, 0, 0),
 ('bx_market_entry_delete', 'cat', 2147483647, 0, 0),
 ('bx_market_entry_delete', 'price', 2147483647, 0, 0),
@@ -252,6 +261,9 @@ INSERT INTO `sys_form_display_inputs`(`display_name`, `input_name`, `visible_for
 ('bx_market_entry_delete', 'do_publish', 2147483647, 0, 0),
 ('bx_market_entry_delete', 'title', 2147483647, 0, 0),
 ('bx_market_entry_delete', 'allow_view_to', 2147483647, 0, 0),
+('bx_market_entry_delete', 'allow_purchase_to', 2147483647, 0, 0),
+('bx_market_entry_delete', 'allow_comment_to', 2147483647, 0, 0),
+('bx_market_entry_delete', 'allow_vote_to', 2147483647, 0, 0),
 ('bx_market_entry_delete', 'delete_confirm', 2147483647, 1, 1),
 ('bx_market_entry_delete', 'do_submit', 2147483647, 1, 2),
 ('bx_market_entry_edit', 'do_publish', 2147483647, 0, 1),
@@ -263,8 +275,11 @@ INSERT INTO `sys_form_display_inputs`(`display_name`, `input_name`, `visible_for
 ('bx_market_entry_edit', 'files', 2147483647, 1, 7),
 ('bx_market_entry_edit', 'price', 2147483647, 1, 8),
 ('bx_market_entry_edit', 'allow_view_to', 2147483647, 1, 9),
-('bx_market_entry_edit', 'location', 2147483647, 1, 10),
-('bx_market_entry_edit', 'do_submit', 2147483647, 1, 11),
+('bx_market_entry_edit', 'allow_purchase_to', 2147483647, 1, 10),
+('bx_market_entry_edit', 'allow_comment_to', 2147483647, 1, 11),
+('bx_market_entry_edit', 'allow_vote_to', 2147483647, 1, 12),
+('bx_market_entry_edit', 'location', 2147483647, 1, 13),
+('bx_market_entry_edit', 'do_submit', 2147483647, 1, 14),
 ('bx_market_entry_view', 'location', 2147483647, 0, 0),
 ('bx_market_entry_view', 'cat', 2147483647, 0, 0),
 ('bx_market_entry_view', 'price', 2147483647, 0, 0),
@@ -275,7 +290,10 @@ INSERT INTO `sys_form_display_inputs`(`display_name`, `input_name`, `visible_for
 ('bx_market_entry_view', 'do_publish', 2147483647, 0, 0),
 ('bx_market_entry_view', 'title', 2147483647, 0, 0),
 ('bx_market_entry_view', 'do_submit', 2147483647, 0, 0),
-('bx_market_entry_view', 'allow_view_to', 2147483647, 0, 0);
+('bx_market_entry_view', 'allow_view_to', 2147483647, 0, 0),
+('bx_market_entry_view', 'allow_purchase_to', 2147483647, 0, 0),
+('bx_market_entry_view', 'allow_comment_to', 2147483647, 0, 0),
+('bx_market_entry_view', 'allow_vote_to', 2147483647, 0, 0);
 
 -- PRE-VALUES
 INSERT INTO `sys_form_pre_lists`(`key`, `title`, `module`, `use_for_sets`) VALUES

+ 10 - 2
modules/boonex/russian/data/langs/bx_market/ru.xml

@@ -42,8 +42,14 @@
 	<string name="_bx_market_form_entry_input_files_use_as_main"><![CDATA[Использовать как главный]]></string>
 	<string name="_bx_market_form_entry_input_files_name"><![CDATA[Имя:]]></string>
 	<string name="_bx_market_form_entry_input_files_version"><![CDATA[Версия:]]></string>
-    <string name="_bx_market_form_entry_input_sys_allow_view_to"><![CDATA[Видимость]]></string>
-    <string name="_bx_market_form_entry_input_allow_view_to"><![CDATA[Видимость]]></string>
+    <string name="_bx_market_form_entry_input_sys_allow_view_to"><![CDATA[Кто может смотреть]]></string>
+    <string name="_bx_market_form_entry_input_allow_view_to"><![CDATA[Кто может смотреть]]></string>
+	<string name="_bx_market_form_entry_input_sys_allow_purchase_to"><![CDATA[Кто может покупать]]></string>
+    <string name="_bx_market_form_entry_input_allow_purchase_to"><![CDATA[Кто может покупать]]></string>
+    <string name="_bx_market_form_entry_input_sys_allow_comment_to"><![CDATA[Кто может рецензировать]]></string>
+    <string name="_bx_market_form_entry_input_allow_comment_to"><![CDATA[Кто может рецензировать]]></string>
+    <string name="_bx_market_form_entry_input_sys_allow_vote_to"><![CDATA[Кто может голосовать]]></string>
+    <string name="_bx_market_form_entry_input_allow_vote_to"><![CDATA[Кто может голосовать]]></string>
 
 	<string name="_bx_market_acl_action_create_entry"><![CDATA[Создать продукт]]></string>
 	<string name="_bx_market_acl_action_delete_entry"><![CDATA[Удалить продукт]]></string>
@@ -52,6 +58,8 @@
 	<string name="_bx_market_acl_action_set_thumb"><![CDATA[Назначить значок продукта]]></string>
 	<string name="_bx_market_acl_action_edit_any_entry"><![CDATA[Редактировать любой продукт]]></string>
 
+	<string name="_bx_market_privacy_group_customers"><![CDATA[Клиенты]]></string>
+
 	<string name="_bx_market_page_title_sys_create_entry"><![CDATA[Новый продукт]]></string>
 	<string name="_bx_market_page_title_create_entry"><![CDATA[Новый продукт]]></string>
 	<string name="_bx_market_page_block_title_create_entry"><![CDATA[Новый продукт]]></string>