Przeglądaj źródła

#556 Files module - privacy fixes, use older version of tika-app

Alex Trofimov 9 lat temu
rodzic
commit
3175ddbbbe

+ 10 - 2
modules/boonex/files/classes/BxFilesFormEntry.php

@@ -23,20 +23,28 @@ class BxFilesFormEntry extends BxBaseModTextFormEntry
         
         if (isset($this->aInputs[$CNF['FIELD_PHOTO']]))
             $this->aInputs[$CNF['FIELD_PHOTO']]['multiple'] = false;
+    }
 
+    function initChecker ($aValues = array (), $aSpecificValues = array()) 
+    {
         $CNF = &$this->_oModule->_oConfig->CNF;
         if (isset($this->aInputs[$CNF['FIELD_ALLOW_VIEW_TO']]) && $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW'])) {
 
+            $oProfile = isset($aValues[$CNF['FIELD_AUTHOR']]) ? BxDolProfile::getInstance($aValues[$CNF['FIELD_AUTHOR']]) : false;
+            $oPrivacy->setCustomPrivacy($oProfile && BxDolService::call($oProfile->getModule(), 'is_group_profile') ? true : false);
+            
             $aSave = array('db' => array('pass' => 'Xss'));
             array_walk($this->aInputs[$CNF['FIELD_ALLOW_VIEW_TO']], function ($a, $k, $aSave) {
                 if (in_array($k, array('info', 'caption', 'value')))
                     $aSave[0][$k] = $a;
             }, array(&$aSave));
             
-            $aGroupChooser = $oPrivacy->getGroupChooser($CNF['OBJECT_PRIVACY_VIEW']);
+            $aGroupChooser = $oPrivacy->getGroupChooserCustom($CNF['OBJECT_PRIVACY_VIEW'], $oPrivacy->isCustomPrivacy());
             
             $this->aInputs[$CNF['FIELD_ALLOW_VIEW_TO']] = array_merge($this->aInputs[$CNF['FIELD_ALLOW_VIEW_TO']], $aGroupChooser, $aSave);
-		}
+        }
+        
+        return parent::initChecker ($aValues, $aSpecificValues);
     }
 
     protected function _associalFileWithContent($oStorage, $iFileId, $iProfileId, $iContentId, $sPictureField = '')

+ 4 - 1
modules/boonex/files/classes/BxFilesFormUpload.php

@@ -27,13 +27,16 @@ class BxFilesFormUpload extends BxBaseModTextFormEntry
         $CNF = &$this->_oModule->_oConfig->CNF;
         if (isset($this->aInputs[$CNF['FIELD_ALLOW_VIEW_TO']]) && $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW'])) {
 
+            $oProfile = bx_get('profile_id') ? BxDolProfile::getInstance(bx_get('profile_id')) : false;
+            $oPrivacy->setCustomPrivacy(bx_get('profile_id') && $oProfile && BxDolService::call($oProfile->getModule(), 'is_group_profile') ? true : false);
+
             $aSave = array('db' => array('pass' => 'Xss'));
             array_walk($this->aInputs[$CNF['FIELD_ALLOW_VIEW_TO']], function ($a, $k, $aSave) {
                 if (in_array($k, array('info', 'caption', 'value')))
                     $aSave[0][$k] = $a;
             }, array(&$aSave));
             
-            $aGroupChooser = $oPrivacy->getGroupChooser($CNF['OBJECT_PRIVACY_VIEW']);
+            $aGroupChooser = $oPrivacy->getGroupChooserCustom($CNF['OBJECT_PRIVACY_VIEW'], $oPrivacy->isCustomPrivacy());
             
             $this->aInputs[$CNF['FIELD_ALLOW_VIEW_TO']] = array_merge($this->aInputs[$CNF['FIELD_ALLOW_VIEW_TO']], $aGroupChooser, $aSave);
 		}

+ 21 - 9
modules/boonex/files/classes/BxFilesPrivacy.php

@@ -12,6 +12,7 @@
 class BxFilesPrivacy extends BxTemplPrivacy
 {
     protected $_oModule;
+    protected $_bCustomPrivacy = false;
 
     public function __construct($aOptions, $oTemplate = false)
     {
@@ -20,6 +21,16 @@ class BxFilesPrivacy extends BxTemplPrivacy
         $this->_oModule = BxDolModule::getInstance('bx_files');
     }
 
+    public function setCustomPrivacy($b)
+    {
+        $this->_bCustomPrivacy = $b;
+    }
+
+    public function isCustomPrivacy()
+    {
+        return $this->_bCustomPrivacy;
+    }
+
 	/**
      * Check whethere viewer is a member of dynamic group.
      *
@@ -43,22 +54,23 @@ class BxFilesPrivacy extends BxTemplPrivacy
         return false;
     }
 
-    static function getGroupChooser ($sObject, $iOwnerId = 0, $aParams = array())
+    static function getGroupChooserCustom ($sObject, $bCustomPrivacy)
     {
-        if (!$iOwnerId)
-    		$iOwnerId = bx_get_logged_profile_id();
+    	$iOwnerId = bx_get_logged_profile_id();
 
-        $aParams['dynamic_groups'] = array(
-			array ('key' => 'a', 'value' => _t('_bx_files_privacy_public')),
-			array ('key' => 'm', 'value' => _t('_bx_files_privacy_participants')),
-		);
+        $aParams = array();
+        if ($bCustomPrivacy)
+            $aParams['dynamic_groups'] = array(
+                array ('key' => 'a', 'value' => _t('_bx_files_privacy_public')),
+                array ('key' => 'm', 'value' => _t('_bx_files_privacy_participants')),
+            );
 
         return parent::getGroupChooser($sObject, $iOwnerId, $aParams);
     }
 
     protected function getGroups() 
-    {
-        return array();
+    {        
+        return $this->_bCustomPrivacy ? array() : parent::getGroups();
     }
 }